Search in sources :

Example 11 with AttributesMutator

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

the class CacheXml66DUnitTest method testMultipleCacheListener.

/**
   * Tests multiple cache listeners on one region
   * 
   * @since GemFire 5.0
   */
@Test
public void testMultipleCacheListener() throws Exception {
    CacheCreation cache = new CacheCreation();
    RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    CacheListener l1 = new MyTestCacheListener();
    CacheListener l2 = new MySecondTestCacheListener();
    attrs.addCacheListener(l1);
    attrs.addCacheListener(l2);
    cache.createRegion("root", attrs);
    testXml(cache);
    {
        Cache c = getCache();
        Region r = c.getRegion("root");
        assertEquals(Arrays.asList(new CacheListener[] { l1, l2 }), Arrays.asList(r.getAttributes().getCacheListeners()));
        AttributesMutator am = r.getAttributesMutator();
        am.removeCacheListener(l2);
        assertEquals(Arrays.asList(new CacheListener[] { l1 }), Arrays.asList(r.getAttributes().getCacheListeners()));
        am.removeCacheListener(l1);
        assertEquals(Arrays.asList(new CacheListener[] {}), Arrays.asList(r.getAttributes().getCacheListeners()));
        am.addCacheListener(l1);
        assertEquals(Arrays.asList(new CacheListener[] { l1 }), Arrays.asList(r.getAttributes().getCacheListeners()));
        am.addCacheListener(l1);
        assertEquals(Arrays.asList(new CacheListener[] { l1 }), Arrays.asList(r.getAttributes().getCacheListeners()));
        am.addCacheListener(l2);
        assertEquals(Arrays.asList(new CacheListener[] { l1, l2 }), Arrays.asList(r.getAttributes().getCacheListeners()));
        am.removeCacheListener(l1);
        assertEquals(Arrays.asList(new CacheListener[] { l2 }), Arrays.asList(r.getAttributes().getCacheListeners()));
        am.removeCacheListener(l1);
        assertEquals(Arrays.asList(new CacheListener[] { l2 }), Arrays.asList(r.getAttributes().getCacheListeners()));
        am.initCacheListeners(new CacheListener[] { l1, l2 });
        assertEquals(Arrays.asList(new CacheListener[] { l1, l2 }), Arrays.asList(r.getAttributes().getCacheListeners()));
    }
}
Also used : RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) CacheListener(org.apache.geode.cache.CacheListener) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) AttributesMutator(org.apache.geode.cache.AttributesMutator) Test(org.junit.Test)

Example 12 with AttributesMutator

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

the class MultiVMRegionTestCase method versionTestTombstones.

public void versionTestTombstones() {
    disconnectAllFromDS();
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final int numEntries = 100;
    // create replicated regions in VM 0 and 1, then perform concurrent ops
    // on the same key while creating the region in VM2. Afterward make
    // sure that all three regions are consistent
    final long oldServerTimeout = TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT;
    final long oldClientTimeout = TombstoneService.NON_REPLICATE_TOMBSTONE_TIMEOUT;
    final int oldExpiredTombstoneLimit = TombstoneService.EXPIRED_TOMBSTONE_LIMIT;
    final boolean oldIdleExpiration = TombstoneService.IDLE_EXPIRATION;
    final double oldLimit = TombstoneService.GC_MEMORY_THRESHOLD;
    final long oldMaxSleepTime = TombstoneService.MAX_SLEEP_TIME;
    try {
        SerializableRunnable setTimeout = new SerializableRunnable() {

            @Override
            public void run() {
                TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT = 1000;
                TombstoneService.NON_REPLICATE_TOMBSTONE_TIMEOUT = 900;
                TombstoneService.EXPIRED_TOMBSTONE_LIMIT = numEntries;
                TombstoneService.IDLE_EXPIRATION = true;
                // turn this off so heap profile won't cause
                TombstoneService.GC_MEMORY_THRESHOLD = 0;
                // test to fail
                TombstoneService.MAX_SLEEP_TIME = 500;
            }
        };
        vm0.invoke(setTimeout);
        vm1.invoke(setTimeout);
        final String name = this.getUniqueName() + "-CC";
        SerializableRunnable createRegion = new SerializableRunnable("Create Region") {

            @Override
            public void run() {
                try {
                    RegionFactory f = getCache().createRegionFactory(getRegionAttributes());
                    CCRegion = (LocalRegion) f.create(name);
                    for (int i = 0; i < numEntries; i++) {
                        CCRegion.put("cckey" + i, "ccvalue");
                    }
                    if (CCRegion.getScope().isDistributedNoAck()) {
                        // flush the ops
                        sendSerialMessageToAll();
                    }
                } catch (CacheException ex) {
                    fail("While creating region", ex);
                }
            }
        };
        vm0.invoke(createRegion);
        vm1.invoke(createRegion);
        vm0.invoke(new SerializableRunnable("destroy entries and check tombstone count") {

            @Override
            public void run() {
                try {
                    for (int i = 0; i < numEntries; i++) {
                        CCRegion.destroy("cckey" + i);
                        assertTrue("entry should not exist", !CCRegion.containsKey("cckey" + i));
                        assertTrue("entry should not contain a value", !CCRegion.containsValueForKey("cckey" + i));
                    }
                    checkCCRegionTombstoneCount("after destroys in this vm ", numEntries);
                    assertTrue("region should not contain a tombstone", !CCRegion.containsValue(Token.TOMBSTONE));
                    if (CCRegion.getScope().isDistributedNoAck()) {
                        // flush the ops
                        sendSerialMessageToAll();
                    }
                } catch (CacheException e) {
                    fail("while performing destroy operations", e);
                }
            }
        });
        vm1.invoke(new SerializableRunnable("check tombstone count(2)") {

            @Override
            public void run() {
                checkCCRegionTombstoneCount("after destroys in other vm ", numEntries);
                WaitCriterion waitForExpiration = new WaitCriterion() {

                    @Override
                    public boolean done() {
                        return CCRegion.getTombstoneCount() == 0;
                    }

                    @Override
                    public String description() {
                        return "Waiting for all tombstones to expire.  There are now " + CCRegion.getTombstoneCount() + " tombstones left out of " + numEntries + " initial tombstones. " + CCRegion.getCache().getTombstoneService();
                    }
                };
                try {
                    Wait.waitForCriterion(waitForExpiration, TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT + (TombstoneService.MAX_SLEEP_TIME * 9), 100, true);
                } catch (AssertionError e) {
                    CCRegion.dumpBackingMap();
                    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("tombstone service state: " + CCRegion.getCache().getTombstoneService());
                    throw e;
                }
            }
        });
        vm0.invoke(new SerializableRunnable("create/destroy entries and check tombstone count") {

            @Override
            public void run() {
                final int origCount = CCRegion.getTombstoneCount();
                try {
                    WaitCriterion waitForExpiration = new WaitCriterion() {

                        @Override
                        public boolean done() {
                            return CCRegion.getTombstoneCount() == 0;
                        }

                        @Override
                        public String description() {
                            return "Waiting for all tombstones to expire.  There are now " + CCRegion.getTombstoneCount() + " tombstones left out of " + origCount + " initial tombstones. " + CCRegion.getCache().getTombstoneService();
                        }
                    };
                    Wait.waitForCriterion(waitForExpiration, TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT + (TombstoneService.MAX_SLEEP_TIME * 9), 100, true);
                    logger.debug("creating tombstones.  current count={}", CCRegion.getTombstoneCount());
                    for (int i = 0; i < numEntries; i++) {
                        CCRegion.create("cckey" + i, i);
                        CCRegion.destroy("cckey" + i);
                    }
                    logger.debug("done creating tombstones.  current count={}", CCRegion.getTombstoneCount());
                    checkCCRegionTombstoneCount("after create+destroy in this vm ", numEntries);
                    assertEquals(0, CCRegion.size());
                    afterCreates = 0;
                    AttributesMutator m = CCRegion.getAttributesMutator();
                    m.addCacheListener(new CacheListenerAdapter() {

                        @Override
                        public void afterCreate(EntryEvent event) {
                            afterCreates++;
                        }
                    });
                    if (CCRegion.getScope().isDistributedNoAck()) {
                        // flush the ops
                        sendSerialMessageToAll();
                    }
                } catch (AssertionError e) {
                    CCRegion.dumpBackingMap();
                    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("tombstone service state: " + CCRegion.getCache().getTombstoneService());
                    throw e;
                } catch (CacheException e) {
                    fail("while performing create/destroy operations", e);
                }
            }
        });
        vm1.invoke(new SerializableRunnable("check tombstone count and install listener") {

            @Override
            public void run() {
                checkCCRegionTombstoneCount("after create+destroy in other vm ", numEntries);
                afterCreates = 0;
                AttributesMutator m = CCRegion.getAttributesMutator();
                m.addCacheListener(new CacheListenerAdapter() {

                    @Override
                    public void afterCreate(EntryEvent event) {
                        afterCreates++;
                    }
                });
            }
        });
        // Now check to see if tombstones are resurrected by a create.
        // The entries should be created okay and the callback should be afterCreate.
        // The tombstone count won't go down until the entries are swept, but then
        // the count should fall to zero.
        vm0.invoke(new SerializableRunnable("create entries and check afterCreate and tombstone count") {

            @Override
            public void run() {
                try {
                    for (int i = 0; i < numEntries; i++) {
                        CCRegion.create("cckey" + i, i);
                    }
                    checkCCRegionTombstoneCount("after create in this vm", 0);
                    assertEquals("expected " + numEntries + " afterCreates", numEntries, afterCreates);
                    assertEquals(numEntries, CCRegion.size());
                    if (CCRegion.getScope().isDistributedNoAck()) {
                        // flush the ops
                        sendSerialMessageToAll();
                    }
                    WaitCriterion waitForExpiration = new WaitCriterion() {

                        @Override
                        public boolean done() {
                            return CCRegion.getCache().getTombstoneService().getScheduledTombstoneCount() == 0;
                        }

                        @Override
                        public String description() {
                            return "Waiting for all scheduled tombstones to be removed.  There are now " + CCRegion.getCache().getTombstoneService().getScheduledTombstoneCount() + " tombstones left out of " + numEntries + " initial tombstones. " + CCRegion.getCache().getTombstoneService();
                        }
                    };
                    Wait.waitForCriterion(waitForExpiration, TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT * 5, 100, true);
                } catch (CacheException e) {
                    fail("while performing create operations", e);
                }
            }
        });
        vm1.invoke(new SerializableRunnable("check afterCreate and tombstone count") {

            @Override
            public void run() {
                checkCCRegionTombstoneCount("after create in other vm", 0);
                assertEquals("expected " + numEntries + " afterCreates", numEntries, afterCreates);
                assertEquals(numEntries, CCRegion.size());
                WaitCriterion waitForExpiration = new WaitCriterion() {

                    @Override
                    public boolean done() {
                        return CCRegion.getCache().getTombstoneService().getScheduledTombstoneCount() == 0;
                    }

                    @Override
                    public String description() {
                        return "Waiting for all scheduled tombstones to be removed.  There are now " + CCRegion.getCache().getTombstoneService().getScheduledTombstoneCount() + " tombstones left out of " + numEntries + " initial tombstones. " + CCRegion.getCache().getTombstoneService();
                    }
                };
                Wait.waitForCriterion(waitForExpiration, TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT * 5, 100, true);
            }
        });
    } finally {
        SerializableRunnable resetTimeout = new SerializableRunnable() {

            @Override
            public void run() {
                TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT = oldServerTimeout;
                TombstoneService.NON_REPLICATE_TOMBSTONE_TIMEOUT = oldClientTimeout;
                TombstoneService.EXPIRED_TOMBSTONE_LIMIT = oldExpiredTombstoneLimit;
                TombstoneService.IDLE_EXPIRATION = oldIdleExpiration;
                TombstoneService.GC_MEMORY_THRESHOLD = oldLimit;
                TombstoneService.MAX_SLEEP_TIME = oldMaxSleepTime;
            }
        };
        vm0.invoke(resetTimeout);
        vm1.invoke(resetTimeout);
    }
}
Also used : CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) RegionFactory(org.apache.geode.cache.RegionFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) VM(org.apache.geode.test.dunit.VM) EntryEvent(org.apache.geode.cache.EntryEvent) AttributesMutator(org.apache.geode.cache.AttributesMutator)

Example 13 with AttributesMutator

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

the class MultiVMRegionTestCase method testTXUpdateLoadNoConflict.

/**
   * Tests that the push of a loaded value does not cause a conflict on the side receiving the
   * update
   */
@Ignore("TODO: this test always hits early out")
@Test
public void testTXUpdateLoadNoConflict() throws Exception {
    /*
     * this no longer holds true - we have load conflicts now
     * 
     */
    if (true) {
        return;
    }
    assumeTrue(supportsTransactions());
    assumeFalse(getRegionAttributes().getScope().isGlobal());
    assumeFalse(getRegionAttributes().getDataPolicy().withPersistence());
    assertTrue(getRegionAttributes().getScope().isDistributed());
    CacheTransactionManager txMgr = this.getCache().getCacheTransactionManager();
    final String rgnName = getUniqueName();
    SerializableRunnable create = new SerializableRunnable("testTXUpdateLoadNoConflict: Create Region & Load value") {

        @Override
        public void run() {
            CacheTransactionManager txMgr2 = getCache().getCacheTransactionManager();
            MyTransactionListener tl = new MyTransactionListener();
            txMgr2.addListener(tl);
            try {
                Region rgn = createRegion(rgnName);
                AttributesMutator mutator = rgn.getAttributesMutator();
                mutator.setCacheLoader(new CacheLoader() {

                    int count = 0;

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

                    @Override
                    public void close() {
                    }
                });
                Object value = rgn.get("key");
                assertEquals("LV 1", value);
                getSystem().getLogWriter().info("testTXUpdateLoadNoConflict: loaded Key");
                flushIfNecessary(rgn);
            } catch (CacheException e) {
                fail("While creating region", e);
            }
        }
    };
    VM vm0 = Host.getHost(0).getVM(0);
    try {
        MyTransactionListener tl = new MyTransactionListener();
        txMgr.addListener(tl);
        AttributesFactory rgnAtts = new AttributesFactory(getRegionAttributes());
        rgnAtts.setDataPolicy(DataPolicy.REPLICATE);
        Region rgn = createRegion(rgnName, rgnAtts.create());
        txMgr.begin();
        TransactionId myTXId = txMgr.getTransactionId();
        rgn.create("key", "txValue");
        vm0.invoke(create);
        {
            TXStateProxy tx = ((TXManagerImpl) txMgr).internalSuspend();
            assertTrue(rgn.containsKey("key"));
            assertEquals("LV 1", rgn.getEntry("key").getValue());
            ((TXManagerImpl) txMgr).internalResume(tx);
        }
        // make sure transactional view is still correct
        assertEquals("txValue", rgn.getEntry("key").getValue());
        txMgr.commit();
        getSystem().getLogWriter().info("testTXUpdateLoadNoConflict: did commit");
        assertEquals("txValue", rgn.getEntry("key").getValue());
        {
            Collection events = tl.lastEvent.getCreateEvents();
            assertEquals(1, events.size());
            EntryEvent ev = (EntryEvent) events.iterator().next();
            assertEquals(myTXId, ev.getTransactionId());
            assertTrue(ev.getRegion() == rgn);
            assertEquals("key", ev.getKey());
            assertEquals("txValue", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            assertTrue(!ev.getOperation().isLocalLoad());
            assertTrue(!ev.getOperation().isNetLoad());
            assertTrue(!ev.getOperation().isLoad());
            assertTrue(!ev.getOperation().isNetSearch());
            assertTrue(!ev.getOperation().isExpiration());
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(ev.getOperation().isDistributed());
        }
        // Now setup recreate the region in the controller with NONE
        // so test can do local destroys.
        rgn.localDestroyRegion();
        rgnAtts.setDataPolicy(DataPolicy.NORMAL);
        rgn = createRegion(rgnName, rgnAtts.create());
        // now see if net loader is working
        Object v2 = rgn.get("key2");
        assertEquals("LV 2", v2);
        // now confirm that netload does not cause a conflict
        txMgr.begin();
        myTXId = txMgr.getTransactionId();
        rgn.create("key3", "txValue3");
        {
            TXStateProxy tx = ((TXManagerImpl) txMgr).internalSuspend();
            // do a get outside of the transaction to force a net load
            Object v3 = rgn.get("key3");
            assertEquals("LV 3", v3);
            ((TXManagerImpl) txMgr).internalResume(tx);
        }
        // make sure transactional view is still correct
        assertEquals("txValue3", rgn.getEntry("key3").getValue());
        txMgr.commit();
        getSystem().getLogWriter().info("testTXUpdateLoadNoConflict: did commit");
        assertEquals("txValue3", rgn.getEntry("key3").getValue());
        {
            Collection events = tl.lastEvent.getCreateEvents();
            assertEquals(1, events.size());
            EntryEvent ev = (EntryEvent) events.iterator().next();
            assertEquals(myTXId, ev.getTransactionId());
            assertTrue(ev.getRegion() == rgn);
            assertEquals("key3", ev.getKey());
            assertEquals("txValue3", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            assertTrue(!ev.getOperation().isLocalLoad());
            assertTrue(!ev.getOperation().isNetLoad());
            assertTrue(!ev.getOperation().isLoad());
            assertTrue(!ev.getOperation().isNetSearch());
            assertTrue(!ev.getOperation().isExpiration());
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(ev.getOperation().isDistributed());
        }
        // now see if tx net loader is working
        // now confirm that netload does not cause a conflict
        txMgr.begin();
        myTXId = txMgr.getTransactionId();
        Object v4 = rgn.get("key4");
        assertEquals("LV 4", v4);
        assertEquals("LV 4", rgn.get("key4"));
        assertEquals("LV 4", rgn.getEntry("key4").getValue());
        txMgr.rollback();
        // confirm that netLoad is transactional
        assertEquals("LV 5", rgn.get("key4"));
        assertEquals("LV 5", rgn.getEntry("key4").getValue());
        // make sure non-tx netsearch works
        assertEquals("txValue", rgn.get("key"));
        assertEquals("txValue", rgn.getEntry("key").getValue());
        // make sure net-search result does not conflict with commit
        rgn.localInvalidate("key");
        txMgr.begin();
        myTXId = txMgr.getTransactionId();
        rgn.put("key", "new txValue");
        {
            TXStateProxy tx = ((TXManagerImpl) txMgr).internalSuspend();
            // do a get outside of the transaction to force a netsearch
            // does a netsearch
            assertEquals("txValue", rgn.get("key"));
            assertEquals("txValue", rgn.getEntry("key").getValue());
            ((TXManagerImpl) txMgr).internalResume(tx);
        }
        // make sure transactional view is still correct
        assertEquals("new txValue", rgn.getEntry("key").getValue());
        txMgr.commit();
        // give other side change to process commit
        flushIfNecessary(rgn);
        getSystem().getLogWriter().info("testTXUpdateLoadNoConflict: did commit");
        assertEquals("new txValue", rgn.getEntry("key").getValue());
        {
            Collection events = tl.lastEvent.getPutEvents();
            assertEquals(1, events.size());
            EntryEvent ev = (EntryEvent) events.iterator().next();
            assertEquals(myTXId, ev.getTransactionId());
            assertTrue(ev.getRegion() == rgn);
            assertEquals("key", ev.getKey());
            assertEquals("new txValue", ev.getNewValue());
            assertEquals(null, ev.getOldValue());
            assertTrue(!ev.getOperation().isLocalLoad());
            assertTrue(!ev.getOperation().isNetLoad());
            assertTrue(!ev.getOperation().isLoad());
            assertTrue(!ev.getOperation().isNetSearch());
            assertTrue(!ev.getOperation().isExpiration());
            assertEquals(null, ev.getCallbackArgument());
            assertEquals(true, ev.isCallbackArgumentAvailable());
            assertTrue(!ev.isOriginRemote());
            assertTrue(ev.getOperation().isDistributed());
        }
        // make sure tx local invalidate allows netsearch
        Object localCmtValue = rgn.getEntry("key").getValue();
        txMgr.begin();
        assertSame(localCmtValue, rgn.getEntry("key").getValue());
        rgn.localInvalidate("key");
        assertNull(rgn.getEntry("key").getValue());
        // now make sure a get will do a netsearch and find the value
        // in the other vm instead of the one in local cmt state
        Object txValue = rgn.get("key");
        assertNotSame(localCmtValue, txValue);
        assertSame(txValue, rgn.get("key"));
        assertNotSame(localCmtValue, rgn.getEntry("key").getValue());
        // make sure we did a search and not a load
        assertEquals(localCmtValue, rgn.getEntry("key").getValue());
        // now make sure that if we do a tx distributed invalidate
        // that we will do a load and not a search
        rgn.invalidate("key");
        assertNull(rgn.getEntry("key").getValue());
        txValue = rgn.get("key");
        assertEquals("LV 6", txValue);
        assertSame(txValue, rgn.get("key"));
        assertEquals("LV 6", rgn.getEntry("key").getValue());
        // now make sure after rollback that local cmt state has not changed
        txMgr.rollback();
        assertSame(localCmtValue, rgn.getEntry("key").getValue());
    } catch (Exception e) {
        CacheFactory.getInstance(getSystem()).close();
        getSystem().getLogWriter().fine("testTXUpdateLoadNoConflict: Caused exception in createRegion");
        throw e;
    }
}
Also used : CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) 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) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager) TransactionId(org.apache.geode.cache.TransactionId) LoaderHelper(org.apache.geode.cache.LoaderHelper) AttributesFactory(org.apache.geode.cache.AttributesFactory) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) 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) Collection(java.util.Collection) CacheLoader(org.apache.geode.cache.CacheLoader) StoredObject(org.apache.geode.internal.offheap.StoredObject) AttributesMutator(org.apache.geode.cache.AttributesMutator) Ignore(org.junit.Ignore) Test(org.junit.Test) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 14 with AttributesMutator

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

the class MapInterface2JUnitTest method testBasicMapAfterClearCalback.

@Test
public void testBasicMapAfterClearCalback() {
    Region rgn = CacheUtils.getRegion("Portfolios");
    AttributesMutator atm = rgn.getAttributesMutator();
    atm.setCacheListener(new CacheListenerAdapter() {

        public void afterRegionClear(RegionEvent event) {
            synchronized (MapInterface2JUnitTest.this) {
                event.getRegion().getCache().getLogger().info("afterRegionClear call back " + event);
                afterClearCallbackOccurred = true;
                MapInterface2JUnitTest.this.notify();
            }
        }
    });
    int size = rgn.size();
    assertTrue("MapInterface2JUnitTest::basicMapClearNonTranxn: The init size of region is zero", size > 0);
    rgn.clear();
    if (rgn.size() != 0) {
        fail("The region size is non zero even after issuing clear");
    }
    if (rgn.size() != 0) {
        fail("The region size is non zero even after issuing clear");
    }
    try {
        synchronized (this) {
            if (!this.afterClearCallbackOccurred) {
                this.wait(10000);
            }
        }
    } catch (InterruptedException ie) {
        fail(ie.toString());
    }
    if (!this.afterClearCallbackOccurred) {
        fail("afterClear Callback not issued");
    }
}
Also used : CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) Region(org.apache.geode.cache.Region) RegionEvent(org.apache.geode.cache.RegionEvent) AttributesMutator(org.apache.geode.cache.AttributesMutator) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 15 with AttributesMutator

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

the class ForceInvalidateEvictionDUnitTest method addListener.

private void addListener(VM vm) {
    final String name = getUniqueName();
    vm.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(name);
            AttributesMutator am = region.getAttributesMutator();
            am.initCacheListeners(new CacheListener[] { new MyListener() });
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) CacheListener(org.apache.geode.cache.CacheListener) Cache(org.apache.geode.cache.Cache) AttributesMutator(org.apache.geode.cache.AttributesMutator)

Aggregations

AttributesMutator (org.apache.geode.cache.AttributesMutator)37 Region (org.apache.geode.cache.Region)24 Test (org.junit.Test)19 LocalRegion (org.apache.geode.internal.cache.LocalRegion)18 AttributesFactory (org.apache.geode.cache.AttributesFactory)16 RegionAttributes (org.apache.geode.cache.RegionAttributes)13 EntryEvent (org.apache.geode.cache.EntryEvent)11 ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)11 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)11 Properties (java.util.Properties)8 CacheException (org.apache.geode.cache.CacheException)8 CacheLoader (org.apache.geode.cache.CacheLoader)8 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8 HashSet (java.util.HashSet)7 Set (java.util.Set)7 LoaderHelper (org.apache.geode.cache.LoaderHelper)7 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)7 AbstractRegion (org.apache.geode.internal.cache.AbstractRegion)7 CacheListener (org.apache.geode.cache.CacheListener)6 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)6