Search in sources :

Example 11 with Context

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

the class RedisResourceMetadataCacheIT method canUpdateEntry.

@Test
public void canUpdateEntry() {
    Context ctx = Context.DEFAULT_CONTEXT;
    RedisResourceMetadataCache cache = new RedisResourceMetadataCache(REDIS_HOSTNAME, REDIS_PORT, 8, m_registry, new EscapableResourceIdSplitter());
    // Insert
    Resource resource = new Resource("a:b:c");
    ResourceMetadata resourceMetadata = new ResourceMetadata();
    resourceMetadata.putAttribute("a1", "1");
    cache.merge(ctx, resource, resourceMetadata);
    // Verify
    assertTrue("attribute a1 must be set", cache.get(ctx, resource).get().containsAttribute("a1", "1"));
    // Update
    resourceMetadata = new ResourceMetadata();
    resourceMetadata.putAttribute("a2", "2");
    cache.merge(ctx, resource, resourceMetadata);
    // Verify
    assertTrue("attribute a1 must be set", cache.get(ctx, resource).get().containsAttribute("a1", "1"));
    assertTrue("attribute a2 must be set", cache.get(ctx, resource).get().containsAttribute("a2", "2"));
}
Also used : Context(org.opennms.newts.api.Context) EscapableResourceIdSplitter(org.opennms.newts.cassandra.search.EscapableResourceIdSplitter) Resource(org.opennms.newts.api.Resource) ResourceMetadata(org.opennms.newts.cassandra.search.ResourceMetadata) Test(org.junit.Test)

Example 12 with Context

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

the class NewtsFetchStrategyTest method setUp.

@Before
public void setUp() throws Exception {
    m_context = new Context("test");
    m_resourceDao = EasyMock.createNiceMock(ResourceDao.class);
    m_sampleRepository = EasyMock.createNiceMock(SampleRepository.class);
    m_newtsFetchStrategy = new NewtsFetchStrategy();
    m_newtsFetchStrategy.setContext(m_context);
    m_newtsFetchStrategy.setResourceDao(m_resourceDao);
    m_newtsFetchStrategy.setSampleRepository(m_sampleRepository);
}
Also used : Context(org.opennms.newts.api.Context) SampleRepository(org.opennms.newts.api.SampleRepository) ResourceDao(org.opennms.netmgt.dao.api.ResourceDao) Before(org.junit.Before)

Aggregations

Context (org.opennms.newts.api.Context)12 Resource (org.opennms.newts.api.Resource)7 Test (org.junit.Test)5 ResourceMetadata (org.opennms.newts.cassandra.search.ResourceMetadata)5 Timed (com.codahale.metrics.annotation.Timed)4 Path (javax.ws.rs.Path)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 GET (javax.ws.rs.GET)2 Timestamp (org.opennms.newts.api.Timestamp)2 EscapableResourceIdSplitter (org.opennms.newts.cassandra.search.EscapableResourceIdSplitter)2 Gauge (com.codahale.metrics.Gauge)1 Timer (com.codahale.metrics.Timer)1 BoundStatement (com.datastax.driver.core.BoundStatement)1 PreparedStatement (com.datastax.driver.core.PreparedStatement)1 RegularStatement (com.datastax.driver.core.RegularStatement)1 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)1 Statement (com.datastax.driver.core.Statement)1 Joiner (com.google.common.base.Joiner)1 Optional (com.google.common.base.Optional)1 Preconditions (com.google.common.base.Preconditions)1