Search in sources :

Example 6 with MyObject

use of com.examples.snapshot.MyObject in project geode by apache.

the class RegionSnapshotJUnitTest method testExportAndImport.

@Test
public void testExportAndImport() 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);
            region.destroyRegion();
            region = rgen.createRegion(cache, ds.getName(), rt, name);
            region.getAttributesMutator().setCacheWriter(new CacheWriterAdapter<Integer, MyObject>() {

                @Override
                public void beforeCreate(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 afterCreate(EntryEvent<Integer, MyObject> event) {
                    cltest.set(true);
                }
            });
            region.getSnapshotService().load(f, SnapshotFormat.GEMFIRE);
            assertEquals("Comparison failure for " + rt.name() + "/" + st.name(), expected.entrySet(), region.entrySet());
            assertEquals("CacheListener invoked during import", false, cltest.get());
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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 7 with MyObject

use of com.examples.snapshot.MyObject in project geode by apache.

the class RegionSnapshotJUnitTest method testFilterImportException.

@Test
public void testFilterImportException() 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();
            rss.save(f, SnapshotFormat.GEMFIRE);
            region.destroyRegion();
            region = rgen.createRegion(cache, ds.getName(), rt, name);
            rss = region.getSnapshotService();
            SnapshotOptions<Integer, MyObject> options = rss.createOptions().setFilter(oops);
            boolean caughtException = false;
            try {
                rss.load(f, SnapshotFormat.GEMFIRE, options);
            } catch (RuntimeException e) {
                caughtException = true;
            }
            assertTrue(caughtException);
            assertEquals("Comparison failure for " + rt.name() + "/" + st.name(), 0, region.size());
        }
    }
}
Also used : RegionType(org.apache.geode.cache.snapshot.RegionGenerator.RegionType) Entry(java.util.Map.Entry) 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 8 with MyObject

use of com.examples.snapshot.MyObject in project geode by apache.

the class SnapshotDUnitTest method testExportAndImport.

@Test
public void testExportAndImport() throws Exception {
    File dir = new File(getDiskDirs()[0], "snap");
    dir.mkdir();
    // save all regions
    getCache().getSnapshotService().save(dir, SnapshotFormat.GEMFIRE);
    // update regions with data to be overwritten by import
    updateRegions();
    SerializableCallable callbacks = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            for (final RegionType rt : RegionType.values()) {
                for (final SerializationType st : SerializationType.values()) {
                    String name = "test-" + rt.name() + "-" + st.name();
                    Cache c = getCache();
                    Region<Integer, MyObject> region = c.getRegion(name);
                    region.getAttributesMutator().setCacheWriter(new CacheWriterAdapter<Integer, MyObject>() {

                        @Override
                        public void beforeUpdate(EntryEvent<Integer, MyObject> event) {
                            fail("CacheWriter invoked during import");
                        }
                    });
                    region.getAttributesMutator().addCacheListener(new CacheListenerAdapter<Integer, MyObject>() {

                        @Override
                        public void afterUpdate(EntryEvent<Integer, MyObject> event) {
                            fail("CacheListener invoked during import");
                        }
                    });
                }
            }
            return null;
        }
    };
    // add callbacks
    forEachVm(callbacks, true);
    // load all regions
    loadRegions(dir, null);
}
Also used : RegionType(org.apache.geode.cache.snapshot.RegionGenerator.RegionType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) MyObject(com.examples.snapshot.MyObject) File(java.io.File) SerializationType(org.apache.geode.cache.snapshot.RegionGenerator.SerializationType) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 9 with MyObject

use of com.examples.snapshot.MyObject in project geode by apache.

the class SnapshotDUnitTest method postSetUp.

@Override
public final void postSetUp() throws Exception {
    loadCache();
    RegionGenerator rgen = new RegionGenerator();
    for (final RegionType rt : RegionType.values()) {
        for (final SerializationType st : SerializationType.values()) {
            Region<Integer, MyObject> region = getCache().getRegion("test-" + rt.name() + "-" + st.name());
            region.putAll(createExpected(st, rgen));
        }
    }
}
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 10 with MyObject

use of com.examples.snapshot.MyObject in project geode by apache.

the class SnapshotDUnitTest method testExportAndImportWithInvokeCallbacksEnabled.

@Test
public void testExportAndImportWithInvokeCallbacksEnabled() throws Exception {
    File dir = new File(getDiskDirs()[0], "callbacks");
    dir.mkdir();
    // save all regions
    CacheSnapshotService service = getCache().getSnapshotService();
    service.save(dir, SnapshotFormat.GEMFIRE);
    // update regions with data to be overwritten by import
    updateRegions();
    SerializableCallable callbacks = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            for (final RegionType rt : RegionType.values()) {
                for (final SerializationType st : SerializationType.values()) {
                    String name = "test-" + rt.name() + "-" + st.name();
                    Cache cache = getCache();
                    Region<Integer, MyObject> region = cache.getRegion(name);
                    // add CacheWriter and CacheListener
                    AttributesMutator mutator = region.getAttributesMutator();
                    mutator.setCacheWriter(new CountingCacheWriter());
                    mutator.addCacheListener(new CountingCacheListener());
                    // add AsyncEventQueue
                    addAsyncEventQueue(region, name);
                }
            }
            return null;
        }
    };
    // add callbacks
    forEachVm(callbacks, true);
    // load all regions with invoke callbacks enabled
    SnapshotOptions options = service.createOptions();
    options.invokeCallbacks(true);
    loadRegions(dir, options);
    // verify callbacks were invoked
    verifyCallbacksInvoked();
}
Also used : RegionType(org.apache.geode.cache.snapshot.RegionGenerator.RegionType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) MyObject(com.examples.snapshot.MyObject) File(java.io.File) SerializationType(org.apache.geode.cache.snapshot.RegionGenerator.SerializationType) Cache(org.apache.geode.cache.Cache) AttributesMutator(org.apache.geode.cache.AttributesMutator) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

MyObject (com.examples.snapshot.MyObject)25 Test (org.junit.Test)18 RegionType (org.apache.geode.cache.snapshot.RegionGenerator.RegionType)15 SerializationType (org.apache.geode.cache.snapshot.RegionGenerator.SerializationType)15 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)12 File (java.io.File)11 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)9 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Entry (java.util.Map.Entry)4 Cache (org.apache.geode.cache.Cache)4 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)4 HashMap (java.util.HashMap)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 MyPdxSerializer (com.examples.snapshot.MyPdxSerializer)2 CacheFactory (org.apache.geode.cache.CacheFactory)2 Region (org.apache.geode.cache.Region)2 CqAttributesFactory (org.apache.geode.cache.query.CqAttributesFactory)2 CqEvent (org.apache.geode.cache.query.CqEvent)2 CqQuery (org.apache.geode.cache.query.CqQuery)2