[ SEARCH-2090 ] SolrQueueAPIClient refactoring + SolrInformationServer fix

This commit is contained in:
agazzarini
2020-03-10 10:46:24 +01:00
parent c3e670480b
commit 7bbe648979
15 changed files with 230 additions and 285 deletions
@@ -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);
}
@@ -732,33 +732,33 @@ public abstract class AbstractAlfrescoDistributedIT extends SolrITInitializer
public static void indexTransaction(Transaction transaction, List<Node> nodes, List<NodeMetaData> 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<Node> nodes, List<NodeMetaData> nodeMetaDatas, List<String> 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);
}
/**
@@ -622,33 +622,33 @@ public abstract class AbstractAlfrescoSolrIT implements SolrTestFiles, AlfrescoS
public static void indexTransaction(Transaction transaction, List<Node> nodes, List<NodeMetaData> 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<Node> nodes, List<NodeMetaData> nodeMetaDatas, List<String> 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);
}
@@ -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
@@ -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<Node> nodes, List<NodeMetaData> 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<Acl> aclList, List<AclReaders> 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.
@@ -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
@@ -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();
}
/**
@@ -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
@@ -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());
@@ -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();
}
@@ -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();
}
@@ -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();
@@ -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
@@ -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();
}
/**
@@ -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<AclChangeSet> aclChangeSetQueue = Collections.synchronizedList(new ArrayList());
public static Map<Long, List<Acl>> aclMap = Collections.synchronizedMap(new HashMap());
public static Map<Long, AclReaders> aclReadersMap = Collections.synchronizedMap(new HashMap());
public final static List<AclChangeSet> ACL_CHANGE_SET_QUEUE = Collections.synchronizedList(new ArrayList<>());
public final static Map<Long, List<Acl>> ACL_MAP = Collections.synchronizedMap(new HashMap<>());
public final static Map<Long, AclReaders> ACL_READERS_MAP = Collections.synchronizedMap(new HashMap<>());
public static List<Transaction> transactionQueue = Collections.synchronizedList(new ArrayList());
public static Map<Long, List<Node>> nodeMap = Collections.synchronizedMap(new HashMap());
public static Map<Long, NodeMetaData> nodeMetaDataMap = Collections.synchronizedMap(new HashMap());
public static Map<Long, String> nodeContentMap = Collections.synchronizedMap(new HashMap());
public final static List<Transaction> TRANSACTION_QUEUE = Collections.synchronizedList(new ArrayList<>());
public final static Map<Long, List<Node>> NODE_MAP = Collections.synchronizedMap(new HashMap<>());
public final static Map<Long, NodeMetaData> NODE_META_DATA_MAP = Collections.synchronizedMap(new HashMap<>());
public final static Map<Long, String> 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<AclChangeSet> aclChangeSetList = new ArrayList();
for(int i=0; i<size; i++)
{
AclChangeSet aclChangeSet = aclChangeSetQueue.get(i);
if(aclChangeSet.getId() >= 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<AclChangeSet> aclChangeSetList = new ArrayList();
for(int i=0; i<size; i++)
{
AclChangeSet aclChangeSet = aclChangeSetQueue.get(i);
if(aclChangeSet.getCommitTimeMs() < fromCommitTime)
{
//We have moved beyond this aclChangeSet
}
else if(aclChangeSet.getCommitTimeMs() > 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<Acl> getAcls(List<AclChangeSet> aclChangeSets, Long minAclId, int maxResults) throws AuthenticationException, IOException, JSONException
public List<Acl> getAcls(List<AclChangeSet> aclChangeSets, Long minAclId, int maxResults) throws IOException, JSONException
{
if(throwException) {
throw new ConnectException("THROWING EXCEPTION, better be ready!");
}
List<Acl> 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<AclReaders> getAclReaders(List<Acl> acls) throws AuthenticationException, IOException, JSONException
public List<AclReaders> getAclReaders(List<Acl> acls) throws IOException, JSONException
{
if(throwException) {
if(throwException)
{
throw new ConnectException("THROWING EXCEPTION, better be ready!");
}
List<AclReaders> 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<AlfrescoModelDiff> getModelsDiff(String coreName, List<AlfrescoModel> currentModels) throws AuthenticationException, IOException, JSONException
public List<AlfrescoModelDiff> getModelsDiff(String coreName, List<AlfrescoModel> 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<Transaction> transactionList = new ArrayList();
for(int i=0; i<size; i++)
{
Transaction txn = transactionQueue.get(i);
if(txn.getId() >= 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<Transaction> transactionList = new ArrayList();
for(int i=0; i<size; i++)
{
Transaction txn = transactionQueue.get(i);
if(txn.getCommitTimeMs() < fromCommitTime)
{
//We have moved beyond this transaction.
}
else if(txn.getCommitTimeMs() > 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<Node> getNodes(GetNodesParameters parameters, int maxResults) throws AuthenticationException, IOException, JSONException
public List<Node> getNodes(GetNodesParameters parameters, int maxResults) throws IOException, JSONException
{
if(throwException) {
if(throwException)
{
throw new ConnectException("THROWING EXCEPTION, better be ready!");
}
List<Long> txnIds = parameters.getTransactionIds();
List<Node> allNodes = new ArrayList();
for(long txnId : txnIds)
{
List<Node> 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<NodeMetaData> getNodesMetaData(NodeMetaDataParameters params, int maxResults) throws AuthenticationException, IOException, JSONException
public List<NodeMetaData> getNodesMetaData(NodeMetaDataParameters params, int maxResults) throws IOException, JSONException
{
if(throwException) {
if(throwException)
{
throw new ConnectException("THROWING EXCEPTION, better be ready!");
}
List<NodeMetaData> resultNodeMetaDatas = new ArrayList();
List<Long> 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
}
}