use of com.examples.snapshot.MyObject in project geode by apache.
the class ClientSnapshotDUnitTest method testExport.
@Test
public void testExport() throws Exception {
int count = 10000;
for (int i = 0; i < count; i++) {
region.put(i, new MyObject(i, "clienttest " + i));
}
SerializableCallable export = new SerializableCallable() {
@Override
public Object call() throws Exception {
File f = new File(getDiskDirs()[0], "client-export.snapshot");
Region<Integer, MyObject> r = getCache().getRegion("clienttest");
r.getSnapshotService().save(f, SnapshotFormat.GEMFIRE);
return f;
}
};
File snapshot = (File) Host.getHost(0).getVM(3).invoke(export);
SnapshotIterator<Integer, MyObject> iter = SnapshotReader.read(snapshot);
try {
while (iter.hasNext()) {
iter.next();
count--;
}
assertEquals(0, count);
} finally {
iter.close();
}
}
use of com.examples.snapshot.MyObject in project geode by apache.
the class ClientSnapshotDUnitTest method loadCache.
@SuppressWarnings("serial")
public void loadCache() throws Exception {
CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer());
Cache cache = getCache(cf);
CacheServer server = cache.addCacheServer();
final int port = AvailablePortHelper.getRandomAvailableTCPPort();
server.setPort(port);
server.start();
region = cache.<Integer, MyObject>createRegionFactory(RegionShortcut.REPLICATE).create("clienttest");
final Host host = Host.getHost(0);
SerializableCallable client = new SerializableCallable() {
@Override
public Object call() throws Exception {
ClientCacheFactory cf = new ClientCacheFactory().set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel()).setPdxSerializer(new MyPdxSerializer()).addPoolServer(NetworkUtils.getServerHostName(host), port).setPoolSubscriptionEnabled(true).setPoolPRSingleHopEnabled(false);
ClientCache cache = getClientCache(cf);
Region r = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY_HEAP_LRU).setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(5)).create("clienttest");
return null;
}
};
SerializableCallable remote = new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer());
Cache cache = getCache(cf);
cache.<Integer, MyObject>createRegionFactory(RegionShortcut.REPLICATE).create("clienttest");
return null;
}
};
host.getVM(3).invoke(client);
host.getVM(2).invoke(remote);
}
use of com.examples.snapshot.MyObject in project geode by apache.
the class SnapshotTestUtil method checkSnapshotEntries.
public static <K, V> void checkSnapshotEntries(File dir, Map<K, V> expected, String diskStoreName, String regionName) throws Exception {
final Map<K, V> testData = new HashMap<K, V>(expected);
String snapshot = "snapshot-" + diskStoreName + "-" + regionName + ".gfd";
SnapshotIterator<Integer, MyObject> iter = SnapshotReader.read(new File(dir, snapshot));
try {
while (iter.hasNext()) {
Entry<Integer, MyObject> entry = iter.next();
Object expectedVal = testData.remove(entry.getKey());
assertEquals(expectedVal, entry.getValue());
}
assertTrue(testData.isEmpty());
} finally {
iter.close();
}
}
use of com.examples.snapshot.MyObject in project geode by apache.
the class OfflineSnapshotJUnitTest method testExport.
@Test
public void testExport() throws Exception {
int rcount = 0;
for (final RegionType rt : RegionType.persistentValues()) {
for (final SerializationType st : SerializationType.offlineValues()) {
Region<Integer, MyObject> region = rgen.createRegion(cache, ds.getName(), rt, "test" + rcount++);
final Map<Integer, MyObject> expected = createExpected(st, 1000);
region.putAll(expected);
cache.close();
DiskStoreImpl.exportOfflineSnapshot(ds.getName(), new File[] { new File(".") }, new File("."));
SnapshotTestUtil.checkSnapshotEntries(new File("."), expected, ds.getName(), region.getName());
reset();
}
}
}
use of com.examples.snapshot.MyObject 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());
}
}
}
Aggregations