Search in sources :

Example 11 with CacheWriter

use of org.apache.geode.cache.CacheWriter in project geode by apache.

the class RemoveGlobalDUnitTest method testRemoveGlobalSingleVM.

// test methods
@Test
public void testRemoveGlobalSingleVM() throws Throwable {
    SerializableRunnable createRegionWithWriter = new CacheSerializableRunnable("create region with cache writer") {

        public void run2() throws CacheException {
            cache.setLockTimeout(5);
            CacheWriter cacheWriter = new CacheWriterCallBack();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.GLOBAL);
            factory.setCacheWriter(cacheWriter);
            region = cache.createRegion("map", factory.create());
        }
    };
    vm0.invoke(createRegionWithWriter);
    AsyncInvocation async = vm0.invokeAsync(new CacheSerializableRunnable("put object") {

        public void run2() throws CacheException {
            for (int i = 1; i < 5; i++) {
                region.put(new Integer(i), java.lang.Integer.toString(i));
            }
            region.remove(new Integer(2));
        }
    });
    vm0.invoke(new CacheSerializableRunnable("verify locking") {

        public void run2() throws CacheException {
            synchronized (RemoveGlobalDUnitTest.class) {
                if (!lockedForRemove) {
                    try {
                        RemoveGlobalDUnitTest.class.wait();
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
            try {
                // getLogWriter().fine("000000000000000");
                region.put(new Integer(2), "newEntry");
                fail("Should have thrown TimeoutException");
            } catch (TimeoutException tme) {
            // pass
            }
        }
    });
    ThreadUtils.join(async, 30 * 1000);
    if (async.exceptionOccurred())
        throw async.getException();
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) CacheWriter(org.apache.geode.cache.CacheWriter) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) TimeoutException(org.apache.geode.cache.TimeoutException) CacheException(org.apache.geode.cache.CacheException) TimeoutException(org.apache.geode.cache.TimeoutException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 12 with CacheWriter

use of org.apache.geode.cache.CacheWriter in project geode by apache.

the class RemoveAllDAckDUnitTest method createCacheForVM1.

public static void createCacheForVM1() throws Exception {
    CacheWriter aWriter = new BeforeDestroyCallback();
    ds = (new RemoveAllDAckDUnitTest()).getSystem(props);
    cache = CacheFactory.create(ds);
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setCacheWriter(aWriter);
    RegionAttributes attr = factory.create();
    region = cache.createRegion("map", attr);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheWriter(org.apache.geode.cache.CacheWriter)

Example 13 with CacheWriter

use of org.apache.geode.cache.CacheWriter in project geode by apache.

the class DistAckMapMethodsDUnitTest method createRegionToTestRemove.

public static void createRegionToTestRemove() {
    try {
        AttributesFactory factory2 = new AttributesFactory();
        factory2.setScope(Scope.DISTRIBUTED_ACK);
        CacheWriter cacheWriter = new RemoveCacheWriter();
        CacheListener cacheListener = new RemoveCacheListener();
        factory2.setCacheWriter(cacheWriter);
        factory2.setCacheListener(cacheListener);
        RegionAttributes attr2 = factory2.create();
        remRegion = cache.createRegion("remove", attr2);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheWriter(org.apache.geode.cache.CacheWriter) CacheListener(org.apache.geode.cache.CacheListener) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CacheException(org.apache.geode.cache.CacheException)

Example 14 with CacheWriter

use of org.apache.geode.cache.CacheWriter in project geode by apache.

the class PutAllCallBkSingleVMDUnitTest method createCache.

public static synchronized void createCache() {
    try {
        CacheListener aListener = new AfterCreateCallback();
        CacheWriter aWriter = new BeforeCreateCallback();
        ds = (new PutAllCallBkSingleVMDUnitTest()).getSystem(props);
        cache = CacheFactory.create(ds);
        AttributesFactory factory = new AttributesFactory();
        factory.setScope(Scope.DISTRIBUTED_ACK);
        factory.setCacheWriter(aWriter);
        factory.setCacheListener(aListener);
        RegionAttributes attr = factory.create();
        region = cache.createRegion("map", attr);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheWriter(org.apache.geode.cache.CacheWriter) CacheListener(org.apache.geode.cache.CacheListener) CacheException(org.apache.geode.cache.CacheException)

Example 15 with CacheWriter

use of org.apache.geode.cache.CacheWriter in project geode by apache.

the class PutAllDAckDUnitTest method createCacheForVM1.

public static void createCacheForVM1() throws Exception {
    CacheWriter aWriter = new BeforeCreateCallback();
    ds = (new PutAllDAckDUnitTest()).getSystem(props);
    cache = CacheFactory.create(ds);
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setCacheWriter(aWriter);
    RegionAttributes attr = factory.create();
    region = cache.createRegion("map", attr);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheWriter(org.apache.geode.cache.CacheWriter)

Aggregations

CacheWriter (org.apache.geode.cache.CacheWriter)31 AttributesFactory (org.apache.geode.cache.AttributesFactory)16 CacheException (org.apache.geode.cache.CacheException)12 RegionAttributes (org.apache.geode.cache.RegionAttributes)9 CacheListener (org.apache.geode.cache.CacheListener)7 Test (org.junit.Test)7 Set (java.util.Set)6 CacheWriterException (org.apache.geode.cache.CacheWriterException)6 EntryEvent (org.apache.geode.cache.EntryEvent)6 TimeoutException (org.apache.geode.cache.TimeoutException)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 HashSet (java.util.HashSet)5 RegionEvent (org.apache.geode.cache.RegionEvent)5 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)5 CacheLoader (org.apache.geode.cache.CacheLoader)4 Region (org.apache.geode.cache.Region)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AttributesMutator (org.apache.geode.cache.AttributesMutator)3 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)3