]> source.dussan.org Git - jgit.git/commitdiff
LocalDiskRepositoryTestCase#createRepository: Default auto-close to false 12/135412/2
authorDavid Pursehouse <david.pursehouse@gmail.com>
Sun, 20 Jan 2019 10:58:10 +0000 (19:58 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Sun, 20 Jan 2019 11:09:16 +0000 (20:09 +0900)
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>
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryCacheTest.java

index 12b216950008d59dfa944e7a7c6116e3b3c4e9ce..4b2eadf4188d2fded42bb2852a36ed08c7c08ed3 100644 (file)
@@ -394,10 +394,11 @@ public abstract class LocalDiskRepositoryTestCase {
         * @return the newly created repository, opened for access
         * @throws IOException
         *             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 {
-               return createRepository(bare, true /* auto close */);
+               return createRepository(bare, false /* auto close */);
        }
 
        /**
@@ -407,11 +408,13 @@ public abstract class LocalDiskRepositoryTestCase {
         *            true to create a bare repository; false to make a repository
         *            within its working directory
         * @param autoClose
-        *            auto close the repository in #tearDown
+        *            auto close the repository in {@link #tearDown()}
         * @return the newly created repository, opened for access
         * @throws IOException
         *             the repository could not be created in the temporary area
+        * @deprecated use {@link #createRepository(boolean)} instead
         */
+       @Deprecated
        public FileRepository createRepository(boolean bare, boolean autoClose)
                        throws IOException {
                File gitdir = createUniqueTestGitDir(bare);
index 58b005c282329c8f7302fff27a1b64da0ba1da2b..15c4e4a029b1e9e5e3650296fbe5ac7d7eacf988 100644 (file)
@@ -110,7 +110,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
        @Test
        public void testFileKeyOpenNew() throws IOException {
                File gitdir;
-               try (Repository n = createRepository(true, false)) {
+               try (Repository n = createRepository(true)) {
                        gitdir = n.getDirectory();
                }
                recursiveDelete(gitdir);
@@ -192,7 +192,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
        @Test
        public void testRepositoryUsageCountWithRegisteredRepository()
                        throws IOException {
-               @SuppressWarnings("resource") // We are testing the close() method
+               @SuppressWarnings({"resource", "deprecation"}) // We are testing the close() method
                Repository repo = createRepository(false, false);
                assertEquals(1, repo.useCnt.get());
                RepositoryCache.register(repo);
@@ -240,9 +240,9 @@ public class RepositoryCacheTest extends RepositoryTestCase {
 
        @Test
        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);
-               @SuppressWarnings("resource") // We are testing the close() method
+               @SuppressWarnings({"resource", "deprecation"}) // We are testing the close() method
                Repository repoB = createRepository(true, false);
                Repository repoC = createBareRepository();
                RepositoryCache.register(repoA);
@@ -276,7 +276,7 @@ public class RepositoryCacheTest extends RepositoryTestCase {
 
        @Test
        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);
                RepositoryCache.register(repo);
                assertTrue(RepositoryCache.isCached(repo));