Skip to content

Commit

Permalink
OAK-5273 - Reintroduce tests disabled or removed for OAK-5223
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1775077 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
francescomari committed Dec 19, 2016
1 parent d9ef049 commit a01e58d
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}.
*/
Expand All @@ -55,7 +55,7 @@ public abstract class AbstractBlobTrackerRegistrationTest {

@Rule
public OsgiContext context = new OsgiContext();

protected String repoHome;

@Before
Expand All @@ -72,8 +72,9 @@ public void tearDown() throws Exception {

@Test
public void registerBlobTrackingStore() throws Exception {
registerTrackingBlobStore();
registerNodeStoreService();
assertServiceNotActivated();
registerTrackingBlobStore();
assertServiceActivated();

BlobStore blobStore = context.getService(BlobStore.class);
Expand All @@ -85,8 +86,9 @@ public void registerBlobTrackingStore() throws Exception {

@Test
public void reRegisterBlobTrackingStore() throws Exception {
registerTrackingBlobStore();
registerNodeStoreService();
assertServiceNotActivated();
registerTrackingBlobStore();
assertServiceActivated();

BlobStore blobStore = context.getService(BlobStore.class);
Expand All @@ -111,11 +113,11 @@ public void reRegisterBlobTrackingStore() throws Exception {
private void assertTrackerReinitialized() {
File blobIdFiles = new File(repoHome, "blobids");
ImmutableList<File> files =
Files.fileTreeTraverser().postOrderTraversal(blobIdFiles).filter(new Predicate<File>() {
@Override public boolean apply(@Nullable File input) {
return input.getAbsolutePath().endsWith(".process");
}
}).toList();
Files.fileTreeTraverser().postOrderTraversal(blobIdFiles).filter(new Predicate<File>() {
@Override public boolean apply(@Nullable File input) {
return input.getAbsolutePath().endsWith(".process");
}
}).toList();
assertEquals(1, files.size());
}

Expand Down
1 change: 1 addition & 0 deletions oak-segment-tar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.osgi-mock</artifactId>
<version>1.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

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 static com.google.common.collect.Maps.newHashMap;
import static org.apache.sling.testing.mock.osgi.MockOsgi.deactivate;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;

/**
* Tests OSGi registration for {@link BlobTrackingStore} in {@link SegmentNodeStoreService}.
Expand All @@ -35,15 +37,28 @@ public class SegmentBlobTrackerRegistrationTest extends AbstractBlobTrackerRegis
private SegmentNodeStoreService service;

@Override
protected void registerNodeStoreService() {Map<String, Object> properties = newHashMap();
protected void registerNodeStoreService() {
Map<String, Object> 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());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,41 @@ public void testUseCustomBlobStoreWithBlobStore() {
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) {
Expand Down

0 comments on commit a01e58d

Please sign in to comment.