ValueDistributor valueDistributor = new ValueDistributor();
Timer t = new Timer("HeartbeatConduitTest");
new Heartbeater(valueDistributor, new HeartbeatSender(conduit, OpenGammaFudgeContext.getInstance()), t, 100);
// subscribe on the client side - starts sending heartbeats
LiveDataSpecification subscription = new LiveDataSpecification(
dataServer.getDefaultNormalizationRuleSetId(),
ExternalId.of(identificationDomain, "USSw5 Curncy"));
CollectingLiveDataListener listener = new CollectingLiveDataListener();
valueDistributor.addListener(subscription, listener);
assertEquals(dataServer.getSubscriptions().size(), 0);
// subscribe on the server side
dataServer.subscribe(subscription, false);
// Send a couple of heartbeats
Thread.sleep(300);
assertEquals(dataServer.getSubscriptions().size(), 1);
// Unsubscribe the server
dataServer.unsubscribe(subscription.getIdentifier(identificationDomain));
assertEquals(dataServer.getSubscriptions().size(), 0);
// Send a couple of heartbeats
Thread.sleep(300);
expirationManager.housekeep(dataServer);
// Now we should be subscribed again due to heartbeating
assertEquals(dataServer.getSubscriptions().size(), 1);
// Check the recording of what happened:
// we subscribed (via client), unsubscribed (at the server) and subscribed again (due to heartbeating)
assertEquals(dataServer.getActualSubscriptions().size(), 2);
assertEquals(dataServer.getActualUnsubscriptions().size(), 1);
assertEquals(dataServer.getActualSubscriptions().get(0), subscription.getIdentifier(identificationDomain));
assertEquals(dataServer.getActualSubscriptions().get(1), subscription.getIdentifier(identificationDomain));
assertEquals(dataServer.getActualUnsubscriptions().get(0), subscription.getIdentifier(identificationDomain));
}