assertEquals(0, RepositoryCache.getRegisteredKeys().size());
}
+ @Test
+ public void testRepositoryUsageCount() throws Exception {
+ FileKey loc = FileKey.exact(db.getDirectory(), db.getFS());
+ Repository d2 = RepositoryCache.open(loc);
+ assertEquals(1, d2.useCnt.get());
+ RepositoryCache.open(FileKey.exact(loc.getFile(), db.getFS()));
+ assertEquals(2, d2.useCnt.get());
+ d2.close();
+ assertEquals(1, d2.useCnt.get());
+ d2.close();
+ assertEquals(0, d2.useCnt.get());
+ }
+
+ @Test
+ public void testRepositoryUsageCountWithRegisteredRepository() {
+ assertEquals(1, ((Repository) db).useCnt.get());
+ RepositoryCache.register(db);
+ assertEquals(1, ((Repository) db).useCnt.get());
+ db.close();
+ assertEquals(0, ((Repository) db).useCnt.get());
+ }
}
return globalListeners;
}
- private final AtomicInteger useCnt = new AtomicInteger(1);
+ /** Use counter */
+ final AtomicInteger useCnt = new AtomicInteger(1);
/** Metadata directory holding the repository's critical files. */
private final File gitDir;
db = location.open(mustExist);
ref = new SoftReference<Repository>(db);
cacheMap.put(location, ref);
+ } else {
+ db.incrementOpen();
}
}
+ } else {
+ db.incrementOpen();
}
- db.incrementOpen();
return db;
}
private void registerRepository(final Key location, final Repository db) {
- db.incrementOpen();
SoftReference<Repository> newRef = new SoftReference<Repository>(db);
Reference<Repository> oldRef = cacheMap.put(location, newRef);
Repository oldDb = oldRef != null ? oldRef.get() : null;