public RequestValidator() { ElasticSearchAdmin esa = Framework.getLocalService(ElasticSearchAdmin.class); indexTypes = new HashMap<>(); for (String name : esa.getRepositoryNames()) { List<String> types = new ArrayList<>(); types.add(ElasticSearchConstants.DOC_TYPE); indexTypes.put(esa.getIndexNameForRepository(name), types); } }
public void startTransaction() { if (syncMode) { ElasticSearchInlineListener.useSyncIndexing.set(true); } if (!TransactionHelper.isTransactionActive()) { TransactionHelper.startTransaction(); } Assert.assertEquals(0, esa.getPendingWorkerCount()); commandProcessed = esa.getTotalCommandProcessed(); }
@Test public void shouldUnIndexSubTree() throws Exception { buildAndIndexTree(); DocumentRef ref = new PathRef("/folder0/folder1/folder2"); Assert.assertTrue(session.exists(ref)); startTransaction(); session.removeDocument(ref); TransactionHelper.commitOrRollbackTransaction(); waitForCompletion(); assertNumberOfCommandProcessed(1); startTransaction(); SearchResponse searchResponse = esa.getClient() .prepareSearch(IDX_NAME) .setTypes(TYPE_NAME) .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setFrom(0) .setSize(60) .execute() .actionGet(); Assert.assertEquals(2, searchResponse.getHits().getTotalHits()); }
protected void flushAndSync() throws Exception { TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(); Assert.assertTrue(Framework.getLocalService(AuditLogger.class).await(10, TimeUnit.SECONDS)); esa.getClient() .admin() .indices() .prepareFlush(esa.getIndexNameForType(ElasticSearchConstants.ENTRY_TYPE)) .execute() .actionGet(); esa.getClient() .admin() .indices() .prepareRefresh(esa.getIndexNameForType(ElasticSearchConstants.ENTRY_TYPE)) .execute() .actionGet(); }
@Test public void shouldIndexTree() throws Exception { buildAndIndexTree(); // check sub tree search SearchResponse searchResponse = esa.getClient() .prepareSearch(IDX_NAME) .setTypes(TYPE_NAME) .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setQuery(QueryBuilders.prefixQuery("ecm:path", "/folder0/folder1/folder2")) .execute() .actionGet(); Assert.assertEquals(8, searchResponse.getHits().getTotalHits()); }
protected void buildAndIndexTree() throws Exception { startTransaction(); buildTree(); TransactionHelper.commitOrRollbackTransaction(); waitForCompletion(); assertNumberOfCommandProcessed(10); startTransaction(); // check indexing at ES level SearchResponse searchResponse = esa.getClient() .prepareSearch(IDX_NAME) .setTypes(TYPE_NAME) .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setFrom(0) .setSize(60) .execute() .actionGet(); Assert.assertEquals(10, searchResponse.getHits().getTotalHits()); }
/** Wait for async worker completion then wait for indexing completion */ public void waitForCompletion() throws Exception { workManager.awaitCompletion(20, TimeUnit.SECONDS); esa.prepareWaitForIndexing().get(20, TimeUnit.SECONDS); esa.refresh(); }
public void assertNumberOfCommandProcessed(int processed) throws Exception { Assert.assertEquals(processed, esa.getTotalCommandProcessed() - commandProcessed); }
@Test public void shouldIndexMovedSubTree() throws Exception { buildAndIndexTree(); startTransaction(); DocumentRef ref = new PathRef("/folder0/folder1/folder2"); Assert.assertTrue(session.exists(ref)); DocumentModel doc = session.getDocument(ref); // move in the same folder : rename session.move(ref, doc.getParentRef(), "folderA"); TransactionHelper.commitOrRollbackTransaction(); waitForCompletion(); if (syncMode) { // in sync we split recursive update into 2 commands: // 1 sync non recurse + 1 async recursive assertNumberOfCommandProcessed(9); } else { assertNumberOfCommandProcessed(8); } startTransaction(); SearchResponse searchResponse = esa.getClient() .prepareSearch(IDX_NAME) .setTypes(TYPE_NAME) .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setFrom(0) .setSize(60) .execute() .actionGet(); Assert.assertEquals(10, searchResponse.getHits().getTotalHits()); // check sub tree search searchResponse = esa.getClient() .prepareSearch(IDX_NAME) .setTypes(TYPE_NAME) .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setQuery(QueryBuilders.prefixQuery("ecm:path", "/folder0/folder1/folder2")) .execute() .actionGet(); Assert.assertEquals(0, searchResponse.getHits().getTotalHits()); searchResponse = esa.getClient() .prepareSearch(IDX_NAME) .setTypes(TYPE_NAME) .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setQuery(QueryBuilders.prefixQuery("ecm:path", "/folder0/folder1/folderA")) .execute() .actionGet(); Assert.assertEquals(8, searchResponse.getHits().getTotalHits()); searchResponse = esa.getClient() .prepareSearch(IDX_NAME) .setTypes(TYPE_NAME) .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setQuery(QueryBuilders.prefixQuery("ecm:path", "/folder0/folder1")) .execute() .actionGet(); Assert.assertEquals(9, searchResponse.getHits().getTotalHits()); }
@Before public void setUpMapping() throws Exception { esa.initIndexes(true); }
@Before public void setupIndex() throws Exception { esa.initIndexes(true); }