From d98a70108d7b008946d41b1ac5df5d52ee77236e Mon Sep 17 00:00:00 2001 From: Nick Reich Date: Thu, 31 Aug 2017 16:29:23 -0700 Subject: [PATCH] GEODE-3550: Improve snapshot filter testing This closes #754 --- .../snapshot/RegionSnapshotJUnitTest.java | 60 ++++++++++++++++++- .../cache/snapshot/SnapshotTestCase.java | 2 +- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/geode-core/src/test/java/org/apache/geode/cache/snapshot/RegionSnapshotJUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/snapshot/RegionSnapshotJUnitTest.java index 46c491c33d5e..1de1b032524b 100644 --- a/geode-core/src/test/java/org/apache/geode/cache/snapshot/RegionSnapshotJUnitTest.java +++ b/geode-core/src/test/java/org/apache/geode/cache/snapshot/RegionSnapshotJUnitTest.java @@ -107,7 +107,65 @@ public void afterCreate(EntryEvent event) { } @Test - public void testFilter() throws Exception { + public void testFilterOnExport() throws Exception { + SnapshotFilter odd = + (SnapshotFilter) entry -> entry.getKey() % 2 == 1; + + for (final RegionType rt : RegionType.values()) { + for (final SerializationType st : SerializationType.values()) { + String name = "test-" + rt.name() + "-" + st.name(); + Region region = + regionGenerator.createRegion(cache, diskStore.getName(), rt, name); + final Map expected = createExpected(st); + + region.putAll(expected); + RegionSnapshotService rss = region.getSnapshotService(); + SnapshotOptions options = rss.createOptions().setFilter(odd); + rss.save(snapshotFile, SnapshotFormat.GEMFIRE, options); + + region.destroyRegion(); + region = regionGenerator.createRegion(cache, diskStore.getName(), rt, name); + + rss = region.getSnapshotService(); + rss.load(snapshotFile, SnapshotFormat.GEMFIRE, rss.createOptions()); + + region.entrySet().forEach(entry -> assertTrue(odd.accept(entry))); + assertTrue("Comparison failure for " + rt.name() + "/" + st.name(), region.size() > 0); + } + } + } + + @Test + public void testFilterOnImport() throws Exception { + SnapshotFilter odd = + (SnapshotFilter) entry -> entry.getKey() % 2 == 1; + + for (final RegionType rt : RegionType.values()) { + for (final SerializationType st : SerializationType.values()) { + String name = "test-" + rt.name() + "-" + st.name(); + Region region = + regionGenerator.createRegion(cache, diskStore.getName(), rt, name); + final Map expected = createExpected(st); + + region.putAll(expected); + RegionSnapshotService rss = region.getSnapshotService(); + rss.save(snapshotFile, SnapshotFormat.GEMFIRE, rss.createOptions()); + + region.destroyRegion(); + region = regionGenerator.createRegion(cache, diskStore.getName(), rt, name); + + rss = region.getSnapshotService(); + SnapshotOptions options = rss.createOptions().setFilter(odd); + rss.load(snapshotFile, SnapshotFormat.GEMFIRE, options); + + region.entrySet().forEach(entry -> assertTrue(odd.accept(entry))); + assertTrue("Comparison failure for " + rt.name() + "/" + st.name(), region.size() > 0); + } + } + } + + @Test + public void testFilterOnExportAndImport() throws Exception { SnapshotFilter even = (SnapshotFilter) entry -> entry.getKey() % 2 == 0; diff --git a/geode-core/src/test/java/org/apache/geode/cache/snapshot/SnapshotTestCase.java b/geode-core/src/test/java/org/apache/geode/cache/snapshot/SnapshotTestCase.java index d0040f7b8f43..25a4c17dde6b 100644 --- a/geode-core/src/test/java/org/apache/geode/cache/snapshot/SnapshotTestCase.java +++ b/geode-core/src/test/java/org/apache/geode/cache/snapshot/SnapshotTestCase.java @@ -67,7 +67,7 @@ File getSnapshotDirectory() { Map createExpected(SerializationType type) { Map expected = new HashMap<>(); - for (int i = 0; i < 1000; i++) { + for (int i = 0; i < 100; i++) { expected.put(i, regionGenerator.createData(type, i, "The number is " + i)); } return expected;