Search in sources :

Example 1 with EscapableResourceIdSplitter

use of org.opennms.newts.cassandra.search.EscapableResourceIdSplitter in project opennms by OpenNMS.

the class RedisResourceMetadataCacheIT method canGetEntriesWithPrefix.

@Test
public void canGetEntriesWithPrefix() {
    Context ctx = Context.DEFAULT_CONTEXT;
    RedisResourceMetadataCache cache = new RedisResourceMetadataCache(REDIS_HOSTNAME, REDIS_PORT, 8, m_registry, new EscapableResourceIdSplitter());
    assertTrue(cache.getResourceIdsWithPrefix(ctx, "a").isEmpty());
    Resource resource = new Resource("a:b:c");
    ResourceMetadata resourceMetadata = new ResourceMetadata();
    cache.merge(ctx, resource, resourceMetadata);
    assertTrue(cache.getResourceIdsWithPrefix(ctx, "a").contains("a:b:c"));
    assertTrue(cache.getResourceIdsWithPrefix(ctx, "a:b").contains("a:b:c"));
    assertTrue(cache.getResourceIdsWithPrefix(ctx, "a:b:c").contains("a:b:c"));
    assertTrue(cache.getResourceIdsWithPrefix(ctx, "a:b:c:d").isEmpty());
}
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 2 with EscapableResourceIdSplitter

use of org.opennms.newts.cassandra.search.EscapableResourceIdSplitter 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)

Aggregations

Test (org.junit.Test)2 Context (org.opennms.newts.api.Context)2 Resource (org.opennms.newts.api.Resource)2 EscapableResourceIdSplitter (org.opennms.newts.cassandra.search.EscapableResourceIdSplitter)2 ResourceMetadata (org.opennms.newts.cassandra.search.ResourceMetadata)2