use of org.apache.geode.cache.snapshot.RegionGenerator.SerializationType in project geode by apache.
the class RegionSnapshotJUnitTest method testFilterExportException.
@Test
public void testFilterExportException() throws Exception {
SnapshotFilter<Integer, MyObject> oops = new SnapshotFilter<Integer, MyObject>() {
@Override
public boolean accept(Entry<Integer, MyObject> entry) {
throw new RuntimeException();
}
};
for (final RegionType rt : RegionType.values()) {
for (final SerializationType st : SerializationType.values()) {
String name = "test-" + rt.name() + "-" + st.name();
Region<Integer, MyObject> region = rgen.createRegion(cache, ds.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(oops);
boolean caughtException = false;
try {
rss.save(f, SnapshotFormat.GEMFIRE, options);
} catch (RuntimeException e) {
caughtException = true;
}
assertTrue(caughtException);
region.destroyRegion();
region = rgen.createRegion(cache, ds.getName(), rt, name);
rss = region.getSnapshotService();
rss.load(f, SnapshotFormat.GEMFIRE, options);
assertEquals("Comparison failure for " + rt.name() + "/" + st.name(), 0, region.size());
}
}
}
use of org.apache.geode.cache.snapshot.RegionGenerator.SerializationType in project geode by apache.
the class RegionSnapshotJUnitTest method testExportAndImport.
@Test
public void testExportAndImport() throws Exception {
for (final RegionType rt : RegionType.values()) {
for (final SerializationType st : SerializationType.values()) {
String name = "test-" + rt.name() + "-" + st.name();
Region<Integer, MyObject> region = rgen.createRegion(cache, ds.getName(), rt, name);
final Map<Integer, MyObject> expected = createExpected(st);
region.putAll(expected);
region.getSnapshotService().save(f, SnapshotFormat.GEMFIRE);
region.destroyRegion();
region = rgen.createRegion(cache, ds.getName(), rt, name);
region.getAttributesMutator().setCacheWriter(new CacheWriterAdapter<Integer, MyObject>() {
@Override
public void beforeCreate(EntryEvent<Integer, MyObject> event) {
fail("CacheWriter invoked during import");
}
});
final AtomicBoolean cltest = new AtomicBoolean(false);
region.getAttributesMutator().addCacheListener(new CacheListenerAdapter<Integer, MyObject>() {
@Override
public void afterCreate(EntryEvent<Integer, MyObject> event) {
cltest.set(true);
}
});
region.getSnapshotService().load(f, SnapshotFormat.GEMFIRE);
assertEquals("Comparison failure for " + rt.name() + "/" + st.name(), expected.entrySet(), region.entrySet());
assertEquals("CacheListener invoked during import", false, cltest.get());
}
}
}
use of org.apache.geode.cache.snapshot.RegionGenerator.SerializationType in project geode by apache.
the class RegionSnapshotJUnitTest method testFilterImportException.
@Test
public void testFilterImportException() throws Exception {
SnapshotFilter<Integer, MyObject> oops = new SnapshotFilter<Integer, MyObject>() {
@Override
public boolean accept(Entry<Integer, MyObject> entry) {
throw new RuntimeException();
}
};
for (final RegionType rt : RegionType.values()) {
for (final SerializationType st : SerializationType.values()) {
String name = "test-" + rt.name() + "-" + st.name();
Region<Integer, MyObject> region = rgen.createRegion(cache, ds.getName(), rt, name);
final Map<Integer, MyObject> expected = createExpected(st);
region.putAll(expected);
RegionSnapshotService<Integer, MyObject> rss = region.getSnapshotService();
rss.save(f, SnapshotFormat.GEMFIRE);
region.destroyRegion();
region = rgen.createRegion(cache, ds.getName(), rt, name);
rss = region.getSnapshotService();
SnapshotOptions<Integer, MyObject> options = rss.createOptions().setFilter(oops);
boolean caughtException = false;
try {
rss.load(f, SnapshotFormat.GEMFIRE, options);
} catch (RuntimeException e) {
caughtException = true;
}
assertTrue(caughtException);
assertEquals("Comparison failure for " + rt.name() + "/" + st.name(), 0, region.size());
}
}
}
use of org.apache.geode.cache.snapshot.RegionGenerator.SerializationType in project geode by apache.
the class SnapshotDUnitTest method testExportAndImport.
@Test
public void testExportAndImport() throws Exception {
File dir = new File(getDiskDirs()[0], "snap");
dir.mkdir();
// save all regions
getCache().getSnapshotService().save(dir, SnapshotFormat.GEMFIRE);
// update regions with data to be overwritten by import
updateRegions();
SerializableCallable callbacks = new SerializableCallable() {
@Override
public Object call() throws Exception {
for (final RegionType rt : RegionType.values()) {
for (final SerializationType st : SerializationType.values()) {
String name = "test-" + rt.name() + "-" + st.name();
Cache c = getCache();
Region<Integer, MyObject> region = c.getRegion(name);
region.getAttributesMutator().setCacheWriter(new CacheWriterAdapter<Integer, MyObject>() {
@Override
public void beforeUpdate(EntryEvent<Integer, MyObject> event) {
fail("CacheWriter invoked during import");
}
});
region.getAttributesMutator().addCacheListener(new CacheListenerAdapter<Integer, MyObject>() {
@Override
public void afterUpdate(EntryEvent<Integer, MyObject> event) {
fail("CacheListener invoked during import");
}
});
}
}
return null;
}
};
// add callbacks
forEachVm(callbacks, true);
// load all regions
loadRegions(dir, null);
}
use of org.apache.geode.cache.snapshot.RegionGenerator.SerializationType in project geode by apache.
the class SnapshotDUnitTest method postSetUp.
@Override
public final void postSetUp() throws Exception {
loadCache();
RegionGenerator rgen = new RegionGenerator();
for (final RegionType rt : RegionType.values()) {
for (final SerializationType st : SerializationType.values()) {
Region<Integer, MyObject> region = getCache().getRegion("test-" + rt.name() + "-" + st.name());
region.putAll(createExpected(st, rgen));
}
}
}
Aggregations