use of com.examples.snapshot.MyObject in project geode by apache.
the class SnapshotPerformanceDUnitTest method execute.
private void execute(int iterations, int dataCount) throws Exception {
RegionType[] rts = new RegionType[] { RegionType.REPLICATE, RegionType.PARTITION };
SerializationType[] sts = new SerializationType[] { SerializationType.DATA_SERIALIZABLE, SerializationType.PDX };
for (RegionType rt : rts) {
for (SerializationType st : sts) {
for (int i = 0; i < iterations; i++) {
Region<Integer, MyObject> region = createRegion(rt, st);
LogWriterUtils.getLogWriter().info("SNP: Testing region " + region.getName() + ", iteration = " + i);
loadData(region, st, dataCount);
doExport(region);
region = createRegion(rt, st);
doImport(region);
}
}
}
}
use of com.examples.snapshot.MyObject in project geode by apache.
the class SnapshotPerformanceDUnitTest method createRegion.
private Region<Integer, MyObject> createRegion(final RegionType rt, final SerializationType st) throws Exception {
final String name = "snapshot-" + rt.name() + "-" + st.name();
Region<Integer, MyObject> region = getCache().getRegion(name);
if (region != null) {
region.destroyRegion();
}
SerializableCallable setup = new SerializableCallable() {
@Override
public Object call() throws Exception {
Cache cache = getCache();
new RegionGenerator().createRegion(cache, null, rt, name);
return null;
}
};
SnapshotDUnitTest.forEachVm(setup, true);
return getCache().getRegion(name);
}
use of com.examples.snapshot.MyObject in project geode by apache.
the class ClientSnapshotDUnitTest method testImport.
@Test
public void testImport() throws Exception {
int count = 1000;
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-import.snapshot");
Region<Integer, MyObject> r = getCache().getRegion("clienttest");
r.getSnapshotService().save(f, SnapshotFormat.GEMFIRE);
return f;
}
};
Host.getHost(0).getVM(3).invoke(export);
for (int i = 0; i < count; i++) {
region.put(i, new MyObject(i, "XXX"));
}
SerializableCallable imp = new SerializableCallable() {
@Override
public Object call() throws Exception {
final AtomicBoolean cqtest = new AtomicBoolean(false);
CqAttributesFactory af = new CqAttributesFactory();
af.addCqListener(new CqListenerAdapter() {
@Override
public void onEvent(CqEvent aCqEvent) {
cqtest.set(true);
}
});
Region<Integer, MyObject> r = getCache().getRegion("clienttest");
CqQuery cq = r.getRegionService().getQueryService().newCq("SELECT * FROM /clienttest", af.create());
cq.execute();
File f = new File(getDiskDirs()[0], "client-import.snapshot");
r.getSnapshotService().load(f, SnapshotFormat.GEMFIRE);
return cqtest.get();
}
};
// add callbacks
region.getAttributesMutator().setCacheWriter(new CacheWriterAdapter<Integer, MyObject>() {
@Override
public void beforeUpdate(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 afterUpdate(EntryEvent<Integer, MyObject> event) {
cltest.set(true);
}
});
boolean cqtest = (Boolean) Host.getHost(0).getVM(3).invoke(imp);
assertEquals("CacheListener invoked during import", false, cltest.get());
assertEquals("CqListener invoked during import", false, cqtest);
for (MyObject obj : region.values()) {
assertTrue(obj.getF2().startsWith("clienttest"));
}
}
use of com.examples.snapshot.MyObject in project geode by apache.
the class ClientSnapshotDUnitTest method testClientCallbacks.
@Test
public void testClientCallbacks() throws Exception {
int count = 1000;
for (int i = 0; i < count; i++) {
region.put(i, new MyObject(i, "clienttest " + i));
}
File f = new File(getDiskDirs()[0], "client-callback.snapshot");
region.getSnapshotService().save(f, SnapshotFormat.GEMFIRE);
for (int i = 0; i < count; i++) {
region.put(i, new MyObject(i, "XXX"));
}
SerializableCallable callbacks = new SerializableCallable() {
@Override
public Object call() throws Exception {
Region<Integer, MyObject> r = getCache().getRegion("clienttest");
r.registerInterestRegex(".*");
r.getAttributesMutator().setCacheWriter(new CacheWriterAdapter<Integer, MyObject>() {
@Override
public void beforeUpdate(EntryEvent<Integer, MyObject> event) {
fail("CacheWriter invoked during import");
}
});
r.getAttributesMutator().addCacheListener(new CacheListenerAdapter<Integer, MyObject>() {
@Override
public void afterUpdate(EntryEvent<Integer, MyObject> event) {
fail("CacheListener was invoked during import");
}
});
final AtomicBoolean cqtest = new AtomicBoolean(false);
CqAttributesFactory af = new CqAttributesFactory();
af.addCqListener(new CqListenerAdapter() {
@Override
public void onEvent(CqEvent aCqEvent) {
fail("Cq was invoked during import");
}
});
CqQuery cq = r.getRegionService().getQueryService().newCq("SELECT * FROM /clienttest", af.create());
cq.execute();
return null;
}
};
Host.getHost(0).getVM(3).invoke(callbacks);
region.getSnapshotService().load(f, SnapshotFormat.GEMFIRE);
}
use of com.examples.snapshot.MyObject in project geode by apache.
the class ClientSnapshotDUnitTest method testInvalidate.
@Test
public void testInvalidate() throws Exception {
SerializableCallable invalid = new SerializableCallable() {
@Override
public Object call() throws Exception {
Region<Integer, MyObject> r = getCache().getRegion("clienttest");
r.put(1, new MyObject(1, "invalidate"));
r.invalidate(1);
File f = new File(getDiskDirs()[0], "client-invalidate.snapshot");
r.getSnapshotService().save(f, SnapshotFormat.GEMFIRE);
r.getSnapshotService().load(f, SnapshotFormat.GEMFIRE);
return null;
}
};
Host.getHost(0).getVM(3).invoke(invalid);
assertTrue(region.containsKey(1));
assertFalse(region.containsValueForKey(1));
assertNull(region.get(1));
}
Aggregations