Search in sources :

Example 1 with ApplicationLevelNumberConnectionsGuardImpl

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);
}
Also used : SvnIdeaRepositoryPoolManager(org.jetbrains.idea.svn.svnkit.lowLevel.SvnIdeaRepositoryPoolManager) ApplicationLevelNumberConnectionsGuardImpl(org.jetbrains.idea.svn.svnkit.lowLevel.ApplicationLevelNumberConnectionsGuardImpl) CachingSvnRepositoryPool(org.jetbrains.idea.svn.svnkit.lowLevel.CachingSvnRepositoryPool) FileBasedTest(com.intellij.testFramework.vcs.FileBasedTest) Test(org.junit.Test)

Example 2 with ApplicationLevelNumberConnectionsGuardImpl

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());
}
Also used : ApplicationLevelNumberConnectionsGuardImpl(org.jetbrains.idea.svn.svnkit.lowLevel.ApplicationLevelNumberConnectionsGuardImpl) CachingSvnRepositoryPool(org.jetbrains.idea.svn.svnkit.lowLevel.CachingSvnRepositoryPool)

Example 3 with ApplicationLevelNumberConnectionsGuardImpl

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);
}
Also used : SVNURL(org.tmatesoft.svn.core.SVNURL) ArrayList(java.util.ArrayList) SVNException(org.tmatesoft.svn.core.SVNException) Random(java.util.Random) ApplicationLevelNumberConnectionsGuardImpl(org.jetbrains.idea.svn.svnkit.lowLevel.ApplicationLevelNumberConnectionsGuardImpl) CachingSvnRepositoryPool(org.jetbrains.idea.svn.svnkit.lowLevel.CachingSvnRepositoryPool)

Aggregations

ApplicationLevelNumberConnectionsGuardImpl (org.jetbrains.idea.svn.svnkit.lowLevel.ApplicationLevelNumberConnectionsGuardImpl)3 CachingSvnRepositoryPool (org.jetbrains.idea.svn.svnkit.lowLevel.CachingSvnRepositoryPool)3 FileBasedTest (com.intellij.testFramework.vcs.FileBasedTest)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 SvnIdeaRepositoryPoolManager (org.jetbrains.idea.svn.svnkit.lowLevel.SvnIdeaRepositoryPoolManager)1 Test (org.junit.Test)1 SVNException (org.tmatesoft.svn.core.SVNException)1 SVNURL (org.tmatesoft.svn.core.SVNURL)1