@BeforeMethod(alwaysRun = true) @Override public void setUp() throws Exception { super.setUp(); loc = app.newSimulatedLocation(); entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); otherEntity = app.createAndManageChild(EntitySpec.create(TestEntity.class)); listener = new RecordingSensorEventListener(); policy = new AbstractPolicy() {}; entity.addPolicy(policy); app.start(ImmutableList.of(loc)); }
@Test public void testServiceRestarterWorksAfterRebind() throws Exception { origEntity.addPolicy( PolicySpec.create(ServiceRestarter.class) .configure(ServiceRestarter.FAILURE_SENSOR_TO_MONITOR, HASensors.ENTITY_FAILED)); TestApplication newApp = rebind(); final TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class)); newEntity.emit(HASensors.ENTITY_FAILED, new FailureDescriptor(origEntity, "simulate failure")); Asserts.succeedsEventually( new Runnable() { @Override public void run() { assertEquals(newEntity.getCallHistory(), ImmutableList.of("restart")); } }); }