Browse Source

LocalDiskRepositoryTestCase#createRepository: Default auto-close to false

Since 8ed59c5 ("Make TestRepository AutoCloseable", Jan 11, 2019) the
TestRepository class is auto-closeable, but instantiations of it were
not converted to use try-with-resource.

Converting to try-with-resource results, in several cases, in the
repository being closed twice because LocalDiskRepositoryTestCase has
logic to close created repositories in the tearDown method. This results
in several tests emitting a warning to the console:

  close() called when useCnt is already zero

Change the default behavior of the createRepository method to not use
the auto-close logic in LocalDiskRepositoryTestCase, so that thy will
instead be closed (only once) using the AutoCloseable implementation.

Deprecate the method that has the autoClose parameter.

Change-Id: I63d62c9913f9b61271667861dae144e551d358c1
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
tags/v5.3.0.201903061415-rc1
David Pursehouse 5 years ago
parent
commit
52923e9b07

+ 6
- 3
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java View File

* @return the newly created repository, opened for access * @return the newly created repository, opened for access
* @throws IOException * @throws IOException
* the repository could not be created in the temporary area * the repository could not be created in the temporary area
* @since 5.3
*/ */
private FileRepository createRepository(boolean bare)
protected FileRepository createRepository(boolean bare)
throws IOException { throws IOException {
return createRepository(bare, true /* auto close */);
return createRepository(bare, false /* auto close */);
} }


/** /**
* true to create a bare repository; false to make a repository * true to create a bare repository; false to make a repository
* within its working directory * within its working directory
* @param autoClose * @param autoClose
* auto close the repository in #tearDown
* auto close the repository in {@link #tearDown()}
* @return the newly created repository, opened for access * @return the newly created repository, opened for access
* @throws IOException * @throws IOException
* the repository could not be created in the temporary area * the repository could not be created in the temporary area
* @deprecated use {@link #createRepository(boolean)} instead
*/ */
@Deprecated
public FileRepository createRepository(boolean bare, boolean autoClose) public FileRepository createRepository(boolean bare, boolean autoClose)
throws IOException { throws IOException {
File gitdir = createUniqueTestGitDir(bare); File gitdir = createUniqueTestGitDir(bare);

+ 5
- 5
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java View File

@Test @Test
public void testFileKeyOpenNew() throws IOException { public void testFileKeyOpenNew() throws IOException {
File gitdir; File gitdir;
try (Repository n = createRepository(true, false)) {
try (Repository n = createRepository(true)) {
gitdir = n.getDirectory(); gitdir = n.getDirectory();
} }
recursiveDelete(gitdir); recursiveDelete(gitdir);
@Test @Test
public void testRepositoryUsageCountWithRegisteredRepository() public void testRepositoryUsageCountWithRegisteredRepository()
throws IOException { throws IOException {
@SuppressWarnings("resource") // We are testing the close() method
@SuppressWarnings({"resource", "deprecation"}) // We are testing the close() method
Repository repo = createRepository(false, false); Repository repo = createRepository(false, false);
assertEquals(1, repo.useCnt.get()); assertEquals(1, repo.useCnt.get());
RepositoryCache.register(repo); RepositoryCache.register(repo);


@Test @Test
public void testRepositoryUnregisteringWhenExpired() throws Exception { public void testRepositoryUnregisteringWhenExpired() throws Exception {
@SuppressWarnings("resource") // We are testing the close() method
@SuppressWarnings({"resource", "deprecation"}) // We are testing the close() method
Repository repoA = createRepository(true, false); Repository repoA = createRepository(true, false);
@SuppressWarnings("resource") // We are testing the close() method
@SuppressWarnings({"resource", "deprecation"}) // We are testing the close() method
Repository repoB = createRepository(true, false); Repository repoB = createRepository(true, false);
Repository repoC = createBareRepository(); Repository repoC = createBareRepository();
RepositoryCache.register(repoA); RepositoryCache.register(repoA);


@Test @Test
public void testReconfigure() throws InterruptedException, IOException { public void testReconfigure() throws InterruptedException, IOException {
@SuppressWarnings("resource") // We are testing the close() method
@SuppressWarnings({"resource", "deprecation"}) // We are testing the close() method
Repository repo = createRepository(false, false); Repository repo = createRepository(false, false);
RepositoryCache.register(repo); RepositoryCache.register(repo);
assertTrue(RepositoryCache.isCached(repo)); assertTrue(RepositoryCache.isCached(repo));

Loading…
Cancel
Save