/** * this method will call initialize for each message, since we are caching the entity indexes, we * don't worry about aggregating by app id * * @param indexOperationMessage */ private void initializeEntityIndexes(final IndexOperationMessage indexOperationMessage) { // create a set so we can have a unique list of appIds for which we call createEntityIndex Set<UUID> appIds = new HashSet<>(); // loop through all indexRequests and add the appIds to the set indexOperationMessage .getIndexRequests() .forEach( req -> { UUID appId = IndexingUtils.getApplicationIdFromIndexDocId(req.documentId); appIds.add(appId); }); // loop through all deindexRequests and add the appIds to the set indexOperationMessage .getDeIndexRequests() .forEach( req -> { UUID appId = IndexingUtils.getApplicationIdFromIndexDocId(req.documentId); appIds.add(appId); }); // for each of the appIds in the unique set, call create entity index to ensure the aliases are // created appIds.forEach( appId -> { ApplicationScope appScope = CpNamingUtils.getApplicationScope(appId); entityIndexFactory.createEntityIndex( indexLocationStrategyFactory.getIndexLocationStrategy(appScope)); }); }
@Test public void testDeletes() throws Exception { EntityManager entityManager = this.app.getEntityManager(); Map<String, Object> map = new HashMap<>(); for (int i = 0; i < 10; i++) { map.put("somekey", UUID.randomUUID()); Entity entity = entityManager.create("tests", map); } this.app.refreshIndex(); Thread.sleep(500); ApplicationScope appScope = CpNamingUtils.getApplicationScope(entityManager.getApplicationId()); Observable<Id> ids = this.app.getApplicationService().deleteAllEntities(appScope, 5); int count = ids.count().toBlocking().last(); Assert.assertEquals(count, 5); ids = this.app.getApplicationService().deleteAllEntities(appScope, 5); count = ids.count().toBlocking().last(); Assert.assertEquals(count, 5); this.app.refreshIndex(); Thread.sleep(5000); Injector injector = SpringResource.getInstance().getBean(Injector.class); GraphManagerFactory factory = injector.getInstance(GraphManagerFactory.class); GraphManager graphManager = factory.createEdgeManager(appScope); SimpleSearchByEdgeType simpleSearchByEdgeType = new SimpleSearchByEdgeType( appScope.getApplication(), CpNamingUtils.getEdgeTypeFromCollectionName("tests"), Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.<Edge>absent()); Iterator<Edge> results = graphManager.loadEdgesFromSource(simpleSearchByEdgeType).toBlocking().getIterator(); if (results.hasNext()) { Assert.fail("should be empty"); } else { Results searchCollection = entityManager.searchCollection(entityManager.getApplication(), "tests", Query.all()); Assert.assertEquals(searchCollection.size(), 0); AggregationServiceFactory aggregationServiceFactory = injector.getInstance(AggregationServiceFactory.class); long size = aggregationServiceFactory.getAggregationService().getCollectionSize(appScope, "tests"); Assert.assertEquals(size, 0); // success } }