use of org.opennms.newts.cassandra.search.ResourceMetadata 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());
}
use of org.opennms.newts.cassandra.search.ResourceMetadata in project opennms by OpenNMS.
the class GuavaSearchableResourceMetadataCacheTest method getResourceIdsWithPrefixPerftTest.
@Test
@Ignore
public void getResourceIdsWithPrefixPerftTest() {
long numResourceIdsToCache = 200000;
long numSearches = 1000;
Context ctx = Context.DEFAULT_CONTEXT;
GuavaSearchableResourceMetadataCache cache = new GuavaSearchableResourceMetadataCache(numResourceIdsToCache, m_registry);
ResourceMetadata resourceMetadata = new ResourceMetadata();
for (long k = 0; k < numResourceIdsToCache; k++) {
Resource resource = new Resource(String.format("snmp:%d:eth0-x:ifHcInOctets", k));
cache.merge(ctx, resource, resourceMetadata);
}
long start = System.currentTimeMillis();
String prefix = "snmp:" + (numResourceIdsToCache - 1);
for (long k = 0; k < numSearches; k++) {
assertEquals(1, cache.getResourceIdsWithPrefix(ctx, prefix).size());
}
long elapsed = System.currentTimeMillis() - start;
System.err.println("elapsed: " + elapsed);
}
use of org.opennms.newts.cassandra.search.ResourceMetadata in project opennms by OpenNMS.
the class GuavaSearchableResourceMetadataCacheTest method canGetEntriesWithPrefix.
@Test
public void canGetEntriesWithPrefix() {
Context ctx = Context.DEFAULT_CONTEXT;
GuavaSearchableResourceMetadataCache cache = new GuavaSearchableResourceMetadataCache(2048, m_registry);
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());
}
use of org.opennms.newts.cassandra.search.ResourceMetadata 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"));
}
use of org.opennms.newts.cassandra.search.ResourceMetadata in project opennms by OpenNMS.
the class GuavaSearchableResourceMetadataCache method merge.
@Override
public void merge(Context context, Resource resource, ResourceMetadata metadata) {
Optional<ResourceMetadata> o = get(context, resource);
if (!o.isPresent()) {
ResourceMetadata newMetadata = new ResourceMetadata(m_metricReqs, m_attributeReqs, m_metricMisses, m_attributeMisses);
newMetadata.merge(metadata);
String key = key(context, resource.getId());
m_cache.put(key, newMetadata);
m_radixTree.put(key, newMetadata);
return;
}
o.get().merge(metadata);
}
Aggregations