From 3ab403e0b07b439f245ce79b04bb45ca40afccfb Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 28 Jul 2016 15:23:24 -0400 Subject: [PATCH] SEARCH-67: Improved AlfrescoSolrReloadTest --- .../org/alfresco/solr/AlfrescoSolrUtils.java | 24 ++- .../solr/test/AlfrescoSolrReloadTest.java | 142 +++++------------- 2 files changed, 58 insertions(+), 108 deletions(-) diff --git a/search-services/alfresco-solr/src/test/java/org/alfresco/solr/AlfrescoSolrUtils.java b/search-services/alfresco-solr/src/test/java/org/alfresco/solr/AlfrescoSolrUtils.java index d93a9bee3..21ea32efc 100644 --- a/search-services/alfresco-solr/src/test/java/org/alfresco/solr/AlfrescoSolrUtils.java +++ b/search-services/alfresco-solr/src/test/java/org/alfresco/solr/AlfrescoSolrUtils.java @@ -104,7 +104,7 @@ public class AlfrescoSolrUtils */ public static Transaction getTransaction(int deletes, int updates) { - long txnCommitTime = generateId(); + long txnCommitTime = System.currentTimeMillis(); Transaction transaction = new Transaction(); transaction.setCommitTimeMs(txnCommitTime); transaction.setId(generateId()); @@ -112,6 +112,19 @@ public class AlfrescoSolrUtils transaction.setUpdates(updates); return transaction; } + + public static Transaction getTransaction(int deletes, int updates, long id) + { + long txnCommitTime = System.currentTimeMillis(); + Transaction transaction = new Transaction(); + transaction.setCommitTimeMs(txnCommitTime); + transaction.setId(id); + transaction.setDeletes(deletes); + transaction.setUpdates(updates); + return transaction; + } + + /** * Get a node. * @param txn @@ -225,6 +238,13 @@ public class AlfrescoSolrUtils AclChangeSet aclChangeSet = new AclChangeSet(generateId(), System.currentTimeMillis(), aclCount); return aclChangeSet; } + + public static AclChangeSet getAclChangeSet(int aclCount, long id) + { + AclChangeSet aclChangeSet = new AclChangeSet(id, System.currentTimeMillis(), aclCount); + return aclChangeSet; + } + private static AtomicLong id = new AtomicLong(System.currentTimeMillis()); /** * Creates a unique id. @@ -241,7 +261,6 @@ public class AlfrescoSolrUtils * @param doc the Document to add * @param args 0th and Even numbered args are param names, Odds are param values. * @see #add - * @see #doc */ public static String add(XmlDoc doc, String... args) { @@ -550,7 +569,6 @@ public class AlfrescoSolrUtils } /** * Add an acl. - * @param solrQueryRequest * @param core * @param dataModel * @param acltxid diff --git a/search-services/alfresco-solr/src/test/java/org/alfresco/solr/test/AlfrescoSolrReloadTest.java b/search-services/alfresco-solr/src/test/java/org/alfresco/solr/test/AlfrescoSolrReloadTest.java index 723ea896b..b8d20fb6c 100644 --- a/search-services/alfresco-solr/src/test/java/org/alfresco/solr/test/AlfrescoSolrReloadTest.java +++ b/search-services/alfresco-solr/src/test/java/org/alfresco/solr/test/AlfrescoSolrReloadTest.java @@ -49,42 +49,11 @@ public class AlfrescoSolrReloadTest extends AbstractAlfrescoSolrTests { private static long MAX_WAIT_TIME = 80000; static AlfrescoCoreAdminHandler admin; - private static NodeRef rootNodeRef; - private static NodeRef n01NodeRef; @BeforeClass public static void beforeClass() throws Exception { initAlfrescoCore("solrconfig-afts.xml", "schema-afts.xml"); - admin = (AlfrescoCoreAdminHandler) h.getCoreContainer().getMultiCoreHandler(); - - // Root - SolrCore core = h.getCore(); - AlfrescoSolrDataModel dataModel = AlfrescoSolrDataModel.getInstance(); - dataModel.setCMDefaultUri(); - - rootNodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID()); - addStoreRoot(core, dataModel, rootNodeRef, 1, 1, 1, 1); - - // 1 - n01NodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID()); - QName n01QName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "one"); - ChildAssociationRef n01CAR = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, n01QName, - n01NodeRef, true, 0); - - Map testProperties = new HashMap(); - Date orderDate = new Date(); - testProperties.put(createdDate, - new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, orderDate))); - testProperties.put(createdTime, - new StringPropertyValue(DefaultTypeConverter.INSTANCE.convert(String.class, orderDate))); - testProperties.put(ContentModel.PROP_CONTENT, new StringPropertyValue("lettice and cabbage")); - testProperties.put(ContentModel.PROP_NAME, new StringPropertyValue("reload")); - - addNode(core, dataModel, 1, 2, 1, testSuperType, null, testProperties, null, "andy", - new ChildAssociationRef[]{n01CAR}, new NodeRef[]{rootNodeRef}, new String[]{"/" - + n01QName.toString()}, n01NodeRef, true); - - testNodeRef = n01NodeRef; + admin = (AlfrescoCoreAdminHandler)h.getCore().getCoreDescriptor().getCoreContainer().getMultiCoreHandler(); } @After @@ -98,51 +67,55 @@ public class AlfrescoSolrReloadTest extends AbstractAlfrescoSolrTests { } @Test - public void testReloadUsingNodes() throws Exception { + public void testReload() throws Exception { + long localId = 0L; logger.info("######### Starting tracker reload test NODES ###########"); - assertAQuery("PATH:\"/\"", 1); - assertAQuery("TYPE:\"" + testSuperType + "\"", 1); + AclChangeSet aclChangeSet = getAclChangeSet(1, ++localId); + + Acl acl = getAcl(aclChangeSet); + + AclReaders aclReaders = getAclReaders(aclChangeSet, acl, list("joel"), list("phil"), null); + + indexAclChangeSet(aclChangeSet, + list(acl), + list(aclReaders)); + + int numNodes = 1000; + List nodes = new ArrayList(); + List nodeMetaDatas = new ArrayList(); + + Transaction bigTxn = getTransaction(0, numNodes, ++localId); + + for(int i=0; i trackers = getTrackers(); int numOfTrackers = trackers.size(); int jobs = getJobsCount(); - addNodes(1, 10); - assertAQuery("TYPE:\"" + testSuperType + "\"", 10); - reloadAndAssertCorrect(trackers, numOfTrackers, jobs); - addNodes(10, 21); - assertAQuery("TYPE:\"" + testSuperType + "\"", 21); - } + Transaction bigTxn2 = getTransaction(0, numNodes, ++localId); - @Test - public void testReloadUsingAcls() throws Exception { + for(int i=0; i trackers = getTrackers(); - int numOfTrackers = trackers.size(); - int jobs = getJobsCount(); - - indexAndVerify(250, 251); - - reloadAndAssertCorrect(trackers, numOfTrackers, jobs); - - //This is a bit of a hack to skip integrity checking. This is because our test client doesn't correctly - //similate the Alfresco repo. This "hack" doesn't invalidate the test. - Optional aTracker = getTrackers().stream().filter(tracker -> tracker.getClass().equals(AclTracker.class)).findFirst(); - aTracker.ifPresent(foundTracker -> - { - AclTracker aclTracker = (AclTracker) foundTracker; - aclTracker.getTrackerState().setCheckedLastAclTransactionTime(true); - aclTracker.getTrackerState().setCheckedFirstAclTransactionTime(true); - logger.info("Changed CheckedLastAclTransactionTime for " + aclTracker.getClass().getSimpleName() + " " + aclTracker.hashCode()); - aclTracker.track(); - }); + indexTransaction(bigTxn2, nodes, nodeMetaDatas); + waitForDocCount(new TermQuery(new Term("content@s___t@{http://www.alfresco.org/model/content/1.0}content", "world")), 2000, 100000); } private void reloadAndAssertCorrect(Collection trackers, int numOfTrackers, int jobs) throws Exception { @@ -162,46 +135,6 @@ public class AlfrescoSolrReloadTest extends AbstractAlfrescoSolrTests { }); } - - private void addNodes(int startInclusive, int endExclusive) { - IntStream.range(startInclusive, endExclusive).forEach(i -> - { - NodeRef newNodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID()); - QName n2Name = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "loop"+i); - ChildAssociationRef childAssoc = new ChildAssociationRef(ContentModel.ASSOC_CHILDREN, rootNodeRef, n2Name, newNodeRef, true, 0); - try { - addNode(h.getCore(), dataModel, 1+i, 2+i, 1+i, testSuperType, null, null, null, "andy", - new ChildAssociationRef[]{childAssoc}, new NodeRef[]{rootNodeRef}, new String[]{"/"+ n2Name.toString()}, - newNodeRef, true); - } catch (IOException e) { - e.printStackTrace(); - } - } - ); - } - - private void indexAndVerify(int numAcls, int expected) throws Exception { - - AclChangeSet bulkAclChangeSet = getAclChangeSet(numAcls); - - List bulkAcls = new ArrayList(); - List bulkAclReaders = new ArrayList(); - - for(int i=0; i