@Test public void testOverrun() throws Exception { BoundMetricFifo fifo = new BoundMetricFifo(10, 2); SingleMetric metric; for (int i = 1; i <= 3; i++) { metric = new SingleMetric("" + i, (long) i, (double) i); fifo.offer(metric); } assert fifo.size() == 2 : "Fifo size should be 2, but was " + fifo.size(); // element "1" should have been pushed out, so 2 and 3 should be there SingleMetric result = fifo.poll(); assert result != null; assert result.getTimestamp() == 2 : "Expected ts =2, but it was " + result.getTimestamp(); result = fifo.poll(); assert result != null; assert result.getTimestamp() == 3 : "Expected ts =3, but it was " + result.getTimestamp(); // we have retrieved all elements assert fifo.isEmpty(); }
@Test public void testEmptyFifo() throws Exception { BoundMetricFifo fifo = new BoundMetricFifo(10, 15); assert fifo.size() == 0; assert fifo.isEmpty(); assert fifo.poll() == null; }
@Test public void testFifoAddOne() throws Exception { BoundMetricFifo fifo = new BoundMetricFifo(10, 15); SingleMetric metric = new SingleMetric("foo", 12345L, 42.0d); fifo.offer(metric); assert fifo.size() == 1 : "Size should be 1 but was " + fifo.size(); assert !fifo.isEmpty() : "Fifo should not be empty but it was"; SingleMetric pollResult = fifo.poll(); assert pollResult != null : "Got nothing back from the fifo"; assert pollResult.equals(metric); }