use of org.apache.geode.cache.snapshot.RegionGenerator.SerializationType in project geode by apache.
the class SnapshotDUnitTest method verifyCallbacksInvoked.
private void verifyCallbacksInvoked() throws Exception {
for (final RegionType rt : RegionType.values()) {
for (final SerializationType st : SerializationType.values()) {
SerializableCallable counts = new SerializableCallable() {
@Override
public Object call() throws Exception {
String name = "test-" + rt.name() + "-" + st.name();
Region<Integer, MyObject> region = getCache().getRegion(name);
// get CacheWriter and CacheListener events
CountingCacheWriter writer = (CountingCacheWriter) region.getAttributes().getCacheWriter();
CountingCacheListener listener = (CountingCacheListener) region.getAttributes().getCacheListener();
// get AsyncEventListener events
int numAeqEvents = 0;
AsyncEventQueue aeq = getCache().getAsyncEventQueue(name);
CountingAsyncEventListener aeqListener = (CountingAsyncEventListener) aeq.getAsyncEventListener();
if (aeq.isPrimary()) {
Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> aeqListener.getEvents() == NUM_ENTRIES);
numAeqEvents = aeqListener.getEvents();
}
return new int[] { writer.getEvents(), listener.getEvents(), numAeqEvents };
}
};
Object result = forEachVm(counts, true);
int totalWriterUpdates = 0, totalListenerUpdates = 0, totalAeqEvents = 0;
List<int[]> list = (List) result;
for (int[] vmResult : list) {
totalWriterUpdates += vmResult[0];
totalListenerUpdates += vmResult[1];
totalAeqEvents += vmResult[2];
}
if (rt.name().contains("PARTITION")) {
assertEquals(NUM_ENTRIES, totalListenerUpdates);
} else {
assertEquals(NUM_ENTRIES * (Host.getHost(0).getVMCount() + 1), totalListenerUpdates);
}
assertEquals(NUM_ENTRIES, totalWriterUpdates);
assertEquals(NUM_ENTRIES, totalAeqEvents);
}
}
}
use of org.apache.geode.cache.snapshot.RegionGenerator.SerializationType in project geode by apache.
the class SnapshotDUnitTest method updateRegions.
private void updateRegions() {
for (final RegionType rt : RegionType.values()) {
for (final SerializationType st : SerializationType.values()) {
String name = "test-" + rt.name() + "-" + st.name();
// overwrite region with bad data
Region<Integer, MyObject> region = getCache().getRegion(name);
for (Entry<Integer, MyObject> entry : region.entrySet()) {
region.put(entry.getKey(), new MyObject(Integer.MAX_VALUE, "bad!!"));
}
}
}
}
use of org.apache.geode.cache.snapshot.RegionGenerator.SerializationType in project geode by apache.
the class SnapshotDUnitTest method loadCache.
public void loadCache() throws Exception {
SerializableCallable setup = new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer()).setPdxPersistent(true);
Cache cache = getCache(cf);
DiskStore ds = cache.createDiskStoreFactory().setMaxOplogSize(1).setDiskDirs(getDiskDirs()).create("snapshotTest");
RegionGenerator rgen = new RegionGenerator();
for (final RegionType rt : RegionType.values()) {
for (final SerializationType st : SerializationType.values()) {
rgen.createRegion(cache, ds.getName(), rt, "test-" + rt.name() + "-" + st.name());
}
}
return null;
}
};
forEachVm(setup, true);
}
use of org.apache.geode.cache.snapshot.RegionGenerator.SerializationType 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 org.apache.geode.cache.snapshot.RegionGenerator.SerializationType 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();
}
}
}
}
Aggregations