use of org.opennms.newts.api.Counter in project opennms by OpenNMS.
the class NewtsWriterTest method samplesAreDroppedWhenRingBufferIsFull.
/**
* Fills the ring buffer and locks all of the writer threads to verify
* that samples additional samples are dropped.
*/
@Test
public void samplesAreDroppedWhenRingBufferIsFull() throws Exception {
Resource x = new Resource("x");
int ringBufferSize = 1024;
int numWriterThreads = 8;
Lock lock = new ReentrantLock();
LockedSampleRepository sampleRepo = new LockedSampleRepository(lock);
MetricRegistry registry = new MetricRegistry();
NewtsWriter writer = new NewtsWriter(1, ringBufferSize, numWriterThreads, registry);
writer.setSampleRepository(sampleRepo);
lock.lock();
for (int i = 0; i < ringBufferSize; i++) {
Sample s = new Sample(Timestamp.now(), x, "y", MetricType.COUNTER, new Counter(i));
writer.insert(Lists.newArrayList(s));
}
// The ring buffer should be full, and all of the threads should be locked
Thread.sleep(250);
assertEquals(numWriterThreads, sampleRepo.getNumThreadsLocked());
// Attempt to insert another batch of samples
for (int i = 0; i < 8; i++) {
Sample s = new Sample(Timestamp.now(), x, "y", MetricType.COUNTER, new Counter(i));
writer.insert(Lists.newArrayList(s));
}
;
// Unlock the writer threads and wait for the ring buffer to drain
lock.unlock();
writer.destroy();
// Verify the number of inserted samples
assertEquals(0, sampleRepo.getNumThreadsLocked());
assertEquals(ringBufferSize, sampleRepo.getNumSamplesInserted());
}
Aggregations