@Override @BeforeMethod(alwaysRun=true) public void setUp() throws Exception { super.setUp(); entities = Lists.newArrayList(); for (int i = 0; i < 10; i++) { entities.add(app.createAndManageChild(EntitySpec.create(TestEntity.class))); } entity = entities.get(0); app.start(ImmutableList.of(loc)); subscriptionManager = app.getManagementContext().getSubscriptionManager(); }
nonDeploymentManagementContext.getSubscriptionManager().setDelegate((AbstractSubscriptionManager) managementContext.getSubscriptionManager()); nonDeploymentManagementContext.getSubscriptionManager().startDelegatingForSubscribing();
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); events = new CopyOnWriteArrayList<SensorEvent<FailureDescriptor>>(); app.getManagementContext().getSubscriptionManager().subscribe( app, HASensors.CONNECTION_FAILED, new SensorEventListener<FailureDescriptor>() { @Override public void onEvent(SensorEvent<FailureDescriptor> event) { events.add(event); } }); app.getManagementContext().getSubscriptionManager().subscribe( app, HASensors.CONNECTION_RECOVERED, new SensorEventListener<FailureDescriptor>() { @Override public void onEvent(SensorEvent<FailureDescriptor> event) { events.add(event); } }); serverSocketAddress = startServerSocket(); }
app.getManagementContext().getSubscriptionManager().subscribe(javaProcess, VanillaJavaApp.PROCESS_CPU_TIME_FRACTION_LAST, new SensorEventListener<Double>() { @Override public void onEvent(SensorEvent<Double> event) {
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); events = new CopyOnWriteArrayList<SensorEvent<FailureDescriptor>>(); eventListener = new SensorEventListener<FailureDescriptor>() { @Override public void onEvent(SensorEvent<FailureDescriptor> event) { events.add(event); } }; e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); e1.enrichers().add(ServiceStateLogic.newEnricherForServiceStateFromProblemsAndUp()); app.getManagementContext().getSubscriptionManager().subscribe(e1, HASensors.ENTITY_FAILED, eventListener); app.getManagementContext().getSubscriptionManager().subscribe(e1, HASensors.ENTITY_RECOVERED, eventListener); }
final List<Object> events = new CopyOnWriteArrayList<Object>(); newManagementContext.getSubscriptionManager().subscribe(null, MyLatchingEntityImpl.MY_SENSOR, new SensorEventListener<Object>() { @Override public void onEvent(SensorEvent<Object> event) { events.add(event.getValue()); newManagementContext.getSubscriptionManager().publish(new BasicSensorEvent<String>(TestApplication.MY_ATTRIBUTE, null, "myvaltooearly")); Asserts.continually(Suppliers.ofInstance(MyLatchingEntityImpl.events), Predicates.equalTo(Collections.emptyList())); newManagementContext.getSubscriptionManager().publish(new BasicSensorEvent<String>(TestApplication.MY_ATTRIBUTE, null, "myvaltoreceive")); Asserts.eventually(Suppliers.ofInstance(MyLatchingEntityImpl.events), Predicates.<List<Object>>equalTo(ImmutableList.of((Object)"myvaltoreceive")));
@Test public void testServiceFailureDetectorWorksAfterRebind() throws Exception { origEntity.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class)); // rebind TestApplication newApp = rebind(); final TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class)); newApp.getManagementContext().getSubscriptionManager().subscribe(newEntity, HASensors.ENTITY_FAILED, eventListener); newEntity.sensors().set(TestEntity.SERVICE_UP, true); ServiceStateLogic.setExpectedState(newEntity, Lifecycle.RUNNING); // trigger the failure newEntity.sensors().set(TestEntity.SERVICE_UP, false); assertHasEventEventually(HASensors.ENTITY_FAILED, Predicates.<Object>equalTo(newEntity), null); assertEquals(events.size(), 1, "events="+events); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); events = new CopyOnWriteArrayList<SensorEvent<FailureDescriptor>>(); e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class)); e1.sensors().set(TestEntity.SERVICE_UP, true); ServiceStateLogic.setExpectedState(e1, Lifecycle.RUNNING); app.getManagementContext().getSubscriptionManager().subscribe( e1, HASensors.ENTITY_FAILED, new SensorEventListener<FailureDescriptor>() { @Override public void onEvent(SensorEvent<FailureDescriptor> event) { events.add(event); } }); app.getManagementContext().getSubscriptionManager().subscribe( e1, HASensors.ENTITY_RECOVERED, new SensorEventListener<FailureDescriptor>() { @Override public void onEvent(SensorEvent<FailureDescriptor> event) { events.add(event); } }); }
final TestEntity e1 = (TestEntity) Iterables.get(initialMembers, 1); newApp.getManagementContext().getSubscriptionManager().subscribe(e1, HASensors.ENTITY_FAILED, eventListener); newApp.getManagementContext().getSubscriptionManager().subscribe(e1, HASensors.ENTITY_RECOVERED, eventListener);
@Test public void testTransformingRespectsUnchangedButWillRepublish() throws Exception { RecordingSensorEventListener<String> record = new RecordingSensorEventListener<>(); app.getManagementContext().getSubscriptionManager().subscribe(entity, STR2, record);
private void refreshSensors() { ManagementContext managementContext = getManagementContext(); BasicExecutionManager execManager = (BasicExecutionManager) (managementContext != null ? managementContext.getExecutionManager() : null); LocalSubscriptionManager subsManager = (LocalSubscriptionManager) (managementContext != null ? managementContext.getSubscriptionManager() : null); if (managementContext != null) { sensors().set(TOTAL_EFFECTORS_INVOKED, ((ManagementContextInternal)managementContext).getTotalEffectorInvocations()); } if (execManager != null) { sensors().set(TOTAL_TASKS_SUBMITTED, execManager.getTotalTasksSubmitted()); sensors().set(NUM_INCOMPLETE_TASKS, execManager.getNumIncompleteTasks()); sensors().set(NUM_ACTIVE_TASKS, execManager.getNumActiveTasks()); } if (subsManager != null) { sensors().set(TOTAL_EVENTS_PUBLISHED, subsManager.getTotalEventsPublished()); sensors().set(TOTAL_EVENTS_DELIVERED, subsManager.getTotalEventsDelivered()); sensors().set(NUM_SUBSCRIPTIONS, subsManager.getNumSubscriptions()); } } }
public void testTransformingSuppressDuplicates() { RecordingSensorEventListener<String> record = new RecordingSensorEventListener<>(); app.getManagementContext().getSubscriptionManager().subscribe(entity, STR2, record); entity.enrichers().add(Enrichers.builder() .transforming(STR1) .publishing(STR2) .computing(Functions.<String>identity()) .suppressDuplicates(true) .build()); entity.sensors().set(STR1, "myval"); Asserts.eventually(Suppliers.ofInstance(record), CollectionFunctionals.sizeEquals(1)); EntityAsserts.assertAttributeEquals(entity, STR2, "myval"); entity.sensors().set(STR1, "myval2"); entity.sensors().set(STR1, "myval2"); entity.sensors().set(STR1, "myval3"); EntityAsserts.assertAttributeEqualsContinually(entity, STR2, "myval3"); Asserts.assertThat(record.getEvents(), CollectionFunctionals.sizeEquals(3)); }