Search in sources :

Example 21 with CacheLoaderException

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

the class RemoteTransactionDUnitTest method testPRTXGetOnLocalWithLoader.

@Test
public void testPRTXGetOnLocalWithLoader() {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore = host.getVM(1);
    initAccessorAndDataStore(accessor, datastore, 0);
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            AttributesMutator am = getCache().getRegion(CUSTOMER).getAttributesMutator();
            am.setCacheLoader(new CacheLoader() {

                public Object load(LoaderHelper helper) throws CacheLoaderException {
                    return new Customer("sup dawg", "addr");
                }

                public void close() {
                }
            });
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.begin();
            Region cust = getCache().getRegion(CUSTOMER);
            CustId custId = new CustId(6);
            Customer s = (Customer) cust.get(custId);
            mgr.commit();
            Customer s2 = (Customer) cust.get(custId);
            Customer expectedCust = new Customer("sup dawg", "addr");
            assertEquals(s, expectedCust);
            assertEquals(s2, expectedCust);
            return null;
        }
    });
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            return null;
        }
    });
}
Also used : LoaderHelper(org.apache.geode.cache.LoaderHelper) Customer(org.apache.geode.internal.cache.execute.data.Customer) CustId(org.apache.geode.internal.cache.execute.data.CustId) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) CacheLoader(org.apache.geode.cache.CacheLoader) NamingException(javax.naming.NamingException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) RollbackException(javax.transaction.RollbackException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) CommitConflictException(org.apache.geode.cache.CommitConflictException) AttributesMutator(org.apache.geode.cache.AttributesMutator) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 22 with CacheLoaderException

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

the class RemoteTransactionDUnitTest method testPRTXGetOnRemoteWithLoader.

@Test
public void testPRTXGetOnRemoteWithLoader() {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore = host.getVM(1);
    initAccessorAndDataStore(accessor, datastore, 0);
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            AttributesMutator am = getCache().getRegion(CUSTOMER).getAttributesMutator();
            am.setCacheLoader(new CacheLoader() {

                public Object load(LoaderHelper helper) throws CacheLoaderException {
                    return new Customer("sup dawg", "add");
                }

                public void close() {
                }
            });
            return null;
        }
    });
    accessor.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            CacheTransactionManager mgr = getGemfireCache().getTxManager();
            mgr.begin();
            Region cust = getCache().getRegion(CUSTOMER);
            Customer s = (Customer) cust.get(new CustId(8));
            assertEquals(new Customer("sup dawg", "add"), s);
            assertTrue(cust.containsKey(new CustId(8)));
            TXStateProxy tx = ((TXManagerImpl) mgr).internalSuspend();
            assertFalse(cust.containsKey(new CustId(8)));
            ((TXManagerImpl) mgr).internalResume(tx);
            mgr.commit();
            Customer s2 = (Customer) cust.get(new CustId(8));
            Customer ex = new Customer("sup dawg", "add");
            assertEquals(ex, s);
            assertEquals(ex, s2);
            return null;
        }
    });
}
Also used : Customer(org.apache.geode.internal.cache.execute.data.Customer) Host(org.apache.geode.test.dunit.Host) NamingException(javax.naming.NamingException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) RollbackException(javax.transaction.RollbackException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) CommitConflictException(org.apache.geode.cache.CommitConflictException) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) LoaderHelper(org.apache.geode.cache.LoaderHelper) CustId(org.apache.geode.internal.cache.execute.data.CustId) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) CacheLoader(org.apache.geode.cache.CacheLoader) AttributesMutator(org.apache.geode.cache.AttributesMutator) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 23 with CacheLoaderException

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

the class LRUEvictionControllerDUnitTest method testCacheLoader.

/**
   * Carefully verifies that region operations effect the {@link LRUStatistics} as expected in the
   * presense of a {@link CacheLoader}.
   */
@Test
public void testCacheLoader() throws CacheException {
    int threshold = 10;
    final String name = this.getUniqueName();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(threshold));
    factory.setCacheLoader(new CacheLoader() {

        public Object load(LoaderHelper helper) throws CacheLoaderException {
            return "LOADED VALUE";
        }

        public void close() {
        }
    });
    Region region;
    if (usingMain) {
        DistributedSystem system = DistributedSystem.connect(new Properties());
        Cache cache = CacheFactory.create(system);
        region = cache.createRegion("Test", factory.create());
    } else {
        region = createRegion(name, factory.create());
    }
    LRUStatistics lruStats = getLRUStats(region);
    assertNotNull(lruStats);
    for (int i = 1; i <= 10; i++) {
        Object key = new Integer(i);
        Object value = String.valueOf(i);
        region.put(key, value);
        assertEquals(i, lruStats.getCounter());
        assertEquals(0, lruStats.getEvictions());
    }
    for (int i = 11; i <= 20; i++) {
        Object key = new Integer(i);
        // Object value = String.valueOf(i);
        // Invoke loader
        region.get(key);
        assertEquals(10, lruStats.getCounter());
        assertEquals(i - 10, lruStats.getEvictions());
    }
}
Also used : Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) LoaderHelper(org.apache.geode.cache.LoaderHelper) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) CacheLoader(org.apache.geode.cache.CacheLoader) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 24 with CacheLoaderException

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

the class LocalRegionDUnitTest method testLocalLoaderNetSearch.

/**
   * Tests that if a <code>CacheLoader</code> for a local region invokes
   * {@link LoaderHelper#netSearch}, a {@link CacheLoaderException} is thrown.
   */
@Test
public void testLocalLoaderNetSearch() throws CacheException {
    assertEquals(Scope.LOCAL, getRegionAttributes().getScope());
    final String name = this.getUniqueName();
    final Object key = this.getUniqueName();
    TestCacheLoader loader = new TestCacheLoader() {

        public Object load2(LoaderHelper helper) throws CacheLoaderException {
            try {
                helper.netSearch(true);
            } catch (TimeoutException ex) {
                Assert.fail("Why did I timeout?", ex);
            }
            return null;
        }
    };
    AttributesFactory factory = new AttributesFactory(getRegionAttributes());
    factory.setCacheLoader(loader);
    Region region = createRegion(name, factory.create());
    assertEquals(Scope.LOCAL, region.getAttributes().getScope());
    try {
        region.get(key);
        fail("Should have thrown a CacheLoaderException");
    } catch (CacheLoaderException ex) {
        String expected = org.apache.geode.internal.cache.LoaderHelperImpl.NET_SEARCH_LOCAL.toLocalizedString();
        String message = ex.getMessage();
        assertTrue("Unexpected message \"" + message + "\"", message.indexOf(expected) != -1);
    }
}
Also used : LoaderHelper(org.apache.geode.cache.LoaderHelper) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) Region(org.apache.geode.cache.Region) TimeoutException(org.apache.geode.cache.TimeoutException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 25 with CacheLoaderException

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

the class TXJUnitTest method testCacheCallbacks.

/**
   * Test to make sure CacheListener callbacks are called in place with the CacheEvents properly
   * constructed
   */
@Test
public void testCacheCallbacks() throws CacheException {
    final String key1 = "Key1";
    final String value1 = "value1";
    final String value2 = "value2";
    final String callBackArg = "call back arg";
    // install listeners
    AttributesMutator<String, String> mutator = this.region.getAttributesMutator();
    TXCallBackValidator cbv = new TXCallBackValidator();
    // Cache Listener
    ValidatableCacheListener vCl = new ValidatableCacheListener() {

        TXCallBackValidator v;

        int callCount;

        int prevCallCount;

        EntryEvent lastEvent;

        @Override
        public void validate() {
            this.v.validate(this.lastEvent, this.callCount);
        }

        void validate(EntryEvent event) {
            this.v.validate(event, ++this.callCount);
        }

        @Override
        public void setValidator(TXCallBackValidator v) {
            this.v = v;
        }

        @Override
        public void close() {
        }

        @Override
        public void afterCreate(EntryEvent event) {
            lastEvent = event;
            if (this.v.isSuspendValidation()) {
                return;
            }
            this.validate(event);
            this.v.setPassedValidation(false);
            assertTrue("IsCreate Assertion!", this.v.isCreate());
            assertTrue(event.getRegion().containsKey(this.v.getKey()));
            assertTrue(event.getRegion().containsValueForKey(this.v.getKey()));
            assertNotNull(event.getRegion().getEntry(event.getKey()).getValue());
            this.v.setPassedValidation(true);
        }

        @Override
        public void afterUpdate(EntryEvent event) {
            lastEvent = event;
            if (this.v.isSuspendValidation()) {
                return;
            }
            validate(event);
            this.v.setPassedValidation(false);
            assertTrue("IsUpdate Assertion!", this.v.isUpdate());
            assertTrue(event.getRegion().containsKey(this.v.getKey()));
            assertTrue(event.getRegion().containsValueForKey(this.v.getKey()));
            assertNotNull(event.getRegion().getEntry(event.getKey()).getValue());
            this.v.setPassedValidation(true);
        }

        @Override
        public void afterInvalidate(EntryEvent event) {
            lastEvent = event;
            if (this.v.isSuspendValidation()) {
                return;
            }
            validate(event);
            this.v.setPassedValidation(false);
            assertTrue("IsInvalidate Assertion!", this.v.isInvalidate());
            assertTrue(event.getRegion().containsKey(this.v.getKey()));
            assertTrue(!event.getRegion().containsValueForKey(this.v.getKey()));
            assertNull(event.getRegion().getEntry(event.getKey()).getValue());
            this.v.setPassedValidation(true);
        }

        @Override
        public void afterDestroy(EntryEvent event) {
            lastEvent = event;
            if (this.v.isSuspendValidation()) {
                return;
            }
            validate(event);
            this.v.setPassedValidation(false);
            assertTrue("IsDestroy Assertion!", this.v.isDestroy());
            assertTrue(!event.getRegion().containsKey(this.v.getKey()));
            assertTrue(!event.getRegion().containsValueForKey(this.v.getKey()));
            assertNull(event.getRegion().getEntry(event.getKey()));
            this.v.setPassedValidation(true);
        }

        @Override
        public void afterRegionInvalidate(RegionEvent event) {
            fail("Unexpected invocation of afterRegionInvalidate");
        }

        @Override
        public void afterRegionDestroy(RegionEvent event) {
            if (!event.getOperation().isClose()) {
                fail("Unexpected invocation of afterRegionDestroy");
            }
        }

        @Override
        public void afterRegionClear(RegionEvent event) {
        }

        @Override
        public void afterRegionCreate(RegionEvent event) {
        }

        @Override
        public void afterRegionLive(RegionEvent event) {
        }

        @Override
        public void reset() {
            lastEvent = null;
            prevCallCount = callCount;
        }

        @Override
        public void validateNoEvents() {
            assertNull("Did not expect listener callback", lastEvent);
            assertEquals(prevCallCount, callCount);
        }

        @Override
        public void setExpectedCount(int count) {
            callCount = count;
        }

        @Override
        public int getCallCount() {
            return callCount;
        }
    };
    vCl.setValidator(cbv);
    mutator.setCacheListener(vCl);
    // CacheWriter
    ValidatableCacheWriter vCw = new ValidatableCacheWriter() {

        TXCallBackValidator v;

        int callCount;

        int prevCallCount;

        EntryEvent lastEvent;

        @Override
        public int getCallCount() {
            return this.callCount;
        }

        @Override
        public void localDestroyMakeup(int count) {
            this.callCount += count;
        }

        @Override
        public void validate() {
            this.v.validate(this.lastEvent, this.callCount);
        }

        void validate(EntryEvent event) {
            this.v.validate(event, ++this.callCount);
        }

        @Override
        public void setValidator(TXCallBackValidator v) {
            this.v = v;
        }

        @Override
        public void close() {
        }

        @Override
        public void beforeCreate(EntryEvent event) {
            lastEvent = event;
            if (this.v.isSuspendValidation()) {
                return;
            }
            validate(event);
            this.v.setPassedValidation(false);
            assertTrue("IsCreate Assertion!", this.v.isCreate());
            assertTrue(!event.getRegion().containsKey(this.v.getKey()));
            assertTrue(!event.getRegion().containsValueForKey(this.v.getKey()));
            assertNull(event.getRegion().getEntry(event.getKey()));
            this.v.setPassedValidation(true);
        }

        @Override
        public void beforeUpdate(EntryEvent event) {
            lastEvent = event;
            if (this.v.isSuspendValidation()) {
                return;
            }
            validate(event);
            this.v.setPassedValidation(false);
            assertTrue("IsUpdate Assertion!", this.v.isUpdate());
            assertTrue(event.getRegion().containsKey(this.v.getKey()));
            // Can not assert the following line, as the value being update may be invalid
            // assertTrue(event.getRegion().containsValueForKey(this.v.getKey()));
            this.v.setPassedValidation(true);
        }

        @Override
        public void beforeDestroy(EntryEvent event) {
            lastEvent = event;
            if (this.v.isSuspendValidation()) {
                return;
            }
            validate(event);
            this.v.setPassedValidation(false);
            assertTrue("IsDestroy Assertion!", this.v.isDestroy());
            assertTrue(event.getRegion().containsKey(this.v.getKey()));
            this.v.setPassedValidation(true);
        }

        @Override
        public void beforeRegionDestroy(RegionEvent event) {
            fail("Unexpected invocation of beforeRegionDestroy");
        }

        @Override
        public void beforeRegionClear(RegionEvent event) {
            fail("Unexpected invocation of beforeRegionClear");
        }

        @Override
        public void reset() {
            lastEvent = null;
            prevCallCount = callCount;
        }

        @Override
        public void validateNoEvents() {
            assertNull("Did not expect a writer event", lastEvent);
            assertEquals(prevCallCount, callCount);
        }
    };
    vCw.setValidator(cbv);
    mutator.setCacheWriter(vCw);
    // Cache Loader
    mutator.setCacheLoader(new CacheLoader() {

        int count = 0;

        @Override
        public Object load(LoaderHelper helper) throws CacheLoaderException {
            return count++;
        }

        @Override
        public void close() {
        }
    });
    // Use this to track the number of callout method invocations
    int appCallCount = 1;
    // Create => beforeCreate/afterCreate tests
    cbv.setKey(key1);
    cbv.setCallBackArg(callBackArg);
    cbv.setNewValue(value1, false);
    cbv.setOldValue(null, true);
    cbv.setIsDistributed(true);
    cbv.setIsLoad(false);
    cbv.setIsCreate(true);
    cbv.setIsUpdate(false);
    // Test non-transactional create expecting beforeCreate/afterCreate call
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.create(key1, value1, callBackArg);
    assertTrue("Non-TX Create Validation Assertion", cbv.passedValidation());
    cbv.suspendValidation(true);
    this.region.localDestroy(key1);
    cbv.suspendValidation(false);
    // Test transactional create expecting afterCreate call
    this.txMgr.begin();
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.create(key1, value1, callBackArg);
    this.txMgr.commit();
    assertTrue("TX Create Validation Assertion", cbv.passedValidation());
    cbv.suspendValidation(true);
    this.region.localDestroy(key1);
    // Put => afterCreate tests
    cbv.suspendValidation(false);
    cbv.setNewValue(value2, false);
    cbv.setOldValue(null, true);
    cbv.setIsDistributed(true);
    cbv.setIsLoad(false);
    cbv.setIsCreate(true);
    cbv.setIsUpdate(false);
    // Test non-transactional put expecting afterCreate call due to no
    // previous Entry
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.put(key1, value2, callBackArg);
    assertTrue("Non-TX Put->Create Validation Assertion", cbv.passedValidation());
    cbv.suspendValidation(true);
    this.region.localDestroy(key1);
    cbv.suspendValidation(false);
    // Test transactional put expecting afterCreate call due to no
    // previous Entry
    this.txMgr.begin();
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.put(key1, value2, callBackArg);
    this.txMgr.commit();
    assertTrue("TX Put->Create Validation Assertion", cbv.passedValidation());
    // Put => afterUpdate tests
    cbv.setNewValue(value1, false);
    cbv.setOldValue(value2, false);
    cbv.setIsDistributed(true);
    cbv.setIsLoad(false);
    cbv.setIsCreate(false);
    cbv.setIsUpdate(true);
    // Test non-transactional put expecting afterUpdate call due to
    // previous Entry
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.put(key1, value1, callBackArg);
    assertTrue("Non-TX Put->Update Validation Assertion", cbv.passedValidation());
    cbv.suspendValidation(true);
    this.region.localDestroy(key1);
    this.region.put(key1, value2);
    cbv.suspendValidation(false);
    // Test transactional put expecting afterUpdate call due to
    // previous Entry
    this.txMgr.begin();
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.put(key1, value1, callBackArg);
    this.txMgr.commit();
    assertTrue("TX Put->Update Validation Assertion", cbv.passedValidation());
    // LocalDestroy => afterDestroy, non-distributed tests
    cbv.setNewValue(null, true);
    cbv.setOldValue(value1, false);
    cbv.setIsDistributed(false);
    cbv.setIsLoad(false);
    cbv.setIsDestroy(true);
    cbv.setIsUpdate(false);
    // Test non-transactional localDestroy, expecting afterDestroy,
    // non-distributed
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.localDestroy(key1, callBackArg);
    if (!isPR())
        // Account for cacheWriter not begin called
        vCw.localDestroyMakeup(1);
    assertTrue("Non-TX LocalDestroy Validation Assertion", cbv.passedValidation());
    cbv.suspendValidation(true);
    this.region.create(key1, value1);
    cbv.suspendValidation(false);
    // Test transactional localDestroy expecting afterDestroy,
    // non-distributed
    this.txMgr.begin();
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.localDestroy(key1, callBackArg);
    if (!isPR())
        // Account for cacheWriter not begin called
        vCw.localDestroyMakeup(1);
    this.txMgr.commit();
    assertTrue("TX LocalDestroy Validation Assertion", cbv.passedValidation());
    // Destroy => afterDestroy, distributed tests
    cbv.setNewValue(null, true);
    cbv.setOldValue(value1, false);
    cbv.setIsDistributed(true);
    cbv.setIsLoad(false);
    cbv.setIsDestroy(true);
    cbv.suspendValidation(true);
    this.region.create(key1, value1);
    cbv.suspendValidation(false);
    // Test non-transactional Destroy, expecting afterDestroy,
    // distributed
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.destroy(key1, callBackArg);
    assertTrue("Non-TX Destroy Validation Assertion", cbv.passedValidation());
    cbv.suspendValidation(true);
    this.region.create(key1, value1);
    cbv.suspendValidation(false);
    // Test transactional Destroy, expecting afterDestroy,
    // distributed
    this.txMgr.begin();
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.destroy(key1, callBackArg);
    this.txMgr.commit();
    assertTrue("TX Destroy Validation Assertion", cbv.passedValidation());
    // localInvalidate => afterInvalidate, non-distributed tests
    cbv.setNewValue(null, true);
    cbv.setOldValue(value1, false);
    cbv.setIsDistributed(false);
    cbv.setIsLoad(false);
    cbv.setIsInvalidate(true);
    cbv.setIsDestroy(false);
    cbv.suspendValidation(true);
    this.region.create(key1, value1);
    cbv.suspendValidation(false);
    // Test non-transactional localInvalidate, expecting afterInvalidate
    // non-distributed
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.localInvalidate(key1, callBackArg);
    assertTrue("Non-TX LocalInvalidate Validation Assertion", cbv.passedValidation());
    // Account for cacheWriter not begin called
    vCw.localDestroyMakeup(1);
    cbv.suspendValidation(true);
    this.region.put(key1, value1);
    cbv.suspendValidation(false);
    // Test transactional localInvalidate, expecting afterInvalidate
    // non-distributed
    this.txMgr.begin();
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.localInvalidate(key1, callBackArg);
    this.txMgr.commit();
    assertTrue("TX LocalInvalidate Validation Assertion", cbv.passedValidation());
    // Account for cacheWriter not begin called
    vCw.localDestroyMakeup(1);
    cbv.suspendValidation(true);
    this.region.localDestroy(key1);
    // Invalidate => afterInvalidate, distributed tests
    cbv.setNewValue(null, true);
    cbv.setOldValue(value1, false);
    cbv.setIsDistributed(true);
    cbv.setIsLoad(false);
    cbv.suspendValidation(true);
    this.region.create(key1, value1);
    cbv.suspendValidation(false);
    // Test non-transactional Invalidate, expecting afterInvalidate
    // distributed
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.invalidate(key1, callBackArg);
    // Account for cacheWriter not begin called
    vCw.localDestroyMakeup(1);
    assertTrue("Non-TX Invalidate Validation Assertion", cbv.passedValidation());
    cbv.suspendValidation(true);
    this.region.put(key1, value1);
    cbv.suspendValidation(false);
    // Test transactional Invalidate, expecting afterInvalidate
    // distributed
    this.txMgr.begin();
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.invalidate(key1, callBackArg);
    this.txMgr.commit();
    // Account for cacheWriter not begin called
    vCw.localDestroyMakeup(1);
    assertTrue("TX Invalidate Validation Assertion", cbv.passedValidation());
    cbv.suspendValidation(true);
    this.region.localDestroy(key1);
    cbv.suspendValidation(false);
    // Create load Event tests
    int loaderValCheck = 0;
    cbv.setNewValue(loaderValCheck++, false);
    cbv.setCallBackArg(null);
    cbv.setOldValue(null, false);
    cbv.setIsDistributed(true);
    cbv.setIsCreate(true);
    cbv.setIsUpdate(false);
    cbv.setIsLoad(true);
    // Test non-transactional load, expecting afterCreate distributed
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.get(key1);
    assertTrue("Non-TX Invalidate Validation Assertion", cbv.passedValidation());
    vCl.validate();
    vCw.validate();
    cbv.suspendValidation(true);
    this.region.localDestroy(key1);
    cbv.suspendValidation(false);
    // Test transactional load, expecting afterCreate distributed
    vCl.reset();
    this.txMgr.begin();
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setNewValue(loaderValCheck++, false);
    cbv.setExpectedCount(appCallCount++);
    this.region.get(key1);
    this.txMgr.rollback();
    assertTrue("TX Invalidate Validation Assertion", cbv.passedValidation());
    vCw.validate();
    vCl.validateNoEvents();
    vCl.setExpectedCount(vCl.getCallCount() + 1);
    this.txMgr.begin();
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setNewValue(loaderValCheck++, false);
    cbv.setExpectedCount(appCallCount++);
    this.region.get(key1);
    vCw.validate();
    vCw.reset();
    this.txMgr.commit();
    vCw.validateNoEvents();
    assertTrue("TX Invalidate Validation Assertion", cbv.passedValidation());
    vCl.validate();
    cbv.suspendValidation(true);
    this.region.localDestroy(key1);
    cbv.suspendValidation(false);
    // Update load Event tests
    cbv.suspendValidation(true);
    this.region.create(key1, null);
    cbv.suspendValidation(false);
    assertTrue(this.region.containsKey(key1));
    assertTrue(!this.region.containsValueForKey(key1));
    cbv.setNewValue(loaderValCheck++, false);
    cbv.setOldValue(null, false);
    cbv.setIsDistributed(true);
    cbv.setCallBackArg(null);
    cbv.setIsCreate(false);
    cbv.setIsUpdate(true);
    cbv.setIsLoad(true);
    // Test non-transactional load, expecting afterUpdate distributed
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    this.region.get(key1);
    assertTrue("Non-TX Invalidate Validation Assertion", cbv.passedValidation());
    vCw.validate();
    vCl.validate();
    cbv.suspendValidation(true);
    this.region.invalidate(key1);
    cbv.suspendValidation(false);
    assertTrue(this.region.containsKey(key1));
    assertTrue(!this.region.containsValueForKey(key1));
    // Test transactional load, expecting afterUpdate distributed
    this.txMgr.begin();
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    cbv.setNewValue(loaderValCheck++, false);
    this.region.get(key1);
    vCw.validate();
    vCw.reset();
    this.txMgr.commit();
    vCw.validateNoEvents();
    vCl.validate();
    cbv.suspendValidation(true);
    this.region.invalidate(key1);
    cbv.suspendValidation(false);
    vCl.reset();
    this.txMgr.begin();
    cbv.setTXId(txMgr.getTransactionId());
    cbv.setExpectedCount(appCallCount++);
    cbv.setNewValue(loaderValCheck++, false);
    this.region.get(key1);
    this.txMgr.rollback();
    assertTrue("TX Invalidate Validation Assertion", cbv.passedValidation());
    vCw.validate();
    vCl.validateNoEvents();
}
Also used : RegionEvent(org.apache.geode.cache.RegionEvent) LoaderHelper(org.apache.geode.cache.LoaderHelper) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) EntryEvent(org.apache.geode.cache.EntryEvent) CacheLoader(org.apache.geode.cache.CacheLoader) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

CacheLoaderException (org.apache.geode.cache.CacheLoaderException)45 Test (org.junit.Test)32 LoaderHelper (org.apache.geode.cache.LoaderHelper)31 Region (org.apache.geode.cache.Region)31 AttributesFactory (org.apache.geode.cache.AttributesFactory)25 VM (org.apache.geode.test.dunit.VM)23 CacheException (org.apache.geode.cache.CacheException)22 Host (org.apache.geode.test.dunit.Host)22 CacheLoader (org.apache.geode.cache.CacheLoader)19 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)19 TimeoutException (org.apache.geode.cache.TimeoutException)15 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)15 LocalRegion (org.apache.geode.internal.cache.LocalRegion)14 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)11 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)10 CacheWriterException (org.apache.geode.cache.CacheWriterException)9 StoredObject (org.apache.geode.internal.offheap.StoredObject)8 EntryEvent (org.apache.geode.cache.EntryEvent)7 AttributesMutator (org.apache.geode.cache.AttributesMutator)6 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)6