當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。