private FunctionCosts _cost = new FunctionCosts ();
@Test(timeOut = 3_000L)
public void testBasicBehaviour () {
final AtomicInteger messages = new AtomicInteger ();
final FunctionInvocationStatisticsSender sender = new FunctionInvocationStatisticsSender ();
final FunctionInvocationStatisticsReceiver receiver = new FunctionInvocationStatisticsReceiver (_cost);
sender.setExecutorService(Executors.newCachedThreadPool ());
sender.setFudgeMessageSender(new FudgeMessageSender () {
@Override
public FudgeContext getFudgeContext() {
return FudgeContext.GLOBAL_DEFAULT;
}
@Override
public void send(final FudgeMsg message) {
messages.incrementAndGet ();
s_logger.debug ("Received {}", message);
receiver.messageReceived(getFudgeContext (), new FudgeMsgEnvelope (message));
}
});
sender.setUpdatePeriod(Duration.ofSeconds(1));
long t = System.nanoTime ();
for (int i = 0; i < 100; i++) {
sender.functionInvoked("A", "1", 1, 2.0, 3.0, 4.0);
sender.functionInvoked("A", "2", 1, 2.0, 3.0, 4.0);
sender.functionInvoked("A", "1", 1, 2.0, 3.0, 4.0);
try {
Thread.sleep (20);
} catch (InterruptedException e) {
}
}
sender.functionInvoked ("A", "3", 300, 300 * 4.0, 300 * 5.0, 300 * 6.0);
t = (System.nanoTime () - t) / 1000000000;
sender.flush ();
if ((messages.get () < t) || (messages.get () > t + 2)) {
Assert.fail ("Unexpected number of messages (" + messages.get () + ") from " + t + "s execution");
}
assertEquals (2.0, _cost.getStatistics ("A", "1").getInvocationCost (), 1e-5);
assertEquals (3.0, _cost.getStatistics ("A", "1").getDataInputCost (), 1e-5);