Search in sources :

Example 11 with MyObject

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

the class SnapshotPerformanceDUnitTest method execute.

private void execute(int iterations, int dataCount) throws Exception {
    RegionType[] rts = new RegionType[] { RegionType.REPLICATE, RegionType.PARTITION };
    SerializationType[] sts = new SerializationType[] { SerializationType.DATA_SERIALIZABLE, SerializationType.PDX };
    for (RegionType rt : rts) {
        for (SerializationType st : sts) {
            for (int i = 0; i < iterations; i++) {
                Region<Integer, MyObject> region = createRegion(rt, st);
                LogWriterUtils.getLogWriter().info("SNP: Testing region " + region.getName() + ", iteration = " + i);
                loadData(region, st, dataCount);
                doExport(region);
                region = createRegion(rt, st);
                doImport(region);
            }
        }
    }
}
Also used : RegionType(org.apache.geode.cache.snapshot.RegionGenerator.RegionType) MyObject(com.examples.snapshot.MyObject) SerializationType(org.apache.geode.cache.snapshot.RegionGenerator.SerializationType)

Example 12 with MyObject

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

the class SnapshotPerformanceDUnitTest method createRegion.

private Region<Integer, MyObject> createRegion(final RegionType rt, final SerializationType st) throws Exception {
    final String name = "snapshot-" + rt.name() + "-" + st.name();
    Region<Integer, MyObject> region = getCache().getRegion(name);
    if (region != null) {
        region.destroyRegion();
    }
    SerializableCallable setup = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Cache cache = getCache();
            new RegionGenerator().createRegion(cache, null, rt, name);
            return null;
        }
    };
    SnapshotDUnitTest.forEachVm(setup, true);
    return getCache().getRegion(name);
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) MyObject(com.examples.snapshot.MyObject) Cache(org.apache.geode.cache.Cache)

Example 13 with MyObject

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

the class ClientSnapshotDUnitTest method testImport.

@Test
public void testImport() throws Exception {
    int count = 1000;
    for (int i = 0; i < count; i++) {
        region.put(i, new MyObject(i, "clienttest " + i));
    }
    SerializableCallable export = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            File f = new File(getDiskDirs()[0], "client-import.snapshot");
            Region<Integer, MyObject> r = getCache().getRegion("clienttest");
            r.getSnapshotService().save(f, SnapshotFormat.GEMFIRE);
            return f;
        }
    };
    Host.getHost(0).getVM(3).invoke(export);
    for (int i = 0; i < count; i++) {
        region.put(i, new MyObject(i, "XXX"));
    }
    SerializableCallable imp = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            final AtomicBoolean cqtest = new AtomicBoolean(false);
            CqAttributesFactory af = new CqAttributesFactory();
            af.addCqListener(new CqListenerAdapter() {

                @Override
                public void onEvent(CqEvent aCqEvent) {
                    cqtest.set(true);
                }
            });
            Region<Integer, MyObject> r = getCache().getRegion("clienttest");
            CqQuery cq = r.getRegionService().getQueryService().newCq("SELECT * FROM /clienttest", af.create());
            cq.execute();
            File f = new File(getDiskDirs()[0], "client-import.snapshot");
            r.getSnapshotService().load(f, SnapshotFormat.GEMFIRE);
            return cqtest.get();
        }
    };
    // add callbacks
    region.getAttributesMutator().setCacheWriter(new CacheWriterAdapter<Integer, MyObject>() {

        @Override
        public void beforeUpdate(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 afterUpdate(EntryEvent<Integer, MyObject> event) {
            cltest.set(true);
        }
    });
    boolean cqtest = (Boolean) Host.getHost(0).getVM(3).invoke(imp);
    assertEquals("CacheListener invoked during import", false, cltest.get());
    assertEquals("CqListener invoked during import", false, cqtest);
    for (MyObject obj : region.values()) {
        assertTrue(obj.getF2().startsWith("clienttest"));
    }
}
Also used : CqListenerAdapter(org.apache.geode.cache.util.CqListenerAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CqEvent(org.apache.geode.cache.query.CqEvent) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) MyObject(com.examples.snapshot.MyObject) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqQuery(org.apache.geode.cache.query.CqQuery) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) File(java.io.File) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 14 with MyObject

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

the class ClientSnapshotDUnitTest method testClientCallbacks.

@Test
public void testClientCallbacks() throws Exception {
    int count = 1000;
    for (int i = 0; i < count; i++) {
        region.put(i, new MyObject(i, "clienttest " + i));
    }
    File f = new File(getDiskDirs()[0], "client-callback.snapshot");
    region.getSnapshotService().save(f, SnapshotFormat.GEMFIRE);
    for (int i = 0; i < count; i++) {
        region.put(i, new MyObject(i, "XXX"));
    }
    SerializableCallable callbacks = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Region<Integer, MyObject> r = getCache().getRegion("clienttest");
            r.registerInterestRegex(".*");
            r.getAttributesMutator().setCacheWriter(new CacheWriterAdapter<Integer, MyObject>() {

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

                @Override
                public void afterUpdate(EntryEvent<Integer, MyObject> event) {
                    fail("CacheListener was invoked during import");
                }
            });
            final AtomicBoolean cqtest = new AtomicBoolean(false);
            CqAttributesFactory af = new CqAttributesFactory();
            af.addCqListener(new CqListenerAdapter() {

                @Override
                public void onEvent(CqEvent aCqEvent) {
                    fail("Cq was invoked during import");
                }
            });
            CqQuery cq = r.getRegionService().getQueryService().newCq("SELECT * FROM /clienttest", af.create());
            cq.execute();
            return null;
        }
    };
    Host.getHost(0).getVM(3).invoke(callbacks);
    region.getSnapshotService().load(f, SnapshotFormat.GEMFIRE);
}
Also used : CqListenerAdapter(org.apache.geode.cache.util.CqListenerAdapter) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CqEvent(org.apache.geode.cache.query.CqEvent) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) MyObject(com.examples.snapshot.MyObject) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqQuery(org.apache.geode.cache.query.CqQuery) File(java.io.File) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 15 with MyObject

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

the class ClientSnapshotDUnitTest method testInvalidate.

@Test
public void testInvalidate() throws Exception {
    SerializableCallable invalid = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Region<Integer, MyObject> r = getCache().getRegion("clienttest");
            r.put(1, new MyObject(1, "invalidate"));
            r.invalidate(1);
            File f = new File(getDiskDirs()[0], "client-invalidate.snapshot");
            r.getSnapshotService().save(f, SnapshotFormat.GEMFIRE);
            r.getSnapshotService().load(f, SnapshotFormat.GEMFIRE);
            return null;
        }
    };
    Host.getHost(0).getVM(3).invoke(invalid);
    assertTrue(region.containsKey(1));
    assertFalse(region.containsValueForKey(1));
    assertNull(region.get(1));
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) MyObject(com.examples.snapshot.MyObject) File(java.io.File) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) 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