* @throws Exception
*/
@Test
public void testOFStatisticsFuture() throws Exception {
// Test for a single stats reply
IOFSwitch sw = createMock(IOFSwitch.class);
sw.cancelStatisticsReply(1);
OFStatisticsFuture sf = new OFStatisticsFuture(tp, sw, 1);
replay(sw);
List<OFStatistics> stats;
FutureFetcher<List<OFStatistics>> ff = new FutureFetcher<List<OFStatistics>>(sf);
Thread t = new Thread(ff);
t.start();
sf.deliverFuture(sw, getStatisticsReply(1, 10, false));
t.join();
stats = ff.getValue();
verify(sw);
assertEquals(10, stats.size());
// Test multiple stats replies
reset(sw);
sw.cancelStatisticsReply(1);
sf = new OFStatisticsFuture(tp, sw, 1);
replay(sw);
ff = new FutureFetcher<List<OFStatistics>>(sf);
t = new Thread(ff);
t.start();
sf.deliverFuture(sw, getStatisticsReply(1, 10, true));
sf.deliverFuture(sw, getStatisticsReply(1, 5, false));
t.join();
stats = sf.get();
verify(sw);
assertEquals(15, stats.size());
// Test cancellation
reset(sw);
sw.cancelStatisticsReply(1);
sf = new OFStatisticsFuture(tp, sw, 1);
replay(sw);
ff = new FutureFetcher<List<OFStatistics>>(sf);
t = new Thread(ff);
t.start();
sf.cancel(true);
t.join();
stats = sf.get();
verify(sw);
assertEquals(0, stats.size());
// Test self timeout
reset(sw);
sw.cancelStatisticsReply(1);
sf = new OFStatisticsFuture(tp, sw, 1, 75, TimeUnit.MILLISECONDS);
replay(sw);
ff = new FutureFetcher<List<OFStatistics>>(sf);
t = new Thread(ff);