Search in sources :

Example 76 with EntryEvent

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

the class FilterProfile method fillInInterestRoutingInfo.

/**
   * Fills in the routing information for clients that have registered interest in the given event.
   * The routing information is stored in the given FilterRoutingInfo object for use in message
   * delivery.
   * 
   * @param event the event being applied to the cache
   * @param profiles the profiles of members having the affected region
   * @param filterRoutingInfo the routing object that is modified by this method (may be null)
   * @param cacheOpRecipients members that will receive a CacheDistributionMessage for the event
   * @return the resulting FilterRoutingInfo
   */
public FilterRoutingInfo fillInInterestRoutingInfo(CacheEvent event, Profile[] profiles, FilterRoutingInfo filterRoutingInfo, Set cacheOpRecipients) {
    Set clientsInv = Collections.emptySet();
    Set clients = Collections.emptySet();
    if (logger.isTraceEnabled(LogMarker.BRIDGE_SERVER)) {
        logger.trace(LogMarker.BRIDGE_SERVER, "finding interested clients for {}", event);
    }
    FilterRoutingInfo frInfo = filterRoutingInfo;
    for (int i = 0; i < profiles.length; i++) {
        CacheProfile cf = (CacheProfile) profiles[i];
        if (!cf.hasCacheServer) {
            continue;
        }
        FilterProfile pf = cf.filterProfile;
        if (pf == null) {
            continue;
        }
        if (logger.isTraceEnabled(LogMarker.BRIDGE_SERVER)) {
            logger.trace(LogMarker.BRIDGE_SERVER, "Processing {}", pf);
        }
        if (!pf.hasInterest()) {
            // the routing.
            if (!pf.isLocalProfile() && cacheOpRecipients.contains(cf.getDistributedMember())) {
                if (frInfo == null)
                    frInfo = new FilterRoutingInfo();
                frInfo.addInterestedClients(cf.getDistributedMember(), Collections.emptySet(), Collections.emptySet(), false);
            }
            continue;
        }
        if (event.getOperation().isEntry()) {
            EntryEvent entryEvent = (EntryEvent) event;
            if (pf.allKeyClientsInv != null || pf.keysOfInterestInv != null || pf.patternsOfInterestInv != null || pf.filtersOfInterestInv != null) {
                clientsInv = pf.getInterestedClients(entryEvent, pf.allKeyClientsInv, pf.keysOfInterestInv, pf.patternsOfInterestInv, pf.filtersOfInterestInv);
            }
            if (pf.allKeyClients != null || pf.keysOfInterest != null || pf.patternsOfInterest != null || pf.filtersOfInterest != null) {
                clients = pf.getInterestedClients(entryEvent, pf.allKeyClients, pf.keysOfInterest, pf.patternsOfInterest, pf.filtersOfInterest);
            }
        } else {
            if (event.getOperation().isRegionDestroy() || event.getOperation().isClear()) {
                clientsInv = pf.getAllClientsWithInterestInv();
                clients = pf.getAllClientsWithInterest();
            } else {
                return frInfo;
            }
        }
        if (pf.isLocalProfile) {
            if (logger.isDebugEnabled()) {
                logger.debug("Setting local interested clients={} and clientsInv={}", clients, clientsInv);
            }
            if (frInfo == null)
                frInfo = new FilterRoutingInfo();
            frInfo.setLocalInterestedClients(clients, clientsInv);
        } else {
            if (// always send a routing with
            cacheOpRecipients.contains(cf.getDistributedMember()) || // CacheOperationMessages
            (clients != null && !clients.isEmpty()) || (clientsInv != null && !clientsInv.isEmpty())) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Adding interested clients={} and clientsIn={} to {}", clients, clientsInv, filterRoutingInfo);
                }
                if (frInfo == null)
                    frInfo = new FilterRoutingInfo();
                frInfo.addInterestedClients(cf.getDistributedMember(), clients, clientsInv, this.clientMap.hasLongID);
            }
        }
    }
    return frInfo;
}
Also used : CacheProfile(org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile) Set(java.util.Set) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) EntryEvent(org.apache.geode.cache.EntryEvent)

Example 77 with EntryEvent

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

the class FilterProfile method getFilterRoutingInfoPart1.

/**
   * Compute the full routing information for the given set of peers. This will not include local
   * routing information from interest processing. That is done by getFilterRoutingInfoPart2
   */
public FilterRoutingInfo getFilterRoutingInfoPart1(CacheEvent event, Profile[] peerProfiles, Set cacheOpRecipients) {
    // early out if there are no cache servers in the system
    boolean anyServers = false;
    for (int i = 0; i < peerProfiles.length; i++) {
        if (((CacheProfile) peerProfiles[i]).hasCacheServer) {
            anyServers = true;
            break;
        }
    }
    if (!anyServers && !this.localProfile.hasCacheServer) {
        return null;
    }
    FilterRoutingInfo frInfo = null;
    CqService cqService = getCqService(event.getRegion());
    if (cqService.isRunning()) {
        frInfo = new FilterRoutingInfo();
        // bug #50809 - local routing for transactional ops must be done here
        // because the event isn't available later and we lose the old value for the entry
        final boolean processLocalProfile = event.getOperation().isEntry() && ((EntryEvent) event).getTransactionId() != null;
        fillInCQRoutingInfo(event, processLocalProfile, peerProfiles, frInfo);
    }
    // Process InterestList.
    // return fillInInterestRoutingInfo(event, peerProfiles, frInfo, cacheOpRecipients);
    frInfo = fillInInterestRoutingInfo(event, peerProfiles, frInfo, cacheOpRecipients);
    if (frInfo == null || !frInfo.hasMemberWithFilterInfo()) {
        return null;
    } else {
        return frInfo;
    }
}
Also used : CacheProfile(org.apache.geode.internal.cache.CacheDistributionAdvisor.CacheProfile) EntryEvent(org.apache.geode.cache.EntryEvent) CqService(org.apache.geode.cache.query.internal.cq.CqService)

Example 78 with EntryEvent

use of org.apache.geode.cache.EntryEvent 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)

Example 79 with EntryEvent

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

the class Bug34387DUnitTest method testCreateAndLI.

/**
   * test create followed by localInvalidate
   */
@Test
public void testCreateAndLI() throws CacheException {
    initOtherId();
    AttributesFactory af = new AttributesFactory();
    af.setDataPolicy(DataPolicy.REPLICATE);
    af.setScope(Scope.DISTRIBUTED_ACK);
    af.setConcurrencyChecksEnabled(true);
    callbackFailure = false;
    CacheListener cl1 = new CacheListenerAdapter() {

        public void afterCreate(EntryEvent e) {
            callbackAssertEquals("key not equal", "createKey", e.getKey());
            callbackAssertEquals("value not equal", "createValue", e.getNewValue());
            Bug34387DUnitTest.this.invokeCount++;
        }
    };
    af.addCacheListener(cl1);
    Region r1 = createRootRegion("r1", af.create());
    this.invokeCount = 0;
    assertNull(r1.getEntry("createKey"));
    doCommitOtherVm(false);
    assertNotNull(r1.getEntry("createKey"));
    assertEquals("createValue", r1.getEntry("createKey").getValue());
    assertEquals(1, this.invokeCount);
    assertFalse("Errors in callbacks; check logs for details", callbackFailure);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) EntryEvent(org.apache.geode.cache.EntryEvent) Region(org.apache.geode.cache.Region) CacheListener(org.apache.geode.cache.CacheListener) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 80 with EntryEvent

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

the class Bug38013DUnitTest method doCreateOtherVm.

private void doCreateOtherVm() {
    VM vm = getOtherVm();
    vm.invoke(new CacheSerializableRunnable("create root") {

        public void run2() throws CacheException {
            getSystem();
            AttributesFactory af = new AttributesFactory();
            CacheListener cl = new CacheListenerAdapter() {

                public void afterCreate(EntryEvent event) {
                    // getLogWriter().info("afterCreate " + event.getKey());
                    if (event.getCallbackArgument() != null) {
                        lastCallback = event.getCallbackArgument();
                    }
                }

                public void afterUpdate(EntryEvent event) {
                    // getLogWriter().info("afterUpdate " + event.getKey());
                    if (event.getCallbackArgument() != null) {
                        lastCallback = event.getCallbackArgument();
                    }
                }

                public void afterInvalidate(EntryEvent event) {
                    if (event.getCallbackArgument() != null) {
                        lastCallback = event.getCallbackArgument();
                    }
                }

                public void afterDestroy(EntryEvent event) {
                    if (event.getCallbackArgument() != null) {
                        lastCallback = event.getCallbackArgument();
                    }
                }
            };
            af.setCacheListener(cl);
            // create a pr with a data store
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(0);
            // use defaults so this is a data store
            af.setPartitionAttributes(paf.create());
            createRootRegion("bug38013", af.create());
        }
    });
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) EntryEvent(org.apache.geode.cache.EntryEvent) CacheListener(org.apache.geode.cache.CacheListener)

Aggregations

EntryEvent (org.apache.geode.cache.EntryEvent)111 AttributesFactory (org.apache.geode.cache.AttributesFactory)75 Region (org.apache.geode.cache.Region)69 Test (org.junit.Test)66 CacheListenerAdapter (org.apache.geode.cache.util.CacheListenerAdapter)55 RegionAttributes (org.apache.geode.cache.RegionAttributes)37 LocalRegion (org.apache.geode.internal.cache.LocalRegion)32 CacheException (org.apache.geode.cache.CacheException)30 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)30 VM (org.apache.geode.test.dunit.VM)29 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)26 CacheWriterException (org.apache.geode.cache.CacheWriterException)22 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)22 Host (org.apache.geode.test.dunit.Host)21 Properties (java.util.Properties)20 RegionEvent (org.apache.geode.cache.RegionEvent)18 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)17 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)15 ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)15 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)15