diff options
author | Hugo Arès <hugo.ares@ericsson.com> | 2016-10-12 06:54:52 -0400 |
---|---|---|
committer | Hugo Arès <hugo.ares@ericsson.com> | 2016-10-12 07:07:03 -0400 |
commit | 5a1e147eaa729ba0ba75bdeebcc745a55bff6232 (patch) | |
tree | ed0e7f952f1fe90d2bf49f9767dd6d22dfc06b88 /org.eclipse.jgit.test | |
parent | 15341ce5777c25dd41a52cf4b633ba363e3bf7a2 (diff) | |
download | jgit-5a1e147eaa729ba0ba75bdeebcc745a55bff6232.tar.gz jgit-5a1e147eaa729ba0ba75bdeebcc745a55bff6232.zip |
Fix eviction of repositories with negative usage count
If the repository close method was called twice (or more) for one open,
the usage count became negative and the repository was never be evicted
from the cache because the method checking if repository is expired was
not considering negative usage count.
Change-Id: I18a80c415c54c37d1b9def2b311ff2d0afa455ca
Signed-off-by: Hugo Arès <hugo.ares@ericsson.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java index 6bea320120..b44b4c34a7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java @@ -210,6 +210,27 @@ public class RepositoryCacheTest extends RepositoryTestCase { } @Test + public void testRepositoryUnregisteringWhenExpiredAndUsageCountNegative() + throws Exception { + Repository repoA = createBareRepository(); + RepositoryCache.register(repoA); + + assertEquals(1, RepositoryCache.getRegisteredKeys().size()); + assertTrue(RepositoryCache.isCached(repoA)); + + // close the repo twice to make usage count negative + repoA.close(); + repoA.close(); + // fake that repoA was closed more than 1 hour ago (default expiration + // time) + repoA.closedAt.set(System.currentTimeMillis() - 65 * 60 * 1000); + + RepositoryCache.clearExpired(); + + assertEquals(0, RepositoryCache.getRegisteredKeys().size()); + } + + @Test public void testRepositoryUnregisteringWhenExpired() throws Exception { Repository repoA = createBareRepository(); Repository repoB = createBareRepository(); |