X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Ftestingservices%2Fscheduledthreadpool%2Ftest%2FRuntimeBeanTest.java;h=12753002af67eb411aa7e475b2cff2753b942bac;hp=19e6ef3b78baed4f3a55af2ad1ba650d96053337;hb=f43b01b81319959b1907e3e04537f5169e7f33d8;hpb=ebb4158697741bc88fde22ac5f75edf65869506f diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/scheduledthreadpool/test/RuntimeBeanTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/scheduledthreadpool/test/RuntimeBeanTest.java index 19e6ef3b78..12753002af 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/scheduledthreadpool/test/RuntimeBeanTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/testingservices/scheduledthreadpool/test/RuntimeBeanTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2013, 2017 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, @@ -30,9 +30,11 @@ import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; /** * TestingScheduledThreadPool exports 2 interfaces:
- * {@link org.opendaylight.controller.config.manager.testingservices.scheduledthreadpool.TestingScheduledThreadPoolModuleFactory#NAME} + * {@link org.opendaylight.controller.config.manager.testingservices + * .scheduledthreadpool.TestingScheduledThreadPoolModuleFactory#NAME} * ,
- * {@link org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPoolModuleFactory#NAME} + * {@link org.opendaylight.controller.config.manager + * .testingservices.threadpool.TestingFixedThreadPoolModuleFactory#NAME} *
*
* It also exports 2 runtime beans, one default and one with additional @@ -40,25 +42,21 @@ import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; */ public class RuntimeBeanTest extends AbstractScheduledTest { - ObjectName ifc1runtimeON1 = ObjectNameUtil.createRuntimeBeanName( - TestingScheduledThreadPoolModuleFactory.NAME, scheduled1, - Maps. newHashMap()); + ObjectName ifc1runtimeON1 = ObjectNameUtil.createRuntimeBeanName(TestingScheduledThreadPoolModuleFactory.NAME, + SCHEDULED1, Maps.newHashMap()); // additional runtime bean - ObjectName ifc1runtimeON2 = ObjectNameUtil.createRuntimeBeanName( - TestingScheduledThreadPoolModuleFactory.NAME, scheduled1, - ImmutableMap.of("a", "b")); + ObjectName ifc1runtimeON2 = ObjectNameUtil.createRuntimeBeanName(TestingScheduledThreadPoolModuleFactory.NAME, + SCHEDULED1, ImmutableMap.of("a", "b")); - List allObjectNames = Lists.newArrayList(ifc1runtimeON1, - ifc1runtimeON2); + List allObjectNames = Lists.newArrayList(ifc1runtimeON1, ifc1runtimeON2); - private ObjectName createScheduled() throws InstanceAlreadyExistsException, - ConflictingVersionException, ValidationException { - ConfigTransactionJMXClient transaction = configRegistryClient - .createTransaction(); + private ObjectName createScheduled() + throws InstanceAlreadyExistsException, ConflictingVersionException, ValidationException { + ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction(); // create using TestingThreadPoolIfc: - ObjectName createdConfigBean = transaction.createModule( - TestingScheduledThreadPoolModuleFactory.NAME, scheduled1); + ObjectName createdConfigBean = transaction.createModule(TestingScheduledThreadPoolModuleFactory.NAME, + SCHEDULED1); // commit transaction.commit(); return createdConfigBean; @@ -72,48 +70,42 @@ public class RuntimeBeanTest extends AbstractScheduledTest { private void checkRuntimeBeans() throws Exception { // check runtime bean - on 2 places - for (ObjectName on : allObjectNames) + for (ObjectName on : allObjectNames) { checkRuntimeBean(on); + } } - private void checkRuntimeBean(ObjectName on) throws Exception { - assertEquals(0, - platformMBeanServer.getAttribute(on, "ActualNumberOfThreads")); + private static void checkRuntimeBean(final ObjectName on) throws Exception { + assertEquals(0, platformMBeanServer.getAttribute(on, "ActualNumberOfThreads")); } - private void checkRuntimeBeanDoesNotExist(ObjectName on) throws Exception { + private static void checkRuntimeBeanDoesNotExist(final ObjectName on) throws Exception { try { checkRuntimeBean(on); fail(); - } catch (InstanceNotFoundException e) { - + } catch (final InstanceNotFoundException e) { + // No-op } } @Test public void testLookup() throws Exception { createScheduled(); - assertEquals(Sets.newHashSet(ifc1runtimeON1, ifc1runtimeON2), - configRegistryClient.lookupRuntimeBeans()); + assertEquals(Sets.newHashSet(ifc1runtimeON1, ifc1runtimeON2), configRegistryClient.lookupRuntimeBeans()); } @Test public void testReuse() throws Exception { ObjectName createdConfigBean = createScheduled(); // empty transaction - CommitStatus commitInfo = configRegistryClient.createTransaction() - .commit(); + CommitStatus commitInfo = configRegistryClient.createTransaction().commit(); // check that it was reused - ObjectName readableConfigBean = ObjectNameUtil - .withoutTransactionName(createdConfigBean); - List newInstances = Collections. emptyList(); - List reusedInstances = Lists - .newArrayList(readableConfigBean); - List recreatedInstaces = Collections - . emptyList(); - assertEquals(new CommitStatus(newInstances, reusedInstances, - recreatedInstaces), commitInfo); + ObjectName readableConfigBean = ObjectNameUtil.withoutTransactionName(createdConfigBean); + List newInstances = Collections.emptyList(); + List reusedInstances = Lists.newArrayList(readableConfigBean); + List recreatedInstaces = Collections.emptyList(); + assertEquals(new CommitStatus(newInstances, reusedInstances, recreatedInstaces), commitInfo); checkRuntimeBeans(); } @@ -121,36 +113,31 @@ public class RuntimeBeanTest extends AbstractScheduledTest { public void testRecreate() throws Exception { ObjectName createdConfigBean = createScheduled(); // empty transaction - ConfigTransactionJMXClient configTransaction = configRegistryClient - .createTransaction(); - ObjectName scheduledWritableON = configTransaction.lookupConfigBean( - TestingScheduledThreadPoolModuleFactory.NAME, scheduled1); + ConfigTransactionJMXClient configTransaction = configRegistryClient.createTransaction(); + ObjectName scheduledWritableON = configTransaction + .lookupConfigBean(TestingScheduledThreadPoolModuleFactory.NAME, SCHEDULED1); TestingScheduledThreadPoolConfigBeanMXBean scheduledWritableProxy = configTransaction .newMXBeanProxy(scheduledWritableON, TestingScheduledThreadPoolConfigBeanMXBean.class); scheduledWritableProxy.setRecreate(true); CommitStatus commitInfo = configTransaction.commit(); // check that it was recreated - ObjectName readableConfigBean = ObjectNameUtil - .withoutTransactionName(createdConfigBean); - List newInstances = Collections. emptyList(); - List reusedInstances = Collections. emptyList(); - List recreatedInstaces = Lists - .newArrayList(readableConfigBean); - assertEquals(new CommitStatus(newInstances, reusedInstances, - recreatedInstaces), commitInfo); + ObjectName readableConfigBean = ObjectNameUtil.withoutTransactionName(createdConfigBean); + List newInstances = Collections.emptyList(); + List reusedInstances = Collections.emptyList(); + List recreatedInstaces = Lists.newArrayList(readableConfigBean); + assertEquals(new CommitStatus(newInstances, reusedInstances, recreatedInstaces), commitInfo); checkRuntimeBeans(); } @Test public void testDestroy_shouldUnregisterRuntimeBeans() throws Exception { ObjectName createdConfigBean = createScheduled(); - ConfigTransactionJMXClient configTransaction = configRegistryClient - .createTransaction(); - configTransaction.destroyModule(ObjectNameUtil - .createTransactionModuleON(configTransaction.getTransactionName(), createdConfigBean)); + ConfigTransactionJMXClient configTransaction = configRegistryClient.createTransaction(); + configTransaction.destroyModule( + ObjectNameUtil.createTransactionModuleON(configTransaction.getTransactionName(), createdConfigBean)); configTransaction.commit(); - for (ObjectName on : allObjectNames) + for (ObjectName on : allObjectNames) { checkRuntimeBeanDoesNotExist(on); + } } - }