summaryrefslogtreecommitdiffstats
path: root/infra/translate-utils/src/test
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2017-03-21 13:38:21 +0100
committerMarek Gradzki <mgradzki@cisco.com>2017-03-22 08:58:00 +0100
commit3bd0a6a0bcd1cec006500c60de20eb0904697263 (patch)
tree847fedb3a20a63eac6cc20830d22c1d84f767564 /infra/translate-utils/src/test
parent9297f70f8a75fae4c3b5ad8fe7324a5420895352 (diff)
HONEYCOMB-348: include dump params in entity key
Change-Id: I18b2ea3c897c467740f19bf346d13240aac458ac Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'infra/translate-utils/src/test')
-rw-r--r--infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManagerTest.java29
-rw-r--r--infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactoryTest.java36
2 files changed, 46 insertions, 19 deletions
diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManagerTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManagerTest.java
index 74aef67d0..dfdcd089b 100644
--- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManagerTest.java
+++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManagerTest.java
@@ -80,7 +80,7 @@ public class DumpCacheManagerTest {
@Test
public void testCaching() throws ReadFailedException {
final IpDetailsReplyDump stage1Data = new IpDetailsReplyDump();
- final String key = cacheKeyFactory.createKey(identifier);
+ final String key = cacheKeyFactory.createKey(identifier, NO_PARAMS);
// executor cant return null data
@@ -134,14 +134,14 @@ public class DumpCacheManagerTest {
@Test
public void testSameKeyDifferentTypes() throws ReadFailedException {
final DumpCacheManager<String, Void> stringManager =
- new DumpCacheManager.DumpCacheManagerBuilder<String, Void>()
- .withExecutor((InstanceIdentifier, Void) -> "value")
- .acceptOnly(String.class)
- .build();
+ new DumpCacheManager.DumpCacheManagerBuilder<String, Void>()
+ .withExecutor((InstanceIdentifier, Void) -> "value")
+ .acceptOnly(String.class)
+ .build();
final DumpCacheManager<Integer, Void> intManager = new DumpCacheManager.DumpCacheManagerBuilder<Integer, Void>()
- .acceptOnly(Integer.class)
- .withExecutor((InstanceIdentifier, Void) -> 3).build();
+ .acceptOnly(Integer.class)
+ .withExecutor((InstanceIdentifier, Void) -> 3).build();
final Optional<String> stringDump = stringManager.getDump(identifier, cache, NO_PARAMS);
final Optional<Integer> integerDump = intManager.getDump(identifier, cache, NO_PARAMS);
@@ -153,6 +153,21 @@ public class DumpCacheManagerTest {
}
+ @Test
+ public void testCachingWithDifferentParams() throws ReadFailedException {
+ final DumpCacheManager<Integer, Integer> manager =
+ new DumpCacheManager.DumpCacheManagerBuilder<Integer, Integer>()
+ .withExecutor((iid, param) -> param)
+ .acceptOnly(Integer.class)
+ .build();
+
+ final Optional<Integer> dump1 = manager.getDump(identifier, cache, 1);
+ final Optional<Integer> dump2 = manager.getDump(identifier, cache, 2);
+
+ assertEquals(1, dump1.get().intValue());
+ assertEquals(2, dump2.get().intValue());
+ }
+
private EntityDumpPostProcessingFunction<IpDetailsReplyDump> createPostProcessor() {
return ipDetailsReplyDump -> {
IpDetailsReplyDump modified = new IpDetailsReplyDump();
diff --git a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactoryTest.java b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactoryTest.java
index 305fba143..fa247f99b 100644
--- a/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactoryTest.java
+++ b/infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/TypeAwareIdentifierCacheKeyFactoryTest.java
@@ -16,6 +16,8 @@
package io.fd.honeycomb.translate.util.read.cache;
+import static io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor.NO_PARAMS;
+import static io.fd.honeycomb.translate.util.read.cache.TypeAwareIdentifierCacheKeyFactory.NO_PARAMS_KEY;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -35,8 +37,9 @@ public class TypeAwareIdentifierCacheKeyFactoryTest {
private InstanceIdentifier<DataObjectChild> identifierBothKeyed;
private InstanceIdentifier<DataObjectChild> identifierOneMissing;
private InstanceIdentifier<DataObjectChild> identifierNoneKeyed;
- private TypeAwareIdentifierCacheKeyFactory simpleKeyFactory;
- private TypeAwareIdentifierCacheKeyFactory complexKeyFactory;
+ private TypeAwareIdentifierCacheKeyFactory<Void> simpleKeyFactory;
+ private TypeAwareIdentifierCacheKeyFactory<Void> complexKeyFactory;
+ private TypeAwareIdentifierCacheKeyFactory<Integer> complexIntegerKeyFactory;
@Before
public void init() {
@@ -49,19 +52,27 @@ public class TypeAwareIdentifierCacheKeyFactoryTest {
.child(DataObjectChild.class);
complexKeyFactory =
- new TypeAwareIdentifierCacheKeyFactory(String.class, ImmutableSet.of(DataObjectParent.class));
- simpleKeyFactory = new TypeAwareIdentifierCacheKeyFactory(String.class);
+ new TypeAwareIdentifierCacheKeyFactory<>(String.class, ImmutableSet.of(DataObjectParent.class));
+ simpleKeyFactory = new TypeAwareIdentifierCacheKeyFactory<>(String.class);
+ complexIntegerKeyFactory =
+ new TypeAwareIdentifierCacheKeyFactory<>(String.class, ImmutableSet.of(DataObjectParent.class));
}
@Test
public void createKeyBothKeyedComplex() {
- final String key = complexKeyFactory.createKey(identifierBothKeyed);
+ final String key = complexKeyFactory.createKey(identifierBothKeyed, NO_PARAMS);
/**
* Should pass because key constructed in this case should look like :
* additional_scope_type[additional_scope_type_key]|cached_type
* */
- verifyComplexKey(key);
+ verifyComplexKey(key, NO_PARAMS_KEY);
+ }
+
+ @Test
+ public void createKeyBothKeyedComplexWithParams() {
+ final String key = complexIntegerKeyFactory.createKey(identifierBothKeyed, 123);
+ verifyComplexKey(key, "123");
}
/**
@@ -69,7 +80,7 @@ public class TypeAwareIdentifierCacheKeyFactoryTest {
*/
@Test(expected = IllegalArgumentException.class)
public void createKeyOneMissingComplex() {
- complexKeyFactory.createKey(identifierOneMissing);
+ complexKeyFactory.createKey(identifierOneMissing, NO_PARAMS);
}
/**
@@ -77,12 +88,12 @@ public class TypeAwareIdentifierCacheKeyFactoryTest {
*/
@Test(expected = IllegalArgumentException.class)
public void createKeyNoneKeyedComplex() {
- complexKeyFactory.createKey(identifierNoneKeyed);
+ complexKeyFactory.createKey(identifierNoneKeyed, NO_PARAMS);
}
@Test
public void createKeyBothKeyedSimple() {
- final String key = simpleKeyFactory.createKey(identifierBothKeyed);
+ final String key = simpleKeyFactory.createKey(identifierBothKeyed, NO_PARAMS);
/**
* Should pass because key constructed in this case should look like : cached_type
@@ -92,7 +103,7 @@ public class TypeAwareIdentifierCacheKeyFactoryTest {
@Test
public void createKeyOneMissingSimple() {
- final String key = simpleKeyFactory.createKey(identifierOneMissing);
+ final String key = simpleKeyFactory.createKey(identifierOneMissing, NO_PARAMS);
/**
* Should pass because key constructed in this case should look like : cached_type
* */
@@ -104,20 +115,21 @@ public class TypeAwareIdentifierCacheKeyFactoryTest {
*/
@Test
public void createKeyNoneKeyedSimple() {
- final String key = simpleKeyFactory.createKey(identifierNoneKeyed);
+ final String key = simpleKeyFactory.createKey(identifierNoneKeyed, NO_PARAMS);
/**
* Should pass because key constructed in this case should look like : cached_type
* */
verifySimpleKey(key);
}
- private void verifyComplexKey(final String key) {
+ private void verifyComplexKey(final String key, final String params) {
assertTrue(key.contains(String.class.getTypeName()));
assertTrue(key.contains(DataObjectParent.class.getTypeName()));
assertTrue(key.contains(parentKey.toString()));
assertTrue(key.contains(DataObjectChild.class.getTypeName()));
assertFalse(key.contains(childKey.toString()));
assertFalse(key.contains(SuperDataObject.class.getTypeName()));
+ assertTrue(key.contains(params));
}
private void verifySimpleKey(final String key) {