From 7bbe648979481cdb1d0e3d00412baba7ae4f3d07 Mon Sep 17 00:00:00 2001 From: agazzarini Date: Tue, 10 Mar 2020 10:46:24 +0100 Subject: [PATCH] [ SEARCH-2090 ] SolrQueueAPIClient refactoring + SolrInformationServer fix --- .../alfresco/solr/SolrInformationServer.java | 2 +- .../solr/AbstractAlfrescoDistributedIT.java | 14 +- .../alfresco/solr/AbstractAlfrescoSolrIT.java | 14 +- .../alfresco/solr/AlfrescoSolrReloadIT.java | 12 +- .../org/alfresco/solr/AlfrescoSolrUtils.java | 16 +- .../solr/AlfrescoTrackerRegistrationIT.java | 12 +- .../org/alfresco/solr/SolrITInitializer.java | 12 +- .../solr/highlight/AlfrescoHighlighterIT.java | 14 +- .../solr/query/AlfrescoSolrFingerprintIT.java | 14 +- .../AlfrescoSolrTrackerExceptionIT.java | 12 +- .../solr/tracker/AlfrescoSolrTrackerIT.java | 12 +- .../AlfrescoSolrTrackerRollbackIT.java | 14 +- .../tracker/AlfrescoSolrTrackerStateIT.java | 12 +- .../alfresco/solr/tracker/CascadingIT.java | 12 +- .../solr/client/SOLRAPIQueueClient.java | 343 ++++++++---------- 15 files changed, 230 insertions(+), 285 deletions(-) diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java index ead6f6efe..9de54db5e 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java @@ -2298,7 +2298,7 @@ public class SolrInformationServer implements InformationServer private void deleteErrorNode(UpdateRequestProcessor processor, SolrQueryRequest request, Node node) throws IOException { DeleteUpdateCommand delErrorDocCmd = new DeleteUpdateCommand(request); - delErrorDocCmd.setId(FIELD_SOLR4_ID + ":" + PREFIX_ERROR + node.getId()); + delErrorDocCmd.setId(PREFIX_ERROR + node.getId()); processor.processDelete(delErrorDocCmd); } diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/AbstractAlfrescoDistributedIT.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/AbstractAlfrescoDistributedIT.java index 841f60a27..bed47eeb4 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/AbstractAlfrescoDistributedIT.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/AbstractAlfrescoDistributedIT.java @@ -732,33 +732,33 @@ public abstract class AbstractAlfrescoDistributedIT extends SolrITInitializer public static void indexTransaction(Transaction transaction, List nodes, List nodeMetaDatas) { //First map the nodes to a transaction. - SOLRAPIQueueClient.nodeMap.put(transaction.getId(), nodes); + SOLRAPIQueueClient.NODE_MAP.put(transaction.getId(), nodes); //Next map a node to the NodeMetaData for(NodeMetaData nodeMetaData : nodeMetaDatas) { - SOLRAPIQueueClient.nodeMetaDataMap.put(nodeMetaData.getId(), nodeMetaData); + SOLRAPIQueueClient.NODE_META_DATA_MAP.put(nodeMetaData.getId(), nodeMetaData); } //Next add the transaction to the queue - SOLRAPIQueueClient.transactionQueue.add(transaction); + SOLRAPIQueueClient.TRANSACTION_QUEUE.add(transaction); } public static void indexTransaction(Transaction transaction, List nodes, List nodeMetaDatas, List content) { //First map the nodes to a transaction. - SOLRAPIQueueClient.nodeMap.put(transaction.getId(), nodes); + SOLRAPIQueueClient.NODE_MAP.put(transaction.getId(), nodes); //Next map a node to the NodeMetaData int i=0; for(NodeMetaData nodeMetaData : nodeMetaDatas) { - SOLRAPIQueueClient.nodeMetaDataMap.put(nodeMetaData.getId(), nodeMetaData); - SOLRAPIQueueClient.nodeContentMap.put(nodeMetaData.getId(), content.get(i++)); + SOLRAPIQueueClient.NODE_META_DATA_MAP.put(nodeMetaData.getId(), nodeMetaData); + SOLRAPIQueueClient.NODE_CONTENT_MAP.put(nodeMetaData.getId(), content.get(i++)); } //Next add the transaction to the queue - SOLRAPIQueueClient.transactionQueue.add(transaction); + SOLRAPIQueueClient.TRANSACTION_QUEUE.add(transaction); } /** diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/AbstractAlfrescoSolrIT.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/AbstractAlfrescoSolrIT.java index 72b724bd8..9dc5f589f 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/AbstractAlfrescoSolrIT.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/AbstractAlfrescoSolrIT.java @@ -622,33 +622,33 @@ public abstract class AbstractAlfrescoSolrIT implements SolrTestFiles, AlfrescoS public static void indexTransaction(Transaction transaction, List nodes, List nodeMetaDatas) { //First map the nodes to a transaction. - SOLRAPIQueueClient.nodeMap.put(transaction.getId(), nodes); + SOLRAPIQueueClient.NODE_MAP.put(transaction.getId(), nodes); //Next map a node to the NodeMetaData for(NodeMetaData nodeMetaData : nodeMetaDatas) { - SOLRAPIQueueClient.nodeMetaDataMap.put(nodeMetaData.getId(), nodeMetaData); + SOLRAPIQueueClient.NODE_META_DATA_MAP.put(nodeMetaData.getId(), nodeMetaData); } //Next add the transaction to the queue - SOLRAPIQueueClient.transactionQueue.add(transaction); + SOLRAPIQueueClient.TRANSACTION_QUEUE.add(transaction); } public static void indexTransaction(Transaction transaction, List nodes, List nodeMetaDatas, List content) { //First map the nodes to a transaction. - SOLRAPIQueueClient.nodeMap.put(transaction.getId(), nodes); + SOLRAPIQueueClient.NODE_MAP.put(transaction.getId(), nodes); //Next map a node to the NodeMetaData int i=0; for(NodeMetaData nodeMetaData : nodeMetaDatas) { - SOLRAPIQueueClient.nodeMetaDataMap.put(nodeMetaData.getId(), nodeMetaData); - SOLRAPIQueueClient.nodeContentMap.put(nodeMetaData.getId(), content.get(i++)); + SOLRAPIQueueClient.NODE_META_DATA_MAP.put(nodeMetaData.getId(), nodeMetaData); + SOLRAPIQueueClient.NODE_CONTENT_MAP.put(nodeMetaData.getId(), content.get(i++)); } //Next add the transaction to the queue - SOLRAPIQueueClient.transactionQueue.add(transaction); + SOLRAPIQueueClient.TRANSACTION_QUEUE.add(transaction); } diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoSolrReloadIT.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoSolrReloadIT.java index a7988b098..22f82c167 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoSolrReloadIT.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoSolrReloadIT.java @@ -45,12 +45,12 @@ public class AlfrescoSolrReloadIT extends AbstractAlfrescoSolrIT @After public void clearQueue() { - SOLRAPIQueueClient.nodeMetaDataMap.clear(); - SOLRAPIQueueClient.transactionQueue.clear(); - SOLRAPIQueueClient.aclChangeSetQueue.clear(); - SOLRAPIQueueClient.aclReadersMap.clear(); - SOLRAPIQueueClient.aclMap.clear(); - SOLRAPIQueueClient.nodeMap.clear(); + SOLRAPIQueueClient.NODE_META_DATA_MAP.clear(); + SOLRAPIQueueClient.TRANSACTION_QUEUE.clear(); + SOLRAPIQueueClient.ACL_CHANGE_SET_QUEUE.clear(); + SOLRAPIQueueClient.ACL_READERS_MAP.clear(); + SOLRAPIQueueClient.ACL_MAP.clear(); + SOLRAPIQueueClient.NODE_MAP.clear(); } @Test diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoSolrUtils.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoSolrUtils.java index 3a9b32e1f..1c75b5423 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoSolrUtils.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoSolrUtils.java @@ -57,7 +57,6 @@ import static org.junit.Assert.assertEquals; import java.io.IOException; import java.io.StringWriter; import java.util.ArrayList; -import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -76,7 +75,6 @@ import org.alfresco.repo.tenant.TenantService; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; import org.alfresco.service.namespace.QName; import org.alfresco.solr.AbstractAlfrescoSolrIT.SolrServletRequest; import org.alfresco.solr.client.Acl; @@ -90,13 +88,11 @@ import org.alfresco.solr.client.SOLRAPIQueueClient; import org.alfresco.solr.client.StringPropertyValue; import org.alfresco.solr.client.Transaction; import org.alfresco.util.ISO9075; -import org.apache.lucene.util.BytesRef; import org.apache.solr.SolrTestCaseJ4.XmlDoc; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.common.params.CoreAdminParams; import org.apache.solr.common.params.ModifiableSolrParams; import org.apache.solr.common.params.SolrParams; -import org.apache.solr.common.util.JavaBinCodec; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.XML; import org.apache.solr.core.CoreContainer; @@ -273,16 +269,16 @@ public class AlfrescoSolrUtils public void indexTransaction(Transaction transaction, List nodes, List nodeMetaDatas) { //First map the nodes to a transaction. - SOLRAPIQueueClient.nodeMap.put(transaction.getId(), nodes); + SOLRAPIQueueClient.NODE_MAP.put(transaction.getId(), nodes); //Next map a node to the NodeMetaData for(NodeMetaData nodeMetaData : nodeMetaDatas) { - SOLRAPIQueueClient.nodeMetaDataMap.put(nodeMetaData.getId(), nodeMetaData); + SOLRAPIQueueClient.NODE_META_DATA_MAP.put(nodeMetaData.getId(), nodeMetaData); } //Next add the transaction to the queue - SOLRAPIQueueClient.transactionQueue.add(transaction); + SOLRAPIQueueClient.TRANSACTION_QUEUE.add(transaction); } /** * @@ -387,17 +383,17 @@ public class AlfrescoSolrUtils public static void indexAclChangeSet(AclChangeSet aclChangeSet, List aclList, List aclReadersList) { //First map the nodes to a transaction. - SOLRAPIQueueClient.aclMap.put(aclChangeSet.getId(), aclList); + SOLRAPIQueueClient.ACL_MAP.put(aclChangeSet.getId(), aclList); //Next map a node to the NodeMetaData for(AclReaders aclReaders : aclReadersList) { - SOLRAPIQueueClient.aclReadersMap.put(aclReaders.getId(), aclReaders); + SOLRAPIQueueClient.ACL_READERS_MAP.put(aclReaders.getId(), aclReaders); } //Next add the transaction to the queue - SOLRAPIQueueClient.aclChangeSetQueue.add(aclChangeSet); + SOLRAPIQueueClient.ACL_CHANGE_SET_QUEUE.add(aclChangeSet); } /** * Generate a collection from input. diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoTrackerRegistrationIT.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoTrackerRegistrationIT.java index 3747cb356..1a20f0a9c 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoTrackerRegistrationIT.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/AlfrescoTrackerRegistrationIT.java @@ -41,12 +41,12 @@ public class AlfrescoTrackerRegistrationIT extends AbstractAlfrescoSolrIT @After public void clearQueue() { - SOLRAPIQueueClient.nodeMetaDataMap.clear(); - SOLRAPIQueueClient.transactionQueue.clear(); - SOLRAPIQueueClient.aclChangeSetQueue.clear(); - SOLRAPIQueueClient.aclReadersMap.clear(); - SOLRAPIQueueClient.aclMap.clear(); - SOLRAPIQueueClient.nodeMap.clear(); + SOLRAPIQueueClient.NODE_META_DATA_MAP.clear(); + SOLRAPIQueueClient.TRANSACTION_QUEUE.clear(); + SOLRAPIQueueClient.ACL_CHANGE_SET_QUEUE.clear(); + SOLRAPIQueueClient.ACL_READERS_MAP.clear(); + SOLRAPIQueueClient.ACL_MAP.clear(); + SOLRAPIQueueClient.NODE_MAP.clear(); } @Test diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/SolrITInitializer.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/SolrITInitializer.java index d6f27945e..40bf8ac20 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/SolrITInitializer.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/SolrITInitializer.java @@ -228,12 +228,12 @@ public abstract class SolrITInitializer extends SolrTestCaseJ4 System.clearProperty("solr.log.dir"); System.clearProperty("solr.solr.home"); - SOLRAPIQueueClient.nodeMetaDataMap.clear(); - SOLRAPIQueueClient.transactionQueue.clear(); - SOLRAPIQueueClient.aclChangeSetQueue.clear(); - SOLRAPIQueueClient.aclReadersMap.clear(); - SOLRAPIQueueClient.aclMap.clear(); - SOLRAPIQueueClient.nodeMap.clear(); + SOLRAPIQueueClient.NODE_META_DATA_MAP.clear(); + SOLRAPIQueueClient.TRANSACTION_QUEUE.clear(); + SOLRAPIQueueClient.ACL_CHANGE_SET_QUEUE.clear(); + SOLRAPIQueueClient.ACL_READERS_MAP.clear(); + SOLRAPIQueueClient.ACL_MAP.clear(); + SOLRAPIQueueClient.NODE_MAP.clear(); } /** diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/highlight/AlfrescoHighlighterIT.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/highlight/AlfrescoHighlighterIT.java index 3ccb159c6..12bbae599 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/highlight/AlfrescoHighlighterIT.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/highlight/AlfrescoHighlighterIT.java @@ -146,13 +146,13 @@ public class AlfrescoHighlighterIT extends AbstractAlfrescoSolrIT @AfterClass public static void clearQueue() { - SOLRAPIQueueClient.nodeMetaDataMap.clear(); - SOLRAPIQueueClient.transactionQueue.clear(); - SOLRAPIQueueClient.aclChangeSetQueue.clear(); - SOLRAPIQueueClient.aclReadersMap.clear(); - SOLRAPIQueueClient.aclMap.clear(); - SOLRAPIQueueClient.nodeMap.clear(); - SOLRAPIQueueClient.nodeContentMap.clear(); + SOLRAPIQueueClient.NODE_META_DATA_MAP.clear(); + SOLRAPIQueueClient.TRANSACTION_QUEUE.clear(); + SOLRAPIQueueClient.ACL_CHANGE_SET_QUEUE.clear(); + SOLRAPIQueueClient.ACL_READERS_MAP.clear(); + SOLRAPIQueueClient.ACL_MAP.clear(); + SOLRAPIQueueClient.NODE_MAP.clear(); + SOLRAPIQueueClient.NODE_CONTENT_MAP.clear(); } @Test diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/query/AlfrescoSolrFingerprintIT.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/query/AlfrescoSolrFingerprintIT.java index d9f0694e2..41bade7c9 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/query/AlfrescoSolrFingerprintIT.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/query/AlfrescoSolrFingerprintIT.java @@ -88,13 +88,13 @@ public class AlfrescoSolrFingerprintIT extends AbstractAlfrescoSolrIT @After public void clearQueue() { - SOLRAPIQueueClient.nodeMetaDataMap.clear(); - SOLRAPIQueueClient.transactionQueue.clear(); - SOLRAPIQueueClient.aclChangeSetQueue.clear(); - SOLRAPIQueueClient.aclReadersMap.clear(); - SOLRAPIQueueClient.aclMap.clear(); - SOLRAPIQueueClient.nodeMap.clear(); - SOLRAPIQueueClient.nodeContentMap.clear(); + SOLRAPIQueueClient.NODE_META_DATA_MAP.clear(); + SOLRAPIQueueClient.TRANSACTION_QUEUE.clear(); + SOLRAPIQueueClient.ACL_CHANGE_SET_QUEUE.clear(); + SOLRAPIQueueClient.ACL_READERS_MAP.clear(); + SOLRAPIQueueClient.ACL_MAP.clear(); + SOLRAPIQueueClient.NODE_MAP.clear(); + SOLRAPIQueueClient.NODE_CONTENT_MAP.clear(); clearIndex(); assertU(commit()); diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerExceptionIT.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerExceptionIT.java index 1ee16f923..65266046b 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerExceptionIT.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerExceptionIT.java @@ -81,12 +81,12 @@ public class AlfrescoSolrTrackerExceptionIT extends AbstractAlfrescoSolrIT @After public void clearQueue() throws Exception { - SOLRAPIQueueClient.nodeMetaDataMap.clear(); - SOLRAPIQueueClient.transactionQueue.clear(); - SOLRAPIQueueClient.aclChangeSetQueue.clear(); - SOLRAPIQueueClient.aclReadersMap.clear(); - SOLRAPIQueueClient.aclMap.clear(); - SOLRAPIQueueClient.nodeMap.clear(); + SOLRAPIQueueClient.NODE_META_DATA_MAP.clear(); + SOLRAPIQueueClient.TRANSACTION_QUEUE.clear(); + SOLRAPIQueueClient.ACL_CHANGE_SET_QUEUE.clear(); + SOLRAPIQueueClient.ACL_READERS_MAP.clear(); + SOLRAPIQueueClient.ACL_MAP.clear(); + SOLRAPIQueueClient.NODE_MAP.clear(); } diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerIT.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerIT.java index 09c53ae07..ca98f473d 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerIT.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerIT.java @@ -82,12 +82,12 @@ public class AlfrescoSolrTrackerIT extends AbstractAlfrescoSolrIT @After public void clearQueue() throws Exception { - SOLRAPIQueueClient.nodeMetaDataMap.clear(); - SOLRAPIQueueClient.transactionQueue.clear(); - SOLRAPIQueueClient.aclChangeSetQueue.clear(); - SOLRAPIQueueClient.aclReadersMap.clear(); - SOLRAPIQueueClient.aclMap.clear(); - SOLRAPIQueueClient.nodeMap.clear(); + SOLRAPIQueueClient.NODE_META_DATA_MAP.clear(); + SOLRAPIQueueClient.TRANSACTION_QUEUE.clear(); + SOLRAPIQueueClient.ACL_CHANGE_SET_QUEUE.clear(); + SOLRAPIQueueClient.ACL_READERS_MAP.clear(); + SOLRAPIQueueClient.ACL_MAP.clear(); + SOLRAPIQueueClient.NODE_MAP.clear(); } diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerRollbackIT.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerRollbackIT.java index 9baf19990..1d6b25243 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerRollbackIT.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerRollbackIT.java @@ -78,12 +78,12 @@ public class AlfrescoSolrTrackerRollbackIT extends AbstractAlfrescoSolrIT @After public void clearQueue() throws Exception { - SOLRAPIQueueClient.nodeMetaDataMap.clear(); - SOLRAPIQueueClient.transactionQueue.clear(); - SOLRAPIQueueClient.aclChangeSetQueue.clear(); - SOLRAPIQueueClient.aclReadersMap.clear(); - SOLRAPIQueueClient.aclMap.clear(); - SOLRAPIQueueClient.nodeMap.clear(); + SOLRAPIQueueClient.NODE_META_DATA_MAP.clear(); + SOLRAPIQueueClient.TRANSACTION_QUEUE.clear(); + SOLRAPIQueueClient.ACL_CHANGE_SET_QUEUE.clear(); + SOLRAPIQueueClient.ACL_READERS_MAP.clear(); + SOLRAPIQueueClient.ACL_MAP.clear(); + SOLRAPIQueueClient.NODE_MAP.clear(); } @@ -194,7 +194,7 @@ public class AlfrescoSolrTrackerRollbackIT extends AbstractAlfrescoSolrIT //Take the rollback transaction out of the queue so it doesn't get re-indexed following the rollback. //This will prove the rollback transaction was rolled back - SOLRAPIQueueClient.transactionQueue.remove(rollbackTxn); + SOLRAPIQueueClient.TRANSACTION_QUEUE.remove(rollbackTxn); metadataTracker.setRollback(true, new Exception("Forced rollback!")); commitTracker.getRunLock().release(); diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerStateIT.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerStateIT.java index fc7965443..b77fce2b0 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerStateIT.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/AlfrescoSolrTrackerStateIT.java @@ -82,12 +82,12 @@ public class AlfrescoSolrTrackerStateIT extends AbstractAlfrescoSolrIT @After public void clearQueue() throws Exception { - SOLRAPIQueueClient.nodeMetaDataMap.clear(); - SOLRAPIQueueClient.transactionQueue.clear(); - SOLRAPIQueueClient.aclChangeSetQueue.clear(); - SOLRAPIQueueClient.aclReadersMap.clear(); - SOLRAPIQueueClient.aclMap.clear(); - SOLRAPIQueueClient.nodeMap.clear(); + SOLRAPIQueueClient.NODE_META_DATA_MAP.clear(); + SOLRAPIQueueClient.TRANSACTION_QUEUE.clear(); + SOLRAPIQueueClient.ACL_CHANGE_SET_QUEUE.clear(); + SOLRAPIQueueClient.ACL_READERS_MAP.clear(); + SOLRAPIQueueClient.ACL_MAP.clear(); + SOLRAPIQueueClient.NODE_MAP.clear(); } @Before diff --git a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/CascadingIT.java b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/CascadingIT.java index 7d1e145a9..79dc0c3fb 100644 --- a/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/CascadingIT.java +++ b/search-services/alfresco-search/src/test/java/org/alfresco/solr/tracker/CascadingIT.java @@ -150,12 +150,12 @@ public class CascadingIT extends AbstractAlfrescoSolrIT @After public void clearQueue() { - SOLRAPIQueueClient.nodeMetaDataMap.clear(); - SOLRAPIQueueClient.transactionQueue.clear(); - SOLRAPIQueueClient.aclChangeSetQueue.clear(); - SOLRAPIQueueClient.aclReadersMap.clear(); - SOLRAPIQueueClient.aclMap.clear(); - SOLRAPIQueueClient.nodeMap.clear(); + SOLRAPIQueueClient.NODE_META_DATA_MAP.clear(); + SOLRAPIQueueClient.TRANSACTION_QUEUE.clear(); + SOLRAPIQueueClient.ACL_CHANGE_SET_QUEUE.clear(); + SOLRAPIQueueClient.ACL_READERS_MAP.clear(); + SOLRAPIQueueClient.ACL_MAP.clear(); + SOLRAPIQueueClient.NODE_MAP.clear(); } /** diff --git a/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/SOLRAPIQueueClient.java b/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/SOLRAPIQueueClient.java index c8f3976c3..64ab13577 100644 --- a/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/SOLRAPIQueueClient.java +++ b/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/SOLRAPIQueueClient.java @@ -26,16 +26,26 @@ package org.alfresco.solr.client; -import java.io.*; +import static java.util.Optional.ofNullable; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; import java.net.ConnectException; -import java.util.*; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.Collectors; -import org.alfresco.httpclient.AuthenticationException; import org.alfresco.httpclient.Response; import org.alfresco.repo.dictionary.NamespaceDAO; import org.alfresco.repo.index.shard.ShardState; import org.alfresco.service.namespace.QName; -import org.apache.commons.codec.EncoderException; import org.apache.commons.httpclient.HttpStatus; import org.json.JSONException; @@ -44,17 +54,16 @@ import org.json.JSONException; /** * A client that reads from an internal queue. This is used for test cases. */ - public class SOLRAPIQueueClient extends SOLRAPIClient { - public static List aclChangeSetQueue = Collections.synchronizedList(new ArrayList()); - public static Map> aclMap = Collections.synchronizedMap(new HashMap()); - public static Map aclReadersMap = Collections.synchronizedMap(new HashMap()); + public final static List ACL_CHANGE_SET_QUEUE = Collections.synchronizedList(new ArrayList<>()); + public final static Map> ACL_MAP = Collections.synchronizedMap(new HashMap<>()); + public final static Map ACL_READERS_MAP = Collections.synchronizedMap(new HashMap<>()); - public static List transactionQueue = Collections.synchronizedList(new ArrayList()); - public static Map> nodeMap = Collections.synchronizedMap(new HashMap()); - public static Map nodeMetaDataMap = Collections.synchronizedMap(new HashMap()); - public static Map nodeContentMap = Collections.synchronizedMap(new HashMap()); + public final static List TRANSACTION_QUEUE = Collections.synchronizedList(new ArrayList<>()); + public final static Map> NODE_MAP = Collections.synchronizedMap(new HashMap<>()); + public final static Map NODE_META_DATA_MAP = Collections.synchronizedMap(new HashMap<>()); + public final static Map NODE_CONTENT_MAP = Collections.synchronizedMap(new HashMap<>()); private static boolean throwException; @@ -63,71 +72,42 @@ public class SOLRAPIQueueClient extends SOLRAPIClient super(null,null,namespaceDAO); } - public static void setThrowException(boolean _throwException) { + public static void setThrowException(boolean _throwException) + { throwException = _throwException; } - public AclChangeSets getAclChangeSets(Long fromCommitTime, Long minAclChangeSetId, Long toCommitTime, Long maxAclChangeSetId, int maxResults) - throws AuthenticationException, IOException, JSONException + @Override + public AclChangeSets getAclChangeSets(Long fromCommitTime, Long minAclChangeSetId, Long toCommitTime, Long maxAclChangeSetId, int maxResults) throws IOException, JSONException { - if(throwException) { + if(throwException) + { throw new ConnectException("THROWING EXCEPTION, better be ready!"); } - int size = aclChangeSetQueue.size(); - long maxTime = 0L; - long maxId = 0L; + final AtomicLong maxTime = new AtomicLong(); + final AtomicLong maxId = new AtomicLong(); - if(fromCommitTime == null && toCommitTime == null) + if (fromCommitTime == null && toCommitTime == null) { - List aclChangeSetList = new ArrayList(); - for(int i=0; i= minAclChangeSetId && aclChangeSet.getId() < maxAclChangeSetId) - { - aclChangeSetList.add(aclChangeSet); - maxTime = Math.max(aclChangeSet.getCommitTimeMs(), maxTime); - maxId = Math.max(aclChangeSet.getId(), maxId); - } - - if(aclChangeSetList.size() == maxResults) { - break; - } - } - - return new AclChangeSets(aclChangeSetList, maxTime, maxId); + return new AclChangeSets( + ACL_CHANGE_SET_QUEUE.stream() + .filter(aclChangeSet -> aclChangeSet.getId() >= minAclChangeSetId && aclChangeSet.getId() < maxAclChangeSetId) + .limit(maxResults) + .peek(aclChangeSet -> { + maxTime.set(Math.max(aclChangeSet.getCommitTimeMs(), maxTime.get())); + maxId.set(Math.max(aclChangeSet.getId(), maxId.get()));}) + .collect(Collectors.toList()), maxTime.get(), maxId.get()); } - List aclChangeSetList = new ArrayList(); - - for(int i=0; i toCommitTime) - { - //We have not yet reached this alcChangeSet so break out of the loop - break; - } - else - { - aclChangeSetList.add(aclChangeSet); - maxTime = aclChangeSet.getCommitTimeMs(); - maxId = aclChangeSet.getId(); - - if(aclChangeSetList.size() == maxResults) - { - break; - } - } - } - - return new AclChangeSets(aclChangeSetList, maxTime, maxId); + return new AclChangeSets( + ACL_CHANGE_SET_QUEUE.stream() + .filter(aclChangeSet -> aclChangeSet.getCommitTimeMs() >= fromCommitTime && aclChangeSet.getCommitTimeMs() <= toCommitTime) + .limit(maxResults) + .peek(aclChangeSet -> { + maxTime.set(Math.max(aclChangeSet.getCommitTimeMs(), maxTime.get())); + maxId.set(Math.max(aclChangeSet.getId(), maxId.get()));}) + .collect(Collectors.toList()), maxTime.get(), maxId.get()); } /** @@ -140,173 +120,123 @@ public class SOLRAPIQueueClient extends SOLRAPIClient * @param maxResults the maximum number of results to retrieve * @return the ACLs (includes ChangeSet ID) */ - public List getAcls(List aclChangeSets, Long minAclId, int maxResults) throws AuthenticationException, IOException, JSONException + public List getAcls(List aclChangeSets, Long minAclId, int maxResults) throws IOException, JSONException { if(throwException) { throw new ConnectException("THROWING EXCEPTION, better be ready!"); } - List allAcls = new ArrayList(); - for(AclChangeSet aclChangeSet : aclChangeSets) - { - List aclList = aclMap.get(aclChangeSet.getId()); - allAcls.addAll(aclList); - } - return allAcls; + return aclChangeSets.stream() + .map(AclChangeSet::getId) + .map(ACL_MAP::get) + .flatMap(Collection::stream) + .collect(Collectors.toList()); } /** * Get the ACL readers for a given list of ACLs * - * @param acls the ACLs - * @return the readers for the ACLs + * @param acls the ACLs + * @return the readers for the ACLs */ - public List getAclReaders(List acls) throws AuthenticationException, IOException, JSONException + public List getAclReaders(List acls) throws IOException, JSONException { - if(throwException) { + if(throwException) + { throw new ConnectException("THROWING EXCEPTION, better be ready!"); } - List allAclReaders = new ArrayList(); - for(Acl acl : acls) - { - AclReaders aclReaders = aclReadersMap.get(acl.getId()); - allAclReaders.add(aclReaders); - } - return allAclReaders; + return acls.stream() + .map(Acl::getId) + .map(ACL_READERS_MAP::get) + .collect(Collectors.toList()); } - public List getModelsDiff(String coreName, List currentModels) throws AuthenticationException, IOException, JSONException + public List getModelsDiff(String coreName, List currentModels) throws IOException, JSONException { - if(throwException) { + if(throwException) + { throw new ConnectException("THROWING EXCEPTION, better be ready!"); } - return new ArrayList(); + return Collections.emptyList(); } - public Transactions getTransactions(Long fromCommitTime, Long minTxnId, Long toCommitTime, Long maxTxnId, int maxResults) throws AuthenticationException, IOException, JSONException + public Transactions getTransactions(Long fromCommitTime, Long minTxnId, Long toCommitTime, Long maxTxnId, int maxResults) throws IOException, JSONException { - if(throwException) { + if(throwException) + { throw new ConnectException("THROWING EXCEPTION, better be ready!"); } - try - { - return getTransactions(fromCommitTime, minTxnId, toCommitTime, maxTxnId, maxResults, null); - } - catch(EncoderException e) - { - throw new IOException(e); - } + + return getTransactions(fromCommitTime, minTxnId, toCommitTime, maxTxnId, maxResults, null); } - - - - public Transactions getTransactions(Long fromCommitTime, Long minTxnId, Long toCommitTime, Long maxTxnId, int maxResults, ShardState shardState) throws AuthenticationException, IOException, JSONException, EncoderException + public Transactions getTransactions(Long fromCommitTime, Long minTxnId, Long toCommitTime, Long maxTxnId, int maxResults, ShardState shardState) throws IOException, JSONException { - if(throwException) { + if(throwException) + { throw new ConnectException("THROWING EXCEPTION, better be ready!"); } - int size = transactionQueue.size(); + final AtomicLong maxTime = new AtomicLong(); + final AtomicLong maxId = new AtomicLong(); - long maxTime = 0L; - long maxId = 0L; - - if(fromCommitTime == null && toCommitTime == null) + if (fromCommitTime == null && toCommitTime == null) { - List transactionList = new ArrayList(); - - for(int i=0; i= minTxnId && txn.getId() < maxTxnId) - { - transactionList.add(txn); - maxTime = Math.max(txn.getCommitTimeMs(), maxTime); - maxId = Math.max(txn.getId(), maxId); - } - - if(transactionList.size() == maxResults) { - break; - } - } - - return new Transactions(transactionList, maxTime, maxId); + return new Transactions( + TRANSACTION_QUEUE.stream() + .filter(txn -> txn.getId() >= minTxnId && txn.getId() < maxTxnId) + .limit(maxResults) + .peek(txn -> { + maxTime.set(Math.max(txn.getCommitTimeMs(), maxTime.get())); + maxId.set(Math.max(txn.getId(), maxId.get()));}) + .collect(Collectors.toList()), maxTime.get(), maxId.get()); } - List transactionList = new ArrayList(); - - for(int i=0; i toCommitTime) - { - //We have not yet reached this transaction so break out of the loop - break; - } - else - { - //We have a transaction to work with - transactionList.add(txn); - maxTime = txn.getCommitTimeMs(); - maxId = txn.getId(); - - if(transactionList.size() == maxResults) - { - break; - } - } - } - - return new Transactions(transactionList, maxTime, maxId); + return new Transactions( + TRANSACTION_QUEUE.stream() + .filter(txn -> txn.getCommitTimeMs() >= fromCommitTime && txn.getCommitTimeMs() <= toCommitTime) + .limit(maxResults) + .peek(txn -> { + maxTime.set(Math.max(txn.getCommitTimeMs(), maxTime.get())); + maxId.set(Math.max(txn.getId(), maxId.get()));}) + .collect(Collectors.toList()), maxTime.get(), maxId.get()); } - public List getNodes(GetNodesParameters parameters, int maxResults) throws AuthenticationException, IOException, JSONException + public List getNodes(GetNodesParameters parameters, int maxResults) throws IOException, JSONException { - if(throwException) { + if(throwException) + { throw new ConnectException("THROWING EXCEPTION, better be ready!"); } - List txnIds = parameters.getTransactionIds(); - List allNodes = new ArrayList(); - for(long txnId : txnIds) - { - List nodes = nodeMap.get(txnId); - allNodes.addAll(nodes); - } - - return allNodes; + return parameters.getTransactionIds().stream() + .map(NODE_MAP::get) + .flatMap(Collection::stream) + .collect(Collectors.toList()); } - public List getNodesMetaData(NodeMetaDataParameters params, int maxResults) throws AuthenticationException, IOException, JSONException + public List getNodesMetaData(NodeMetaDataParameters params, int maxResults) throws IOException, JSONException { - if(throwException) { + if(throwException) + { throw new ConnectException("THROWING EXCEPTION, better be ready!"); } - List resultNodeMetaDatas = new ArrayList(); - List nodeIds = params.getNodeIds(); - if(nodeIds != null) { - for (long nodeId : nodeIds) { - NodeMetaData fullNodeMetadata = nodeMetaDataMap.get(nodeId); - NodeMetaData requestedMetadata = this.getOnlyRequestedMetadata(fullNodeMetadata, params); - resultNodeMetaDatas.add(requestedMetadata); - } - } else { - Long fromId = params.getFromNodeId(); - NodeMetaData fullNodeMetadata = nodeMetaDataMap.get(fromId); - NodeMetaData requestedMetadata = this.getOnlyRequestedMetadata(fullNodeMetadata, params); - resultNodeMetaDatas.add(requestedMetadata); - } - - return resultNodeMetaDatas; + return ofNullable(params.getNodeIds()) + .map(identifiers -> + identifiers.stream() + .map(NODE_META_DATA_MAP::get) + .map(metadata -> getOnlyRequestedMetadata(metadata, params)) + .collect(Collectors.toList())) + .orElseGet(() -> + ofNullable(params.getFromNodeId()) + .map(NODE_META_DATA_MAP::get) + .map(metadata -> getOnlyRequestedMetadata(metadata, params)) + .map(Collections::singletonList) + .orElseGet(Collections::emptyList)); } /** @@ -326,44 +256,54 @@ public class SOLRAPIQueueClient extends SOLRAPIClient { paramFiltered.setType(nodeMetaData.getType()); } + if (params.isIncludeAclId()) { paramFiltered.setAclId(nodeMetaData.getAclId()); } + if (params.isIncludeAspects()) { paramFiltered.setAspects(nodeMetaData.getAspects()); } + if (params.isIncludeProperties()) { paramFiltered.setProperties(nodeMetaData.getProperties()); } + if (params.isIncludeChildAssociations()) { paramFiltered.setChildAssocs(nodeMetaData.getChildAssocs()); } + if (params.isIncludeParentAssociations()) { paramFiltered.setParentAssocs(nodeMetaData.getParentAssocs()); paramFiltered.setParentAssocsCrc(nodeMetaData.getParentAssocsCrc()); } + if (params.isIncludeChildIds()) { paramFiltered.setChildIds(nodeMetaData.getChildIds()); } + if (params.isIncludePaths()) { paramFiltered.setPaths(nodeMetaData.getPaths()); paramFiltered.setNamePaths(nodeMetaData.getNamePaths()); } + if (params.isIncludeOwner()) { paramFiltered.setOwner(nodeMetaData.getOwner()); } + if (params.isIncludeNodeRef()) { paramFiltered.setNodeRef(nodeMetaData.getNodeRef()); } + if (params.isIncludeTxnId()) { paramFiltered.setTxnId(nodeMetaData.getTxnId()); @@ -377,55 +317,64 @@ public class SOLRAPIQueueClient extends SOLRAPIClient return paramFiltered; } - public GetTextContentResponse getTextContent(Long nodeId, QName propertyQName, Long modifiedSince) throws AuthenticationException, IOException + public GetTextContentResponse getTextContent(Long nodeId, QName propertyQName, Long modifiedSince) throws IOException { - if(throwException) { + if(throwException) + { throw new ConnectException("THROWING EXCEPTION, better be ready!"); } - //Just put the nodeId innto the content so we query for this in tests. - - if(nodeContentMap.containsKey(nodeId)) { - return new GetTextContentResponse(new DummyResponse(nodeContentMap.get(nodeId))); + if(NODE_CONTENT_MAP.containsKey(nodeId)) + { + return new GetTextContentResponse(new DummyResponse(NODE_CONTENT_MAP.get(nodeId))); } - return new GetTextContentResponse(new DummyResponse("Hello world "+nodeId)); + return new GetTextContentResponse(new DummyResponse("Hello world " + nodeId)); } - private class DummyResponse implements Response + private static class DummyResponse implements Response { - private String text; + private final String text; public DummyResponse(String text) { this.text = text; } + @Override public InputStream getContentAsStream() { return new ByteArrayInputStream(text.getBytes()); } - public int getStatus() { + @Override + public int getStatus() + { return HttpStatus.SC_OK; } + @Override public void release() { } - public String getHeader(String key) { + @Override + public String getHeader(String key) + { return null; } - public String getContentType() { + @Override + public String getContentType() + { return "text/html"; } } + @Override public void close() { - + // Nothing to be done here } }