Skip to content

Commit

Permalink
GEODE-3550: Improve snapshot filter testing
Browse files Browse the repository at this point in the history
This closes apache#754
  • Loading branch information
Nick Reich authored and dschneider-pivotal committed Sep 1, 2017
1 parent fecec42 commit d98a701
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,65 @@ public void afterCreate(EntryEvent<Integer, MyObject> event) {
}

@Test
public void testFilter() throws Exception {
public void testFilterOnExport() throws Exception {
SnapshotFilter<Integer, MyObject> odd =
(SnapshotFilter<Integer, MyObject>) 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<Integer, MyObject> region =
regionGenerator.createRegion(cache, diskStore.getName(), rt, name);
final Map<Integer, MyObject> expected = createExpected(st);

region.putAll(expected);
RegionSnapshotService<Integer, MyObject> rss = region.getSnapshotService();
SnapshotOptions<Integer, MyObject> 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<Integer, MyObject> odd =
(SnapshotFilter<Integer, MyObject>) 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<Integer, MyObject> region =
regionGenerator.createRegion(cache, diskStore.getName(), rt, name);
final Map<Integer, MyObject> expected = createExpected(st);

region.putAll(expected);
RegionSnapshotService<Integer, MyObject> rss = region.getSnapshotService();
rss.save(snapshotFile, SnapshotFormat.GEMFIRE, rss.createOptions());

region.destroyRegion();
region = regionGenerator.createRegion(cache, diskStore.getName(), rt, name);

rss = region.getSnapshotService();
SnapshotOptions<Integer, MyObject> 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<Integer, MyObject> even =
(SnapshotFilter<Integer, MyObject>) entry -> entry.getKey() % 2 == 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ File getSnapshotDirectory() {

Map<Integer, MyObject> createExpected(SerializationType type) {
Map<Integer, MyObject> 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;
Expand Down

0 comments on commit d98a701

Please sign in to comment.