use of com.examples.snapshot.MyObject in project geode by apache.
the class RegionSnapshotJUnitTest method testInvalidate.
@Test
public void testInvalidate() throws Exception {
Region<Integer, MyObject> region = rgen.createRegion(cache, ds.getName(), RegionType.REPLICATE, "test");
MyObject obj = rgen.createData(SerializationType.SERIALIZABLE, 1, "invalidated value");
region.put(1, obj);
region.invalidate(1);
region.getSnapshotService().save(f, SnapshotFormat.GEMFIRE);
region.getSnapshotService().load(f, SnapshotFormat.GEMFIRE);
assertTrue(region.containsKey(1));
assertFalse(region.containsValueForKey(1));
assertNull(region.get(1));
}
use of com.examples.snapshot.MyObject in project geode by apache.
the class RegionSnapshotJUnitTest method testFilter.
@Test
public void testFilter() throws Exception {
SnapshotFilter<Integer, MyObject> even = new SnapshotFilter<Integer, MyObject>() {
@Override
public boolean accept(Entry<Integer, MyObject> entry) {
return entry.getKey() % 2 == 0;
}
};
SnapshotFilter<Integer, MyObject> odd = new SnapshotFilter<Integer, MyObject>() {
@Override
public boolean accept(Entry<Integer, MyObject> entry) {
return 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 = 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(even);
rss.save(f, SnapshotFormat.GEMFIRE, options);
region.destroyRegion();
region = rgen.createRegion(cache, ds.getName(), rt, name);
rss = region.getSnapshotService();
options = rss.createOptions().setFilter(odd);
rss.load(f, SnapshotFormat.GEMFIRE, options);
assertEquals("Comparison failure for " + rt.name() + "/" + st.name(), 0, region.size());
}
}
}
use of com.examples.snapshot.MyObject in project geode by apache.
the class RegionSnapshotJUnitTest method testExportAndReadSnapshot.
@Test
public void testExportAndReadSnapshot() 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);
final Map<Integer, Object> read = new HashMap<Integer, Object>();
SnapshotIterator<Integer, Object> iter = SnapshotReader.read(f);
try {
while (iter.hasNext()) {
Entry<Integer, Object> entry = iter.next();
read.put(entry.getKey(), entry.getValue());
}
assertEquals("Comparison failure for " + rt.name() + "/" + st.name(), expected, read);
} finally {
iter.close();
}
}
}
}
use of com.examples.snapshot.MyObject in project geode by apache.
the class RegionSnapshotJUnitTest method testDSID.
@Test
public void testDSID() throws Exception {
cache.close();
CacheFactory cf = new CacheFactory().set(MCAST_PORT, "0").set(LOG_LEVEL, "error").setPdxSerializer(new MyPdxSerializer()).set(DISTRIBUTED_SYSTEM_ID, "1");
cache = cf.create();
RegionType rt = RegionType.REPLICATE;
SerializationType st = SerializationType.PDX_SERIALIZER;
String name = "test-" + rt.name() + "-" + st.name() + "-dsid";
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);
cache.close();
// change the DSID from 1 -> 100
CacheFactory cf2 = new CacheFactory().set(MCAST_PORT, "0").set(LOG_LEVEL, "error").setPdxSerializer(new MyPdxSerializer()).set(DISTRIBUTED_SYSTEM_ID, "100");
cache = cf2.create();
final Map<Integer, Object> read = new HashMap<Integer, Object>();
SnapshotIterator<Integer, Object> iter = SnapshotReader.read(f);
try {
while (iter.hasNext()) {
Entry<Integer, Object> entry = iter.next();
read.put(entry.getKey(), entry.getValue());
}
assertEquals("Comparison failure for " + rt.name() + "/" + st.name(), expected, read);
} finally {
iter.close();
}
}
use of com.examples.snapshot.MyObject in project geode by apache.
the class OfflineSnapshotJUnitTest method testLargeFileExport.
@Test
public void testLargeFileExport() throws Exception {
int count = 10000;
Region<Integer, MyObject> region = rgen.createRegion(cache, ds.getName(), RegionType.PARTITION_PERSISTENT, "test");
System.out.println("Creating entries...");
final Map<Integer, MyObject> expected = createExpected(SerializationType.DATA_SERIALIZABLE, count);
region.putAll(expected);
cache.close();
System.out.println("Recovering entries...");
for (int i = 0; i < 10; i++) {
long start = System.currentTimeMillis();
DiskStoreImpl.exportOfflineSnapshot(ds.getName(), new File[] { new File(".") }, new File("."));
long elapsed = System.currentTimeMillis() - start;
double rate = 1.0 * count / elapsed;
System.out.println("Created snapshot with " + count + " entries in " + elapsed + " ms (" + rate + " entries/ms)");
SnapshotTestUtil.checkSnapshotEntries(new File("."), expected, ds.getName(), region.getName());
}
}
Aggregations