本文整理汇总了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());
}
示例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());
}