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/03 13:51:01 UTC
svn commit: r1368899 - in
/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub:
index/src/main/java/org/apache/stanbol/contenthub/index/ldpath/
revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/
test/src/mai...
Author: suat
Date: Fri Aug 3 11:51:01 2012
New Revision: 1368899
URL: http://svn.apache.org/viewvc?rev=1368899&view=rev
Log:
STANBOL-498: Improvement in tests and revision management
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/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/RevisionManager.java
incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/test/src/main/java/org/apache/stanbol/contenthub/test/index/ldpath/LDPathSemanticIndexTest.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=1368899&r1=1368898&r2=1368899&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 Fri Aug 3 11:51:01 2012
@@ -825,7 +825,7 @@ public class LDPathSemanticIndex impleme
@Override
public void run() {
// create temporary core
- IndexMetadata temporaryCoreMetadata;
+ IndexMetadata temporaryCoreMetadata = null;
try {
temporaryCoreMetadata = createTemporarySolrCore();
logger.info(
@@ -835,21 +835,28 @@ public class LDPathSemanticIndex impleme
logger.error("Failed to create temporary Solr core while reindexing the index: {}", name, e);
return;
}
- // initialize solr server tracker for the temporary core
- String temporaryCoreName = temporaryCoreMetadata.getIndexName();
- initializeTracker(temporaryCoreName);
-
- // index documents in the store according to the new configuration
+ String temporaryCoreName = temporaryCoreMetadata.getIndexName();;
try {
+ // initialize solr server tracker for the temporary core
+ initializeTracker(temporaryCoreName);
+
+ // index documents in the store according to the new configuration
+
revision = indexDocuments();
logger.info(
"Documents have been re-indexed according to the new configuration of the Semantic Index: {}",
name);
} catch (StoreException e) {
logger.error("Failed to obtain changes from Store while reindexing the index: {}", name, e);
+ managedSolrServer.removeIndex(temporaryCoreName, true);
return;
} catch (IndexException e) {
logger.error("IndexException while reindexing the index: {}", name, e);
+ managedSolrServer.removeIndex(temporaryCoreName, true);
+ return;
+ } catch (Exception e) {
+ logger.error("Exception while reindexing the index: {}", name, e);
+ managedSolrServer.removeIndex(temporaryCoreName, true);
return;
}
Modified: incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/RevisionManager.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/RevisionManager.java?rev=1368899&r1=1368898&r2=1368899&view=diff
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/RevisionManager.java (original)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/contenthub/revisionmanager/src/main/java/org/apache/stanbol/contenthub/revisionmanager/RevisionManager.java Fri Aug 3 11:51:01 2012
@@ -167,77 +167,87 @@ public class RevisionManager {
* @throws StoreException
*/
public <Item> ChangeSet<Item> getChanges(Store<Item> store, long revision, int batchSize) throws StoreException {
- // get connection
- Connection con = dbManager.getConnection();
- String revisionTableName = getStoreID(store);
- batchSize = batchSize == Integer.MAX_VALUE ? batchSize - 1 : batchSize;
-
- // check existence of record for the given content item id
- PreparedStatement ps = null;
- ResultSet rs = null;
- try {
- ps = con.prepareStatement(String.format(SELECT_CHANGES, revisionTableName),
- ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
- ps.setLong(1, revision);
- ps.setMaxRows(batchSize + 1);
- rs = ps.executeQuery();
-
- Set<String> changedUris = new LinkedHashSet<String>();
+ synchronized (RevisionManager.class) {
- if (!rs.first()) {
- return new ChangeSetImpl<Item>(store, store.getEpoch(), Long.MIN_VALUE, Long.MAX_VALUE,
- changedUris);
- }
- if (rs.absolute(batchSize + 1)) {
- long lastRowRevision = rs.getLong(2);
- rs.previous();
- long nextToLastRowRevision = rs.getLong(2);
- rs.beforeFirst();
- // if we are in the middle of a revision, add all changes in that revision to changedUris
- if (lastRowRevision == nextToLastRowRevision) {
- ps = con.prepareStatement(String.format(SELECT_MORECHANGES, revisionTableName),
- ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
- ps.setLong(1, revision);
- rs = ps.executeQuery();
-
- while (rs.next()) {
- changedUris.add(rs.getString(1));
+ // get connection
+ Connection con = dbManager.getConnection();
+ String revisionTableName = getStoreID(store);
+ batchSize = batchSize == Integer.MAX_VALUE ? batchSize - 1 : batchSize;
+
+ // check existence of record for the given content item id
+ PreparedStatement ps = null;
+ ResultSet rs = null;
+ try {
+ ps = con.prepareStatement(String.format(SELECT_CHANGES, revisionTableName),
+ ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+ ps.setLong(1, revision);
+ ps.setMaxRows(batchSize + 1);
+ rs = ps.executeQuery();
+
+ Set<String> changedUris = new LinkedHashSet<String>();
+
+ if (!rs.first()) {
+ return new ChangeSetImpl<Item>(store, store.getEpoch(), Long.MIN_VALUE, Long.MAX_VALUE,
+ changedUris);
+ }
+ if (rs.absolute(batchSize + 1)) {
+ long lastRowRevision = rs.getLong(2);
+ rs.previous();
+ long nextToLastRowRevision = rs.getLong(2);
+ rs.beforeFirst();
+ // if we are in the middle of a revision, add all changes in that revision to changedUris
+ if (lastRowRevision == nextToLastRowRevision) {
+ PreparedStatement ps2 = null;
+ ResultSet rs2 = null;
+ try {
+ ps2 = con.prepareStatement(String.format(SELECT_MORECHANGES, revisionTableName),
+ ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
+ ps2.setLong(1, revision);
+ rs2 = ps2.executeQuery();
+
+ while (rs2.next()) {
+ changedUris.add(rs2.getString(1));
+ }
+ } finally {
+ dbManager.closeResultSet(rs2);
+ dbManager.closeStatement(ps2);
+ }
+ } else {
+ while (rs.next()) {
+ if (rs.isLast()) {
+ break;
+ }
+ changedUris.add(rs.getString(1));
+ }
}
+
} else {
+ rs.beforeFirst();
while (rs.next()) {
- if (rs.isLast()) {
- break;
- }
changedUris.add(rs.getString(1));
}
}
- } else {
- rs.beforeFirst();
- while (rs.next()) {
- changedUris.add(rs.getString(1));
+ // set minimum and maximum revision numbers of the change set
+ if (rs.isLast()) {
+ rs.previous();
+ } else {
+ rs.last();
}
+ long to = rs.getLong(2);
+ rs.first();
+ long from = rs.getLong(2);
+
+ return new ChangeSetImpl<Item>(store, store.getEpoch(), from, to, changedUris);
+
+ } catch (SQLException e) {
+ log.error("Failed to get changes", e);
+ throw new StoreException("Failed to get changes", e);
+ } finally {
+ dbManager.closeResultSet(rs);
+ dbManager.closeStatement(ps);
+ dbManager.closeConnection(con);
}
-
- // set minimum and maximum revision numbers of the change set
- if (rs.isLast()) {
- rs.previous();
- } else {
- rs.last();
- }
- long to = rs.getLong(2);
- rs.first();
- long from = rs.getLong(2);
-
- return new ChangeSetImpl<Item>(store, store.getEpoch(), from, to, changedUris);
-
- } catch (SQLException e) {
- log.error("Failed to get changes", e);
- throw new StoreException("Failed to get changes", e);
- } finally {
- dbManager.closeResultSet(rs);
- dbManager.closeStatement(ps);
- dbManager.closeConnection(con);
}
}
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=1368899&r1=1368898&r2=1368899&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 Fri Aug 3 11:51:01 2012
@@ -99,23 +99,13 @@ public class LDPathSemanticIndexTest {
private static String pid;
private static int counter = 0;
- @SuppressWarnings("unchecked")
@Before
public void before() throws IndexManagementException, IndexException, InterruptedException, IOException {
String name = "test_index_name";
if (counter == 0) {
String program = "@prefix dbp-ont : <http://dbpedia.org/ontology/>; city = dbp-ont:city / rdfs:label :: xsd:string; country = dbp-ont:country / rdfs:label :: xsd:string; ";
pid = ldPathSemanticIndexManager.createIndex(name, "test_index_description", program);
- SemanticIndex<ContentItem> tempSemanticIndex = (SemanticIndex<ContentItem>) semanticIndexManager
- .getIndex(name);
- int timeoutCount = 0;
- while (tempSemanticIndex == null) {
- if (timeoutCount == 8) break;
- Thread.sleep(500);
- tempSemanticIndex = (SemanticIndex<ContentItem>) semanticIndexManager.getIndex(name);
- timeoutCount++;
- }
- assertNotNull("SemanticIndex '" + name + "' not available after waiting 4sec!", tempSemanticIndex);
+ SemanticIndex<ContentItem> tempSemanticIndex = getLDPathSemanticIndex(name);
assertTrue("This tests assume that the Semantic Index with the name '" + name + "' is of type "
+ LDPathSemanticIndex.class.getSimpleName(),
tempSemanticIndex instanceof LDPathSemanticIndex);
@@ -352,15 +342,7 @@ public class LDPathSemanticIndexTest {
String pid = ldPathSemanticIndexManager.createIndex(name, "", program);
try {
- LDPathSemanticIndex semanticIndex = (LDPathSemanticIndex) semanticIndexManager.getIndex(name);
- int timeoutCount = 0;
- while (semanticIndex == null) {
- if (timeoutCount == 8) break;
- Thread.sleep(500);
- semanticIndex = (LDPathSemanticIndex) semanticIndexManager.getIndex(name);
- timeoutCount++;
- }
-
+ SemanticIndex<ContentItem> semanticIndex = getLDPathSemanticIndex(name);
ContentItem ci = contentItemFactory.createContentItem(new StringSource(
"Michael Jackson is a very famous person, and he was born in Indiana."));
jobManager.enhanceContent(ci);
@@ -378,15 +360,9 @@ public class LDPathSemanticIndexTest {
properties.put(LDPathSemanticIndex.PROP_LD_PATH_PROGRAM, newProgram);
properties.put(LDPathSemanticIndex.PROP_DESCRIPTION, "reindexing");
config.update(properties);
+ Thread.sleep(1000);
- semanticIndex = (LDPathSemanticIndex) semanticIndexManager.getIndex(name);
- timeoutCount = 0;
- while (semanticIndex == null || !semanticIndex.getDescription().equals("reindexing")) {
- if (timeoutCount == 8) break;
- Thread.sleep(500);
- semanticIndex = (LDPathSemanticIndex) semanticIndexManager.getIndex(name);
- timeoutCount++;
- }
+ semanticIndex = getLDPathSemanticIndex(name);
// index ci to new semantic index
while (semanticIndex.getState() != IndexState.ACTIVE) {
Thread.sleep(500);
@@ -425,15 +401,7 @@ public class LDPathSemanticIndexTest {
String pid = ldPathSemanticIndexManager.createIndex(props);
try {
- LDPathSemanticIndex semanticIndex = (LDPathSemanticIndex) semanticIndexManager.getIndex(name);
- int timeoutCount = 0;
- while (semanticIndex == null) {
- if (timeoutCount == 8) break;
- Thread.sleep(500);
- semanticIndex = (LDPathSemanticIndex) semanticIndexManager.getIndex(name);
- timeoutCount++;
- }
-
+ SemanticIndex<ContentItem> semanticIndex = getLDPathSemanticIndex(name);
ContentItem ci = contentItemFactory.createContentItem(new StringSource(
"Michael Jackson is a very famous person, and he was born in Indiana."));
fileStore.put(ci);
@@ -467,6 +435,23 @@ public class LDPathSemanticIndexTest {
}
@SuppressWarnings("unchecked")
+ private SemanticIndex<ContentItem> getLDPathSemanticIndex(String name) throws InterruptedException,
+ IndexManagementException {
+
+ SemanticIndex<ContentItem> tempSemanticIndex = (SemanticIndex<ContentItem>) semanticIndexManager
+ .getIndex(name);
+ int timeoutCount = 0;
+ while (tempSemanticIndex == null) {
+ if (timeoutCount == 8) break;
+ Thread.sleep(500);
+ tempSemanticIndex = (SemanticIndex<ContentItem>) semanticIndexManager.getIndex(name);
+ timeoutCount++;
+ }
+ assertNotNull("Failed to retrieve SemanticIndex: " + name, tempSemanticIndex);
+ return tempSemanticIndex;
+ }
+
+ @SuppressWarnings("unchecked")
private Store<ContentItem> getContenthubStore() {
Store<ContentItem> contentHubStore = null;
try {