@Override public Collection<Entity> getEntitiesInApplication(Application application) { if (isInitialManagementContextReal()) { return initialManagementContext.getEntityManager().getEntitiesInApplication(application); } else { return Collections.emptyList(); } }
@Test(groups = "Integration") private void testReadAndWriteDifferentRouters() { MongoDBShardedDeployment deployment = makeAndStartDeployment(); EntityAsserts.assertAttributeEqualsEventually(deployment, Startable.SERVICE_UP, true); MongoDBRouter router1 = (MongoDBRouter) Iterables.get(deployment.getRouterCluster().getMembers(), 0); MongoDBRouter router2 = (MongoDBRouter) Iterables.get(deployment.getRouterCluster().getMembers(), 1); EntityAsserts.assertAttributeEqualsEventually(router1, Startable.SERVICE_UP, true); EntityAsserts.assertAttributeEqualsEventually(router2, Startable.SERVICE_UP, true); String documentId = MongoDBTestHelper.insert(router1, "meaning-of-life", 42); DBObject docOut = MongoDBTestHelper.getById(router2, documentId); Assert.assertEquals(docOut.get("meaning-of-life"), 42); for (Entity entity : Iterables.filter(app.getManagementContext().getEntityManager().getEntitiesInApplication(app), AbstractMongoDBServer.class)) { EntityAsserts.assertAttributeEqualsEventually(entity, Startable.SERVICE_UP, true); } }
@Test public void testGetEntities() { TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)); TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); TestEntity child = entity.createAndManageChild(EntitySpec.create(TestEntity.class)); Asserts.assertEqualsIgnoringOrder(entityManager.getEntitiesInApplication(app), ImmutableList.of(app, entity, child)); Asserts.assertEqualsIgnoringOrder(entityManager.getEntities(), ImmutableList.of(app, entity, child, app2)); Asserts.assertEqualsIgnoringOrder(entityManager.findEntities(Predicates.instanceOf(TestApplication.class)), ImmutableList.of(app, app2)); Asserts.assertEqualsIgnoringOrder(entityManager.findEntitiesInApplication(app, Predicates.instanceOf(TestApplication.class)), ImmutableList.of(app)); }