Search in sources :

Example 36 with Sample

use of org.opennms.newts.api.Sample 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());
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Counter(org.opennms.newts.api.Counter) Sample(org.opennms.newts.api.Sample) MetricRegistry(com.codahale.metrics.MetricRegistry) Resource(org.opennms.newts.api.Resource) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock) Test(org.junit.Test)

Example 37 with Sample

use of org.opennms.newts.api.Sample in project opennms by OpenNMS.

the class NewtsPersistOperationBuilder method getSamplesToIndex.

public List<Sample> getSamplesToIndex() {
    final List<Sample> samples = Lists.newLinkedList();
    // Convert string attributes to samples
    for (Entry<ResourcePath, Map<String, String>> entry : m_stringAttributesByPath.entrySet()) {
        Resource resource = new Resource(toResourceId(entry.getKey()), Optional.of(entry.getValue()));
        samples.add(NewtsUtils.createSampleForIndexingStrings(m_context, resource));
    }
    return samples;
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) Sample(org.opennms.newts.api.Sample) Resource(org.opennms.newts.api.Resource) Map(java.util.Map)

Aggregations

Sample (org.opennms.newts.api.Sample)37 Resource (org.opennms.newts.api.Resource)18 Test (org.junit.Test)14 Timestamp (org.opennms.newts.api.Timestamp)12 MetricRegistry (com.codahale.metrics.MetricRegistry)9 Gauge (org.opennms.newts.api.Gauge)6 ContextConfigurations (org.opennms.newts.cassandra.ContextConfigurations)6 Timer (com.codahale.metrics.Timer)5 List (java.util.List)5 Counter (org.opennms.newts.api.Counter)5 Row (org.opennms.newts.api.Results.Row)5 CassandraSession (org.opennms.newts.cassandra.CassandraSession)5 Map (java.util.Map)4 Context (org.opennms.newts.api.Context)4 Results (org.opennms.newts.api.Results)4 Meter (com.codahale.metrics.Meter)3 BoundStatement (com.datastax.driver.core.BoundStatement)3 PreparedStatement (com.datastax.driver.core.PreparedStatement)3 RegularStatement (com.datastax.driver.core.RegularStatement)3 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)3