X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fjmx%2Fmbeans%2Fshard%2FShardStatsTest.java;h=c4d0b85fb54546faa5e0667e58e472d549d5836f;hb=67d58d1ab50f3c3bbe19a96fb6f0d9d94211829f;hp=f7c467652d329550dc665e53a2dd7b93e9342d12;hpb=516a4b2ea78179c9bd6ebb584862e8fc686ebf08;p=controller.git 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 f7c467652d..c4d0b85fb5 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,3 +1,10 @@ +/* + * 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; @@ -8,48 +15,148 @@ import org.opendaylight.controller.cluster.datastore.jmx.mbeans.AbstractBaseMBea import javax.management.MBeanServer; import javax.management.ObjectName; +import java.text.SimpleDateFormat; +import java.util.Date; public class ShardStatsTest { - private MBeanServer mbeanServer; - private ShardStats shardStats; - private ObjectName testMBeanName; + private MBeanServer mbeanServer; + private ShardStats shardStats; + private ObjectName testMBeanName; - @Before - public void setUp() throws Exception { + @Before + public void setUp() throws Exception { - shardStats = new ShardStats("shard-1"); - shardStats.registerMBean(); - mbeanServer= shardStats.getMBeanServer(); - String objectName = AbstractBaseMBean.BASE_JMX_PREFIX + "type="+shardStats.getMBeanType()+",Category="+ - shardStats.getMBeanCategory() + ",name="+ - shardStats.getMBeanName(); - testMBeanName = new ObjectName(objectName); - } + shardStats = new ShardStats("shard-1"); + shardStats.registerMBean(); + mbeanServer = shardStats.getMBeanServer(); + String objectName = + AbstractBaseMBean.BASE_JMX_PREFIX + "type=" + shardStats + .getMBeanType() + ",Category=" + + shardStats.getMBeanCategory() + ",name=" + + shardStats.getMBeanName(); + testMBeanName = new ObjectName(objectName); + } - @After - public void tearDown() throws Exception { - shardStats.unregisterMBean(); - } + @After + public void tearDown() throws Exception { + shardStats.unregisterMBean(); + } - @Test - public void testGetShardName() throws Exception { + @Test + public void testGetShardName() throws Exception { - Object attribute = mbeanServer.getAttribute(testMBeanName,"ShardName"); - Assert.assertEquals((String) attribute, "shard-1"); + Object attribute = mbeanServer.getAttribute(testMBeanName, "ShardName"); + Assert.assertEquals((String) attribute, "shard-1"); - } + } - @Test - public void testGetCommittedTransactionsCount() throws Exception { - //let us increment some transactions count and then check - shardStats.incrementCommittedTransactionCount(); - shardStats.incrementCommittedTransactionCount(); - shardStats.incrementCommittedTransactionCount(); + @Test + public void testGetCommittedTransactionsCount() throws Exception { + //let us increment some 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((Long) attribute, (Long)3L); + //now let us get from MBeanServer what is the transaction count. + Object attribute = mbeanServer.getAttribute(testMBeanName, + "CommittedTransactionsCount"); + Assert.assertEquals((Long) attribute, (Long) 3L); - } -} \ No newline at end of file + } + + @Test + public void testGetLastCommittedTransactionTime() throws Exception { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + Assert.assertEquals(shardStats.getLastCommittedTransactionTime(), + sdf.format(new Date(0L))); + long millis = System.currentTimeMillis(); + shardStats.setLastCommittedTransactionTime(new Date(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, + sdf.format(new Date(millis - 1))); + + } + + @Test + public void testGetFailedTransactionsCount() throws Exception { + //let us increment some transactions count and then check + shardStats.incrementFailedTransactionsCount(); + shardStats.incrementFailedTransactionsCount(); + + + //now let us get from MBeanServer what is the transaction count. + Object attribute = + mbeanServer.getAttribute(testMBeanName, "FailedTransactionsCount"); + Assert.assertEquals((Long) attribute, (Long) 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((Long) attribute, (Long) 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((Long) attribute, (Long) 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((Long) attribute, (Long) 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((Long) attribute, (Long) 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((Long) attribute, (Long) 0L); + + attribute = + mbeanServer.getAttribute(testMBeanName, "FailedReadTransactionsCount"); + Assert.assertEquals((Long) attribute, (Long) 0L); + + + } +}