@Test
public void testSendMultipleInOrderThenUnsubscribe() throws Exception {
HelloEntity h = app.createAndManageChild(EntitySpec.create(HelloEntity.class));
app.start(ImmutableList.of(loc));
final List<Integer> data = Lists.newArrayList();
final CountDownLatch latch = new CountDownLatch(5);
app.subscriptions().subscribe(h, HelloEntity.AGE, new SensorEventListener<Integer>() {
@Override public void onEvent(SensorEvent<Integer> event) {
data.add(event.getValue());
Time.sleep((int)(20*Math.random()));
log.info("Thread "+Thread.currentThread()+" notify on subscription received for "+event.getValue()+", data is "+data);
latch.countDown();
}});
Stopwatch stopwatch = Stopwatch.createStarted();
for (int i = 1; i <= 5; i++) {
h.setAge(i);
}
assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
app.subscriptions().unsubscribeAll();
h.setAge(6);
long totalTime = stopwatch.elapsed(TimeUnit.MILLISECONDS);
Asserts.continually(MutableMap.of("timeout", 50), Suppliers.ofInstance(data), Predicates.<Object>equalTo(ImmutableList.of(1,2,3,4,5)));
assertTrue(totalTime < 2000, "totalTime="+totalTime);
}