@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
    }
  }