Search in sources :

Example 16 with CachePerfStats

use of org.apache.geode.internal.cache.CachePerfStats in project geode by apache.

the class TXJUnitTest method testCacheStats.

@Test
public void testCacheStats() throws CacheException {
    CachePerfStats cacheStats = this.cache.getCachePerfStats();
    // quick sanity check to make sure perf stats work non-tx
    int creates;
    int destroys;
    int puts;
    int invalidates;
    creates = cacheStats.getCreates();
    destroys = cacheStats.getDestroys();
    puts = cacheStats.getPuts();
    invalidates = cacheStats.getInvalidates();
    this.region.create("key1", "value1");
    assertEquals(creates + 1, cacheStats.getCreates());
    assertEquals(destroys, cacheStats.getDestroys());
    assertEquals(puts + 1, cacheStats.getPuts());
    assertEquals(invalidates, cacheStats.getInvalidates());
    creates = cacheStats.getCreates();
    destroys = cacheStats.getDestroys();
    puts = cacheStats.getPuts();
    invalidates = cacheStats.getInvalidates();
    this.region.put("key1", "value2");
    assertEquals(creates, cacheStats.getCreates());
    assertEquals(destroys, cacheStats.getDestroys());
    assertEquals(puts + 1, cacheStats.getPuts());
    assertEquals(invalidates, cacheStats.getInvalidates());
    creates = cacheStats.getCreates();
    destroys = cacheStats.getDestroys();
    puts = cacheStats.getPuts();
    invalidates = cacheStats.getInvalidates();
    this.region.invalidate("key1");
    assertEquals(creates, cacheStats.getCreates());
    assertEquals(destroys, cacheStats.getDestroys());
    assertEquals(puts, cacheStats.getPuts());
    assertEquals(invalidates + 1, cacheStats.getInvalidates());
    creates = cacheStats.getCreates();
    destroys = cacheStats.getDestroys();
    puts = cacheStats.getPuts();
    invalidates = cacheStats.getInvalidates();
    this.region.destroy("key1");
    assertEquals(creates, cacheStats.getCreates());
    assertEquals(destroys + 1, cacheStats.getDestroys());
    assertEquals(puts, cacheStats.getPuts());
    assertEquals(invalidates, cacheStats.getInvalidates());
    // now make sure they do not change from tx ops and from rollbacks
    creates = cacheStats.getCreates();
    destroys = cacheStats.getDestroys();
    puts = cacheStats.getPuts();
    invalidates = cacheStats.getInvalidates();
    this.txMgr.begin();
    this.region.create("key1", "value1");
    this.region.put("key1", "value2");
    this.region.invalidate("key1");
    this.region.put("key1", "value3");
    this.region.localInvalidate("key1");
    this.region.put("key1", "value4");
    this.region.localDestroy("key1");
    this.region.put("key1", "value5");
    this.region.destroy("key1");
    this.txMgr.rollback();
    assertEquals(creates, cacheStats.getCreates());
    assertEquals(destroys, cacheStats.getDestroys());
    assertEquals(puts, cacheStats.getPuts());
    assertEquals(invalidates, cacheStats.getInvalidates());
    // now make sure they do change when a commit is done
    creates = cacheStats.getCreates();
    destroys = cacheStats.getDestroys();
    puts = cacheStats.getPuts();
    invalidates = cacheStats.getInvalidates();
    this.txMgr.begin();
    this.region.create("key1", "value1");
    assertEquals(creates, cacheStats.getCreates());
    assertEquals(puts, cacheStats.getPuts());
    this.txMgr.commit();
    assertEquals(creates + 1, cacheStats.getCreates());
    assertEquals(destroys, cacheStats.getDestroys());
    assertEquals(puts + 1, cacheStats.getPuts());
    assertEquals(invalidates, cacheStats.getInvalidates());
    creates = cacheStats.getCreates();
    destroys = cacheStats.getDestroys();
    puts = cacheStats.getPuts();
    invalidates = cacheStats.getInvalidates();
    this.txMgr.begin();
    this.region.put("key1", "value1");
    assertEquals(puts, cacheStats.getPuts());
    this.txMgr.commit();
    assertEquals(creates, cacheStats.getCreates());
    assertEquals(destroys, cacheStats.getDestroys());
    assertEquals(puts + 1, cacheStats.getPuts());
    assertEquals(invalidates, cacheStats.getInvalidates());
    creates = cacheStats.getCreates();
    destroys = cacheStats.getDestroys();
    puts = cacheStats.getPuts();
    invalidates = cacheStats.getInvalidates();
    this.txMgr.begin();
    this.region.localInvalidate("key1");
    assertEquals(invalidates, cacheStats.getInvalidates());
    this.txMgr.commit();
    assertEquals(creates, cacheStats.getCreates());
    assertEquals(destroys, cacheStats.getDestroys());
    assertEquals(puts, cacheStats.getPuts());
    assertEquals(invalidates + 1, cacheStats.getInvalidates());
    creates = cacheStats.getCreates();
    destroys = cacheStats.getDestroys();
    puts = cacheStats.getPuts();
    invalidates = cacheStats.getInvalidates();
    this.txMgr.begin();
    this.region.localDestroy("key1");
    assertEquals(destroys, cacheStats.getDestroys());
    this.txMgr.commit();
    assertEquals(creates, cacheStats.getCreates());
    assertEquals(destroys + 1, cacheStats.getDestroys());
    assertEquals(puts, cacheStats.getPuts());
    assertEquals(invalidates, cacheStats.getInvalidates());
}
Also used : CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 17 with CachePerfStats

use of org.apache.geode.internal.cache.CachePerfStats in project geode by apache.

the class CacheRegionsReliablityStatsCheckDUnitTest method testRegionsReliablityStats.

/**
   * The tests check to see if all the reliablity stats are working fine and asserts their values to
   * constants.
   */
@Test
public void testRegionsReliablityStats() throws Exception {
    final String rr1 = "roleA";
    final String regionNoAccess = "regionNoAccess";
    final String regionLimitedAccess = "regionLimitedAccess";
    final String regionFullAccess = "regionFullAccess";
    // final String regionNameRoleA = "roleA";
    String[] requiredRoles = { rr1 };
    Cache myCache = getCache();
    MembershipAttributes ra = new MembershipAttributes(requiredRoles, LossAction.NO_ACCESS, ResumptionAction.NONE);
    AttributesFactory fac = new AttributesFactory();
    fac.setMembershipAttributes(ra);
    fac.setScope(Scope.DISTRIBUTED_ACK);
    fac.setDataPolicy(DataPolicy.REPLICATE);
    RegionAttributes attr = fac.create();
    myCache.createRegion(regionNoAccess, attr);
    ra = new MembershipAttributes(requiredRoles, LossAction.LIMITED_ACCESS, ResumptionAction.NONE);
    fac = new AttributesFactory();
    fac.setMembershipAttributes(ra);
    fac.setScope(Scope.DISTRIBUTED_ACK);
    fac.setDataPolicy(DataPolicy.REPLICATE);
    attr = fac.create();
    myCache.createRegion(regionLimitedAccess, attr);
    ra = new MembershipAttributes(requiredRoles, LossAction.FULL_ACCESS, ResumptionAction.NONE);
    fac = new AttributesFactory();
    fac.setMembershipAttributes(ra);
    fac.setScope(Scope.DISTRIBUTED_ACK);
    fac.setDataPolicy(DataPolicy.REPLICATE);
    attr = fac.create();
    myCache.createRegion(regionFullAccess, attr);
    CachePerfStats stats = ((GemFireCacheImpl) myCache).getCachePerfStats();
    assertEquals(stats.getReliableRegionsMissingNoAccess(), 1);
    assertEquals(stats.getReliableRegionsMissingLimitedAccess(), 1);
    assertEquals(stats.getReliableRegionsMissingFullAccess(), 1);
    assertEquals(stats.getReliableRegionsMissing(), (stats.getReliableRegionsMissingNoAccess() + stats.getReliableRegionsMissingLimitedAccess() + stats.getReliableRegionsMissingFullAccess()));
    Host host = Host.getHost(0);
    VM vm1 = host.getVM(1);
    SerializableRunnable roleAPlayer = new CacheSerializableRunnable("ROLEAPLAYER") {

        public void run2() throws CacheException {
            Properties props = new Properties();
            props.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            props.setProperty(ROLES, rr1);
            getSystem(props);
            Cache cache = getCache();
            AttributesFactory fac = new AttributesFactory();
            fac.setScope(Scope.DISTRIBUTED_ACK);
            fac.setDataPolicy(DataPolicy.REPLICATE);
            RegionAttributes attr = fac.create();
            cache.createRegion(regionNoAccess, attr);
            cache.createRegion(regionLimitedAccess, attr);
            cache.createRegion(regionFullAccess, attr);
        }
    };
    vm1.invoke(roleAPlayer);
    assertEquals(stats.getReliableRegionsMissingNoAccess(), 0);
    assertEquals(stats.getReliableRegionsMissingLimitedAccess(), 0);
    assertEquals(stats.getReliableRegionsMissingFullAccess(), 0);
    assertEquals(stats.getReliableRegionsMissing(), (stats.getReliableRegionsMissingNoAccess() + stats.getReliableRegionsMissingLimitedAccess() + stats.getReliableRegionsMissingFullAccess()));
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) AttributesFactory(org.apache.geode.cache.AttributesFactory) VM(org.apache.geode.test.dunit.VM) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Cache(org.apache.geode.cache.Cache) MembershipAttributes(org.apache.geode.cache.MembershipAttributes) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 18 with CachePerfStats

use of org.apache.geode.internal.cache.CachePerfStats in project geode by apache.

the class QueueMsgDUnitTest method testQueueWhenRoleMissing.

/**
   * Make sure that cache operations are queued when a required role is missing
   */
@Ignore("TODO: test is disabled")
@Test
public void testQueueWhenRoleMissing() throws Exception {
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    DistributedRegion r = (DistributedRegion) createRootRegion(factory.create());
    final CachePerfStats stats = r.getCachePerfStats();
    int queuedOps = stats.getReliableQueuedOps();
    r.create("createKey", "createValue", "createCBArg");
    r.invalidate("createKey", "invalidateCBArg");
    r.put("createKey", "putValue", "putCBArg");
    r.destroy("createKey", "destroyCBArg");
    assertEquals(queuedOps + 4, stats.getReliableQueuedOps());
    queuedOps = stats.getReliableQueuedOps();
    {
        Map m = new TreeMap();
        m.put("aKey", "aValue");
        m.put("bKey", "bValue");
        r.putAll(m);
    }
    assertEquals(queuedOps + 2, stats.getReliableQueuedOps());
    queuedOps = stats.getReliableQueuedOps();
    r.invalidateRegion("invalidateRegionCBArg");
    assertEquals(queuedOps + 1, stats.getReliableQueuedOps());
    queuedOps = stats.getReliableQueuedOps();
    r.clear();
    assertEquals(queuedOps + 1, stats.getReliableQueuedOps());
    queuedOps = stats.getReliableQueuedOps();
    // @todo darrel: try some other ops
    VM vm = Host.getHost(0).getVM(0);
    // now create a system that fills this role since it does not create the
    // region our queue should not be flushed
    vm.invoke(new SerializableRunnable() {

        public void run() {
            Properties config = new Properties();
            config.setProperty(ROLES, "missing");
            getSystem(config);
        }
    });
    // we still should have everything queued since the region is not created
    assertEquals(queuedOps, stats.getReliableQueuedOps());
    // now create the region
    vm.invoke(new CacheSerializableRunnable("create root") {

        public void run2() throws CacheException {
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.DISTRIBUTED_ACK);
            factory.setDataPolicy(DataPolicy.NORMAL);
            factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
            TestCacheListener cl = new TestCacheListener() {

                public void afterCreate2(EntryEvent event) {
                }

                public void afterUpdate2(EntryEvent event) {
                }

                public void afterInvalidate2(EntryEvent event) {
                }

                public void afterDestroy2(EntryEvent event) {
                }
            };
            cl.enableEventHistory();
            factory.addCacheListener(cl);
            createRootRegion(factory.create());
        }
    });
    // after some amount of time we should see the queuedOps flushed
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            return stats.getReliableQueuedOps() == 0;
        }

        public String description() {
            return "waiting for reliableQueuedOps to become 0";
        }
    };
    Wait.waitForCriterion(ev, 5 * 1000, 200, true);
    // now check that the queued op was delivered
    vm.invoke(new CacheSerializableRunnable("check") {

        public void run2() throws CacheException {
            Region r = getRootRegion();
            assertEquals(null, r.getEntry("createKey"));
            // assertIndexDetailsEquals("putValue", r.getEntry("createKey").getValue());
            {
                int evIdx = 0;
                TestCacheListener cl = (TestCacheListener) r.getAttributes().getCacheListener();
                List events = cl.getEventHistory();
                {
                    CacheEvent ce = (CacheEvent) events.get(evIdx++);
                    assertEquals(Operation.REGION_CREATE, ce.getOperation());
                }
                {
                    EntryEvent ee = (EntryEvent) events.get(evIdx++);
                    assertEquals(Operation.CREATE, ee.getOperation());
                    assertEquals("createKey", ee.getKey());
                    assertEquals("createValue", ee.getNewValue());
                    assertEquals(null, ee.getOldValue());
                    assertEquals("createCBArg", ee.getCallbackArgument());
                    assertEquals(true, ee.isOriginRemote());
                }
                {
                    EntryEvent ee = (EntryEvent) events.get(evIdx++);
                    assertEquals(Operation.INVALIDATE, ee.getOperation());
                    assertEquals("createKey", ee.getKey());
                    assertEquals(null, ee.getNewValue());
                    assertEquals("createValue", ee.getOldValue());
                    assertEquals("invalidateCBArg", ee.getCallbackArgument());
                    assertEquals(true, ee.isOriginRemote());
                }
                {
                    EntryEvent ee = (EntryEvent) events.get(evIdx++);
                    assertEquals(Operation.UPDATE, ee.getOperation());
                    assertEquals("createKey", ee.getKey());
                    assertEquals("putValue", ee.getNewValue());
                    assertEquals(null, ee.getOldValue());
                    assertEquals("putCBArg", ee.getCallbackArgument());
                    assertEquals(true, ee.isOriginRemote());
                }
                {
                    EntryEvent ee = (EntryEvent) events.get(evIdx++);
                    assertEquals(Operation.DESTROY, ee.getOperation());
                    assertEquals("createKey", ee.getKey());
                    assertEquals(null, ee.getNewValue());
                    assertEquals("putValue", ee.getOldValue());
                    assertEquals("destroyCBArg", ee.getCallbackArgument());
                    assertEquals(true, ee.isOriginRemote());
                }
                {
                    EntryEvent ee = (EntryEvent) events.get(evIdx++);
                    assertEquals(Operation.PUTALL_CREATE, ee.getOperation());
                    assertEquals("aKey", ee.getKey());
                    assertEquals("aValue", ee.getNewValue());
                    assertEquals(null, ee.getOldValue());
                    assertEquals(null, ee.getCallbackArgument());
                    assertEquals(true, ee.isOriginRemote());
                }
                {
                    EntryEvent ee = (EntryEvent) events.get(evIdx++);
                    assertEquals(Operation.PUTALL_CREATE, ee.getOperation());
                    assertEquals("bKey", ee.getKey());
                    assertEquals("bValue", ee.getNewValue());
                    assertEquals(null, ee.getOldValue());
                    assertEquals(null, ee.getCallbackArgument());
                    assertEquals(true, ee.isOriginRemote());
                }
                {
                    RegionEvent re = (RegionEvent) events.get(evIdx++);
                    assertEquals(Operation.REGION_INVALIDATE, re.getOperation());
                    assertEquals("invalidateRegionCBArg", re.getCallbackArgument());
                    assertEquals(true, re.isOriginRemote());
                }
                {
                    RegionEvent re = (RegionEvent) events.get(evIdx++);
                    assertEquals(Operation.REGION_CLEAR, re.getOperation());
                    assertEquals(null, re.getCallbackArgument());
                    assertEquals(true, re.isOriginRemote());
                }
                assertEquals(evIdx, events.size());
            }
        }
    });
}
Also used : CacheException(org.apache.geode.cache.CacheException) CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) TreeMap(java.util.TreeMap) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) RegionEvent(org.apache.geode.cache.RegionEvent) AttributesFactory(org.apache.geode.cache.AttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) EntryEvent(org.apache.geode.cache.EntryEvent) CacheEvent(org.apache.geode.cache.CacheEvent) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Region(org.apache.geode.cache.Region) List(java.util.List) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Map(java.util.Map) TreeMap(java.util.TreeMap) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes) Ignore(org.junit.Ignore) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 19 with CachePerfStats

use of org.apache.geode.internal.cache.CachePerfStats in project geode by apache.

the class TXJUnitTest method testNonTxRegionOps.

@Test
public void testNonTxRegionOps() throws Exception {
    final CachePerfStats stats = this.cache.getCachePerfStats();
    doNonTxInvalidateRegionOp(stats);
    doNonTxDestroyRegionOp(stats);
}
Also used : CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 20 with CachePerfStats

use of org.apache.geode.internal.cache.CachePerfStats in project geode by apache.

the class TXJUnitTest method testSimpleOps.

@Test
public void testSimpleOps() throws CacheException {
    final CachePerfStats stats = this.cache.getCachePerfStats();
    // See if things are ok when no transaction
    checkNoTxState();
    this.txMgr.begin();
    // now that a transaction exists make sure things behave as expected
    assertTrue(this.txMgr.getTransactionId() != null);
    assertTrue(this.txMgr.exists());
    try {
        this.txMgr.begin();
        fail("expected IllegalStateException");
    } catch (IllegalStateException expected) {
    }
    try {
        this.txMgr.commit();
    } catch (CommitConflictException unexpected) {
        fail("did not expect " + unexpected);
    }
    checkNoTxState();
    this.txMgr.begin();
    this.txMgr.rollback();
    checkNoTxState();
    this.region.put("uaKey", "val");
    {
        Region.Entry cmtre = this.region.getEntry("uaKey");
        cmtre.setUserAttribute("uaValue1");
        assertEquals("uaValue1", cmtre.getUserAttribute());
        int txRollbackChanges = stats.getTxRollbackChanges();
        int txCommitChanges = stats.getTxCommitChanges();
        int txFailureChanges = stats.getTxFailureChanges();
        this.txMgr.begin();
        Region.Entry txre = this.region.getEntry("uaKey");
        assertEquals(this.region, txre.getRegion());
        if (isPR()) {
            this.region.put("1", "one");
            try {
                txre.setUserAttribute("uaValue2");
            } catch (UnsupportedOperationException e) {
            // expected
            }
            try {
                txre.getUserAttribute();
            } catch (UnsupportedOperationException e) {
            // expected
            }
        } else {
            assertEquals("uaValue1", txre.getUserAttribute());
            txre.setUserAttribute("uaValue2");
            assertEquals("uaValue2", txre.getUserAttribute());
        }
        this.txMgr.rollback();
        try {
            txre.getValue();
            fail("expected IllegalStateException");
        } catch (IllegalStateException ok) {
        }
        try {
            txre.isDestroyed();
            fail("expected IllegalStateException");
        } catch (IllegalStateException ok) {
        }
        try {
            txre.getUserAttribute();
            fail("expected IllegalStateException");
        } catch (IllegalStateException ok) {
        }
        try {
            txre.setUserAttribute("foo");
            fail("expected IllegalStateException");
        } catch (IllegalStateException ok) {
        }
        assertEquals(txRollbackChanges + 1, stats.getTxRollbackChanges());
        assertEquals(txCommitChanges, stats.getTxCommitChanges());
        assertEquals(txFailureChanges, stats.getTxFailureChanges());
        assertEquals("uaValue1", cmtre.getUserAttribute());
    }
    {
        int txRollbackChanges = stats.getTxRollbackChanges();
        int txCommitChanges = stats.getTxCommitChanges();
        int txFailureChanges = stats.getTxFailureChanges();
        this.region.create("key1", "value1");
        this.txMgr.begin();
        this.region.invalidate("key1");
        this.txMgr.rollback();
        assertEquals(this.region.get("key1"), "value1");
        assertEquals(txRollbackChanges + 1, stats.getTxRollbackChanges());
        assertEquals(txCommitChanges, stats.getTxCommitChanges());
        assertEquals(txFailureChanges, stats.getTxFailureChanges());
        txRollbackChanges = stats.getTxRollbackChanges();
        this.txMgr.begin();
        this.region.destroy("key1");
        this.txMgr.rollback();
        assertEquals(this.region.get("key1"), "value1");
        assertEquals(txRollbackChanges + 1, stats.getTxRollbackChanges());
        assertEquals(txCommitChanges, stats.getTxCommitChanges());
        assertEquals(txFailureChanges, stats.getTxFailureChanges());
        txRollbackChanges = stats.getTxRollbackChanges();
        this.txMgr.begin();
        this.region.put("key1", "value2");
        this.txMgr.rollback();
        assertEquals(this.region.get("key1"), "value1");
        assertEquals(txRollbackChanges + 1, stats.getTxRollbackChanges());
        assertEquals(txCommitChanges, stats.getTxCommitChanges());
        assertEquals(txFailureChanges, stats.getTxFailureChanges());
    }
}
Also used : CommitConflictException(org.apache.geode.cache.CommitConflictException) CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

CachePerfStats (org.apache.geode.internal.cache.CachePerfStats)21 Test (org.junit.Test)15 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)7 Compressor (org.apache.geode.compression.Compressor)6 RegionEntryContext (org.apache.geode.internal.cache.RegionEntryContext)6 UnitTest (org.apache.geode.test.junit.categories.UnitTest)6 AttributesFactory (org.apache.geode.cache.AttributesFactory)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 IOException (java.io.IOException)2 List (java.util.List)2 Properties (java.util.Properties)2 CancelException (org.apache.geode.CancelException)2 CacheException (org.apache.geode.cache.CacheException)2 CommitConflictException (org.apache.geode.cache.CommitConflictException)2 EntryEvent (org.apache.geode.cache.EntryEvent)2 RegionAttributes (org.apache.geode.cache.RegionAttributes)2 RegionExistsException (org.apache.geode.cache.RegionExistsException)2 TransactionEvent (org.apache.geode.cache.TransactionEvent)2 TransactionListener (org.apache.geode.cache.TransactionListener)2 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)2