jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1516118 - /jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/tck/TCKBase.java
Date Wed, 21 Aug 2013 09:17:08 GMT
Author: mreutegg
Date: Wed Aug 21 09:17:07 2013
New Revision: 1516118

URL: http://svn.apache.org/r1516118
Log:
OAK-966: Restore RepositoryHelper after TCK tests

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/tck/TCKBase.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/tck/TCKBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/tck/TCKBase.java?rev=1516118&r1=1516117&r2=1516118&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/tck/TCKBase.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/tck/TCKBase.java
Wed Aug 21 09:17:07 2013
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.oak.jcr.tck;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Properties;
 
 import org.apache.jackrabbit.oak.jcr.OakMongoMKRepositoryStub;
@@ -42,15 +45,12 @@ public abstract class TCKBase extends Te
 
     public TCKBase(String name) {
         super(name);
-        addTest(new Setup(OakRepositoryStub.class.getName()));
-        addTests();
+        Setup.wrap(this, OakRepositoryStub.class.getName());
         if (OakSegmentMKRepositoryStub.isAvailable()) {
-            addTest(new Setup(OakSegmentMKRepositoryStub.class.getName()));
-            addTests();
+            Setup.wrap(this, OakSegmentMKRepositoryStub.class.getName());
         }
         if (OakMongoMKRepositoryStub.isMongoDBAvailable()) {
-            addTest(new Setup(OakMongoMKRepositoryStub.class.getName()));
-            addTests();
+            Setup.wrap(this, OakMongoMKRepositoryStub.class.getName());
         }
     }
 
@@ -64,6 +64,15 @@ public abstract class TCKBase extends Te
 
         private final String stubClass;
 
+        private List<RepositoryHelper> helpers = new ArrayList<RepositoryHelper>();
+
+        public static void wrap(TCKBase test, String stubClass) {
+            Setup setup = new Setup(stubClass);
+            test.addTest(setup);
+            test.addTests();
+            test.addTest(setup.getTearDown());
+        }
+
         public Setup(String stubClass) {
             super("testSetup");
             this.stubClass = stubClass;
@@ -73,12 +82,38 @@ public abstract class TCKBase extends Te
             // replace the existing helper with our parametrized version
             RepositoryHelperPool helperPool = RepositoryHelperPoolImpl.getInstance();
             // drain helpers
-            helperPool.borrowHelpers();
+            helpers.addAll(Arrays.asList(helperPool.borrowHelpers()));
             // replace with our own stub
             Properties props = new Properties();
             props.load(getClass().getClassLoader().getResourceAsStream(RepositoryStub.STUB_IMPL_PROPS));
             props.put(RepositoryStub.PROP_STUB_IMPL_CLASS, stubClass);
             helperPool.returnHelper(new RepositoryHelper(props));
         }
+
+        TestCase getTearDown() {
+            return new TearDown(helpers);
+        }
+    }
+
+    public static class TearDown extends TestCase {
+
+        /**
+         * The repository helpers to restore
+         */
+        private List<RepositoryHelper> helpers;
+
+        public TearDown(List<RepositoryHelper> helpers) {
+            super("testTearDown");
+            this.helpers = helpers;
+        }
+
+        public void testTearDown() throws Exception {
+            // restore previous helpers
+            RepositoryHelperPool helperPool = RepositoryHelperPoolImpl.getInstance();
+            helperPool.borrowHelpers();
+            for (RepositoryHelper helper : helpers) {
+                helperPool.returnHelper(helper);
+            }
+        }
     }
 }



Mime
View raw message