Search in sources :

Example 1 with SerializationType

use of org.apache.geode.cache.snapshot.RegionGenerator.SerializationType 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());
        }
    }
}
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 2 with SerializationType

use of org.apache.geode.cache.snapshot.RegionGenerator.SerializationType 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 3 with SerializationType

use of org.apache.geode.cache.snapshot.RegionGenerator.SerializationType 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 4 with SerializationType

use of org.apache.geode.cache.snapshot.RegionGenerator.SerializationType 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 5 with SerializationType

use of org.apache.geode.cache.snapshot.RegionGenerator.SerializationType 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)

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