From 3bd0a6a0bcd1cec006500c60de20eb0904697263 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Tue, 21 Mar 2017 13:38:21 +0100 Subject: HONEYCOMB-348: include dump params in entity key Change-Id: I18b2ea3c897c467740f19bf346d13240aac458ac Signed-off-by: Marek Gradzki --- .../util/read/cache/DumpCacheManagerTest.java | 29 ++++++++++++----- .../TypeAwareIdentifierCacheKeyFactoryTest.java | 36 ++++++++++++++-------- 2 files changed, 46 insertions(+), 19 deletions(-) (limited to 'infra/translate-utils/src/test/java/io') 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 stringManager = - new DumpCacheManager.DumpCacheManagerBuilder() - .withExecutor((InstanceIdentifier, Void) -> "value") - .acceptOnly(String.class) - .build(); + new DumpCacheManager.DumpCacheManagerBuilder() + .withExecutor((InstanceIdentifier, Void) -> "value") + .acceptOnly(String.class) + .build(); final DumpCacheManager intManager = new DumpCacheManager.DumpCacheManagerBuilder() - .acceptOnly(Integer.class) - .withExecutor((InstanceIdentifier, Void) -> 3).build(); + .acceptOnly(Integer.class) + .withExecutor((InstanceIdentifier, Void) -> 3).build(); final Optional stringDump = stringManager.getDump(identifier, cache, NO_PARAMS); final Optional integerDump = intManager.getDump(identifier, cache, NO_PARAMS); @@ -153,6 +153,21 @@ public class DumpCacheManagerTest { } + @Test + public void testCachingWithDifferentParams() throws ReadFailedException { + final DumpCacheManager manager = + new DumpCacheManager.DumpCacheManagerBuilder() + .withExecutor((iid, param) -> param) + .acceptOnly(Integer.class) + .build(); + + final Optional dump1 = manager.getDump(identifier, cache, 1); + final Optional dump2 = manager.getDump(identifier, cache, 2); + + assertEquals(1, dump1.get().intValue()); + assertEquals(2, dump2.get().intValue()); + } + private EntityDumpPostProcessingFunction 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 identifierBothKeyed; private InstanceIdentifier identifierOneMissing; private InstanceIdentifier identifierNoneKeyed; - private TypeAwareIdentifierCacheKeyFactory simpleKeyFactory; - private TypeAwareIdentifierCacheKeyFactory complexKeyFactory; + private TypeAwareIdentifierCacheKeyFactory simpleKeyFactory; + private TypeAwareIdentifierCacheKeyFactory complexKeyFactory; + private TypeAwareIdentifierCacheKeyFactory 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) { -- cgit 1.2.3-korg