Index: oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/AbstractBlobTrackerRegistrationTest.java =================================================================== --- oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/AbstractBlobTrackerRegistrationTest.java (revision 1773776) +++ oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/blob/AbstractBlobTrackerRegistrationTest.java (working copy) @@ -19,12 +19,6 @@ package org.apache.jackrabbit.oak.plugins.blob; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - import java.io.File; import javax.annotation.Nullable; @@ -46,6 +40,12 @@ import org.junit.rules.TemporaryFolder; import org.osgi.framework.ServiceRegistration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + /** * Tests OSGi registration for {@link BlobTrackingStore}. */ @@ -55,7 +55,7 @@ @Rule public OsgiContext context = new OsgiContext(); - + protected String repoHome; @Before @@ -72,8 +72,9 @@ @Test public void registerBlobTrackingStore() throws Exception { + registerNodeStoreService(); + assertServiceNotActivated(); registerTrackingBlobStore(); - registerNodeStoreService(); assertServiceActivated(); BlobStore blobStore = context.getService(BlobStore.class); @@ -85,8 +86,9 @@ @Test public void reRegisterBlobTrackingStore() throws Exception { + registerNodeStoreService(); + assertServiceNotActivated(); registerTrackingBlobStore(); - registerNodeStoreService(); assertServiceActivated(); BlobStore blobStore = context.getService(BlobStore.class); @@ -111,11 +113,11 @@ private void assertTrackerReinitialized() { File blobIdFiles = new File(repoHome, "blobids"); ImmutableList files = - Files.fileTreeTraverser().postOrderTraversal(blobIdFiles).filter(new Predicate() { - @Override public boolean apply(@Nullable File input) { - return input.getAbsolutePath().endsWith(".process"); - } - }).toList(); + Files.fileTreeTraverser().postOrderTraversal(blobIdFiles).filter(new Predicate() { + @Override public boolean apply(@Nullable File input) { + return input.getAbsolutePath().endsWith(".process"); + } + }).toList(); assertEquals(1, files.size()); } Index: oak-segment-tar/pom.xml =================================================================== --- oak-segment-tar/pom.xml (revision 1773776) +++ oak-segment-tar/pom.xml (working copy) @@ -271,6 +271,7 @@ org.apache.sling org.apache.sling.testing.osgi-mock + 1.9.1-SNAPSHOT test Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentBlobTrackerRegistrationTest.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentBlobTrackerRegistrationTest.java (revision 1773776) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentBlobTrackerRegistrationTest.java (working copy) @@ -19,14 +19,16 @@ package org.apache.jackrabbit.oak.segment; +import static com.google.common.collect.Maps.newHashMap; +import static org.apache.sling.testing.mock.osgi.MockOsgi.deactivate; + import java.util.Map; import org.apache.jackrabbit.oak.plugins.blob.AbstractBlobTrackerRegistrationTest; import org.apache.jackrabbit.oak.plugins.blob.BlobTrackingStore; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; -import static com.google.common.collect.Maps.newHashMap; -import static org.apache.sling.testing.mock.osgi.MockOsgi.deactivate; - /** * Tests OSGi registration for {@link BlobTrackingStore} in {@link SegmentNodeStoreService}. */ @@ -35,15 +37,28 @@ private SegmentNodeStoreService service; @Override - protected void registerNodeStoreService() {Map properties = newHashMap(); + protected void registerNodeStoreService() { + Map properties = newHashMap(); properties.put(SegmentNodeStoreService.CUSTOM_BLOB_STORE, true); properties.put(SegmentNodeStoreService.DIRECTORY, repoHome); - service = context.registerInjectActivateService(new SegmentNodeStoreService(), properties); } @Override protected void unregisterNodeStoreService() { - deactivate(service); + ServiceReference[] serviceReferences; + try { + serviceReferences = context.bundleContext().getServiceReferences(SegmentNodeStoreService.class.getName(), null); + } catch (InvalidSyntaxException e) { + throw new IllegalStateException("Unable to read references to SegmentNodeStoreService", e); + } + for (ServiceReference serviceReference : serviceReferences) { + Object service = context.bundleContext().getService(serviceReference); + if (service == null) { + continue; + } + deactivate(service, serviceReference.getBundle().getBundleContext()); + } } + } Index: oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreServiceTest.java =================================================================== --- oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreServiceTest.java (revision 1773776) +++ oak-segment-tar/src/test/java/org/apache/jackrabbit/oak/segment/SegmentNodeStoreServiceTest.java (working copy) @@ -105,6 +105,41 @@ unregisterBlobStore(); } + /** + * A NodeStore service should be registered when the "customBlobStore" + * configuration property is true and a BlobStore service becomes + * dynamically available. + */ + @Test + public void testUseCustomBlobStoreWithDynamicBlobStoreActivation() { + registerSegmentNodeStoreService(true); + assertServiceNotActivated(); + + registerBlobStore(); + assertServiceActivated(); + + unregisterSegmentNodeStoreService(); + unregisterBlobStore(); + } + + /** + * A NodeStore service should be unregistered when the "customBlobStore" + * configuration property is true and a BlobStore service becomes + * dynamically unavailable. + */ + @Test + public void testUseCustomBlobStoreWithDynamicBlobStoreDeactivation() { + registerBlobStore(); + + registerSegmentNodeStoreService(true); + assertServiceActivated(); + + unregisterBlobStore(); + assertServiceNotActivated(); + + unregisterSegmentNodeStoreService(); + } + private SegmentNodeStoreService segmentNodeStoreService; protected void registerSegmentNodeStoreService(boolean customBlobStore) {