@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); loc1 = new SimulatedLocation(); loc2 = new SimulatedLocation(); loc3 = new SimulatedLocation(); }
@Override public OsDetails getOsDetails() { return getMachineDetails().getOsDetails(); }
@Override public synchronized int obtainPort(PortRange range) { for (int p: range) if (obtainSpecificPort(p)) return p; return -1; }
@Test public void testUnsubscribeUsingHandleStopsEvents() { SubscriptionHandle handle1 = loc.subscriptions().subscribe(observedEntity, TestEntity.SEQUENCE, listener); SubscriptionHandle handle2 = loc.subscriptions().subscribe(observedEntity, TestEntity.NAME, listener); SubscriptionHandle handle3 = loc.subscriptions().subscribe(otherEntity, TestEntity.SEQUENCE, listener); loc.subscriptions().unsubscribe(observedEntity, handle2); observedEntity.sensors().set(TestEntity.SEQUENCE, 123); observedEntity.sensors().set(TestEntity.NAME, "myname"); otherEntity.sensors().set(TestEntity.SEQUENCE, 456); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(listener.getEvents(), ImmutableList.of( new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, observedEntity, 123), new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, otherEntity, 456))); }}); }
@Override public SimulatedLocation newSubLocation(Map<?,?> newFlags) { // TODO shouldn't have to copy config bag as it should be inherited (but currently it is not used inherited everywhere; just most places) return getManagementContext().getLocationManager().createLocation(LocationSpec.create(getClass()) .parent(this) .configure(config().getLocalBag().getAllConfig()) // FIXME Should this just be inherited? .configure(newFlags)); }
@Override public void release(MachineLocation machine) { super.release(machine); try { isBlocked = true; lock.await(); isBlocked = false; } catch (InterruptedException e) { throw Exceptions.propagate(e); } }
@Test public void testSimulatedRestrictedPermitted() throws Exception { loc.setPermittedPorts(PortRanges.fromString("1240+")); ConfigToAttributes.apply(entity, ps); int p = entity.getAttribute(ps); assertEquals(p, 1240); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.ENABLE_AVAILABILITY_ZONES, true) .configure(DynamicCluster.INITIAL_SIZE, 0) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class))); loc = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class)); loc.addExtension(AvailabilityZoneExtension.class, new SimulatedAvailabilityZoneExtension(mgmt, loc, ImmutableList.of("zone1", "zone2", "zone3", "zone4"))); }
@Test public void testUnsubscribeRemovesAllSubscriptionsForThatEntity() { loc.subscriptions().subscribe(observedEntity, TestEntity.SEQUENCE, listener); loc.subscriptions().subscribe(observedEntity, TestEntity.NAME, listener); loc.subscriptions().subscribe(observedEntity, TestEntity.MY_NOTIF, listener); loc.subscriptions().subscribe(otherEntity, TestEntity.SEQUENCE, listener); loc.subscriptions().unsubscribe(observedEntity); observedEntity.sensors().set(TestEntity.SEQUENCE, 123); observedEntity.sensors().set(TestEntity.NAME, "myname"); observedEntity.sensors().emit(TestEntity.MY_NOTIF, 123); otherEntity.sensors().set(TestEntity.SEQUENCE, 456); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(listener.getEvents(), ImmutableList.of( new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, otherEntity, 456))); }}); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); loc = new SimulatedLocation(); loc2 = new SimulatedLocation(); }
@Test public void testSubscriptionReceivesEventsInOrder() { final int NUM_EVENTS = 100; loc.subscriptions().subscribe(observedEntity, TestEntity.MY_NOTIF, listener); for (int i = 0; i < NUM_EVENTS; i++) { observedEntity.sensors().emit(TestEntity.MY_NOTIF, i); } Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(Iterables.size(listener.getEvents()), NUM_EVENTS); for (int i = 0; i < NUM_EVENTS; i++) { assertEquals(Iterables.get(listener.getEvents(), i).getValue(), i); } }}); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); locs = ImmutableList.of(new SimulatedLocation()); }
@Test(groups="Integration") public void testSubscribeToMembersIgnoresEventsForDynamicallyRemovedMembers() { loc.subscriptions().subscribeToMembers(observedGroup, TestEntity.SEQUENCE, listener); observedGroup.removeMember(observedMemberEntity); observedMemberEntity.sensors().set(TestEntity.SEQUENCE, 123); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(listener.getEvents(), ImmutableList.of()); }}); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); locs = ImmutableList.of(new SimulatedLocation()); }
@Test public void testSubscribeToChildrenReceivesEventsForDynamicallyAddedChildren() { loc.subscriptions().subscribeToChildren(observedEntity, TestEntity.SEQUENCE, listener); final TestEntity observedChildEntity2 = observedEntity.createAndManageChild(EntitySpec.create(TestEntity.class)); observedChildEntity2.sensors().set(TestEntity.SEQUENCE, 123); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(listener.getEvents(), ImmutableList.of( new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, observedChildEntity2, 123))); }}); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); loc = new SimulatedLocation(); }
@Test public void testSubscriptionReceivesEvents() { loc.subscriptions().subscribe(observedEntity, TestEntity.SEQUENCE, listener); loc.subscriptions().subscribe(observedEntity, TestEntity.NAME, listener); loc.subscriptions().subscribe(observedEntity, TestEntity.MY_NOTIF, listener); otherEntity.sensors().set(TestEntity.SEQUENCE, 123); observedEntity.sensors().set(TestEntity.SEQUENCE, 123); observedEntity.sensors().set(TestEntity.NAME, "myname"); observedEntity.sensors().emit(TestEntity.MY_NOTIF, 456); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(listener.getEvents(), ImmutableList.of( new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, observedEntity, 123), new BasicSensorEvent<String>(TestEntity.NAME, observedEntity, "myname"), new BasicSensorEvent<Integer>(TestEntity.MY_NOTIF, observedEntity, 456))); }}); }
@Override public Location apply(Entity input) { return new SimulatedLocation(MutableMap.of("name", "custom location for "+input)); }};
@Test public void testSubscriptionToAllReceivesEvents() { loc.subscriptions().subscribe(null, TestEntity.SEQUENCE, listener); observedEntity.sensors().set(TestEntity.SEQUENCE, 123); otherEntity.sensors().set(TestEntity.SEQUENCE, 456); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(listener.getEvents(), ImmutableList.of( new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, observedEntity, 123), new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, otherEntity, 456))); }}); }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); loc = new SimulatedLocation(); listener = new RecordingEventListener(); }