public static void assertGroupSizeEqualsEventually(final Group group, int expected) { assertGroupSizeEqualsEventually(ImmutableMap.of(), group, expected); }
@Override public void run() { EntityAsserts.assertGroupSizeEqualsEventually(stooges, 0); } });
@Override public void run() { EntityAsserts.assertGroupSizeEqualsEventually(ImmutableMap.of("timeout", "2s"), stooges, 3); } });
@Test public void testAutoScalerResizesAfterRebind() throws Exception { origCluster.start(ImmutableList.of(origLoc)); origCluster.policies().add(AutoScalerPolicy.builder() .name("myname") .metric(METRIC_SENSOR) .entityWithMetric(origCluster) .metricUpperBound(10) .metricLowerBound(100) .minPoolSize(1) .maxPoolSize(3) .buildSpec()); TestApplication newApp = rebind(); DynamicCluster newCluster = (DynamicCluster) Iterables.getOnlyElement(newApp.getChildren()); assertEquals(newCluster.getCurrentSize(), (Integer)1); ((EntityInternal)newCluster).sensors().set(METRIC_SENSOR, 1000); EntityAsserts.assertGroupSizeEqualsEventually(newCluster, 3); ((EntityInternal)newCluster).sensors().set(METRIC_SENSOR, 1); EntityAsserts.assertGroupSizeEqualsEventually(newCluster, 1); }
t.start(); try { EntityAsserts.assertGroupSizeEqualsEventually(fabric, 2); CassandraDatacenter d1 = (CassandraDatacenter) Iterables.get(fabric.getMembers(), 0); CassandraDatacenter d2 = (CassandraDatacenter) Iterables.get(fabric.getMembers(), 1); EntityAsserts.assertGroupSizeEqualsEventually(d1, 2); final DummyCassandraNode d1a = (DummyCassandraNode) Iterables.get(d1.getMembers(), 0); final DummyCassandraNode d1b = (DummyCassandraNode) Iterables.get(d1.getMembers(), 1); EntityAsserts.assertGroupSizeEqualsEventually(d2, 2); final DummyCassandraNode d2a = (DummyCassandraNode) Iterables.get(d2.getMembers(), 0); final DummyCassandraNode d2b = (DummyCassandraNode) Iterables.get(d2.getMembers(), 1);
@Test public void testQuorumWithStringStates() { final DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntityWithoutEnrichers.class)) .configure(DynamicCluster.INITIAL_SIZE, 1)); cluster.start(ImmutableList.of(app.newSimulatedLocation())); EntityAsserts.assertGroupSizeEqualsEventually(cluster, 1); //manually set state to healthy as enrichers are disabled EntityInternal child = (EntityInternal) cluster.getMembers().iterator().next(); child.sensors().set(Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); child.sensors().set(Attributes.SERVICE_UP, Boolean.TRUE); EntityAsserts.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); //set untyped service state, the quorum check should be able to handle coercion AttributeSensor<Object> stateSensor = Sensors.newSensor(Object.class, Attributes.SERVICE_STATE_ACTUAL.getName()); child.sensors().set(stateSensor, "running"); EntityAsserts.assertAttributeEqualsContinually(cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); }
@Test public void testWaitForServiceSucceedsEventually() throws Exception { Map<?,?> veryShortWait = ImmutableMap.of("timeout", Duration.millis(50)); DynamicCluster cluster = app.addChild(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.START_TIMEOUT, Asserts.DEFAULT_LONG_TIMEOUT.multiply(2)) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class)) .configure("initialSize", 1)); // Indicate that the cluster is not healthy ServiceStateLogic.updateMapSensorEntry(cluster, ServiceStateLogic.SERVICE_NOT_UP_INDICATORS, "simulateNotUpKey", "myVal"); // Start in a background thread Task<Void> task = app.invoke(Startable.START, ImmutableMap.of("locations", ImmutableList.of())); // The member should start, but we should still be waiting for the cluster's service.isUp EntityAsserts.assertGroupSizeEqualsEventually(cluster, 1); TestEntity member = (TestEntity) Iterables.find(cluster.getChildren(), Predicates.instanceOf(TestEntity.class)); EntityAsserts.assertAttributeEqualsEventually(member, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); EntityAsserts.assertAttributeEqualsContinually(veryShortWait, cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STARTING); EntityAsserts.assertAttributeEqualsContinually(veryShortWait, cluster, Attributes.SERVICE_UP, false); assertFalse(task.isDone()); // Clearing the not-up-indicator will allow it to return successfully ServiceStateLogic.updateMapSensorEntry(cluster, ServiceStateLogic.SERVICE_NOT_UP_INDICATORS, "simulateNotUpKey", Entities.REMOVE); EntityAsserts.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_UP, true); EntityAsserts.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); task.get(Asserts.DEFAULT_LONG_TIMEOUT); }
protected void publishSensors(int expectedSize, boolean includeServiceUp, boolean includeHostname, boolean includeAddress) { // First wait for the right size of group; the dynamic group gets notified asynchronously // of nodes added/removed, so if we don't wait then might not set value for all members. EntityAsserts.assertGroupSizeEqualsEventually(testEntities, expectedSize); for (Entity e: testEntities.getMembers()) { if (includeServiceUp) e.sensors().set(Attributes.SERVICE_UP, true); SshMachineLocation l = Machines.findUniqueMachineLocation(e.getLocations(), SshMachineLocation.class).get(); if (includeAddress) e.sensors().set(Attributes.ADDRESS, l.getAddress().getHostAddress()); String h = (String) l.config().getBag().getStringKey("hostname"); if (h==null) h = l.getAddress().getHostName(); if (includeHostname) e.sensors().set(Attributes.HOSTNAME, h); } }