[MNT-23072]

fix intermittend test failure
This commit is contained in:
Elia
2022-08-24 10:51:57 +02:00
parent d111a50252
commit e4bb483b29
2 changed files with 45 additions and 38 deletions

View File

@@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Search Services * Alfresco Search Services
* %% * %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited * Copyright (C) 2005 - 2022 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -23,7 +23,6 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.solr.tracker; package org.alfresco.solr.tracker;
import org.alfresco.solr.AbstractAlfrescoDistributedIT; import org.alfresco.solr.AbstractAlfrescoDistributedIT;
@@ -33,6 +32,7 @@ import org.alfresco.solr.client.AclChangeSet;
import org.alfresco.solr.client.AclReaders; import org.alfresco.solr.client.AclReaders;
import org.alfresco.solr.client.Node; import org.alfresco.solr.client.Node;
import org.alfresco.solr.client.NodeMetaData; import org.alfresco.solr.client.NodeMetaData;
import org.alfresco.solr.client.SOLRAPIQueueClient;
import org.alfresco.solr.client.Transaction; import org.alfresco.solr.client.Transaction;
import org.apache.lucene.index.Term; import org.apache.lucene.index.Term;
import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TermQuery;
@@ -56,7 +56,6 @@ import static org.alfresco.solr.AlfrescoSolrUtils.getNode;
import static org.alfresco.solr.AlfrescoSolrUtils.getNodeMetaData; import static org.alfresco.solr.AlfrescoSolrUtils.getNodeMetaData;
import static org.alfresco.solr.AlfrescoSolrUtils.getTransaction; import static org.alfresco.solr.AlfrescoSolrUtils.getTransaction;
import static org.alfresco.solr.AlfrescoSolrUtils.indexAclChangeSet; import static org.alfresco.solr.AlfrescoSolrUtils.indexAclChangeSet;
import static org.alfresco.solr.AlfrescoSolrUtils.list;
/** /**
* @author Joel * @author Joel
@@ -77,18 +76,23 @@ public class DistributedDbidRangeAlfrescoSolrTrackerIT extends AbstractAlfrescoD
} }
@After @After
public void deleteDataFromIndex() throws Exception { public void deleteDataFromIndex() throws Exception
{
SOLRAPIQueueClient.TRANSACTION_QUEUE.clear();
SOLRAPIQueueClient.NODE_MAP.clear();
deleteByQueryAllClients("*:*"); deleteByQueryAllClients("*:*");
waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 0, MAX_WAIT_TIME); waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 0, MAX_WAIT_TIME);
} }
private List<Acl> createAcls(int numAcls){ private List<Acl> createAcls(int numAcls)
{
AclChangeSet bulkAclChangeSet = getAclChangeSet(numAcls); AclChangeSet bulkAclChangeSet = getAclChangeSet(numAcls);
List<Acl> bulkAcls = new ArrayList<>(); List<Acl> bulkAcls = new ArrayList<>();
List<AclReaders> bulkAclReaders = new ArrayList<>(); List<AclReaders> bulkAclReaders = new ArrayList<>();
for(int i=0; i<numAcls; i++) { for(int i=0; i<numAcls; i++)
{
Acl bulkAcl = getAcl(bulkAclChangeSet); Acl bulkAcl = getAcl(bulkAclChangeSet);
bulkAcls.add(bulkAcl); bulkAcls.add(bulkAcl);
bulkAclReaders.add(getAclReaders(bulkAclChangeSet, bulkAclReaders.add(getAclReaders(bulkAclChangeSet,
@@ -138,38 +142,34 @@ public class DistributedDbidRangeAlfrescoSolrTrackerIT extends AbstractAlfrescoD
} }
@Test @Test
public void testIndexLastTransaction() throws Exception { public void testIndexLastTransaction() throws Exception
{
var acls = createAcls(1);
int txId = 0;
int numAcls = 1; // index 50 trx for each shard
var acls = createAcls(numAcls); for (int k = 0; k < 3; k++)
{
// first range for (int i = 0; i< 50; i++)
Transaction firstRange = getTransaction(0, 1); {
firstRange.setId(0); Transaction trx = getTransaction(0, 1);
var node = getNode( 5, firstRange, acls.get(0), Node.SolrApiNodeStatus.UPDATED ); trx.setId(txId++);
indexTransaction(firstRange, List.of(node), List.of(getNodeMetaData(node, firstRange, acls.get(0), "mike", null, false))); var node = getNode(k*100 + 10 + i, trx, acls.get(0), Node.SolrApiNodeStatus.UPDATED);
waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 1, MAX_WAIT_TIME); indexTransaction(trx, List.of(node), List.of(getNodeMetaData(node, trx, acls.get(0), "mike", null, false)));
}
// second range
Transaction secondRange = getTransaction(0, 1);
secondRange.setId(1);
node = getNode( 105, firstRange, acls.get(0), Node.SolrApiNodeStatus.UPDATED );
indexTransaction(secondRange, List.of(node), List.of(getNodeMetaData(node, secondRange, acls.get(0), "mike", null, false)));
waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 2, MAX_WAIT_TIME);
for (int i = 0; i< 50; i++){
Transaction trxThirdRange = getTransaction(0, 1);
trxThirdRange.setId(2 + i);
node = getNode( 230 + i, trxThirdRange, acls.get(0), Node.SolrApiNodeStatus.UPDATED );
indexTransaction(trxThirdRange, List.of(node), List.of(getNodeMetaData(node, trxThirdRange, acls.get(0), "mike", null, false)));
} }
waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 52, MAX_WAIT_TIME); waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 150, MAX_WAIT_TIME);
// Check all the shards have indexed the last transaction // Check all the shards have indexed the last transaction
assertShardCount(0, new TermQuery(new Term("S_TXID", "51")), 1); assertShardCount(0, new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 50);
assertShardCount(1, new TermQuery(new Term("S_TXID", "51")), 1); assertShardCount(1, new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 50);
assertShardCount(2, new TermQuery(new Term("S_TXID", "51")), 1); assertShardCount(2, new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 50);
// check the last transaction has been indexed in all the shards
assertShardCount(0, new TermQuery(new Term("S_TXID", "149")), 1);
assertShardCount(1, new TermQuery(new Term("S_TXID", "149")), 1);
assertShardCount(2, new TermQuery(new Term("S_TXID", "149")), 1);
} }
protected static Properties getShardMethod() protected static Properties getShardMethod()

View File

@@ -36,6 +36,7 @@ import java.net.ConnectException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -163,21 +164,27 @@ public class SOLRAPIQueueClient extends SOLRAPIClient
return Collections.emptyList(); return Collections.emptyList();
} }
public Long getNextTxCommitTime(String coreName, Long fromCommitTime) throws NoSuchMethodException { public Long getNextTxCommitTime(String coreName, Long fromCommitTime) throws NoSuchMethodException
{
throw new NoSuchMethodException(); throw new NoSuchMethodException();
} }
public Pair<Long, Long> getTxIntervalCommitTime(String coreName, Long fromNodeId, Long toNodeId) public Pair<Long, Long> getTxIntervalCommitTime(String coreName, Long fromNodeId, Long toNodeId)
{ {
List<Transaction> transactions = TRANSACTION_QUEUE.stream() List<Long> transactionCommitTimestamps = TRANSACTION_QUEUE.stream()
.filter(txn -> NODE_MAP.get(txn.getId()) .filter(txn -> NODE_MAP.get(txn.getId())
.stream() .stream()
.anyMatch(node -> node.getId() >= fromNodeId && node.getId() <= toNodeId)) .anyMatch(node -> node.getId() >= fromNodeId && node.getId() <= toNodeId))
.map(tx -> tx.getCommitTimeMs())
.sorted()
.collect(Collectors.toList()); .collect(Collectors.toList());
if (transactions.size() > 0){ if (transactionCommitTimestamps.size() > 0)
return new Pair<>(transactions.get(0).getCommitTimeMs(), transactions.get(transactions.size() - 1).getCommitTimeMs()); {
} else { return new Pair<>( transactionCommitTimestamps.get(0), transactionCommitTimestamps.get(transactionCommitTimestamps.size() - 1));
}
else
{
return new Pair<>(-1l, -1l); return new Pair<>(-1l, -1l);
} }
} }