Search in sources :

Example 11 with RegionType

use of org.apache.geode.cache.snapshot.RegionGenerator.RegionType 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);
        }
    }
}
Also used : RegionType(org.apache.geode.cache.snapshot.RegionGenerator.RegionType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) MyObject(com.examples.snapshot.MyObject) MyObject(com.examples.snapshot.MyObject) ArrayList(java.util.ArrayList) List(java.util.List) SerializationType(org.apache.geode.cache.snapshot.RegionGenerator.SerializationType)

Example 12 with RegionType

use of org.apache.geode.cache.snapshot.RegionGenerator.RegionType 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!!"));
            }
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RegionType(org.apache.geode.cache.snapshot.RegionGenerator.RegionType) MyObject(com.examples.snapshot.MyObject) SerializationType(org.apache.geode.cache.snapshot.RegionGenerator.SerializationType)

Example 13 with RegionType

use of org.apache.geode.cache.snapshot.RegionGenerator.RegionType 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);
}
Also used : MyPdxSerializer(com.examples.snapshot.MyPdxSerializer) DiskStore(org.apache.geode.cache.DiskStore) RegionType(org.apache.geode.cache.snapshot.RegionGenerator.RegionType) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache) SerializationType(org.apache.geode.cache.snapshot.RegionGenerator.SerializationType)

Example 14 with RegionType

use of org.apache.geode.cache.snapshot.RegionGenerator.RegionType 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());
        }
    }
}
Also used : Entry(java.util.Map.Entry) RegionType(org.apache.geode.cache.snapshot.RegionGenerator.RegionType) MyObject(com.examples.snapshot.MyObject) SerializationType(org.apache.geode.cache.snapshot.RegionGenerator.SerializationType) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 15 with RegionType

use of org.apache.geode.cache.snapshot.RegionGenerator.RegionType 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();
            }
        }
    }
}
Also used : RegionType(org.apache.geode.cache.snapshot.RegionGenerator.RegionType) HashMap(java.util.HashMap) MyObject(com.examples.snapshot.MyObject) MyObject(com.examples.snapshot.MyObject) SerializationType(org.apache.geode.cache.snapshot.RegionGenerator.SerializationType) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

RegionType (org.apache.geode.cache.snapshot.RegionGenerator.RegionType)16 SerializationType (org.apache.geode.cache.snapshot.RegionGenerator.SerializationType)16 MyObject (com.examples.snapshot.MyObject)15 Test (org.junit.Test)11 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 File (java.io.File)4 Entry (java.util.Map.Entry)4 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)4 Cache (org.apache.geode.cache.Cache)3 MyPdxSerializer (com.examples.snapshot.MyPdxSerializer)2 HashMap (java.util.HashMap)2 CacheFactory (org.apache.geode.cache.CacheFactory)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 FileFilter (java.io.FileFilter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AttributesMutator (org.apache.geode.cache.AttributesMutator)1 DiskStore (org.apache.geode.cache.DiskStore)1