Search in sources :

Example 1 with MyObject

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

the class ClientSnapshotDUnitTest method testExport.

@Test
public void testExport() throws Exception {
    int count = 10000;
    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-export.snapshot");
            Region<Integer, MyObject> r = getCache().getRegion("clienttest");
            r.getSnapshotService().save(f, SnapshotFormat.GEMFIRE);
            return f;
        }
    };
    File snapshot = (File) Host.getHost(0).getVM(3).invoke(export);
    SnapshotIterator<Integer, MyObject> iter = SnapshotReader.read(snapshot);
    try {
        while (iter.hasNext()) {
            iter.next();
            count--;
        }
        assertEquals(0, count);
    } finally {
        iter.close();
    }
}
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)

Example 2 with MyObject

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

the class ClientSnapshotDUnitTest method loadCache.

@SuppressWarnings("serial")
public void loadCache() throws Exception {
    CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer());
    Cache cache = getCache(cf);
    CacheServer server = cache.addCacheServer();
    final int port = AvailablePortHelper.getRandomAvailableTCPPort();
    server.setPort(port);
    server.start();
    region = cache.<Integer, MyObject>createRegionFactory(RegionShortcut.REPLICATE).create("clienttest");
    final Host host = Host.getHost(0);
    SerializableCallable client = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            ClientCacheFactory cf = new ClientCacheFactory().set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel()).setPdxSerializer(new MyPdxSerializer()).addPoolServer(NetworkUtils.getServerHostName(host), port).setPoolSubscriptionEnabled(true).setPoolPRSingleHopEnabled(false);
            ClientCache cache = getClientCache(cf);
            Region r = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY_HEAP_LRU).setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(5)).create("clienttest");
            return null;
        }
    };
    SerializableCallable remote = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer());
            Cache cache = getCache(cf);
            cache.<Integer, MyObject>createRegionFactory(RegionShortcut.REPLICATE).create("clienttest");
            return null;
        }
    };
    host.getVM(3).invoke(client);
    host.getVM(2).invoke(remote);
}
Also used : MyPdxSerializer(com.examples.snapshot.MyPdxSerializer) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) CacheServer(org.apache.geode.cache.server.CacheServer) MyObject(com.examples.snapshot.MyObject) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) ClientCache(org.apache.geode.cache.client.ClientCache) CacheFactory(org.apache.geode.cache.CacheFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 3 with MyObject

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

the class SnapshotTestUtil method checkSnapshotEntries.

public static <K, V> void checkSnapshotEntries(File dir, Map<K, V> expected, String diskStoreName, String regionName) throws Exception {
    final Map<K, V> testData = new HashMap<K, V>(expected);
    String snapshot = "snapshot-" + diskStoreName + "-" + regionName + ".gfd";
    SnapshotIterator<Integer, MyObject> iter = SnapshotReader.read(new File(dir, snapshot));
    try {
        while (iter.hasNext()) {
            Entry<Integer, MyObject> entry = iter.next();
            Object expectedVal = testData.remove(entry.getKey());
            assertEquals(expectedVal, entry.getValue());
        }
        assertTrue(testData.isEmpty());
    } finally {
        iter.close();
    }
}
Also used : HashMap(java.util.HashMap) MyObject(com.examples.snapshot.MyObject) MyObject(com.examples.snapshot.MyObject) File(java.io.File)

Example 4 with MyObject

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

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

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