@Test public void testAllAndAtLeastOne() { QuorumCheck q = QuorumChecks.atLeastOne(); Assert.assertFalse(q.isQuorate(0, 2)); Assert.assertTrue(q.isQuorate(1, 2)); Assert.assertFalse(q.isQuorate(0, 0)); }
@Test public void testAtLeastOne() { QuorumCheck q = QuorumChecks.atLeastOne(); Assert.assertTrue(q.isQuorate(2, 2)); Assert.assertTrue(q.isQuorate(1, 2)); Assert.assertFalse(q.isQuorate(0, 0)); }
@Test(groups="Broken") public void testStartsThenChildFailsButWithQuorumCausesAppToStayHealthy() throws Exception { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class) .configure(StartableApplication.UP_QUORUM_CHECK, QuorumCheck.QuorumChecks.atLeastOne()) .configure(StartableApplication.RUNNING_QUORUM_CHECK, QuorumCheck.QuorumChecks.atLeastOne()) .child(EntitySpec.create(TestEntity.class)) .child(EntitySpec.create(TestEntity.class))); TestEntity child = (TestEntity) Iterables.get(app.getChildren(), 0); app.start(ImmutableList.<Location>of()); assertUpAndRunningEventually(app); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(child, "myIndicator", "Simulate not-up of child"); assertUpAndRunningEventually(app); }
appChildrenBasedEnricher.config().set(ComputeServiceIndicatorsFromChildrenAndMembers.UP_QUORUM_CHECK, QuorumChecks.atLeastOne()); assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPED); assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, false);
@Test public void testStartWithQuorumOneSecondChildFails() throws Exception { app = mgmt.getEntityManager().createEntity(EntitySpec.create(AsyncApplication.class) .configure(AsyncApplication.RUNNING_QUORUM_CHECK, QuorumChecks.atLeastOne()) .configure(AsyncApplication.UP_QUORUM_CHECK, QuorumChecks.atLeastOne())); AsyncEntity child1 = app.addChild(EntitySpec.create(AsyncEntity.class)); AsyncEntity child2 = app.addChild(EntitySpec.create(AsyncEntity.class)); app.start(ImmutableList.of()); assertStateEventually(app, Lifecycle.STARTING, Lifecycle.STARTING, false); // First child starts child1.clearNotUpIndicators(); child1.setExpected(Lifecycle.RUNNING); assertStateEventually(child1, Lifecycle.RUNNING, Lifecycle.RUNNING, true); assertStateEventually(child2, Lifecycle.STARTING, Lifecycle.STARTING, false); assertStateEventually(app, Lifecycle.STARTING, Lifecycle.RUNNING, true); // Seconds child starts child2.addNotUpIndicator("simulatedFailure", "my failure"); child2.setExpected(Lifecycle.RUNNING); assertStateEventually(child1, Lifecycle.RUNNING, Lifecycle.RUNNING, true); assertStateEventually(child2, Lifecycle.RUNNING, Lifecycle.ON_FIRE, false); assertStateEventually(app, Lifecycle.RUNNING, Lifecycle.RUNNING, true); }
@Test public void testStartWithQuorumOne() throws Exception { app = mgmt.getEntityManager().createEntity(EntitySpec.create(AsyncApplication.class) .configure(AsyncApplication.RUNNING_QUORUM_CHECK, QuorumChecks.atLeastOne()) .configure(AsyncApplication.UP_QUORUM_CHECK, QuorumChecks.atLeastOne())); AsyncEntity child1 = app.addChild(EntitySpec.create(AsyncEntity.class)); AsyncEntity child2 = app.addChild(EntitySpec.create(AsyncEntity.class)); app.start(ImmutableList.of()); assertStateEventually(app, Lifecycle.STARTING, Lifecycle.STARTING, false); // First child starts child1.clearNotUpIndicators(); child1.setExpected(Lifecycle.RUNNING); assertStateEventually(child1, Lifecycle.RUNNING, Lifecycle.RUNNING, true); assertStateEventually(child2, Lifecycle.STARTING, Lifecycle.STARTING, false); assertStateEventually(app, Lifecycle.STARTING, Lifecycle.RUNNING, true); // Seconds child starts child2.clearNotUpIndicators(); child2.setExpected(Lifecycle.RUNNING); assertStateEventually(child1, Lifecycle.RUNNING, Lifecycle.RUNNING, true); assertStateEventually(child2, Lifecycle.RUNNING, Lifecycle.RUNNING, true); assertStateEventually(app, Lifecycle.RUNNING, Lifecycle.RUNNING, true); }
@Test(groups="Broken") public void testStartsThenChildFailsButWithQuorumCausesAppToSucceed() throws Exception { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class) .configure(StartableApplication.UP_QUORUM_CHECK, QuorumCheck.QuorumChecks.atLeastOne()) .configure(StartableApplication.RUNNING_QUORUM_CHECK, QuorumCheck.QuorumChecks.atLeastOne()) .child(EntitySpec.create(TestEntity.class)) .child(EntitySpec.create(TestEntity.class))); TestEntity child = (TestEntity) Iterables.get(app.getChildren(), 0); app.start(ImmutableList.<Location>of()); assertUpAndRunningEventually(app); for (Entity childr : app.getChildren()) { EntityAsserts.assertAttributeEquals(childr, TestEntity.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); } ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(child, "myIndicator", "Simulate not-up of child"); assertHealthContinually(app, Lifecycle.RUNNING, true); mgmt.getEntityManager().unmanage(app); }
@Test public void testStartWithQuorumOneFirstChildFails() throws Exception { app = mgmt.getEntityManager().createEntity(EntitySpec.create(AsyncApplication.class) .configure(AsyncApplication.RUNNING_QUORUM_CHECK, QuorumChecks.atLeastOne()) .configure(AsyncApplication.UP_QUORUM_CHECK, QuorumChecks.atLeastOne())); AsyncEntity child1 = app.addChild(EntitySpec.create(AsyncEntity.class)); AsyncEntity child2 = app.addChild(EntitySpec.create(AsyncEntity.class)); app.start(ImmutableList.of()); assertStateEventually(app, Lifecycle.STARTING, Lifecycle.STARTING, false); // First child starts child1.addNotUpIndicator("simulatedFailure", "my failure"); child1.setExpected(Lifecycle.RUNNING); assertStateEventually(child1, Lifecycle.RUNNING, Lifecycle.ON_FIRE, false); assertStateEventually(child2, Lifecycle.STARTING, Lifecycle.STARTING, false); assertStateEventually(app, Lifecycle.STARTING, Lifecycle.STARTING, false); // Seconds child starts child2.clearNotUpIndicators(); child2.setExpected(Lifecycle.RUNNING); assertStateEventually(child1, Lifecycle.RUNNING, Lifecycle.ON_FIRE, false); assertStateEventually(child2, Lifecycle.RUNNING, Lifecycle.RUNNING, true); assertStateEventually(app, Lifecycle.RUNNING, Lifecycle.RUNNING, true); }
@Test(groups="Broken") public void testChildFailuresOnStartButWithQuorumCausesAppToSucceed() throws Exception { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class) .configure(StartableApplication.UP_QUORUM_CHECK, QuorumCheck.QuorumChecks.atLeastOne()) .configure(StartableApplication.RUNNING_QUORUM_CHECK, QuorumCheck.QuorumChecks.atLeastOne()) .child(EntitySpec.create(TestEntity.class)) .child(EntitySpec.create(FailingEntity.class) .configure(FailingEntity.FAIL_ON_START, true))); startAndAssertException(app, ImmutableList.<Location>of()); assertUpAndRunningEventually(app); }
/** Returns a predicate for a collection which is true if * there is at least one element in the collection given to the predicate * which satisfies the predicate given here. */ public static <T,TT extends Iterable<T>> Predicate<TT> any(Predicate<T> attributeSatisfies) { // implementation could be more efficient -- ie succeed fast return quorum(QuorumChecks.atLeastOne(), attributeSatisfies); }