Skip to content

Commit

Permalink
OAK-5223 - Let SegmentNodeStoreService unregister services correctly
Browse files Browse the repository at this point in the history
SegmentNodeStoreService now uniformly unregisters the services it owns, even
when an external BlobStore is used. Moreover, the reference to the BlobStore
has been changed from dynamic and reluctant to static and greedy to simplify
the implementation of the SegmentNodeStoreService.


git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/oak/trunk@1773038 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
francescomari committed Dec 7, 2016
1 parent 1a5a4fb commit dd3f621
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@

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 @@ -40,12 +46,6 @@
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 @@ -72,9 +72,8 @@ public void tearDown() throws Exception {

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

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

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

BlobStore blobStore = context.getService(BlobStore.class);
Expand Down
5 changes: 5 additions & 0 deletions oak-pojosr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
<artifactId>oak-segment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>oak-segment-tar</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>oak-jcr</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.apache.jackrabbit.oak.run.osgi;

import static com.google.common.base.Preconditions.checkNotNull;

import java.lang.management.ManagementFactory;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -64,8 +66,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.google.common.base.Preconditions.checkNotNull;

/**
* RepositoryFactory which constructs an instance of Oak repository. Thi factory supports following
* parameters
Expand Down Expand Up @@ -133,12 +133,15 @@ public class OakOSGiRepositoryFactory implements RepositoryFactory {
public static final String REPOSITORY_ENV_SPRING_BOOT =
"org.apache.jackrabbit.oak.repository.springBootMode";

public static final String REPOSITORY_BUNDLE_FILTER_DEFAULT = "(|" +
public static final String REPOSITORY_BUNDLE_FILTER_DEFAULT = "(&" +
"(|" +
"(Bundle-SymbolicName=org.apache.jackrabbit*)" +
"(Bundle-SymbolicName=org.apache.sling*)" +
"(Bundle-SymbolicName=org.apache.felix*)" +
"(Bundle-SymbolicName=org.apache.aries*)" +
"(Bundle-SymbolicName=groovy-all)" +
")" +
"(!(Bundle-SymbolicName=org.apache.jackrabbit.oak-segment-tar))" +
")";

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.jackrabbit.oak.run.osgi

import org.apache.felix.connect.launch.PojoServiceRegistry
import org.apache.jackrabbit.oak.spi.blob.BlobStore
import org.apache.jackrabbit.oak.spi.state.NodeStore
import org.junit.Before
import org.junit.Test

import static org.junit.Assert.assertNotNull
import static org.junit.Assert.assertNull
import static org.mockito.Mockito.mock

class TarSegmentNodeStoreConfigTest extends AbstractRepositoryFactoryTest {

private static final String SEGMENT_TAR_BUNDLE_FILTER = "(&" +
"(|" +
"(Bundle-SymbolicName=org.apache.jackrabbit*)" +
"(Bundle-SymbolicName=org.apache.sling*)" +
"(Bundle-SymbolicName=org.apache.felix*)" +
"(Bundle-SymbolicName=org.apache.aries*)" +
"(Bundle-SymbolicName=groovy-all)" +
")" +
"(!(Bundle-SymbolicName=org.apache.jackrabbit.oak-segment))" +
")"

private PojoServiceRegistry registry

@Before
void adjustConfig() {
config[OakOSGiRepositoryFactory.REPOSITORY_BUNDLE_FILTER] = SEGMENT_TAR_BUNDLE_FILTER
registry = repositoryFactory.initializeServiceRegistry(config)
}

@Override
protected PojoServiceRegistry getRegistry() {
return registry
}

@Test
void testDynamicBlobStore() {
createConfig([
'org.apache.jackrabbit.oak.segment.SegmentNodeStoreService': [
"customBlobStore": true
]
])
assertNull(registry.getServiceReference(NodeStore.class.name))
def registration = registry.registerService(BlobStore.class.name, mock(BlobStore.class), null)
assertNotNull(getServiceWithWait(NodeStore.class))
registration.unregister()
assertNull(registry.getServiceReference(NodeStore.class.name))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.jackrabbit.oak.segment;

/**
* A {@link SegmentStoreProvider} that returns a {@link SegmentStore} instance
* provided by the user.
*/
class DefaultSegmentStoreProvider implements SegmentStoreProvider {

private final SegmentStore segmentStore;

DefaultSegmentStoreProvider(SegmentStore segmentStore) {
this.segmentStore = segmentStore;
}

@Override
public SegmentStore getSegmentStore() {
return segmentStore;
}

}
Loading

0 comments on commit dd3f621

Please sign in to comment.