Java Code Examples for java.util.logging.Logger.addHandler()

The following are Jave code examples for showing how to use addHandler() of the java.util.logging.Logger class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: BaseActionProviderTest.java   View Source Code Vote up 6 votes
@Test
public void testOverridenGetTargetNames() throws Exception {
    assertNotNull(ap);
    final Logger log = Logger.getLogger(ActionProviderSupport.class.getName());
    final Level origLevel = log.getLevel();
    final MockHandler handler = new MockHandler();
    log.setLevel(Level.FINE);
    log.addHandler(handler);
    try {
        SwingUtilities.invokeAndWait(() -> {
            ap.invokeAction(ActionProvider.COMMAND_CLEAN, Lookup.EMPTY);
        });
        assertEquals("1", handler.props.get("a"));      //NOI18N
        assertEquals("2", handler.props.get("b"));      //NOI18N
    } finally {
        log.setLevel(origLevel);
        log.removeHandler(handler);
    }
}
 
Example 2
Project: incubator-netbeans   File: ScanStartedTest.java   View Source Code Vote up 6 votes
@Override
protected void tearDown() throws Exception {
    final TestHandler handler = new TestHandler();
    final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests"); //NOI18N
    try {
        logger.setLevel (Level.FINEST);
        logger.addHandler(handler);
        for(String id : registeredClasspaths.keySet()) {
            final Map<ClassPath,Void> classpaths = registeredClasspaths.get(id);
            GlobalPathRegistry.getDefault().unregister(id, classpaths.keySet().toArray(new ClassPath[classpaths.size()]));
        }
        handler.await();
    } finally {
        logger.removeHandler(handler);
    }
    super.tearDown();
}
 
Example 3
Project: incubator-netbeans   File: RepositoryUpdaterTest.java   View Source Code Vote up 6 votes
@Override
protected void tearDown() throws Exception {
    final TestHandler handler = new TestHandler();
    final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests");
    try {
        logger.setLevel (Level.FINEST);
        logger.addHandler(handler);
        for(String id : registeredClasspaths.keySet()) {
            final Map<ClassPath,Void> classpaths = registeredClasspaths.get(id);
            GlobalPathRegistry.getDefault().unregister(id, classpaths.keySet().toArray(new ClassPath[classpaths.size()]));
        }
        handler.await();
    } finally {
        logger.removeHandler(handler);
    }
    super.tearDown();
}
 
Example 4
Project: monarch   File: LogWrapper.java   View Source Code Vote up 6 votes
private static void addDefaultConsoleHandler(Logger logger, String errorMessage,
    String logFilePath) {
  ConsoleHandler consoleHandler = new ConsoleHandler();
  consoleHandler.setFormatter(new GemFireFormatter());
  logger.addHandler(consoleHandler);

  System.err
      .println("ERROR: Could not log to file: " + logFilePath + ". Reason: " + errorMessage);
  System.err.println("Logs will be written on Console.");
  try {
    Thread.sleep(3000); // sleep for 3 secs for the message to appear
  } catch (InterruptedException ignore) {
  }
}
 
Example 5
Project: incubator-netbeans   File: IndexingSupportACIDTest.java   View Source Code Vote up 6 votes
@Override
protected void tearDown() throws Exception {
    final RepositoryUpdaterTest.TestHandler handler = new RepositoryUpdaterTest.TestHandler();
    final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests"); //NOI18N
    try {
        logger.setLevel (Level.FINEST);
        logger.addHandler(handler);
        for(String id : registeredClasspaths.keySet()) {
            final Map<ClassPath,Void> classpaths = registeredClasspaths.get(id);
            GlobalPathRegistry.getDefault().unregister(id, classpaths.keySet().toArray(new ClassPath[classpaths.size()]));
        }
        handler.await();
    } finally {
        logger.removeHandler(handler);
    }
    super.tearDown();
}
 
Example 6
Project: incubator-netbeans   File: StatusTest.java   View Source Code Vote up 5 votes
/**
 * It seems that cache.listFiles and cache.containsFiles called getStatus also on folders. Because folders are usually up-to-date (git does not track them),
 * this results in unnecessary call to getOwner, ignore logic or sharability.
 */
public void testSkipFoldersBug196702 () throws Exception {
    final File f1 = new File(repositoryLocation, "1");
    final File f2 = new File(f1, "2");
    final File f3 = new File(f2, "3");
    f3.mkdirs();
    File f = new File(f3, "f");
    f.createNewFile();
    
    FileStatusCache cache = getCache();
    cache.refreshAllRoots(Collections.<File, Collection<File>>singletonMap(repositoryLocation, Collections.singleton(f1)));
    Logger log = Logger.getLogger("org.netbeans.modules.git.status.cache");
    final boolean[] flags = new boolean[1];
    log.addHandler(new Handler() {
        @Override
        public void publish (LogRecord record) {
            if (record.getMessage().startsWith("getCachedStatus for file {0}:")) {
                if (Arrays.asList(f1, f2, f3).contains((File) record.getParameters()[0])) {
                    flags[0] = true;
                }
            }
        }

        @Override
        public void flush () { }

        @Override
        public void close () throws SecurityException { }
    });
    
    Collection<File> newFiles = Arrays.asList(cache.listFiles(new File[] { f1 }, EnumSet.of(FileInformation.Status.NEW_INDEX_WORKING_TREE)));
    assertEquals(Arrays.asList(f), newFiles);
    assertFalse(flags[0]);
    flags[0] = false;
    assertTrue(cache.containsFiles(Collections.singleton(f1), EnumSet.of(FileInformation.Status.NEW_INDEX_WORKING_TREE), true));
    assertFalse(flags[0]);
    assertFalse(cache.containsFiles(Collections.singleton(f1), EnumSet.of(FileInformation.Status.MODIFIED_INDEX_WORKING_TREE), true));
    assertFalse(flags[0]);
    
    // test we do not break anything with the bugfix: ignored files/folders should be recognized even without getStatus call
    SystemAction.get(IgnoreAction.class).performAction(VCSContext.forNodes(new Node[] { new AbstractNode(Children.LEAF, Lookups.fixed(f1)) }));
    flags[0] = false;
    Collection<File> ignoredFiles = Arrays.asList(cache.listFiles(new File[] { f1 }, EnumSet.of(FileInformation.Status.NOTVERSIONED_EXCLUDED)));
    assertEquals(Arrays.asList(f1), ignoredFiles);
    assertFalse(flags[0]);
    flags[0] = false;
    assertTrue(cache.containsFiles(Collections.singleton(f1), EnumSet.of(FileInformation.Status.NOTVERSIONED_EXCLUDED), true));
    assertFalse(flags[0]);
}
 
Example 7
Project: incubator-netbeans   File: FileStatusCacheTest.java   View Source Code Vote up 5 votes
private void attachCacheLogHandler(NestedReposLogHandler handler) throws Exception {
    Field f = null;
    try {
        f = FileStatusCache.class.getDeclaredField("LOG");
    } catch (Exception ex) {
        throw ex;
    }
    f.setAccessible(true);
    Logger log = (Logger) f.get(getCache());
    log.addHandler(handler);
}
 
Example 8
Project: openjdk-jdk10   File: FailOverDirectExecutionControlTest.java   View Source Code Vote up 5 votes
@BeforeMethod
@Override
public void setUp() {
    Logger logger = Logger.getLogger("jdk.jshell.execution");
    logger.setLevel(Level.ALL);
    hndlr = new LogTestHandler();
    logger.addHandler(hndlr);
    logged = new HashMap<>();
    Compiler compiler = new Compiler();
    Path modDir = Paths.get("mod");
    compiler.compile(modDir,
            "package my.provide; import java.util.Map;\n" +
            "import jdk.jshell.spi.ExecutionControl;\n" +
            "import jdk.jshell.spi.ExecutionControlProvider;\n" +
            "import jdk.jshell.spi.ExecutionEnv;\n" +
            "public class AlwaysFailingProvider implements ExecutionControlProvider {\n" +
            "    @Override\n" +
            "    public String name() {\n" +
            "        return \"alwaysFailing\";\n" +
            "    }\n" +
            "    @Override\n" +
            "    public ExecutionControl generate(ExecutionEnv env, Map<String, String> parameters) throws Throwable {\n" +
            "        throw new UnsupportedOperationException(\"This operation intentionally broken.\");\n" +
            "    }\n" +
            "}\n",
            "module my.provide {\n" +
            "    requires transitive jdk.jshell;\n" +
            "    provides jdk.jshell.spi.ExecutionControlProvider\n" +
            "        with my.provide.AlwaysFailingProvider;\n" +
            " }");
    Path modPath = compiler.getPath(modDir);
    ccl = createAndRunFromModule("my.provide", modPath);

    provider = new FailOverExecutionControlProvider();
    Map<String, String> pm = provider.defaultParameters();
    pm.put("0", "alwaysFailing");
    pm.put("1", "alwaysFailing");
    pm.put("2", "jdi");
    setUp(builder -> builder.executionEngine(provider, pm));
}
 
Example 9
Project: incubator-netbeans   File: ScanMonitor.java   View Source Code Vote up 5 votes
private ScanMonitor() {
    Logger logger = Logger.getLogger("org.netbeans.modules.java.source.usages.RepositoryUpdater.activity"); //NOI18N
    logger.setLevel(Level.FINEST);
    logger.setUseParentHandlers(false);
    logger.addHandler( new Handler() { //NOI18N

        @Override
        public void publish(LogRecord record) {
            if( Level.FINEST.equals( record.getLevel() )
                    && "START".equals(record.getMessage()) ) { //NOI18N
                lock();
                return;
            }

            if( Level.FINEST.equals( record.getLevel() )
                    && "FINISHED".equals(record.getMessage()) ) { //NOI18N
                unlock();
                return;
            }
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    });
}
 
Example 10
Project: incubator-netbeans   File: RepositoryUpdaterTest.java   View Source Code Vote up 5 votes
public void testIncludesChanges() throws Exception {
    //Prepare
    final TestHandler handler = new TestHandler();
    final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests");
    logger.setLevel (Level.FINEST);
    logger.addHandler(handler);
    MutableFilteringResourceImpl r = new MutableFilteringResourceImpl(srcRootWithFiles1.toURL());
    ClassPath cp1 = ClassPathSupport.createClassPath(Collections.singletonList(r));
    ClassPathProviderImpl.register(srcRootWithFiles1, SOURCES, cp1);
    globalPathRegistry_register(SOURCES,new ClassPath[]{cp1});
    assertTrue (handler.await());

    //exclude a file:
    indexerFactory.indexer.setExpectedFile(new URL[0], new URL[] {f1.toURL()}, new URL[0]);
    r.setExcludes(".*/a\\.foo");

    indexerFactory.indexer.awaitDeleted(TIME);
    indexerFactory.indexer.awaitIndex(TIME);

    assertEquals(1, indexerFactory.indexer.deletedCounter);
    assertEquals(Collections.emptySet(), indexerFactory.indexer.expectedDeleted);
    assertEquals(0, indexerFactory.indexer.indexCounter);

    //include the file back:
    indexerFactory.indexer.setExpectedFile(new URL[] {f1.toURL()}, new URL[0], new URL[0]);
    r.setExcludes();

    indexerFactory.indexer.awaitDeleted(TIME);
    indexerFactory.indexer.awaitIndex(TIME);

    assertEquals(0, indexerFactory.indexer.deletedCounter);
    assertEquals(1, indexerFactory.indexer.indexCounter);
    assertEquals(Collections.emptySet(), indexerFactory.indexer.expectedIndex);
}
 
Example 11
Project: incubator-netbeans   File: MimePathLookupTest.java   View Source Code Vote up 5 votes
@Override
protected void setUp() throws java.lang.Exception {
    clearWorkDir();
    // Set up the default lookup, repository, etc.
    EditorTestLookup.setLookup(new String[0], getWorkDir(), new Object[] {},
        getClass().getClassLoader()
    );
    handler = new TestHandler();
    final Logger log = Logger.getLogger(MimePathLookup.class.getName());
    log.setLevel(Level.FINE);
    log.addHandler(handler);
}
 
Example 12
Project: incubator-netbeans   File: SourcePrefetcherTest.java   View Source Code Vote up 5 votes
public void testDeadlock208663() throws Exception {
    CompileTuple ct = files.iterator().next();
    final FileObject fo = URLMapper.findFileObject(ct.indexable.getURL());
    final FileLock lck = fo.lock();
    try {
        final OutputStream out = new BufferedOutputStream(fo.getOutputStream(lck));
        try {
            for (int i = 0; i<101; i++) {
                out.write('a');
            }
        } finally {
            out.close();
        }
    } finally {
        lck.releaseLock();
    }
    
    JavaIndexerWorker.TEST_DO_PREFETCH = true;
    JavaIndexerWorker.BUFFER_SIZE = 100;
    final LogHandler handler = new LogHandler();
    handler.expect("Using concurrent iterator, {0} workers");    //NOI18N
    final Logger log = Logger.getLogger(JavaIndexerWorker.class.getName());
    log.setLevel(Level.FINE);
    log.addHandler(handler);
    try {
        SourcePrefetcher pf = SourcePrefetcher.create(files, SuspendSupport.NOP);
        assertTrue(handler.isFound());
        final Deque<CompileTuple> got = new ArrayDeque<CompileTuple>(FILE_COUNT);
        while (pf.hasNext()) {
            ct = pf.next();
            assertNotNull(getCache(ct.jfo));
            got.offer(ct);
            pf.remove();
            assertNull(getCache(ct.jfo));
        }
        assertCollectionsEqual(files,got);
    } finally {
        log.removeHandler(handler);
    }
}
 
Example 13
Project: incubator-netbeans   File: SourcePrefetcherTest.java   View Source Code Vote up 5 votes
public void testDeletedFile() throws Exception {
    CompileTuple ct = files.iterator().next();
    final FileObject fo = URLMapper.findFileObject(ct.indexable.getURL());        
    fo.delete();
    
    JavaIndexerWorker.TEST_DO_PREFETCH = true;
    final LogHandler handler = new LogHandler();
    handler.expect("Using concurrent iterator, {0} workers");    //NOI18N
    final Logger log = Logger.getLogger(JavaIndexerWorker.class.getName());
    log.setLevel(Level.FINE);
    log.addHandler(handler);
    try {
        SourcePrefetcher pf = SourcePrefetcher.create(files, SuspendSupport.NOP);
        assertTrue(handler.isFound());
        final Deque<CompileTuple> got = new ArrayDeque<CompileTuple>(FILE_COUNT);
        while (pf.hasNext()) {
            ct = pf.next();
            try {
                if (ct != null) {
                    assertNotNull(getCache(ct.jfo));
                    got.offer(ct);
                }
            } finally {
                pf.remove();
            }
            if (ct != null) {
                assertNull(getCache(ct.jfo));
            }
        }
        final List<CompileTuple> allButFirst = new LinkedList<CompileTuple>(files);
        allButFirst.remove(0);
        assertCollectionsEqual(allButFirst,got);
    } finally {
        log.removeHandler(handler);
    }
}
 
Example 14
Project: incubator-netbeans   File: MIMEResolverImplTest.java   View Source Code Vote up 4 votes
/**
 * Bug 240518 - org.openide.filesystems.FileAlreadyLockedException:
 * Services/MIMEResolver/user-defined-mime-resolver.xml.
 *
 * @throws InterruptedException
 */
public void testStoreUserDefinedResolver() throws InterruptedException {
    final Logger mimeResLog = Logger.getLogger(
            MIMEResolverImpl.class.getName());
    final Map<String, Set<String>> mimeToExtensions
            = new HashMap<String, Set<String>>();
    final Throwable[] throwable = new Throwable[1];
    mimeToExtensions.put("text/plan", Collections.singleton("log"));

    Runnable r = new Runnable() {
        @Override
        public void run() {
            MIMEResolverImpl.storeUserDefinedResolver(mimeToExtensions);
        }
    };

    Handler h = new Handler() {

        @Override
        public void publish(LogRecord record) {
            String msg = record.getMessage();
            if (msg != null && msg.startsWith("Cannot delete resolver ")) {
                throwable[0] = record.getThrown();
            }
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    };

    mimeResLog.addHandler(h);
    try {
        // run now to initialize the file
        r.run();

        // run twice in parallel.
        for (int i = 0; i < 10; i++) {
            Thread t1 = new Thread(r, "T1");
            Thread t2 = new Thread(r, "T2");
            t1.start();
            t2.start();
            t1.join();
            t2.join();
            assertNull("No error should occur", throwable[0]);
        }
    } finally {
        mimeResLog.removeHandler(h);
    }
}
 
Example 15
Project: jdk8u-jdk   File: TestAnonymousLogger.java   View Source Code Vote up 4 votes
public static void main(String[] args) {
    System.setSecurityManager(new SecurityManager());
    Logger anonymous = Logger.getAnonymousLogger();

    final TestHandler handler = new TestHandler();
    final TestFilter filter = new TestFilter();
    final ResourceBundle bundle = ResourceBundle.getBundle(TestBundle.class.getName());
    anonymous.setLevel(Level.FINEST);
    anonymous.addHandler(handler);
    anonymous.setFilter(filter);
    anonymous.setUseParentHandlers(true);
    anonymous.setResourceBundle(bundle);

    if (anonymous.getLevel() != Level.FINEST) {
        throw new RuntimeException("Unexpected level: " + anonymous.getLevel());
    } else {
        System.out.println("Got expected level: " + anonymous.getLevel());
    }
    if (!Arrays.asList(anonymous.getHandlers()).contains(handler)) {
        throw new RuntimeException("Expected handler not found in: "
                + Arrays.asList(anonymous.getHandlers()));
    } else {
        System.out.println("Got expected handler in: " + Arrays.asList(anonymous.getHandlers()));
    }
    if (anonymous.getFilter() != filter) {
        throw new RuntimeException("Unexpected filter: " + anonymous.getFilter());
    } else {
        System.out.println("Got expected filter: " + anonymous.getFilter());
    }
    if (!anonymous.getUseParentHandlers()) {
        throw new RuntimeException("Unexpected flag: " + anonymous.getUseParentHandlers());
    } else {
        System.out.println("Got expected flag: " + anonymous.getUseParentHandlers());
    }
    if (anonymous.getResourceBundle() != bundle) {
        throw new RuntimeException("Unexpected bundle: " + anonymous.getResourceBundle());
    } else {
        System.out.println("Got expected bundle: " + anonymous.getResourceBundle());
    }
    try {
        anonymous.setParent(Logger.getLogger("foo.bar"));
        throw new RuntimeException("Expected SecurityException not raised!");
    } catch (SecurityException x) {
        System.out.println("Got expected exception: " + x);
    }
    if (anonymous.getParent() != Logger.getLogger("")) {
        throw new RuntimeException("Unexpected parent: " + anonymous.getParent());
    } else {
        System.out.println("Got expected parent: " + anonymous.getParent());
    }
}
 
Example 16
Project: incubator-netbeans   File: ExternalChangesTest.java   View Source Code Vote up 4 votes
public void testInternalCommandLoggedChanges () throws Exception {
    Mercurial.getInstance().getMercurialInterceptor().pingRepositoryRootFor(workdir);
    FileChangeAdapter fca = new FileChangeAdapter();
    workdirFO.addRecursiveListener(fca);
    final File toAdd = new File(modifiedFile.getParentFile(), "toAdd");
    final File toDelete = new File(modifiedFile.getParentFile(), "toDelete");
    toDelete.createNewFile();
    FileUtil.refreshFor(workdir);
    Thread.sleep(11000); // some time for initial scans to finish and event logger to settle down
    File hgFolder = new File(workdir, ".hg");
    final File lockFile = new File(hgFolder, "wlock");
    Logger GESTURES_LOG = Logger.getLogger("org.netbeans.ui.vcs");
    ExternalCommandUsageHandler h = new ExternalCommandUsageHandler();
    GESTURES_LOG.addHandler(h);
    Mercurial.getInstance().runWithoutExternalEvents(workdir, "MY_COMMAND", new Callable<Void>() {
        @Override
        public Void call () throws Exception {
            createLockFile(lockFile);
            FileUtil.refreshFor(workdir);
            // modification
            write(modifiedFile, "testExternalCommandLoggedChanges");
            // delete
            toDelete.delete();
            // create
            toAdd.createNewFile();
            FileUtil.refreshFor(workdir);
            pause();
            lockFile.delete();
            FileUtil.refreshFor(workdir);
            return null;
        }
    });
    h.waitForEvent();
    assertNotNull(h.event);
    assertEquals(1, h.numberOfEvents);
    assertTrue(h.event.time > 0);
    assertEquals("HG", h.event.vcs);
    assertFalse(h.event.external);
    assertEquals("MY_COMMAND", h.event.command);
    assertEquals(Long.valueOf(3), h.event.modifications);
    GESTURES_LOG.removeHandler(h);
    workdirFO.removeRecursiveListener(fca);
}
 
Example 17
Project: incubator-netbeans   File: RepositoryUpdaterTest.java   View Source Code Vote up 4 votes
public void testBinaryScanStartFinishedCalled() throws Exception {
    binIndexerFactory.scanStartedFor.clear();
    binIndexerFactory.scanFinishedFor.clear();
    final TestHandler handler = new TestHandler();
    final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests");
    logger.setLevel (Level.FINEST);
    logger.addHandler(handler);
    binIndexerFactory.indexer.setExpectedRoots(bootRoot2.toURL());
    MutableClassPathImplementation mcpi1 = new MutableClassPathImplementation ();
    mcpi1.addResource(bootRoot2);
    ClassPath cp = ClassPathFactory.createClassPath(mcpi1);
    globalPathRegistry_register(PLATFORM,new ClassPath[] {cp});
    assertTrue (handler.await());
    assertEquals(1, handler.getBinaries().size());
    assertEquals(0, handler.getSources().size());
    assertEquals(bootRoot2.toURL(), handler.getBinaries().iterator().next());
    assertTrue(binIndexerFactory.indexer.await());
    assertEquals(1, binIndexerFactory.scanStartedFor.size());
    assertEquals(bootRoot2.toURL(), binIndexerFactory.scanStartedFor.get(0));
    assertEquals(1, binIndexerFactory.scanFinishedFor.size());
    assertEquals(bootRoot2.toURL(), binIndexerFactory.scanFinishedFor.get(0));

    binIndexerFactory.scanStartedFor.clear();
    binIndexerFactory.scanFinishedFor.clear();
    handler.reset();
    binIndexerFactory.indexer.setExpectedRoots(bootRoot3.toURL());
    mcpi1.addResource(bootRoot3);
    assertTrue (handler.await());
    assertEquals(1, handler.getBinaries().size());
    assertEquals(0, handler.getSources().size());
    assertEquals(bootRoot3.toURL(), handler.getBinaries().iterator().next());
    assertTrue(binIndexerFactory.indexer.await());
    assertEquals(1, binIndexerFactory.scanStartedFor.size());
    assertEquals(bootRoot3.toURL(), binIndexerFactory.scanStartedFor.get(0));
    assertEquals(1, binIndexerFactory.scanFinishedFor.size());
    assertEquals(bootRoot3.toURL(), binIndexerFactory.scanFinishedFor.get(0));

    binIndexerFactory.scanStartedFor.clear();
    binIndexerFactory.scanFinishedFor.clear();
    handler.reset();
    binIndexerFactory.indexer.setExpectedRoots(new URL[0]);
    globalPathRegistry_unregister(PLATFORM,new ClassPath[]{cp});
    //Give RU a time for refresh - nothing to wait for
    Thread.sleep(2000);
    assertTrue (handler.await());
    assertEquals(0, handler.getBinaries().size());
    assertEquals(0, handler.getSources().size());
    assertEquals(0, binIndexerFactory.indexer.getCount());
    assertEquals(0, binIndexerFactory.scanStartedFor.size());
    assertEquals(0, binIndexerFactory.scanFinishedFor.size());

    binIndexerFactory.scanStartedFor.clear();
    binIndexerFactory.scanFinishedFor.clear();
    handler.reset();
    binIndexerFactory.indexer.setExpectedRoots(bootRoot2.toURL(), bootRoot3.toURL());
    globalPathRegistry_register(PLATFORM,new ClassPath[]{cp});
    assertTrue (handler.await());
    assertEquals(2, handler.getBinaries().size());
    assertEquals(0, handler.getSources().size());
    assertTrue(binIndexerFactory.indexer.await());
    assertEquals(2, binIndexerFactory.scanStartedFor.size());
    assertEquals(new URL[] {bootRoot2.toURL(), bootRoot3.toURL()}, binIndexerFactory.scanStartedFor);
    assertEquals(2, binIndexerFactory.scanFinishedFor.size());
    assertEquals(new URL[] {bootRoot2.toURL(), bootRoot3.toURL()}, binIndexerFactory.scanFinishedFor);
}
 
Example 18
Project: incubator-netbeans   File: FileListWorkOrderingTest.java   View Source Code Vote up 4 votes
/**
 * Tests that consequent file list works on same root with intermediate delete works are collapsed.
 * Runs special work at start which in execution schedules FLW(src1), DEL(src1), FLW(src1), DEL(src1), FLW(src1)
 * FLW, DEL+DEL, FLW+FLW -> 2 FLWs should be executed.
 */
public void testFLWOnSingleRootsWithIntermediateDelWorksFollowedByFLWNotAbsorbed() throws InterruptedException, IOException {

    assertTrue(GlobalPathRegistry.getDefault().getPaths(FOO_SOURCES).isEmpty());
    final RepositoryUpdaterTest.TestHandler handler = new RepositoryUpdaterTest.TestHandler();
    final Logger logger = Logger.getLogger(RepositoryUpdater.class.getName()+".tests"); //NOI18N
    logger.setLevel (Level.FINEST);
    logger.addHandler(handler);
    try {
        globalPathRegistry_register(FOO_SOURCES,new ClassPath[]{cp1});
        assertTrue (handler.await());
        assertEquals(0, handler.getBinaries().size());
        assertEquals(2, handler.getSources().size());

        handler.reset(RepositoryUpdaterTest.TestHandler.Type.FILELIST);
        MimeLookup.getLookup(MimePath.get(FOO_MIME)).
                lookup(FooIndexerFactory.class).
                reset();
        RepositoryUpdater.getDefault().runAsWork(
            new Runnable() {
               @Override
               public void run() {
                   //First schedule of refresh for src1
                   IndexingManager.getDefault().refreshIndex(
                      src1.toURL(),
                      Collections.<URL>emptyList(),
                      false);
                   //Second schedulte some delete in src2
                   RepositoryUpdater.getDefault().addDeleteJob(
                      src1.toURL(),
                      Collections.<String>emptySet(),
                      LogContext.create(LogContext.EventType.PATH, "Test"));    //NOI18N
                   //Third schedule of refresh for src1
                   IndexingManager.getDefault().refreshIndex(
                      src1.toURL(),
                      Collections.<URL>emptyList(),
                      false);
                   //Second schedulte some delete in src2
                   RepositoryUpdater.getDefault().addDeleteJob(
                      src1.toURL(),
                      Collections.<String>emptySet(),
                      LogContext.create(LogContext.EventType.PATH, "Test"));    //NOI18N
                   //Fourth schedule of refresh for src1
                   IndexingManager.getDefault().refreshIndex(
                      src1.toURL(),
                      Collections.<URL>emptyList(),
                      false);
               }
            });
        assertTrue (handler.await());
        assertTrue (awaitRUSilence());
        assertEquals(2, MimeLookup.getLookup(MimePath.get(FOO_MIME)).
                        lookup(FooIndexerFactory.class).
                        getIndexingCount());
    } finally {
        logger.removeHandler(handler);
    }
}
 
Example 19
Project: Cognizant-Intelligent-Test-Scripter   File: LogUtil.java   View Source Code Vote up 4 votes
public static Logger getLogger(String className) {
    init();
    Logger log = Logger.getLogger(className);
    log.addHandler(handler);
    return log;
}
 
Example 20
Project: incubator-netbeans   File: ModuleOraculumTest.java   View Source Code Vote up 4 votes
public void testRootCache() {
    Lookup.getDefault().lookup(CPP.class)
            .add(
                    root1,
                    ClassPath.SOURCE,
                    ClassPathSupport.createClassPath(root1))
            .add(
                    root2,
                    ClassPath.SOURCE,
                    ClassPathSupport.createClassPath(root2));
    final Logger l = Logger.getLogger(ModuleOraculum.class.getName());
    final Level origLogLevel = l.getLevel();
    final H h = new H();
    l.setLevel(Level.FINE);
    l.addHandler(h);
    try {
        final ClasspathInfo cpInfo = new ClasspathInfo.Builder(ClassPath.EMPTY).build();
        final JavacParser parser = new JavacParser(Collections.emptyList(), true);
        JavacTaskImpl impl = JavacParser.createJavacTask(
                javaFile1,
                null,
                cpInfo,
                parser,
                null,
                false);
        assertEquals("Test", Options.instance(impl.getContext()).get("-XD-Xmodule:"));    //NOI18N
        List<? extends FileObject> roots = h.getRoots();
        assertEquals(1, roots.size());
        assertEquals(root1, roots.get(0));
        h.reset();
        impl = JavacParser.createJavacTask(
                javaFile1,
                null,
                cpInfo,
                parser,
                null,
                false);
        assertEquals("Test", Options.instance(impl.getContext()).get("-XD-Xmodule:"));    //NOI18N
        roots = h.getRoots();
        assertEquals(0, roots.size());
        impl = JavacParser.createJavacTask(
                javaFile2,
                null,
                cpInfo,
                parser,
                null,
                false);
        assertEquals("Next", Options.instance(impl.getContext()).get("-XD-Xmodule:"));    //NOI18N
        roots = h.getRoots();
        assertEquals(1, roots.size());
        assertEquals(root2, roots.get(0));
    } finally {
        l.removeHandler(h);
        l.setLevel(origLogLevel);
    }
}