DumpCacheManager: make dumpParams optional 85/8185/1
authorMarek Gradzki <mgradzki@cisco.com>
Wed, 23 Aug 2017 12:10:46 +0000 (14:10 +0200)
committerMarek Gradzki <mgradzki@cisco.com>
Wed, 23 Aug 2017 14:04:49 +0000 (16:04 +0200)
Change-Id: I6ee37f9e39842468f746656dff53b98c2b3796ba
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
infra/translate-utils/src/main/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManager.java
infra/translate-utils/src/test/java/io/fd/honeycomb/translate/util/read/cache/DumpCacheManagerTest.java

index d3cfd41..a085679 100644 (file)
@@ -52,6 +52,21 @@ public final class DumpCacheManager<T, U> {
         this.acceptOnly = builder.acceptOnly;
     }
 
+    /**
+     * Returns {@link Optional<T>} of dump
+     *
+     * @param identifier identifier for origin of dumping context
+     * @param cache      modification cache of current transaction
+     * @throws ReadFailedException if execution of dumping request failed
+     * @returns If present in cache ,returns cached instance, if not, tries to dump data using provided executor,
+     * otherwise Optional.absent()
+     */
+    public Optional<T> getDump(@Nonnull final InstanceIdentifier<?> identifier,
+                               @Nonnull final ModificationCache cache)
+            throws ReadFailedException {
+        return getDump(identifier, cache, null);
+    }
+
     /**
      * Returns {@link Optional<T>} of dump
      *
index dfdcd08..5f93624 100644 (file)
@@ -86,7 +86,7 @@ public class DumpCacheManagerTest {
         // executor cant return null data
         when(executor.executeDump(identifier, NO_PARAMS)).thenReturn(new IpDetailsReplyDump());
 
-        final Optional<IpDetailsReplyDump> stage1Optional = managerNegative.getDump(identifier, cache, NO_PARAMS);
+        final Optional<IpDetailsReplyDump> stage1Optional = managerNegative.getDump(identifier, cache);
 
         // this is first call so instance should be from executor
         // and it should be cached after calling executor
@@ -99,7 +99,7 @@ public class DumpCacheManagerTest {
         IpDetailsReplyDump stage2LoadedDump = new IpDetailsReplyDump();
         when(executor.executeDump(identifier, NO_PARAMS)).thenReturn(stage2LoadedDump);
 
-        final Optional<IpDetailsReplyDump> stage2Optional = managerPositive.getDump(identifier, cache, NO_PARAMS);
+        final Optional<IpDetailsReplyDump> stage2Optional = managerPositive.getDump(identifier, cache);
 
         assertEquals(true, stage2Optional.isPresent());
         assertEquals(stage2LoadedDump, stage2Optional.get());
@@ -108,7 +108,7 @@ public class DumpCacheManagerTest {
         IpDetailsReplyDump stage3LoadedDump = new IpDetailsReplyDump();
         when(executor.executeDump(identifier, NO_PARAMS)).thenReturn(stage3LoadedDump);
 
-        final Optional<IpDetailsReplyDump> stage3Optional = managerPositive.getDump(identifier, cache, NO_PARAMS);
+        final Optional<IpDetailsReplyDump> stage3Optional = managerPositive.getDump(identifier, cache);
         assertEquals(true, stage3Optional.isPresent());
         //check if it returns instance cached from previous stage
         assertEquals(stage2LoadedDump, stage3Optional.get());
@@ -124,7 +124,7 @@ public class DumpCacheManagerTest {
         when(executor.executeDump(identifier, null)).thenReturn(dump);
 
         Optional<IpDetailsReplyDump> optionalDump =
-                managerPositiveWithPostProcessing.getDump(identifier, cache, NO_PARAMS);
+                managerPositiveWithPostProcessing.getDump(identifier, cache);
 
         assertEquals(true, optionalDump.isPresent());
         assertEquals(1, optionalDump.get().ipDetails.size());
@@ -143,8 +143,8 @@ public class DumpCacheManagerTest {
             .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);
+        final Optional<String> stringDump = stringManager.getDump(identifier, cache);
+        final Optional<Integer> integerDump = intManager.getDump(identifier, cache);
 
         assertTrue(stringDump.isPresent());
         assertTrue(integerDump.isPresent());