Search in sources :

Example 1 with RegionEvent

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

the class TXJUnitTest method testTxAlgebra.

@Test
public void testTxAlgebra() throws CacheException {
    TransactionId myTxId;
    Region<String, String> reg1 = this.region;
    this.txMgr.setListener(new TransactionListener() {

        @Override
        public void afterCommit(TransactionEvent event) {
            listenerAfterCommit = 1;
            te = event;
        }

        @Override
        public void afterFailedCommit(TransactionEvent event) {
            listenerAfterFailedCommit = 1;
            te = event;
        }

        @Override
        public void afterRollback(TransactionEvent event) {
            listenerAfterRollback = 1;
            te = event;
        }

        @Override
        public void close() {
            listenerClose = 1;
        }
    });
    AttributesMutator<String, String> mutator = this.region.getAttributesMutator();
    CountingCacheListener cntListener = new CountingCacheListener() {

        volatile int aCreateCalls, aUpdateCalls, aInvalidateCalls, aDestroyCalls, aLocalDestroyCalls;

        @Override
        public void close() {
        }

        @Override
        public void reset() {
            this.aCreateCalls = this.aUpdateCalls = this.aInvalidateCalls = this.aDestroyCalls = this.aLocalDestroyCalls = 0;
        }

        @Override
        public void afterCreate(EntryEvent e) {
            ++this.aCreateCalls;
        }

        @Override
        public void afterUpdate(EntryEvent e) {
            ++this.aUpdateCalls;
        }

        @Override
        public void afterInvalidate(EntryEvent e) {
            ++this.aInvalidateCalls;
        }

        @Override
        public void afterDestroy(EntryEvent e) {
            if (e.getOperation().isDistributed()) {
                ++this.aDestroyCalls;
            } else {
                ++this.aLocalDestroyCalls;
            }
        }

        @Override
        public void afterRegionInvalidate(RegionEvent e) {
            fail("Unexpected afterRegionInvalidate in testTxAlgebra");
        }

        @Override
        public void afterRegionDestroy(RegionEvent e) {
            if (!e.getOperation().isClose()) {
                fail("Unexpected afterRegionDestroy in testTxAlgebra");
            }
        }

        @Override
        public void afterRegionClear(RegionEvent event) {
        }

        @Override
        public void afterRegionCreate(RegionEvent event) {
        }

        @Override
        public void afterRegionLive(RegionEvent event) {
        }

        @Override
        public int getAfterCreateCalls() {
            return this.aCreateCalls;
        }

        @Override
        public int getAfterUpdateCalls() {
            return this.aUpdateCalls;
        }

        @Override
        public int getAfterInvalidateCalls() {
            return this.aInvalidateCalls;
        }

        @Override
        public int getAfterDestroyCalls(boolean fetchLocal) {
            return fetchLocal ? this.aLocalDestroyCalls : this.aDestroyCalls;
        }
    };
    mutator.setCacheListener(cntListener);
    CountingCacheWriter cntWriter = new CountingCacheWriter() {

        int bCreateCalls, bUpdateCalls, bDestroyCalls, bLocalDestroyCalls;

        @Override
        public void close() {
        }

        @Override
        public void reset() {
            this.bCreateCalls = this.bUpdateCalls = this.bDestroyCalls = this.bLocalDestroyCalls = 0;
        }

        @Override
        public void beforeCreate(EntryEvent e) {
            ++this.bCreateCalls;
        }

        @Override
        public void beforeUpdate(EntryEvent e) {
            ++this.bUpdateCalls;
        }

        @Override
        public void beforeDestroy(EntryEvent e) {
            ++this.bDestroyCalls;
        }

        @Override
        public void beforeRegionDestroy(RegionEvent e) {
            fail("Unexpected beforeRegionDestroy in testTxAlgebra");
        }

        @Override
        public void beforeRegionClear(RegionEvent e) {
            fail("Unexpected beforeRegionClear in testTxAlgebra");
        }

        @Override
        public int getBeforeCreateCalls() {
            return this.bCreateCalls;
        }

        @Override
        public int getBeforeUpdateCalls() {
            return this.bUpdateCalls;
        }

        @Override
        public int getBeforeDestroyCalls(boolean fetchLocal) {
            return fetchLocal ? this.bLocalDestroyCalls : this.bDestroyCalls;
        }
    };
    mutator.setCacheWriter(cntWriter);
    CountingCallBackValidator callbackVal = new CountingCallBackValidator(cntListener, cntWriter);
    // make sure each op sequence has the correct affect transaction event
    // check C + C -> EX
    // check C + P -> C
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.create("key1", "value1");
    callbackVal.assertCreateWriterCnt(1);
    try {
        reg1.create("key1", "value2");
        fail("expected EntryExistsException");
    } catch (EntryExistsException ok) {
    }
    callbackVal.assertCreateWriterCnt(1, /* remember */
    false);
    reg1.put("key1", "value2");
    callbackVal.assertUpdateWriterCnt(1);
    assertEquals("value2", reg1.getEntry("key1").getValue());
    // Make sure listener callbacks were not triggered before commit
    callbackVal.assertCreateListenerCnt(0, false);
    callbackVal.assertUpdateListenerCnt(0);
    this.txMgr.commit();
    callbackVal.assertCreateListenerCnt(1);
    callbackVal.reAssert();
    assertEquals("value2", reg1.getEntry("key1").getValue());
    assertEquals(1, this.te.getEvents().size());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value2", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // Check C + DI -> C
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.create("key1", "value1");
    callbackVal.assertCreateWriterCnt(1);
    reg1.invalidate("key1");
    callbackVal.assertInvalidateCnt(0, false);
    assertTrue(reg1.containsKey("key1"));
    assertTrue(!reg1.containsValueForKey("key1"));
    callbackVal.assertCreateListenerCnt(0, false);
    this.txMgr.commit();
    callbackVal.assertCreateListenerCnt(1);
    callbackVal.reAssert();
    assertTrue(reg1.containsKey("key1"));
    assertTrue(!reg1.containsValueForKey("key1"));
    assertEquals(1, this.te.getEvents().size());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals(null, ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // TODO: mitch implement the following
    // check LI + DI -> NOOP
    // check DI + LI -> NOOP
    // check DI + DI -> NOOP
    // check LI + LI -> NOOP
    // check C + DD -> NOOP
    callbackVal.reset();
    this.txMgr.begin();
    reg1.create("key1", "value0");
    callbackVal.assertCreateWriterCnt(1);
    reg1.destroy("key1");
    callbackVal.assertDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    callbackVal.assertDestroyListenerCnt(0);
    this.txMgr.commit();
    callbackVal.assertDestroyListenerCnt(0);
    callbackVal.assertCreateListenerCnt(0);
    callbackVal.reAssert();
    assertTrue(!reg1.containsKey("key1"));
    assertEquals(0, this.te.getEvents().size());
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    // Check C + LI -> C
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.create("key1", "value1");
    callbackVal.assertCreateWriterCnt(1);
    reg1.localInvalidate("key1");
    callbackVal.assertInvalidateCnt(0);
    assertTrue(reg1.containsKey("key1"));
    assertTrue(!reg1.containsValueForKey("key1"));
    this.txMgr.commit();
    callbackVal.assertCreateListenerCnt(1);
    callbackVal.reAssert();
    assertTrue(reg1.containsKey("key1"));
    assertTrue(!reg1.containsValueForKey("key1"));
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals(null, ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // Check C + LI + C -> EX
    // Check C + LI + P -> C
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.create("key1", "value1");
    callbackVal.assertCreateWriterCnt(1);
    reg1.localInvalidate("key1");
    callbackVal.assertInvalidateCnt(0);
    try {
        reg1.create("key1", "ex");
        fail("expected EntryExistsException");
    } catch (EntryExistsException ok) {
    }
    callbackVal.assertCreateWriterCnt(1, /* remember */
    false);
    reg1.put("key1", "value2");
    callbackVal.assertUpdateWriterCnt(1);
    assertTrue(reg1.containsKey("key1"));
    assertEquals("value2", reg1.getEntry("key1").getValue());
    callbackVal.assertUpdateListenerCnt(0);
    callbackVal.assertCreateListenerCnt(0, false);
    this.txMgr.commit();
    callbackVal.assertCreateListenerCnt(1);
    callbackVal.reAssert();
    assertTrue(reg1.containsKey("key1"));
    assertEquals("value2", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value2", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // Check C + LI + LD -> NOOP
    callbackVal.reset();
    this.txMgr.begin();
    reg1.create("key1", "value1");
    callbackVal.assertCreateWriterCnt(1);
    reg1.localInvalidate("key1");
    callbackVal.assertInvalidateCnt(0);
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    this.txMgr.commit();
    callbackVal.assertCreateListenerCnt(0);
    callbackVal.assertDestroyListenerCnt(0);
    callbackVal.reAssert();
    assertTrue(!reg1.containsKey("key1"));
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(0, this.te.getEvents().size());
    // Check C + LI + DD -> NOOP
    callbackVal.reset();
    this.txMgr.begin();
    reg1.create("key1", "value1");
    callbackVal.assertCreateWriterCnt(1);
    reg1.localInvalidate("key1");
    callbackVal.assertInvalidateCnt(0);
    reg1.destroy("key1");
    callbackVal.assertDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    this.txMgr.commit();
    callbackVal.assertDestroyListenerCnt(0);
    callbackVal.assertCreateListenerCnt(0);
    callbackVal.reAssert();
    assertTrue(!reg1.containsKey("key1"));
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(0, this.te.getEvents().size());
    // check C + LD -> NOOP
    callbackVal.reset();
    this.txMgr.begin();
    reg1.create("key1", "value0");
    callbackVal.assertCreateWriterCnt(1);
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    this.txMgr.commit();
    callbackVal.assertCreateListenerCnt(0);
    callbackVal.assertLocalDestroyListenerCnt(0);
    callbackVal.reAssert();
    assertTrue(!reg1.containsKey("key1"));
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(0, this.te.getEvents().size());
    // check C + LD + D -> EX
    // check C + LD + I -> EX
    // check C + LD + C -> C
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.create("key1", "value0");
    callbackVal.assertCreateWriterCnt(1, /* remember */
    false);
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    try {
        reg1.localDestroy("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertLocalDestroyWriterCnt(1, /* remember */
    false);
    try {
        reg1.destroy("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertDestroyWriterCnt(0);
    try {
        reg1.localInvalidate("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertInvalidateCnt(0);
    try {
        reg1.invalidate("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertInvalidateCnt(0, /* remember */
    false);
    reg1.create("key1", "value3");
    callbackVal.assertCreateWriterCnt(2);
    assertEquals("value3", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertCreateListenerCnt(1);
    callbackVal.reAssert();
    assertEquals("value3", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value3", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check C + LD + P -> C
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.create("key1", "value0");
    callbackVal.assertCreateWriterCnt(1, /* remember */
    false);
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    reg1.put("key1", "value3");
    callbackVal.assertCreateWriterCnt(2);
    assertEquals("value3", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertCreateListenerCnt(1);
    callbackVal.assertUpdateListenerCnt(0);
    callbackVal.reAssert();
    assertEquals("value3", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value3", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check put of existing entry
    // check P + C -> EX
    // check P + P -> P
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.put("key1", "value1");
    callbackVal.assertUpdateWriterCnt(1, /* remember */
    false);
    try {
        reg1.create("key1", "value2");
        fail("expected EntryExistsException");
    } catch (EntryExistsException ok) {
    }
    callbackVal.assertUpdateWriterCnt(1, /* remember */
    false);
    callbackVal.assertCreateWriterCnt(0);
    reg1.put("key1", "value3");
    callbackVal.assertUpdateWriterCnt(2);
    assertEquals("value3", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertCreateListenerCnt(0);
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.reAssert();
    assertEquals("value3", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getPutEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value3", ev.getNewValue());
            assertEquals("value0", ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check P + DI -> DI
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.put("key1", "value1");
    callbackVal.assertUpdateWriterCnt(1);
    reg1.invalidate("key1");
    callbackVal.assertInvalidateCnt(0, false);
    assertTrue(reg1.containsKey("key1"));
    assertTrue(!reg1.containsValueForKey("key1"));
    this.txMgr.commit();
    callbackVal.assertInvalidateCnt(1);
    callbackVal.assertUpdateListenerCnt(0);
    callbackVal.reAssert();
    assertTrue(reg1.containsKey("key1"));
    assertTrue(!reg1.containsValueForKey("key1"));
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getInvalidateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals(null, ev.getNewValue());
            assertEquals("value0", ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check P + DD -> D
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.put("key1", "value1");
    callbackVal.assertUpdateWriterCnt(1);
    reg1.destroy("key1");
    callbackVal.assertDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    this.txMgr.commit();
    callbackVal.assertUpdateListenerCnt(0);
    callbackVal.assertLocalDestroyListenerCnt(0);
    callbackVal.assertDestroyListenerCnt(1);
    callbackVal.reAssert();
    assertTrue(!reg1.containsKey("key1"));
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getDestroyEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals(null, ev.getNewValue());
            assertEquals("value0", ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    // check P + LI -> LI
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.put("key1", "value1");
    callbackVal.assertUpdateWriterCnt(1);
    reg1.localInvalidate("key1");
    callbackVal.assertInvalidateCnt(0);
    assertTrue(reg1.containsKey("key1"));
    assertTrue(!reg1.containsValueForKey("key1"));
    this.txMgr.commit();
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.reAssert();
    assertTrue(reg1.containsKey("key1"));
    assertEquals(null, reg1.getEntry("key1").getValue());
    assertTrue(!reg1.containsValueForKey("key1"));
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getInvalidateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals(null, ev.getNewValue());
            assertEquals("value0", ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(!ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // Check P + LI + C -> EX
    // Check P + LI + P -> P
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.put("key1", "value1");
    callbackVal.assertUpdateWriterCnt(1, /* remember */
    false);
    reg1.localInvalidate("key1");
    callbackVal.assertInvalidateCnt(0);
    try {
        reg1.create("key1", "ex");
        fail("expected EntryExistsException");
    } catch (EntryExistsException ok) {
    }
    callbackVal.assertCreateWriterCnt(0);
    callbackVal.assertUpdateWriterCnt(1, /* remember */
    false);
    reg1.put("key1", "value2");
    callbackVal.assertUpdateWriterCnt(2);
    assertTrue(reg1.containsKey("key1"));
    assertEquals("value2", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.reAssert();
    assertTrue(reg1.containsKey("key1"));
    assertEquals("value2", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getPutEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value2", ev.getNewValue());
            assertEquals("value0", ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // Check P + LI + LD -> LD
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.put("key1", "value1");
    callbackVal.assertUpdateWriterCnt(1);
    reg1.localInvalidate("key1");
    callbackVal.assertInvalidateCnt(0);
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    this.txMgr.commit();
    callbackVal.assertUpdateListenerCnt(0);
    callbackVal.assertDestroyListenerCnt(0);
    callbackVal.assertLocalDestroyListenerCnt(1);
    callbackVal.reAssert();
    assertTrue(!reg1.containsKey("key1"));
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getDestroyEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals(null, ev.getNewValue());
            assertEquals("value0", ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(!ev.getOperation().isDistributed());
        }
    }
    // Check P + LI + DD -> DD
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.put("key1", "value1");
    callbackVal.assertUpdateWriterCnt(1);
    reg1.localInvalidate("key1");
    callbackVal.assertInvalidateCnt(0);
    reg1.destroy("key1");
    callbackVal.assertDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    this.txMgr.commit();
    callbackVal.assertUpdateListenerCnt(0);
    callbackVal.assertDestroyListenerCnt(1);
    callbackVal.reAssert();
    assertTrue(!reg1.containsKey("key1"));
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getDestroyEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals(null, ev.getNewValue());
            assertEquals("value0", ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    // check P + LD -> LD
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.put("key1", "value1");
    callbackVal.assertUpdateWriterCnt(1);
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    this.txMgr.commit();
    callbackVal.assertUpdateListenerCnt(0);
    callbackVal.assertDestroyListenerCnt(0);
    callbackVal.assertLocalDestroyListenerCnt(1);
    callbackVal.reAssert();
    assertTrue(!reg1.containsKey("key1"));
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getDestroyEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals(null, ev.getNewValue());
            assertEquals("value0", ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(!ev.getOperation().isDistributed());
        }
    }
    // check P + LD + D -> EX
    // check P + LD + I -> EX
    // check P + LD + C -> C
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.put("key1", "value1");
    callbackVal.assertUpdateWriterCnt(1);
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    try {
        reg1.localDestroy("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertLocalDestroyWriterCnt(1, /* remember */
    false);
    try {
        reg1.destroy("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertDestroyWriterCnt(0);
    try {
        reg1.localInvalidate("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertInvalidateCnt(0, /* remember */
    false);
    try {
        reg1.invalidate("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertInvalidateCnt(0);
    reg1.create("key1", "value3");
    callbackVal.assertCreateWriterCnt(1);
    assertEquals("value3", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertLocalDestroyListenerCnt(0);
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.reAssert();
    assertEquals("value3", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value3", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check P + LD + P -> C
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.put("key1", "value1");
    callbackVal.assertUpdateWriterCnt(1, /* remember */
    false);
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    reg1.put("key1", "value3");
    callbackVal.assertCreateWriterCnt(1);
    assertEquals("value3", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertLocalDestroyListenerCnt(0);
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.reAssert();
    assertEquals("value3", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value3", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check DI + C -> EX
    // check DI + P -> P
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.invalidate("key1");
    callbackVal.assertInvalidateCnt(0);
    try {
        reg1.create("key1", "value1");
        fail("expected EntryExistsException");
    } catch (EntryExistsException ok) {
    }
    callbackVal.assertCreateWriterCnt(0);
    reg1.put("key1", "value2");
    callbackVal.assertUpdateWriterCnt(1);
    assertEquals("value2", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.reAssert();
    assertEquals("value2", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getPutEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value2", ev.getNewValue());
            assertEquals("value0", ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check DI + DD -> D
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.invalidate("key1");
    callbackVal.assertInvalidateCnt(0);
    reg1.destroy("key1");
    callbackVal.assertDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    this.txMgr.commit();
    callbackVal.assertDestroyListenerCnt(1);
    callbackVal.reAssert();
    assertTrue(!reg1.containsKey("key1"));
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getDestroyEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals(null, ev.getNewValue());
            assertEquals("value0", ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    // check DI + LD -> LD
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.invalidate("key1");
    callbackVal.assertInvalidateCnt(0);
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    this.txMgr.commit();
    callbackVal.assertDestroyListenerCnt(0);
    callbackVal.assertLocalDestroyListenerCnt(1);
    callbackVal.reAssert();
    assertTrue(!reg1.containsKey("key1"));
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getDestroyEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals(null, ev.getNewValue());
            assertEquals("value0", ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(!ev.getOperation().isDistributed());
        }
    }
    // check DI + LD + D -> EX
    // check DI + LD + I -> EX
    // check DI + LD + C -> C
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.invalidate("key1");
    callbackVal.assertInvalidateCnt(0, false);
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    try {
        reg1.localDestroy("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertLocalDestroyWriterCnt(1, /* remember */
    false);
    try {
        reg1.destroy("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertDestroyWriterCnt(0);
    try {
        reg1.localInvalidate("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertInvalidateCnt(0, /* remember */
    false);
    try {
        reg1.invalidate("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertInvalidateCnt(0, /* remember */
    false);
    reg1.create("key1", "value3");
    callbackVal.assertCreateWriterCnt(1);
    assertEquals("value3", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertInvalidateCnt(0);
    callbackVal.assertDestroyListenerCnt(0);
    callbackVal.assertLocalDestroyListenerCnt(0);
    callbackVal.assertCreateListenerCnt(0);
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.reAssert();
    assertEquals("value3", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value3", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check DI + LD + P -> C
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.invalidate("key1", "value1");
    callbackVal.assertInvalidateCnt(0, false);
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    reg1.put("key1", "value3");
    callbackVal.assertCreateWriterCnt(1);
    assertEquals("value3", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertInvalidateCnt(0);
    callbackVal.assertCreateListenerCnt(0);
    callbackVal.assertLocalDestroyListenerCnt(0);
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.reAssert();
    assertEquals("value3", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value3", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check LI + C -> EX
    // check LI + P -> P
    reg1.create("key1", "value0");
    this.txMgr.begin();
    callbackVal.reset();
    myTxId = this.txMgr.getTransactionId();
    reg1.localInvalidate("key1");
    callbackVal.assertInvalidateCnt(0, false);
    try {
        reg1.create("key1", "value1");
        fail("expected EntryExistsException");
    } catch (EntryExistsException ok) {
    }
    callbackVal.assertCreateWriterCnt(0);
    reg1.put("key1", "value2");
    callbackVal.assertUpdateWriterCnt(1);
    assertEquals("value2", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.assertInvalidateCnt(0);
    callbackVal.reAssert();
    assertEquals("value2", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getPutEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value2", ev.getNewValue());
            assertEquals("value0", ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check LI + DD -> DD
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.localInvalidate("key1");
    callbackVal.assertInvalidateCnt(0, false);
    reg1.destroy("key1");
    callbackVal.assertDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    this.txMgr.commit();
    callbackVal.assertInvalidateCnt(0);
    callbackVal.assertDestroyListenerCnt(1);
    callbackVal.reAssert();
    assertTrue(!reg1.containsKey("key1"));
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getDestroyEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals(null, ev.getNewValue());
            assertEquals("value0", ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    // check LI + LD -> LD
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.localInvalidate("key1");
    callbackVal.assertInvalidateCnt(0, false);
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    this.txMgr.commit();
    callbackVal.assertInvalidateCnt(0);
    callbackVal.assertLocalDestroyListenerCnt(1);
    callbackVal.reAssert();
    assertTrue(!reg1.containsKey("key1"));
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getDestroyEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals(null, ev.getNewValue());
            assertEquals("value0", ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(!ev.getOperation().isDistributed());
        }
    }
    // check LI + LD + D -> EX
    // check LI + LD + I -> EX
    // check LI + LD + C -> C
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.localInvalidate("key1");
    callbackVal.assertInvalidateCnt(0, false);
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    assertTrue(!reg1.containsKey("key1"));
    try {
        reg1.localDestroy("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertLocalDestroyWriterCnt(1, /* remember */
    false);
    try {
        reg1.destroy("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertDestroyWriterCnt(0);
    try {
        reg1.localInvalidate("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertInvalidateCnt(0, /* remember */
    false);
    try {
        reg1.invalidate("key1");
        fail("expected EntryNotFoundException");
    } catch (EntryNotFoundException ok) {
    }
    callbackVal.assertInvalidateCnt(0, /* remember */
    false);
    reg1.create("key1", "value3");
    callbackVal.assertCreateWriterCnt(1);
    assertEquals("value3", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertInvalidateCnt(0);
    callbackVal.assertDestroyListenerCnt(0);
    callbackVal.assertLocalDestroyListenerCnt(0);
    callbackVal.assertCreateListenerCnt(0);
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.reAssert();
    assertEquals("value3", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value3", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check LI + LD + P -> C
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.localInvalidate("key1", "value1");
    callbackVal.assertInvalidateCnt(0, false);
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    reg1.put("key1", "value3");
    callbackVal.assertCreateWriterCnt(1);
    assertEquals("value3", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertLocalDestroyListenerCnt(0);
    callbackVal.assertCreateListenerCnt(0);
    callbackVal.assertInvalidateCnt(0);
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.reAssert();
    assertEquals("value3", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value3", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check init state LI + P + I -> I token (bug 33073)
    reg1.create("key1", "value0");
    reg1.localInvalidate("key1");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.put("key1", "value1");
    callbackVal.assertUpdateWriterCnt(1);
    assertEquals("value1", reg1.getEntry("key1").getValue());
    reg1.invalidate("key1");
    callbackVal.assertInvalidateCnt(0, false);
    this.txMgr.commit();
    callbackVal.assertUpdateListenerCnt(0);
    callbackVal.assertInvalidateCnt(1);
    callbackVal.reAssert();
    assertNull(reg1.getEntry("key1").getValue());
    {
        // Special check to assert Invaldate token
        LocalRegion.NonTXEntry nonTXe = (LocalRegion.NonTXEntry) reg1.getEntry("key1");
        assertTrue(nonTXe.getRegionEntry().isInvalid());
    }
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getInvalidateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertNull(ev.getNewValue());
            assertNull(ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    // check init state I + P + LI -> LI token (bug 33073)
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.put("key1", "value1");
    callbackVal.assertUpdateWriterCnt(1);
    assertEquals("value1", reg1.getEntry("key1").getValue());
    reg1.localInvalidate("key1");
    callbackVal.assertInvalidateCnt(0, false);
    this.txMgr.commit();
    callbackVal.assertInvalidateCnt(0);
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.assertCreateListenerCnt(0);
    callbackVal.reAssert();
    assertNull(reg1.getEntry("key1").getValue());
    {
        // Special check to assert Local Invaldate token
        LocalRegion.NonTXEntry nonTXe = (LocalRegion.NonTXEntry) reg1.getEntry("key1");
        assertTrue(nonTXe.getRegionEntry().isInvalid());
    }
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(0, this.te.getCreateEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getInvalidateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertNull(ev.getNewValue());
            assertNull(ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(!ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check DD + C -> C
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.destroy("key1");
    callbackVal.assertDestroyWriterCnt(1);
    reg1.create("key1", "value1");
    callbackVal.assertCreateWriterCnt(1);
    assertEquals("value1", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertDestroyListenerCnt(0);
    callbackVal.assertCreateListenerCnt(0);
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.reAssert();
    assertEquals("value1", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value1", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check DD + P -> C
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.destroy("key1");
    callbackVal.assertDestroyWriterCnt(1);
    reg1.put("key1", "value1");
    callbackVal.assertCreateWriterCnt(1);
    assertEquals("value1", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertDestroyListenerCnt(0);
    callbackVal.assertCreateListenerCnt(0);
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.reAssert();
    assertEquals("value1", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value1", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check LD + C -> C
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    reg1.create("key1", "value1");
    callbackVal.assertCreateWriterCnt(1);
    assertEquals("value1", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertLocalDestroyListenerCnt(0);
    callbackVal.assertCreateListenerCnt(0);
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.reAssert();
    assertEquals("value1", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value1", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
    // check LD + P -> C
    reg1.create("key1", "value0");
    callbackVal.reset();
    this.txMgr.begin();
    myTxId = this.txMgr.getTransactionId();
    reg1.localDestroy("key1");
    callbackVal.assertLocalDestroyWriterCnt(1);
    reg1.put("key1", "value1");
    callbackVal.assertCreateWriterCnt(1);
    assertEquals("value1", reg1.getEntry("key1").getValue());
    this.txMgr.commit();
    callbackVal.assertLocalDestroyListenerCnt(0);
    callbackVal.assertCreateListenerCnt(0);
    callbackVal.assertUpdateListenerCnt(1);
    callbackVal.reAssert();
    assertEquals("value1", reg1.getEntry("key1").getValue());
    assertEquals(0, this.te.getPutEvents().size());
    assertEquals(0, this.te.getInvalidateEvents().size());
    assertEquals(0, this.te.getDestroyEvents().size());
    assertEquals(1, this.te.getEvents().size());
    {
        List<EntryEvent<?, ?>> events = this.te.getCreateEvents();
        assertEquals(myTxId, this.te.getTransactionId());
        assertEquals(1, events.size());
        for (EntryEvent ev : events) {
            assertEquals(myTxId, ev.getTransactionId());
            assertTrue(ev.getRegion() == reg1);
            assertEquals("key1", ev.getKey());
            assertEquals("value1", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            verifyEventProps(ev);
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(!ev.getOperation().isExpiration());
            assertTrue(ev.getOperation().isDistributed());
        }
    }
    reg1.localDestroy("key1");
}
Also used : TransactionListener(org.apache.geode.cache.TransactionListener) EntryExistsException(org.apache.geode.cache.EntryExistsException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) RegionEvent(org.apache.geode.cache.RegionEvent) TransactionId(org.apache.geode.cache.TransactionId) TransactionEvent(org.apache.geode.cache.TransactionEvent) EntryEvent(org.apache.geode.cache.EntryEvent) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with RegionEvent

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

the class CacheListenerTestCase method testCacheListenerAfterRegionDestroy.

/**
   * Tests that the <code>CacheListener</code> is called after a region is destroyed.
   *
   * @see CacheListener#afterRegionDestroy
   * @see CacheListener#close
   */
@Test
public void testCacheListenerAfterRegionDestroy() throws CacheException, InterruptedException {
    final String name = this.getUniqueName();
    Object arg = "ARG";
    // final String exception = "EXCEPTION";
    // final boolean localScope = getRegionAttributes().getScope().isLocal();
    TestCacheListener listener = new TestCacheListener() {

        private boolean closed = false;

        private boolean destroyed = false;

        public boolean wasInvoked() {
            boolean value = closed && destroyed;
            super.wasInvoked();
            return value;
        }

        public void close2() {
            this.closed = true;
        }

        public void afterRegionDestroy2(RegionEvent event) {
            assertEquals(name, event.getRegion().getName());
            // this should be a distributed destroy unless the region
            // is local scope
            assertFalse(event.getOperation().isExpiration());
            assertFalse(event.isOriginRemote());
            this.destroyed = true;
        }
    };
    AttributesFactory factory = new AttributesFactory(getRegionAttributes());
    factory.setCacheListener(listener);
    RegionAttributes attrs = factory.create();
    Region region;
    region = createRegion(name, attrs);
    assertTrue(region.getAttributes().getCacheListener() != null);
    // org.apache.geode.internal.util.DebuggerSupport.waitForJavaDebugger(getLogWriter());
    region.destroyRegion();
    // extra pause
    Wait.pause(100);
    assertTrue(region.isDestroyed());
    assertTrue(listener.wasInvoked());
    region = createRegion(name, attrs);
    region.destroyRegion(arg);
    assertTrue(listener.wasInvoked());
    assertTrue(region.isDestroyed());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Region(org.apache.geode.cache.Region) RegionEvent(org.apache.geode.cache.RegionEvent) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 3 with RegionEvent

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

the class CacheListenerTestCase method testCacheListenerAfterRegionInvalidate.

/**
   * Tests that the <code>CacheListener</code> is called after a region is invalidated.
   *
   * @see CacheListener#afterRegionInvalidate
   * @see CacheListener#close
   */
@Test
public void testCacheListenerAfterRegionInvalidate() throws CacheException, InterruptedException {
    final String name = this.getUniqueName();
    // Object arg = "ARG";
    // final String exception = "EXCEPTION";
    TestCacheListener listener = new TestCacheListener() {

        private boolean closed = false;

        private boolean invalidated = false;

        public boolean wasInvoked() {
            boolean value = invalidated;
            super.wasInvoked();
            return value;
        }

        public void close2() {
            this.closed = true;
        }

        public void afterRegionInvalidate2(RegionEvent event) {
            assertEquals(name, event.getRegion().getName());
            assertFalse(event.getOperation().isExpiration());
            assertFalse(event.isOriginRemote());
            this.invalidated = true;
        }
    };
    AttributesFactory factory = new AttributesFactory(getRegionAttributes());
    factory.setCacheListener(listener);
    RegionAttributes attrs = factory.create();
    Region region;
    region = createRegion(name, attrs);
    region.invalidateRegion();
    Wait.pause(500);
    assertTrue(listener.wasInvoked());
    assertEquals(0, region.values().size());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Region(org.apache.geode.cache.Region) RegionEvent(org.apache.geode.cache.RegionEvent) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 4 with RegionEvent

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

the class Bug35214DUnitTest method testNoEntryExpireDuringGII.

/**
   * make sure entries do not expire during a GII
   */
@Test
public void testNoEntryExpireDuringGII() throws Exception {
    initOtherVm();
    AsyncInvocation updater = null;
    try {
        updater = updateOtherVm();
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable e1) {
        Assert.fail("failed due to " + e1, e1);
    }
    System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
    org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 30;
    callbackFailure = false;
    try {
        AttributesFactory af = new AttributesFactory();
        af.setDataPolicy(DataPolicy.REPLICATE);
        af.setScope(Scope.DISTRIBUTED_ACK);
        af.setStatisticsEnabled(true);
        af.setEntryIdleTimeout(new ExpirationAttributes(1, ExpirationAction.INVALIDATE));
        CacheListener cl1 = new CacheListenerAdapter() {

            public void afterRegionCreate(RegionEvent re) {
                afterRegionCreateSeen = true;
            }

            public void afterInvalidate(EntryEvent e) {
                callbackAssertTrue("afterregionCreate not seen", afterRegionCreateSeen);
                // make sure region is initialized
                callbackAssertTrue("not initialized", ((LocalRegion) e.getRegion()).isInitialized());
                expirationCount++;
                org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
            }
        };
        af.addCacheListener(cl1);
        final Region r1 = createRootRegion("r1", af.create());
        ThreadUtils.join(updater, 60 * 1000);
        WaitCriterion ev = new WaitCriterion() {

            public boolean done() {
                return r1.values().size() == 0;
            }

            public String description() {
                return "region never became empty";
            }
        };
        Wait.waitForCriterion(ev, 2 * 1000, 200, true);
        {
            assertEquals(0, r1.values().size());
            assertEquals(ENTRY_COUNT, r1.keySet().size());
        }
    } finally {
        org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
        System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
        assertEquals(null, System.getProperty(LocalRegion.EXPIRY_MS_PROPERTY));
    }
    assertFalse("Errors in callbacks; check logs for details", callbackFailure);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) EntryEvent(org.apache.geode.cache.EntryEvent) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) RegionEvent(org.apache.geode.cache.RegionEvent) CacheListener(org.apache.geode.cache.CacheListener) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 5 with RegionEvent

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

the class MultiVMRegionTestCase method testRemoteCacheListener.

/**
   * Tests that a {@link CacheListener} is invoked in a remote VM.
   */
// GEODE-153 & GEODE-932: time sensitive, waitForInvocation
@Category(FlakyTest.class)
// (waitForCriterion), 3 second timeouts
@Test
public void testRemoteCacheListener() throws Exception {
    assertTrue(getRegionAttributes().getScope().isDistributed());
    final String name = this.getUniqueName();
    final Object key = "KEY";
    final Object oldValue = "OLD_VALUE";
    final Object newValue = "NEW_VALUE";
    // final Object key2 = "KEY2";
    // final Object value2 = "VALUE2";
    SerializableRunnable populate = new CacheSerializableRunnable("Create Region and Put") {

        @Override
        public void run2() throws CacheException {
            Region region = createRegion(name);
            region.put(key, oldValue);
        }
    };
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final VM vm1 = host.getVM(1);
    vm0.invoke(populate);
    vm1.invoke(populate);
    vm1.invoke(new CacheSerializableRunnable("Set listener") {

        @Override
        public void run2() throws CacheException {
            final Region region = getRootRegion().getSubregion(name);
            listener = new TestCacheListener() {

                @Override
                public void afterUpdate2(EntryEvent event) {
                    assertEquals(Operation.UPDATE, event.getOperation());
                    assertEquals(region, event.getRegion());
                    assertTrue(event.getOperation().isDistributed());
                    assertFalse(event.getOperation().isExpiration());
                    assertTrue(event.isOriginRemote());
                    assertEquals(event.getCallbackArgument(), event.getDistributedMember());
                    assertEquals(key, event.getKey());
                    assertEquals(oldValue, event.getOldValue());
                    assertEquals(newValue, event.getNewValue());
                    assertFalse(event.getOperation().isLoad());
                    assertFalse(event.getOperation().isLocalLoad());
                    assertFalse(event.getOperation().isNetLoad());
                    assertFalse(event.getOperation().isNetSearch());
                    if (event.getRegion().getAttributes().getOffHeap()) {
                        // since off heap always serializes the old value is serialized and available
                        assertEquals(oldValue, event.getSerializedOldValue().getDeserializedValue());
                    } else {
                        // since it was put originally in
                        assertEquals(null, event.getSerializedOldValue());
                    // this VM
                    }
                    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(event.getSerializedNewValue().getSerializedValue()));
                    try {
                        assertEquals(newValue, DataSerializer.readObject(dis));
                    } catch (Exception e) {
                        fail("Unexpected Exception", e);
                    }
                }
            };
            region.getAttributesMutator().addCacheListener(listener);
        }
    });
    // I see no reason to pause here.
    // The test used to pause here but only if no-ack.
    // But we have no operations to wait for.
    // The last thing we did was install a listener in vm1
    // and it is possible that vm0 does not yet know we have
    // a listener but for this test it does not matter.
    // So I'm commenting out the following pause:
    // pauseIfNecessary();
    // If needed then do a flushIfNecessary(region) after adding the cache listener
    vm0.invoke(new CacheSerializableRunnable("Update") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            region.put(key, newValue, getSystem().getDistributedMember());
        }
    });
    vm1.invoke(new CacheSerializableRunnable("Verify Update") {

        @Override
        public void run2() throws CacheException {
            listener.waitForInvocation(3000, 10);
            // Setup listener for next test
            final Region region = getRootRegion().getSubregion(name);
            listener = new TestCacheListener() {

                @Override
                public void afterInvalidate2(EntryEvent event) {
                    assertEquals(Operation.INVALIDATE, event.getOperation());
                    assertEquals(region, event.getRegion());
                    assertTrue(event.getOperation().isDistributed());
                    assertFalse(event.getOperation().isExpiration());
                    assertTrue(event.isOriginRemote());
                    assertEquals(event.getCallbackArgument(), event.getDistributedMember());
                    assertEquals(key, event.getKey());
                    assertEquals(newValue, event.getOldValue());
                    assertNull(event.getNewValue());
                    assertFalse(event.getOperation().isLoad());
                    assertFalse(event.getOperation().isLocalLoad());
                    assertFalse(event.getOperation().isNetLoad());
                    assertFalse(event.getOperation().isNetSearch());
                    assertNull(event.getSerializedNewValue());
                    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(event.getSerializedOldValue().getSerializedValue()));
                    try {
                        assertEquals(newValue, DataSerializer.readObject(dis));
                    } catch (Exception e) {
                        fail("Unexpected Exception", e);
                    }
                }
            };
            region.getAttributesMutator().addCacheListener(listener);
        }
    });
    vm0.invoke(new CacheSerializableRunnable("Invalidate") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            region.invalidate(key, getSystem().getDistributedMember());
        }
    });
    vm1.invoke(new CacheSerializableRunnable("Verify Invalidate") {

        @Override
        public void run2() throws CacheException {
            listener.waitForInvocation(3000, 10);
            // Setup listener for next test
            final Region region = getRootRegion().getSubregion(name);
            listener = new TestCacheListener() {

                @Override
                public void afterDestroy2(EntryEvent event) {
                    assertTrue(event.getOperation().isDestroy());
                    assertEquals(region, event.getRegion());
                    assertTrue(event.getOperation().isDistributed());
                    assertFalse(event.getOperation().isExpiration());
                    assertTrue(event.isOriginRemote());
                    assertEquals(event.getCallbackArgument(), event.getDistributedMember());
                    assertEquals(key, event.getKey());
                    assertNull(event.getOldValue());
                    assertNull(event.getNewValue());
                    assertFalse(event.getOperation().isLoad());
                    assertFalse(event.getOperation().isLocalLoad());
                    assertFalse(event.getOperation().isNetLoad());
                    assertFalse(event.getOperation().isNetSearch());
                    assertNull(event.getSerializedOldValue());
                    assertNull(event.getSerializedNewValue());
                }
            };
            region.getAttributesMutator().addCacheListener(listener);
        }
    });
    vm0.invoke(new CacheSerializableRunnable("Destroy") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            region.destroy(key, getSystem().getDistributedMember());
        }
    });
    vm1.invoke(new CacheSerializableRunnable("Verify Destroy") {

        @Override
        public void run2() throws CacheException {
            listener.waitForInvocation(3000, 10);
            // Setup listener for next test
            final Region region = getRootRegion().getSubregion(name);
            listener = new TestCacheListener() {

                @Override
                public void afterRegionInvalidate2(RegionEvent event) {
                    assertEquals(Operation.REGION_INVALIDATE, event.getOperation());
                    assertEquals(region, event.getRegion());
                    assertTrue(event.getOperation().isDistributed());
                    assertFalse(event.getOperation().isExpiration());
                    assertTrue(event.isOriginRemote());
                    assertEquals(event.getCallbackArgument(), event.getDistributedMember());
                }
            };
            region.getAttributesMutator().addCacheListener(listener);
        }
    });
    vm0.invoke(new CacheSerializableRunnable("Invalidate Region") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            region.invalidateRegion(getSystem().getDistributedMember());
        }
    });
    vm1.invoke(new CacheSerializableRunnable("Verify Invalidate Region") {

        @Override
        public void run2() throws CacheException {
            listener.waitForInvocation(3000, 10);
            // Setup listener for next test
            final Region region = getRootRegion().getSubregion(name);
            listener = new TestCacheListener() {

                @Override
                public void afterRegionDestroy2(RegionEvent event) {
                    assertEquals(Operation.REGION_DESTROY, event.getOperation());
                    assertEquals(region, event.getRegion());
                    assertTrue(event.getOperation().isDistributed());
                    assertFalse(event.getOperation().isExpiration());
                    assertTrue(event.isOriginRemote());
                    assertEquals(event.getCallbackArgument(), event.getDistributedMember());
                }
            };
            region.getAttributesMutator().addCacheListener(listener);
        }
    });
    vm0.invoke(new CacheSerializableRunnable("Destroy Region") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            region.destroyRegion(getSystem().getDistributedMember());
        }
    });
    vm1.invoke(new CacheSerializableRunnable("Verify Destroy Region") {

        @Override
        public void run2() throws CacheException {
            listener.waitForInvocation(3000, 10);
        }
    });
}
Also used : CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) DataInputStream(java.io.DataInputStream) RegionEvent(org.apache.geode.cache.RegionEvent) TimeoutException(org.apache.geode.cache.TimeoutException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) InvalidDeltaException(org.apache.geode.InvalidDeltaException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) EntryExistsException(org.apache.geode.cache.EntryExistsException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) ByteArrayInputStream(java.io.ByteArrayInputStream) VM(org.apache.geode.test.dunit.VM) EntryEvent(org.apache.geode.cache.EntryEvent) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) StoredObject(org.apache.geode.internal.offheap.StoredObject) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Aggregations

RegionEvent (org.apache.geode.cache.RegionEvent)29 Test (org.junit.Test)21 Region (org.apache.geode.cache.Region)20 AttributesFactory (org.apache.geode.cache.AttributesFactory)19 EntryEvent (org.apache.geode.cache.EntryEvent)18 CacheException (org.apache.geode.cache.CacheException)12 RegionAttributes (org.apache.geode.cache.RegionAttributes)12 LocalRegion (org.apache.geode.internal.cache.LocalRegion)11 Properties (java.util.Properties)10 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)10 VM (org.apache.geode.test.dunit.VM)9 CacheWriterException (org.apache.geode.cache.CacheWriterException)8 CacheListenerAdapter (org.apache.geode.cache.util.CacheListenerAdapter)8 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)8 Host (org.apache.geode.test.dunit.Host)8 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)7 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)7 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)6 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)6 CacheWriter (org.apache.geode.cache.CacheWriter)5