You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by su...@apache.org on 2012/08/01 09:21:13 UTC
svn commit: r1367872 - in
/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub:
index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/
store/file/src/main/java/org/apache/stanbol/contenthub/store/file/
test/src/main/java/org...
Author: suat
Date: Wed Aug 1 07:21:13 2012
New Revision: 1367872
URL: http://svn.apache.org/viewvc?rev=1367872&view=rev
Log:
STANBOL-498:
-Adapted tests assuming that there can be multiple store instances.
-Handled epoch changes of the associated Store in the LDPathSemanticIndex
Modified:
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndex.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/store/file/FileStoreTest.java
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndex.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndex.java?rev=1367872&r1=1367871&r2=1367872&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndex.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/LDPathSemanticIndex.java Wed Aug 1 07:21:13 2012
@@ -56,6 +56,7 @@ import org.apache.stanbol.commons.semant
import org.apache.stanbol.commons.semanticindex.index.IndexState;
import org.apache.stanbol.commons.semanticindex.index.SemanticIndex;
import org.apache.stanbol.commons.semanticindex.store.ChangeSet;
+import org.apache.stanbol.commons.semanticindex.store.EpochException;
import org.apache.stanbol.commons.semanticindex.store.IndexingSource;
import org.apache.stanbol.commons.semanticindex.store.Store;
import org.apache.stanbol.commons.semanticindex.store.StoreException;
@@ -938,6 +939,18 @@ public class LDPathSemanticIndex impleme
String.format(
"Failed to get changes from FileRevisionManager with start revision: %s and batch size: %s for Store: %s",
revision, batchSize, store.getName()), e);
+ } catch (EpochException e) {
+ if (e.getActiveEpoch() > e.getRequestEpoch()) {
+ // epoch of the store has increased. So, a reindexing is needed.
+ // Start the reindexing thread and terminate this one
+ logger.info(
+ "Epoch of the Store: {} has increase. So, a reindexing will be in progress",
+ store.getName());
+ state = IndexState.REINDEXING;
+ reindexerThread = new Thread(new Reindexer());
+ reindexerThread.start();
+ return;
+ }
}
if (changeSet != null) {
Iterator<String> changedItems = changeSet.iterator();
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java?rev=1367872&r1=1367871&r2=1367872&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/store/file/src/main/java/org/apache/stanbol/contenthub/store/file/FileStore.java Wed Aug 1 07:21:13 2012
@@ -68,6 +68,7 @@ import org.apache.stanbol.contenthub.sto
import org.apache.stanbol.enhancer.servicesapi.Blob;
import org.apache.stanbol.enhancer.servicesapi.ContentItem;
import org.apache.stanbol.enhancer.servicesapi.ContentItemFactory;
+import org.apache.stanbol.enhancer.servicesapi.EnhancementException;
import org.apache.stanbol.enhancer.servicesapi.EnhancementJobManager;
import org.apache.stanbol.enhancer.servicesapi.NoSuchPartException;
import org.apache.stanbol.enhancer.servicesapi.helper.ContentItemHelper;
@@ -380,12 +381,14 @@ public class FileStore implements Store<
@Override
public String put(ContentItem ci) throws StoreException {
- // try {
- // jobManager.enhanceContent(ci);
- // } catch (EnhancementException e) {
- // throw new StoreException(String.format("Failed to enhance given content item with URI: %s",
- // ci.getUri()), e);
- // }
+ if (ci.getMetadata() == null || ci.getMetadata().size() == 0) {
+ try {
+ jobManager.enhanceContent(ci);
+ } catch (EnhancementException e) {
+ throw new StoreException(String.format("Failed to enhance given content item with URI: %s",
+ ci.getUri()), e);
+ }
+ }
long enhancementCount = getEnhancementCount(ci);
JSONObject htmlMetadata = getHTMLMetadata(ci);
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java?rev=1367872&r1=1367871&r2=1367872&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.java Wed Aug 1 07:21:13 2012
@@ -21,6 +21,8 @@ import static org.junit.Assert.assertTru
import java.io.IOException;
import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
import java.util.Dictionary;
import java.util.List;
import java.util.Map;
@@ -40,6 +42,7 @@ import org.apache.stanbol.commons.semant
import org.apache.stanbol.commons.semanticindex.index.IndexState;
import org.apache.stanbol.commons.semanticindex.index.SemanticIndex;
import org.apache.stanbol.commons.semanticindex.index.SemanticIndexManager;
+import org.apache.stanbol.commons.semanticindex.store.Store;
import org.apache.stanbol.commons.semanticindex.store.StoreException;
import org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndex;
import org.apache.stanbol.contenthub.index.ldpath.LDPathSemanticIndexManager;
@@ -57,6 +60,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
@@ -68,7 +72,7 @@ public class LDPathSemanticIndexTest {
private static Logger logger = LoggerFactory.getLogger(LDPathSemanticIndexTest.class);
- private static final int TESTCOUNT = 15;
+ private static final int TESTCOUNT = 16;
@TestReference
private LDPathSemanticIndexManager ldPathSemanticIndexManager;
@@ -85,6 +89,8 @@ public class LDPathSemanticIndexTest {
@TestReference
private EnhancementJobManager jobManager;
+ private Store<ContentItem> fileStore;
+
@TestReference
private BundleContext bundleContext;
@@ -116,6 +122,16 @@ public class LDPathSemanticIndexTest {
semanticIndex = (LDPathSemanticIndex) tempSemanticIndex;
solrServer = semanticIndex.getServer();
}
+ if (fileStore == null) {
+ if (bundleContext != null) {
+ fileStore = getContenthubStore(bundleContext);
+ if (fileStore == null) {
+ throw new IllegalStateException("Null Store");
+ }
+ } else {
+ throw new IllegalStateException("Null bundle context");
+ }
+ }
}
@Test
@@ -389,6 +405,11 @@ public class LDPathSemanticIndexTest {
}
}
+ @Test
+ public void epochChangeTest() {
+
+ }
+
@After
public void after() throws IndexManagementException {
counter++;
@@ -397,4 +418,31 @@ public class LDPathSemanticIndexTest {
ldPathSemanticIndexManager.removeIndex(pid);
}
}
+
+ @SuppressWarnings("unchecked")
+ private Store<ContentItem> getContenthubStore(BundleContext bundleContext) {
+ Store<ContentItem> contentHubStore = null;
+ try {
+ ServiceReference[] stores = bundleContext.getServiceReferences(Store.class.getName(), null);
+ for (ServiceReference serviceReference : stores) {
+ Object store = bundleContext.getService(serviceReference);
+ Type[] genericInterfaces = store.getClass().getGenericInterfaces();
+ if (genericInterfaces.length == 1 && genericInterfaces[0] instanceof ParameterizedType) {
+ Type[] types = ((ParameterizedType) genericInterfaces[0]).getActualTypeArguments();
+ try {
+ @SuppressWarnings("unused")
+ Class<ContentItem> contentItemClass = (Class<ContentItem>) types[0];
+ if (((Store<ContentItem>) store).getName().equals("contenthubFileStore")) {
+ contentHubStore = (Store<ContentItem>) store;
+ }
+ } catch (ClassCastException e) {
+ // ignore
+ }
+ }
+ }
+ } catch (InvalidSyntaxException e) {
+ // ignore as there is no filter
+ }
+ return contentHubStore;
+ }
}
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/store/file/FileStoreTest.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/store/file/FileStoreTest.java?rev=1367872&r1=1367871&r2=1367872&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/store/file/FileStoreTest.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/store/file/FileStoreTest.java Wed Aug 1 07:21:13 2012
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertTru
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
import java.net.URLEncoder;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -34,6 +36,8 @@ import org.apache.clerezza.rdf.core.UriR
import org.apache.sling.junit.annotations.SlingAnnotationsTestRunner;
import org.apache.sling.junit.annotations.TestReference;
import org.apache.stanbol.commons.indexedgraph.IndexedMGraph;
+import org.apache.stanbol.commons.semanticindex.index.IndexException;
+import org.apache.stanbol.commons.semanticindex.index.IndexManagementException;
import org.apache.stanbol.commons.semanticindex.store.Store;
import org.apache.stanbol.commons.semanticindex.store.StoreException;
import org.apache.stanbol.contenthub.revisionmanager.RevisionManager;
@@ -44,9 +48,12 @@ import org.apache.stanbol.enhancer.servi
import org.apache.stanbol.enhancer.servicesapi.ContentItemFactory;
import org.apache.stanbol.enhancer.servicesapi.impl.StringSource;
import org.codehaus.jettison.json.JSONException;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,9 +61,6 @@ import org.slf4j.LoggerFactory;
public class FileStoreTest {
private static final Logger log = LoggerFactory.getLogger(FileStoreTest.class);
- @TestReference(name = "FileStore")
- private Store<ContentItem> store;
-
@TestReference()
private BundleContext bundleContext;
@@ -69,6 +73,22 @@ public class FileStoreTest {
@TestReference
private RevisionManager revisionManager;
+ private Store<ContentItem> store;
+
+ @Before
+ public void before() throws IndexManagementException, IndexException, InterruptedException, IOException {
+ if (store == null) {
+ if (bundleContext != null) {
+ store = getContenthubStore(bundleContext);
+ if (store == null) {
+ throw new IllegalStateException("Null Store");
+ }
+ } else {
+ throw new IllegalStateException("Null bundle context");
+ }
+ }
+ }
+
@Test
public void fileStoreTest() {
assertNotNull("Expecting FileStore to be injected by Sling test runner", store);
@@ -175,8 +195,7 @@ public class FileStoreTest {
f.delete();
// delete the database records
- String query = String.format("DELETE FROM %s WHERE id = ?",
- revisionManager.getStoreID(store));
+ String query = String.format("DELETE FROM %s WHERE id = ?", revisionManager.getStoreID(store));
Connection connection = dbManager.getConnection();
PreparedStatement ps = null;
try {
@@ -219,4 +238,31 @@ public class FileStoreTest {
throw new StoreException("Failed to encode id: " + id, e);
}
}
+
+ @SuppressWarnings("unchecked")
+ private Store<ContentItem> getContenthubStore(BundleContext bundleContext) {
+ Store<ContentItem> contentHubStore = null;
+ try {
+ ServiceReference[] stores = bundleContext.getServiceReferences(Store.class.getName(), null);
+ for (ServiceReference serviceReference : stores) {
+ Object store = bundleContext.getService(serviceReference);
+ Type[] genericInterfaces = store.getClass().getGenericInterfaces();
+ if (genericInterfaces.length == 1 && genericInterfaces[0] instanceof ParameterizedType) {
+ Type[] types = ((ParameterizedType) genericInterfaces[0]).getActualTypeArguments();
+ try {
+ @SuppressWarnings("unused")
+ Class<ContentItem> contentItemClass = (Class<ContentItem>) types[0];
+ if (((Store<ContentItem>) store).getName().equals("contenthubFileStore")) {
+ contentHubStore = (Store<ContentItem>) store;
+ }
+ } catch (ClassCastException e) {
+ // ignore
+ }
+ }
+ }
+ } catch (InvalidSyntaxException e) {
+ // ignore as there is no filter
+ }
+ return contentHubStore;
+ }
}