Search in sources :

Example 31 with CacheWriter

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

the class RemoveGlobalDUnitTest method testRemoveGlobalMultiVM.

// end of testRemoveGlobalSingleVM
@Test
public void testRemoveGlobalMultiVM() throws Throwable {
    // Commented the Test.As it is failing @ line no 145 : AssertionError
    SerializableRunnable createSimpleRegion = new CacheSerializableRunnable("create region with cache writer") {

        public void run2() throws CacheException {
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.GLOBAL);
            region = cache.createRegion("map", factory.create());
        }
    };
    SerializableRunnable createRegionWithWriter = new CacheSerializableRunnable("create region with capacity controller") {

        public void run2() throws CacheException {
            CacheWriter cw = new CacheWriterCallBack();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.GLOBAL);
            factory.setCacheWriter(cw);
            region = cache.createRegion("map", factory.create());
        }
    };
    vm0.invoke(createSimpleRegion);
    vm1.invoke(createRegionWithWriter);
    vm0.invoke(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));
            }
        }
    });
    vm1.invoke(new CacheSerializableRunnable("get object") {

        public void run2() throws CacheException {
            for (int i = 1; i < 5; i++) {
                region.get(new Integer(i));
            }
        }
    });
    AsyncInvocation async = vm0.invokeAsync(new CacheSerializableRunnable("remove object") {

        public void run2() throws CacheException {
            region.remove(new Integer(2));
        }
    });
    vm1.invoke(new CacheSerializableRunnable("verify locking") {

        public void run2() throws CacheException {
            cache.setLockTimeout(5);
            synchronized (RemoveGlobalDUnitTest.class) {
                if (!lockedForRemove) {
                    try {
                        RemoveGlobalDUnitTest.class.wait();
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
            try {
                // getLogWriter().fine("11111111111111");
                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)

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