RepositoryCacheTest: avoid to close already closed repository
The tearDown() of the superclass closed the repository once more which led to a negative use count warning logged by Repository.close(). Change-Id: I331f85a540c68264a53456276c32f72b79113d61 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
ac6353e9e5
commit
53ad437382
|
@ -359,12 +359,32 @@ protected FileRepository createWorkRepository() throws IOException {
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* the repository could not be created in the temporary area
|
* the repository could not be created in the temporary area
|
||||||
*/
|
*/
|
||||||
private FileRepository createRepository(boolean bare) throws IOException {
|
private FileRepository createRepository(boolean bare)
|
||||||
|
throws IOException {
|
||||||
|
return createRepository(bare, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new empty repository.
|
||||||
|
*
|
||||||
|
* @param bare
|
||||||
|
* true to create a bare repository; false to make a repository
|
||||||
|
* within its working directory
|
||||||
|
* @param autoClose
|
||||||
|
* auto close the repository in #tearDown
|
||||||
|
* @return the newly created repository, opened for access
|
||||||
|
* @throws IOException
|
||||||
|
* the repository could not be created in the temporary area
|
||||||
|
*/
|
||||||
|
public FileRepository createRepository(boolean bare, boolean autoClose)
|
||||||
|
throws IOException {
|
||||||
File gitdir = createUniqueTestGitDir(bare);
|
File gitdir = createUniqueTestGitDir(bare);
|
||||||
FileRepository db = new FileRepository(gitdir);
|
FileRepository db = new FileRepository(gitdir);
|
||||||
assertFalse(gitdir.exists());
|
assertFalse(gitdir.exists());
|
||||||
db.create(bare);
|
db.create(bare);
|
||||||
addRepoToClose(db);
|
if (autoClose) {
|
||||||
|
addRepoToClose(db);
|
||||||
|
}
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ public void testFileKeyOpenExisting() throws IOException {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFileKeyOpenNew() throws IOException {
|
public void testFileKeyOpenNew() throws IOException {
|
||||||
final Repository n = createBareRepository();
|
final Repository n = createRepository(true, false);
|
||||||
final File gitdir = n.getDirectory();
|
final File gitdir = n.getDirectory();
|
||||||
n.close();
|
n.close();
|
||||||
recursiveDelete(gitdir);
|
recursiveDelete(gitdir);
|
||||||
|
@ -187,12 +187,14 @@ public void testRepositoryUsageCount() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRepositoryUsageCountWithRegisteredRepository() {
|
public void testRepositoryUsageCountWithRegisteredRepository()
|
||||||
assertEquals(1, ((Repository) db).useCnt.get());
|
throws IOException {
|
||||||
RepositoryCache.register(db);
|
Repository repo = createRepository(false, false);
|
||||||
assertEquals(1, ((Repository) db).useCnt.get());
|
assertEquals(1, repo.useCnt.get());
|
||||||
db.close();
|
RepositoryCache.register(repo);
|
||||||
assertEquals(0, ((Repository) db).useCnt.get());
|
assertEquals(1, repo.useCnt.get());
|
||||||
|
repo.close();
|
||||||
|
assertEquals(0, repo.useCnt.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -232,8 +234,8 @@ public void testRepositoryUnregisteringWhenExpiredAndUsageCountNegative()
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRepositoryUnregisteringWhenExpired() throws Exception {
|
public void testRepositoryUnregisteringWhenExpired() throws Exception {
|
||||||
Repository repoA = createBareRepository();
|
Repository repoA = createRepository(true, false);
|
||||||
Repository repoB = createBareRepository();
|
Repository repoB = createRepository(true, false);
|
||||||
Repository repoC = createBareRepository();
|
Repository repoC = createBareRepository();
|
||||||
RepositoryCache.register(repoA);
|
RepositoryCache.register(repoA);
|
||||||
RepositoryCache.register(repoB);
|
RepositoryCache.register(repoB);
|
||||||
|
@ -265,11 +267,12 @@ public void testRepositoryUnregisteringWhenExpired() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReconfigure() throws InterruptedException {
|
public void testReconfigure() throws InterruptedException, IOException {
|
||||||
RepositoryCache.register(db);
|
Repository repo = createRepository(false, false);
|
||||||
assertTrue(RepositoryCache.isCached(db));
|
RepositoryCache.register(repo);
|
||||||
db.close();
|
assertTrue(RepositoryCache.isCached(repo));
|
||||||
assertTrue(RepositoryCache.isCached(db));
|
repo.close();
|
||||||
|
assertTrue(RepositoryCache.isCached(repo));
|
||||||
|
|
||||||
// Actually, we would only need to validate that
|
// Actually, we would only need to validate that
|
||||||
// WorkQueue.getExecutor().scheduleWithFixedDelay is called with proper
|
// WorkQueue.getExecutor().scheduleWithFixedDelay is called with proper
|
||||||
|
@ -287,7 +290,7 @@ public void testReconfigure() throws InterruptedException {
|
||||||
// This wait will time out after 2048 ms
|
// This wait will time out after 2048 ms
|
||||||
for (int i = 0; i <= 10; i++) {
|
for (int i = 0; i <= 10; i++) {
|
||||||
Thread.sleep(1 << i);
|
Thread.sleep(1 << i);
|
||||||
if (!RepositoryCache.isCached(db)) {
|
if (!RepositoryCache.isCached(repo)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue