Search in sources :

Example 1 with RegionType

use of org.apache.geode.cache.snapshot.RegionGenerator.RegionType in project geode by apache.

the class OfflineSnapshotJUnitTest method testExport.

@Test
public void testExport() throws Exception {
    int rcount = 0;
    for (final RegionType rt : RegionType.persistentValues()) {
        for (final SerializationType st : SerializationType.offlineValues()) {
            Region<Integer, MyObject> region = rgen.createRegion(cache, ds.getName(), rt, "test" + rcount++);
            final Map<Integer, MyObject> expected = createExpected(st, 1000);
            region.putAll(expected);
            cache.close();
            DiskStoreImpl.exportOfflineSnapshot(ds.getName(), new File[] { new File(".") }, new File("."));
            SnapshotTestUtil.checkSnapshotEntries(new File("."), expected, ds.getName(), region.getName());
            reset();
        }
    }
}
Also used : RegionType(org.apache.geode.cache.snapshot.RegionGenerator.RegionType) MyObject(com.examples.snapshot.MyObject) File(java.io.File) SerializationType(org.apache.geode.cache.snapshot.RegionGenerator.SerializationType) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with RegionType

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

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

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

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

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