You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by am...@apache.org on 2017/10/09 06:01:05 UTC
svn commit: r1811531 - in /jackrabbit/oak/trunk:
oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/
oak-it/src/test/java/org/apache/jackrabbit/oak/plugins/blob/
oak-it/src/test/java/org/apache/jackrabbit/oak/segment/
Author: amitj
Date: Mon Oct 9 06:01:05 2017
New Revision: 1811531
URL: http://svn.apache.org/viewvc?rev=1811531&view=rev
Log:
OAK-6799 - OSGi service tests for Blob GC
- Tests for BlobGC Mbean initialization for OSGi *NodeStoreServices
Added:
jackrabbit/oak/trunk/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/AbstractBlobGCRegistrationTest.java (with props)
jackrabbit/oak/trunk/oak-it/src/test/java/org/apache/jackrabbit/oak/plugins/blob/DocumentBlobGCRegistrationTest.java (with props)
jackrabbit/oak/trunk/oak-it/src/test/java/org/apache/jackrabbit/oak/segment/SegmentBlobGCRegistrationTest.java (with props)
Added: jackrabbit/oak/trunk/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/AbstractBlobGCRegistrationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/AbstractBlobGCRegistrationTest.java?rev=1811531&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/AbstractBlobGCRegistrationTest.java (added)
+++ jackrabbit/oak/trunk/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/AbstractBlobGCRegistrationTest.java Mon Oct 9 06:01:05 2017
@@ -0,0 +1,95 @@
+/*
+ * 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.plugins.blob;
+
+import java.io.File;
+
+import org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreBlobStore;
+import org.apache.jackrabbit.oak.plugins.blob.datastore.DataStoreUtils;
+import org.apache.jackrabbit.oak.spi.blob.BlobStore;
+import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.stats.StatisticsProvider;
+import org.apache.sling.testing.mock.osgi.junit.OsgiContext;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.osgi.framework.ServiceRegistration;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public abstract class AbstractBlobGCRegistrationTest {
+ @Rule
+ public final TemporaryFolder target = new TemporaryFolder(new File("target"));
+ @Rule
+ public OsgiContext context = new OsgiContext();
+
+ protected String repoHome;
+
+ protected ServiceRegistration blobStore;
+
+ @Before
+ public void setUp() throws Exception {
+ context.registerService(StatisticsProvider.class, StatisticsProvider.NOOP);
+ repoHome = target.newFolder().getAbsolutePath();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ unregisterNodeStoreService();
+ unregisterBlobStore();
+ }
+
+ @Test
+ public void testBlobGcRegistered() throws Exception {
+ registerNodeStoreService();
+ assertServiceNotActivated();
+ registerBlobStore();
+ assertServiceActivated();
+
+ BlobGCMBean mbean = context.getService(BlobGCMBean.class);
+ assertNotNull(mbean);
+
+ unregisterNodeStoreService();
+ unregisterBlobStore();
+ }
+
+ protected abstract void registerNodeStoreService();
+
+ protected abstract void unregisterNodeStoreService();
+
+ protected void registerBlobStore() throws Exception {
+ DataStoreBlobStore blobStore = DataStoreUtils.getBlobStore(repoHome);
+ this.blobStore = context.bundleContext().registerService(BlobStore.class.getName(), blobStore, null);
+ }
+
+ protected void unregisterBlobStore() {
+ blobStore.unregister();
+ }
+
+ private void assertServiceNotActivated() {
+ assertNull(context.getService(NodeStore.class));
+ }
+
+ private void assertServiceActivated() {
+ assertNotNull(context.getService(NodeStore.class));
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/AbstractBlobGCRegistrationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-it/src/test/java/org/apache/jackrabbit/oak/plugins/blob/DocumentBlobGCRegistrationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/src/test/java/org/apache/jackrabbit/oak/plugins/blob/DocumentBlobGCRegistrationTest.java?rev=1811531&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-it/src/test/java/org/apache/jackrabbit/oak/plugins/blob/DocumentBlobGCRegistrationTest.java (added)
+++ jackrabbit/oak/trunk/oak-it/src/test/java/org/apache/jackrabbit/oak/plugins/blob/DocumentBlobGCRegistrationTest.java Mon Oct 9 06:01:05 2017
@@ -0,0 +1,65 @@
+/*
+ * 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.plugins.blob;
+
+import java.util.Map;
+
+import org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService;
+import org.apache.jackrabbit.oak.plugins.document.MongoUtils;
+import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.junit.After;
+import org.junit.BeforeClass;
+
+import static com.google.common.collect.Maps.newHashMap;
+import static org.junit.Assume.assumeTrue;
+
+/**
+ * Tests OSGi registration for {@link BlobGCMBean} in {@link DocumentNodeStoreService}.
+ */
+public class DocumentBlobGCRegistrationTest extends AbstractBlobGCRegistrationTest {
+ private DocumentNodeStoreService service;
+
+ @BeforeClass
+ public static void assumptions() {
+ assumeTrue(MongoUtils.isAvailable());
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ unregisterNodeStoreService();
+ unregisterBlobStore();
+ MongoUtils.dropCollections(MongoUtils.DB);
+ }
+
+ @Override
+ protected void registerNodeStoreService() {
+ Map<String, Object> properties = newHashMap();
+ properties.put(DocumentNodeStoreService.CUSTOM_BLOB_STORE, true);
+ properties.put("repository.home", repoHome);
+ properties.put("mongouri", MongoUtils.URL);
+ properties.put("db", MongoUtils.DB);
+ service = context.registerInjectActivateService(new DocumentNodeStoreService(), properties);
+ }
+
+ @Override
+ protected void unregisterNodeStoreService() {
+ MockOsgi.deactivate(service, context.bundleContext());
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-it/src/test/java/org/apache/jackrabbit/oak/plugins/blob/DocumentBlobGCRegistrationTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-it/src/test/java/org/apache/jackrabbit/oak/segment/SegmentBlobGCRegistrationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/src/test/java/org/apache/jackrabbit/oak/segment/SegmentBlobGCRegistrationTest.java?rev=1811531&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-it/src/test/java/org/apache/jackrabbit/oak/segment/SegmentBlobGCRegistrationTest.java (added)
+++ jackrabbit/oak/trunk/oak-it/src/test/java/org/apache/jackrabbit/oak/segment/SegmentBlobGCRegistrationTest.java Mon Oct 9 06:01:05 2017
@@ -0,0 +1,58 @@
+/*
+ * 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;
+
+import java.util.Map;
+
+import org.apache.jackrabbit.oak.plugins.blob.AbstractBlobGCRegistrationTest;
+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;
+
+public class SegmentBlobGCRegistrationTest extends AbstractBlobGCRegistrationTest {
+
+ private SegmentNodeStoreService service;
+
+ @Override
+ protected void registerNodeStoreService() {
+ Map<String, Object> properties = newHashMap();
+ properties.put(SegmentNodeStoreService.CUSTOM_BLOB_STORE, true);
+ properties.put(SegmentNodeStoreService.REPOSITORY_HOME_DIRECTORY, repoHome);
+ service = context.registerInjectActivateService(new SegmentNodeStoreService(), properties);
+ }
+
+ @Override
+ protected void unregisterNodeStoreService() {
+ 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());
+ }
+ }
+}
Propchange: jackrabbit/oak/trunk/oak-it/src/test/java/org/apache/jackrabbit/oak/segment/SegmentBlobGCRegistrationTest.java
------------------------------------------------------------------------------
svn:eol-style = native