X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fjmx%2Fmbeans%2Fshard%2FShardStatsTest.java;h=e9df3ecd49ed83a5d7021d86487277545bbd5787;hp=41adcc55b188296f899b1569e98276906b233c1e;hb=c33b2b55b2eae406df001619885a0610800cb951;hpb=62ee81f764eef592f00e67181b4dbedb3f734de6 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardStatsTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardStatsTest.java index 41adcc55b1..e9df3ecd49 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardStatsTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardStatsTest.java @@ -1,13 +1,22 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.opendaylight.controller.cluster.datastore.jmx.mbeans.AbstractBaseMBean; +import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean; import javax.management.MBeanServer; import javax.management.ObjectName; + +import java.lang.management.ManagementFactory; import java.text.SimpleDateFormat; import java.util.Date; @@ -19,11 +28,11 @@ public class ShardStatsTest { @Before public void setUp() throws Exception { - shardStats = new ShardStats("shard-1"); + shardStats = new ShardStats("shard-1", "DataStore"); shardStats.registerMBean(); - mbeanServer = shardStats.getMBeanServer(); + mbeanServer = ManagementFactory.getPlatformMBeanServer(); String objectName = - AbstractBaseMBean.BASE_JMX_PREFIX + "type=" + shardStats + AbstractMXBean.BASE_JMX_PREFIX + "type=" + shardStats .getMBeanType() + ",Category=" + shardStats.getMBeanCategory() + ",name=" + shardStats.getMBeanName(); @@ -39,7 +48,7 @@ public class ShardStatsTest { public void testGetShardName() throws Exception { Object attribute = mbeanServer.getAttribute(testMBeanName, "ShardName"); - Assert.assertEquals((String) attribute, "shard-1"); + Assert.assertEquals(attribute, "shard-1"); } @@ -53,7 +62,7 @@ public class ShardStatsTest { //now let us get from MBeanServer what is the transaction count. Object attribute = mbeanServer.getAttribute(testMBeanName, "CommittedTransactionsCount"); - Assert.assertEquals((Long) attribute, (Long) 3L); + Assert.assertEquals(attribute, 3L); } @@ -64,13 +73,13 @@ public class ShardStatsTest { Assert.assertEquals(shardStats.getLastCommittedTransactionTime(), sdf.format(new Date(0L))); long millis = System.currentTimeMillis(); - shardStats.setLastCommittedTransactionTime(new Date(millis)); + shardStats.setLastCommittedTransactionTime(millis); //now let us get from MBeanServer what is the transaction count. Object attribute = mbeanServer.getAttribute(testMBeanName, "LastCommittedTransactionTime"); - Assert.assertEquals((String) attribute, sdf.format(new Date(millis))); - Assert.assertNotEquals((String) attribute, + Assert.assertEquals(attribute, sdf.format(new Date(millis))); + Assert.assertNotEquals(attribute, sdf.format(new Date(millis - 1))); } @@ -85,8 +94,70 @@ public class ShardStatsTest { //now let us get from MBeanServer what is the transaction count. Object attribute = mbeanServer.getAttribute(testMBeanName, "FailedTransactionsCount"); - Assert.assertEquals((Long) attribute, (Long) 2L); + Assert.assertEquals(attribute, 2L); + } + + @Test + public void testGetAbortTransactionsCount() throws Exception { + //let us increment AbortTransactions count and then check + shardStats.incrementAbortTransactionsCount(); + shardStats.incrementAbortTransactionsCount(); + + + //now let us get from MBeanServer what is the transaction count. + Object attribute = + mbeanServer.getAttribute(testMBeanName, "AbortTransactionsCount"); + Assert.assertEquals(attribute, 2L); + } + + @Test + public void testGetFailedReadTransactionsCount() throws Exception { + //let us increment FailedReadTransactions count and then check + shardStats.incrementFailedReadTransactionsCount(); + shardStats.incrementFailedReadTransactionsCount(); + + + //now let us get from MBeanServer what is the transaction count. + Object attribute = + mbeanServer.getAttribute(testMBeanName, "FailedReadTransactionsCount"); + Assert.assertEquals(attribute, 2L); + } + + @Test + public void testResetTransactionCounters() throws Exception { + + //let us increment committed transactions count and then check + shardStats.incrementCommittedTransactionCount(); + shardStats.incrementCommittedTransactionCount(); + shardStats.incrementCommittedTransactionCount(); + + //now let us get from MBeanServer what is the transaction count. + Object attribute = mbeanServer.getAttribute(testMBeanName, + "CommittedTransactionsCount"); + Assert.assertEquals(attribute, 3L); + + //let us increment FailedReadTransactions count and then check + shardStats.incrementFailedReadTransactionsCount(); + shardStats.incrementFailedReadTransactionsCount(); + + + //now let us get from MBeanServer what is the transaction count. + attribute = + mbeanServer.getAttribute(testMBeanName, "FailedReadTransactionsCount"); + Assert.assertEquals(attribute, 2L); + + + //here we will reset the counters and check the above ones are 0 after reset + mbeanServer.invoke(testMBeanName, "resetTransactionCounters", null, null); + + //now let us get from MBeanServer what is the transaction count. + attribute = mbeanServer.getAttribute(testMBeanName, + "CommittedTransactionsCount"); + Assert.assertEquals(attribute, 0L); + attribute = + mbeanServer.getAttribute(testMBeanName, "FailedReadTransactionsCount"); + Assert.assertEquals(attribute, 0L); }