use of org.jetbrains.idea.svn.svnkit.lowLevel.ApplicationLevelNumberConnectionsGuardImpl in project intellij-community by JetBrains.
the class SvnCachingRepositoryPoolTest method testCloseWorker.
@Test
public void testCloseWorker() throws Exception {
final SvnIdeaRepositoryPoolManager poolManager = new SvnIdeaRepositoryPoolManager(true, null, null);
final ApplicationLevelNumberConnectionsGuardImpl guard = SvnIdeaRepositoryPoolManager.getOurGuard();
guard.setDelay(20);
((CachingSvnRepositoryPool) poolManager.getPool()).setConnectionTimeout(20);
testBigFlow(poolManager, false);
TimeoutUtil.sleep(50);
Assert.assertEquals(0, guard.getCurrentlyActiveConnections());
final CachingSvnRepositoryPool pool = (CachingSvnRepositoryPool) poolManager.getPool();
Map<String, CachingSvnRepositoryPool.RepoGroup> groups = pool.getGroups();
Assert.assertEquals(1, groups.size());
CachingSvnRepositoryPool.RepoGroup group = groups.values().iterator().next();
Assert.assertEquals(0, group.getUsedSize());
// !!!
Assert.assertEquals(0, group.getInactiveSize());
poolManager.dispose();
checkAfterDispose(poolManager);
}
use of org.jetbrains.idea.svn.svnkit.lowLevel.ApplicationLevelNumberConnectionsGuardImpl in project intellij-community by JetBrains.
the class SvnCachingRepositoryPoolTest method checkAfterDispose.
private void checkAfterDispose(SvnIdeaRepositoryPoolManager poolManager) {
final ApplicationLevelNumberConnectionsGuardImpl guard = SvnIdeaRepositoryPoolManager.getOurGuard();
Assert.assertEquals(0, guard.getCurrentlyActiveConnections());
final CachingSvnRepositoryPool pool = (CachingSvnRepositoryPool) poolManager.getPool();
Map<String, CachingSvnRepositoryPool.RepoGroup> groups = pool.getGroups();
Assert.assertEquals(1, groups.size());
CachingSvnRepositoryPool.RepoGroup group = groups.values().iterator().next();
Assert.assertEquals(0, group.getUsedSize());
Assert.assertEquals(0, guard.getInstanceCount());
Assert.assertEquals(0, guard.getCurrentlyOpenedCount());
Assert.assertEquals(0, group.getUsedSize());
Assert.assertEquals(0, group.getInactiveSize());
}
use of org.jetbrains.idea.svn.svnkit.lowLevel.ApplicationLevelNumberConnectionsGuardImpl in project intellij-community by JetBrains.
the class SvnCachingRepositoryPoolTest method testBigFlow.
private void testBigFlow(final SvnIdeaRepositoryPoolManager poolManager, boolean disposeAfter) throws SVNException, InterruptedException {
poolManager.setCreator(svnurl -> new MockSvnRepository(svnurl, ISVNSession.DEFAULT));
final SVNURL url = SVNURL.parseURIEncoded("http://a.b.c");
final Random random = new Random(System.currentTimeMillis() & 0x00ff);
final int[] cnt = new int[1];
cnt[0] = 25;
final SVNException[] exc = new SVNException[1];
List<Thread> threads = new ArrayList<>();
for (int i = 0; i < 25; i++) {
Runnable target = () -> {
MockSvnRepository repository = null;
try {
repository = (MockSvnRepository) poolManager.createRepository(url, true);
} catch (SVNException e) {
e.printStackTrace();
exc[0] = e;
return;
}
repository.fireConnectionOpened();
TimeoutUtil.sleep(random.nextInt(10));
repository.fireConnectionClosed();
synchronized (cnt) {
--cnt[0];
}
};
Thread thread = new Thread(target, "svn cache");
thread.start();
threads.add(thread);
}
final long start = System.currentTimeMillis();
synchronized (cnt) {
while (cnt[0] > 0 && !timeout(start)) {
try {
cnt.wait(5);
} catch (InterruptedException e) {
//
}
}
}
Assert.assertEquals(0, cnt[0]);
// test no open repositories, but may have inactive
final ApplicationLevelNumberConnectionsGuardImpl guard = SvnIdeaRepositoryPoolManager.getOurGuard();
Assert.assertEquals(0, guard.getCurrentlyActiveConnections());
final CachingSvnRepositoryPool pool = (CachingSvnRepositoryPool) poolManager.getPool();
Map<String, CachingSvnRepositoryPool.RepoGroup> groups = pool.getGroups();
Assert.assertEquals(1, groups.size());
CachingSvnRepositoryPool.RepoGroup group = groups.values().iterator().next();
Assert.assertEquals(0, group.getUsedSize());
if (disposeAfter) {
poolManager.dispose();
Assert.assertEquals(0, guard.getCurrentlyActiveConnections());
Assert.assertEquals(0, guard.getInstanceCount());
Assert.assertEquals(0, group.getUsedSize());
Assert.assertEquals(0, group.getInactiveSize());
}
ConcurrencyUtil.joinAll(threads);
}
Aggregations