当前位置: 首页>>代码示例>>Java>>正文


Java Semaphore.drainPermits方法代码示例

本文整理汇总了Java中java.util.concurrent.Semaphore.drainPermits方法的典型用法代码示例。如果您正苦于以下问题:Java Semaphore.drainPermits方法的具体用法?Java Semaphore.drainPermits怎么用?Java Semaphore.drainPermits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.Semaphore的用法示例。


在下文中一共展示了Semaphore.drainPermits方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAddedClassesNotVisible

import java.util.concurrent.Semaphore; //导入方法依赖的package包/类
/**
 * Checks that added files are not visible until their source root is added,
 * even if the memcache with file contents 
 * is flushed during the scan (will be flushed after each file)
 */
public void testAddedClassesNotVisible() throws Exception {
    commonSetup();
    final Semaphore signal = new Semaphore(0);

    logHandler.beforeFinishCallback = new RootScannedCallback("java", "src/", signal);
    
    Set<ElementHandle<TypeElement>> handles;

    handles = ci.getDeclaredTypes("ConstructorTest", ClassIndex.NameKind.SIMPLE_NAME, Collections.singleton(
            SearchScope.SOURCE));
    // copy over some files
    TestUtil.copyFiles(
            new File(getDataDir(), "indexing/files"),
            new File(FileUtil.toFile(srcRoot), "org/netbeans/parsing/source1".replace('/', File.separatorChar)),
                    "ConstructorTest.java", "EmptyClass.java");

    // must force rescan, indexer does not notice the file-copy ?
    RepositoryUpdater.getDefault().refreshAll(false, false, true, null, 
            srcRoot, srcRoot2);
    try {
        signal.acquire();
        signal.drainPermits();
    } catch (InterruptedException ex) {
        fail("Should rescan the added files");
    }

    handles = ci.getDeclaredTypes("ConstructorTest", ClassIndex.NameKind.SIMPLE_NAME, Collections.singleton(
            SearchScope.SOURCE));
    assertEquals(0, handles.size());    
    
    // check that files STILL do not exist
    File dir = findSegmentDir(srcRoot);
    File targetDir = new File(dir, "org/netbeans/parsing/source1".replace('/', File.separatorChar));
    
    assertFalse(new File(targetDir, "ConstructorTest.sig").exists());
    assertFalse(new File(targetDir, "EmptyClass.sig").exists());
    
    parserBlocker.release();
    
    logHandler.waitForInitialScan();
    
    handles = ci.getDeclaredTypes("ConstructorTest", ClassIndex.NameKind.SIMPLE_NAME, Collections.singleton(
            SearchScope.SOURCE));
    assertEquals(1, handles.size());    

    assertTrue(new File(targetDir, "ConstructorTest.sig").exists());
    assertTrue(new File(targetDir, "EmptyClass.sig").exists());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:54,代码来源:IndexerTransactionTest.java

示例2: testDeletedClassesVisible

import java.util.concurrent.Semaphore; //导入方法依赖的package包/类
/**
 * Checks that deleted classes remain visible until the source root is committed.
 * 
 * @throws Exception 
 */
public void testDeletedClassesVisible() throws Exception {
    commonSetup();
    final Semaphore signal = new Semaphore(0);

    logHandler.beforeFinishCallback = new RootScannedCallback("java", "src/", signal);
    
    Set<ElementHandle<TypeElement>> handles;

    handles = ci.getDeclaredTypes("ClassWithInnerClass", ClassIndex.NameKind.SIMPLE_NAME, Collections.singleton(
            SearchScope.SOURCE));
    
    assertEquals(1, handles.size());
    
    File sourceDir = new File(FileUtil.toFile(srcRoot), "org/netbeans/parsing/source1".replace('/', File.separatorChar));
    new File(sourceDir, "ClassWithInnerClass.java").delete();
    
    // must force rescan, indexer does not notice the file-copy ?
    RepositoryUpdater.getDefault().refreshAll(false, false, true, null, 
            srcRoot, srcRoot2);
    try {
        signal.acquire();
        signal.drainPermits();
    } catch (InterruptedException ex) {
        fail("Should rescan the added files");
    }

    handles = ci.getDeclaredTypes("ClassWithInnerClass", ClassIndex.NameKind.SIMPLE_NAME, Collections.singleton(
            SearchScope.SOURCE));
    assertEquals(1, handles.size());    
    
    // check that files STILL do not exist
    File dir = findSegmentDir(srcRoot);
    File targetDir = new File(dir, "org/netbeans/parsing/source1".replace('/', File.separatorChar));
    
    assertTrue(new File(targetDir, "ClassWithInnerClass.sig").exists());
    
    parserBlocker.release();
    
    logHandler.waitForInitialScan();
    
    handles = ci.getDeclaredTypes("ClassWithInnerClass", ClassIndex.NameKind.SIMPLE_NAME, Collections.singleton(
            SearchScope.SOURCE));
    assertEquals(0, handles.size());    

    assertFalse(new File(targetDir, "ClassWithInnerClass.sig").exists());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:52,代码来源:IndexerTransactionTest.java


注:本文中的java.util.concurrent.Semaphore.drainPermits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。