Search in sources :

Example 21 with MyObject

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

the class RegionSnapshotJUnitTest method testInvalidate.

@Test
public void testInvalidate() throws Exception {
    Region<Integer, MyObject> region = rgen.createRegion(cache, ds.getName(), RegionType.REPLICATE, "test");
    MyObject obj = rgen.createData(SerializationType.SERIALIZABLE, 1, "invalidated value");
    region.put(1, obj);
    region.invalidate(1);
    region.getSnapshotService().save(f, SnapshotFormat.GEMFIRE);
    region.getSnapshotService().load(f, SnapshotFormat.GEMFIRE);
    assertTrue(region.containsKey(1));
    assertFalse(region.containsValueForKey(1));
    assertNull(region.get(1));
}
Also used : MyObject(com.examples.snapshot.MyObject) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 22 with MyObject

use of com.examples.snapshot.MyObject 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 23 with MyObject

use of com.examples.snapshot.MyObject 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)

Example 24 with MyObject

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

the class RegionSnapshotJUnitTest method testDSID.

@Test
public void testDSID() throws Exception {
    cache.close();
    CacheFactory cf = new CacheFactory().set(MCAST_PORT, "0").set(LOG_LEVEL, "error").setPdxSerializer(new MyPdxSerializer()).set(DISTRIBUTED_SYSTEM_ID, "1");
    cache = cf.create();
    RegionType rt = RegionType.REPLICATE;
    SerializationType st = SerializationType.PDX_SERIALIZER;
    String name = "test-" + rt.name() + "-" + st.name() + "-dsid";
    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);
    cache.close();
    // change the DSID from 1 -> 100
    CacheFactory cf2 = new CacheFactory().set(MCAST_PORT, "0").set(LOG_LEVEL, "error").setPdxSerializer(new MyPdxSerializer()).set(DISTRIBUTED_SYSTEM_ID, "100");
    cache = cf2.create();
    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 : MyPdxSerializer(com.examples.snapshot.MyPdxSerializer) RegionType(org.apache.geode.cache.snapshot.RegionGenerator.RegionType) HashMap(java.util.HashMap) MyObject(com.examples.snapshot.MyObject) MyObject(com.examples.snapshot.MyObject) CacheFactory(org.apache.geode.cache.CacheFactory) SerializationType(org.apache.geode.cache.snapshot.RegionGenerator.SerializationType) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 25 with MyObject

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

the class OfflineSnapshotJUnitTest method testLargeFileExport.

@Test
public void testLargeFileExport() throws Exception {
    int count = 10000;
    Region<Integer, MyObject> region = rgen.createRegion(cache, ds.getName(), RegionType.PARTITION_PERSISTENT, "test");
    System.out.println("Creating entries...");
    final Map<Integer, MyObject> expected = createExpected(SerializationType.DATA_SERIALIZABLE, count);
    region.putAll(expected);
    cache.close();
    System.out.println("Recovering entries...");
    for (int i = 0; i < 10; i++) {
        long start = System.currentTimeMillis();
        DiskStoreImpl.exportOfflineSnapshot(ds.getName(), new File[] { new File(".") }, new File("."));
        long elapsed = System.currentTimeMillis() - start;
        double rate = 1.0 * count / elapsed;
        System.out.println("Created snapshot with " + count + " entries in " + elapsed + " ms (" + rate + " entries/ms)");
        SnapshotTestUtil.checkSnapshotEntries(new File("."), expected, ds.getName(), region.getName());
    }
}
Also used : MyObject(com.examples.snapshot.MyObject) File(java.io.File) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

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