Added threadpool config tests. 51/2551/1
authorMilos Fabian <milfabia@cisco.com>
Fri, 8 Nov 2013 12:58:31 +0000 (13:58 +0100)
committerMilos Fabian <milfabia@cisco.com>
Fri, 8 Nov 2013 12:58:31 +0000 (13:58 +0100)
Change-Id: I7664c762b3c6e63085a4b73a92ba871e856e21c6
Signed-off-by: Milos Fabian <milfabia@cisco.com>
opendaylight/config/threadpool-config-impl/pom.xml
opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/async/AsyncEventBusConfigBeanTest.java [new file with mode: 0644]
opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/eventbus/SyncEventBusConfigBeanTest.java [new file with mode: 0644]
opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/eventbus/TestingEventBusModule.java [new file with mode: 0644]
opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/fixed/FixedThreadPoolConfigBeanTest.java [new file with mode: 0644]
opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/fixed/TestingFixedThreadPoolModule.java [new file with mode: 0644]
opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/flexible/FlexibleThreadPoolConfigBeanTest.java [new file with mode: 0644]
opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/naming/NamingThreadPoolFactoryConfigBeanTest.java [new file with mode: 0644]
opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/naming/TestingNamingThreadPoolFactoryModule.java [new file with mode: 0644]
opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/scheduled/ScheduledThreadPoolConfigBeanTest.java [new file with mode: 0644]
opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/scheduled/TestingScheduledThreadPoolModule.java [new file with mode: 0644]

index 1227978..1bad023 100644 (file)
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
       </dependency>
+
+      <!--test dependencies -->
+      <dependency>
+         <groupId>org.opendaylight.controller</groupId>
+         <artifactId>config-manager</artifactId>
+         <scope>test</scope>
+         <type>test-jar</type>
+      </dependency>
+      <dependency>
+         <groupId>org.opendaylight.controller</groupId>
+         <artifactId>config-manager</artifactId>
+         <scope>test</scope>
+      </dependency>
+      <dependency>
+         <groupId>org.opendaylight.controller</groupId>
+         <artifactId>config-util</artifactId>
+         <scope>test</scope>
+      </dependency>
+      <dependency>
+         <groupId>org.opendaylight.bgpcep</groupId>
+         <artifactId>mockito-configuration</artifactId>
+         <scope>test</scope>
+      </dependency>
    </dependencies>
 
    <build>
diff --git a/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/async/AsyncEventBusConfigBeanTest.java b/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/async/AsyncEventBusConfigBeanTest.java
new file mode 100644 (file)
index 0000000..b2fc75d
--- /dev/null
@@ -0,0 +1,100 @@
+package org.opendaylight.controller.config.threadpool.async;\r
+\r
+import static org.junit.Assert.assertThat;\r
+import static org.junit.Assert.fail;\r
+import static org.junit.matchers.JUnitMatchers.containsString;\r
+\r
+import javax.management.InstanceAlreadyExistsException;\r
+import javax.management.ObjectName;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.opendaylight.controller.config.api.ConflictingVersionException;\r
+import org.opendaylight.controller.config.api.ValidationException;\r
+import org.opendaylight.controller.config.api.jmx.CommitStatus;\r
+import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;\r
+import org.opendaylight.controller.config.manager.impl.ClassBasedModuleFactory;\r
+import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;\r
+import org.opendaylight.controller.config.threadpool.scheduled.TestingScheduledThreadPoolModule;\r
+import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.AsyncEventBusModuleFactory;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.AsyncEventBusModuleMXBean;\r
+\r
+public class AsyncEventBusConfigBeanTest extends AbstractConfigTest {\r
+\r
+    private AsyncEventBusModuleFactory factory;\r
+    private final String instanceName = "async1";\r
+    private final String poolImplName = "fixed1";\r
+\r
+    @Before\r
+    public void setUp() {\r
+\r
+        ClassBasedModuleFactory scheduledThreadPoolConfigFactory = createClassBasedCBF(\r
+                TestingScheduledThreadPoolModule.class, poolImplName);\r
+\r
+        factory = new AsyncEventBusModuleFactory();\r
+        super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(factory,\r
+                scheduledThreadPoolConfigFactory));\r
+    }\r
+\r
+    @Test\r
+    public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException,\r
+            ConflictingVersionException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+\r
+        createAsynced(transaction, instanceName, transaction.createModule(poolImplName, "pool-test"));\r
+        transaction.validateConfig();\r
+        CommitStatus status = transaction.commit();\r
+\r
+        assertBeanCount(1, factory.getImplementationName());\r
+        assertStatus(status, 2, 0, 0);\r
+    }\r
+\r
+    @Test\r
+    public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException,\r
+            ValidationException {\r
+\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+        createAsynced(transaction, instanceName, transaction.createModule(poolImplName, "pool-test"));\r
+\r
+        transaction.commit();\r
+\r
+        assertBeanCount(1, factory.getImplementationName());\r
+\r
+        transaction = configRegistryClient.createTransaction();\r
+        CommitStatus status = transaction.commit();\r
+\r
+        assertBeanCount(1, factory.getImplementationName());\r
+        assertStatus(status, 0, 0, 2);\r
+\r
+    }\r
+\r
+    @Test\r
+    public void testInstanceAlreadyExistsException() throws ConflictingVersionException, ValidationException,\r
+            InstanceAlreadyExistsException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+\r
+        ObjectName poolCB = transaction.createModule(poolImplName, "pool-test");\r
+        createAsynced(transaction, instanceName, poolCB);\r
+        transaction.commit();\r
+\r
+        transaction = configRegistryClient.createTransaction();\r
+        try {\r
+            createAsynced(transaction, instanceName, poolCB);\r
+            fail();\r
+        } catch (InstanceAlreadyExistsException e) {\r
+            assertThat(\r
+                    e.getMessage(),\r
+                    containsString("There is an instance registered with name ModuleIdentifier{factoryName='async-eventbus', instanceName='async1'}"));\r
+        }\r
+    }\r
+\r
+    private ObjectName createAsynced(ConfigTransactionJMXClient transaction, String instanceName, ObjectName threadPool)\r
+            throws InstanceAlreadyExistsException {\r
+        ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName);\r
+        AsyncEventBusModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated, AsyncEventBusModuleMXBean.class);\r
+        mxBean.setThreadpool(threadPool);\r
+        return nameCreated;\r
+    }\r
+\r
+}\r
diff --git a/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/eventbus/SyncEventBusConfigBeanTest.java b/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/eventbus/SyncEventBusConfigBeanTest.java
new file mode 100644 (file)
index 0000000..4cd279f
--- /dev/null
@@ -0,0 +1,97 @@
+package org.opendaylight.controller.config.threadpool.eventbus;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.junit.matchers.JUnitMatchers.containsString;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.ObjectName;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.config.api.ConflictingVersionException;
+import org.opendaylight.controller.config.api.ValidationException;
+import org.opendaylight.controller.config.api.jmx.CommitStatus;
+import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
+import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
+import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
+import org.opendaylight.controller.config.yang.threadpool.impl.EventBusModuleFactory;
+
+public class SyncEventBusConfigBeanTest extends AbstractConfigTest {
+
+    private EventBusModuleFactory factory;
+    private final String instanceName = "sync1";
+
+    @Before
+    public void setUp() {
+
+        factory = new EventBusModuleFactory();
+        super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(factory));
+    }
+
+    @Test
+    public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException,
+            ConflictingVersionException {
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+
+        createSynced(transaction, instanceName);
+        transaction.validateConfig();
+        CommitStatus status = transaction.commit();
+
+        assertEquals(1, configRegistry.lookupConfigBeans(factory.getImplementationName()).size());
+        assertEquals(1, status.getNewInstances().size());
+        assertEquals(0, status.getRecreatedInstances().size());
+        assertEquals(0, status.getReusedInstances().size());
+        // TODO test dead event collector
+    }
+
+    @Test
+    public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException,
+            ValidationException {
+
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+        createSynced(transaction, instanceName);
+
+        transaction.commit();
+
+        assertEquals(1, configRegistry.lookupConfigBeans(factory.getImplementationName()).size());
+
+        transaction = configRegistryClient.createTransaction();
+        CommitStatus status = transaction.commit();
+
+        assertEquals(1, configRegistry.lookupConfigBeans(factory.getImplementationName()).size());
+        assertEquals(0, status.getNewInstances().size());
+        assertEquals(0, status.getRecreatedInstances().size());
+        assertEquals(1, status.getReusedInstances().size());
+
+    }
+
+    @Test
+    public void testInstanceAlreadyExistsException() throws ConflictingVersionException, ValidationException {
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
+
+        try {
+            createSynced(transaction, instanceName);
+            transaction.commit();
+        } catch (InstanceAlreadyExistsException e1) {
+            fail();
+        }
+
+        transaction = configRegistryClient.createTransaction();
+        try {
+            createSynced(transaction, instanceName);
+            fail();
+        } catch (InstanceAlreadyExistsException e) {
+            assertThat(
+                    e.getMessage(),
+                    containsString("There is an instance registered with name ModuleIdentifier{factoryName='eventbus', instanceName='sync1'}"));
+        }
+    }
+
+    private ObjectName createSynced(ConfigTransactionJMXClient transaction, String instanceName)
+            throws InstanceAlreadyExistsException {
+        ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName);
+        return nameCreated;
+    }
+}
diff --git a/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/eventbus/TestingEventBusModule.java b/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/eventbus/TestingEventBusModule.java
new file mode 100644 (file)
index 0000000..ee6bbc5
--- /dev/null
@@ -0,0 +1,28 @@
+package org.opendaylight.controller.config.threadpool.eventbus;\r
+\r
+import static org.mockito.Mockito.doNothing;\r
+import static org.mockito.Mockito.mock;\r
+\r
+import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;\r
+import org.opendaylight.controller.config.api.ModuleIdentifier;\r
+import org.opendaylight.controller.config.manager.impl.AbstractMockedModule;\r
+import org.opendaylight.controller.config.spi.Module;\r
+import org.opendaylight.controller.config.threadpool.util.CloseableEventBus;\r
+import org.opendaylight.controller.config.yang.threadpool.EventBusServiceInterface;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.EventBusModuleMXBean;\r
+\r
+public class TestingEventBusModule extends AbstractMockedModule implements Module, EventBusServiceInterface,\r
+        EventBusModuleMXBean {\r
+\r
+    public TestingEventBusModule(DynamicMBeanWithInstance old, ModuleIdentifier id) {\r
+        super(old, id);\r
+    }\r
+\r
+    @Override\r
+    protected AutoCloseable prepareMockedInstance() throws Exception {\r
+        CloseableEventBus bus = mock(CloseableEventBus.class);\r
+        doNothing().when(bus).close();\r
+        return bus;\r
+    }\r
+\r
+}\r
diff --git a/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/fixed/FixedThreadPoolConfigBeanTest.java b/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/fixed/FixedThreadPoolConfigBeanTest.java
new file mode 100644 (file)
index 0000000..4fda06b
--- /dev/null
@@ -0,0 +1,129 @@
+package org.opendaylight.controller.config.threadpool.fixed;\r
+\r
+import static org.junit.Assert.assertThat;\r
+import static org.junit.Assert.fail;\r
+import static org.junit.matchers.JUnitMatchers.containsString;\r
+\r
+import javax.management.InstanceAlreadyExistsException;\r
+import javax.management.InstanceNotFoundException;\r
+import javax.management.ObjectName;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.opendaylight.controller.config.api.ConflictingVersionException;\r
+import org.opendaylight.controller.config.api.ValidationException;\r
+import org.opendaylight.controller.config.api.jmx.CommitStatus;\r
+import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;\r
+import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;\r
+import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.FixedThreadPoolModuleFactory;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.FixedThreadPoolModuleMXBean;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleFactory;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleMXBean;\r
+\r
+public class FixedThreadPoolConfigBeanTest extends AbstractConfigTest {\r
+\r
+    private FixedThreadPoolModuleFactory factory;\r
+    private final String nameInstance = "fixedInstance";\r
+\r
+    @Before\r
+    public void setUp() {\r
+        factory = new FixedThreadPoolModuleFactory();\r
+        super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(factory,\r
+                new NamingThreadFactoryModuleFactory()));\r
+    }\r
+\r
+    @Test\r
+    public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException,\r
+            ConflictingVersionException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+        createFixed(transaction, nameInstance, 2);\r
+\r
+        transaction.validateConfig();\r
+        CommitStatus status = transaction.commit();\r
+\r
+        assertBeanCount(1, factory.getImplementationName());\r
+        assertStatus(status, 2, 0, 0);\r
+    }\r
+\r
+    @Test\r
+    public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException,\r
+            ValidationException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+        createFixed(transaction, nameInstance, 4);\r
+\r
+        transaction.validateConfig();\r
+        transaction.commit();\r
+\r
+        assertBeanCount(1, factory.getImplementationName());\r
+\r
+        transaction = configRegistryClient.createTransaction();\r
+        CommitStatus status = transaction.commit();\r
+\r
+        assertBeanCount(1, factory.getImplementationName());\r
+        assertStatus(status, 0, 0, 2);\r
+    }\r
+\r
+    @Test\r
+    public void testNegative() throws ConflictingVersionException, ValidationException, InstanceAlreadyExistsException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+\r
+        createFixed(transaction, nameInstance, 5);\r
+        transaction.commit();\r
+\r
+        transaction = configRegistryClient.createTransaction();\r
+        try {\r
+            createFixed(transaction, nameInstance, 0);\r
+            fail();\r
+        } catch (InstanceAlreadyExistsException e) {\r
+            assertThat(\r
+                    e.getMessage(),\r
+                    containsString("There is an instance registered with name ModuleIdentifier{factoryName='threadpool-fixed', instanceName='fixedInstance'}"));\r
+        }\r
+    }\r
+\r
+    @Test\r
+    public void testDestroy() throws InstanceAlreadyExistsException, ValidationException, ConflictingVersionException,\r
+            InstanceNotFoundException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+        createFixed(transaction, nameInstance, 1);\r
+\r
+        transaction.commit();\r
+\r
+        transaction = configRegistryClient.createTransaction();\r
+        transaction.destroyConfigBean(factory.getImplementationName(), nameInstance);\r
+        CommitStatus status = transaction.commit();\r
+\r
+        assertBeanCount(0, factory.getImplementationName());\r
+        assertStatus(status, 0, 0, 1);\r
+    }\r
+\r
+    @Test\r
+    public void testValidationException() throws InstanceAlreadyExistsException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+        createFixed(transaction, nameInstance, -1);\r
+        try {\r
+            transaction.validateConfig();\r
+            fail();\r
+        } catch (ValidationException e) {\r
+            assertThat(e.getMessage(), containsString("MaxThreadCount must be greater than zero"));\r
+        }\r
+    }\r
+\r
+    private ObjectName createFixed(ConfigTransactionJMXClient transaction, String name, int numberOfThreads)\r
+            throws InstanceAlreadyExistsException {\r
+        ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), name);\r
+        FixedThreadPoolModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, FixedThreadPoolModuleMXBean.class);\r
+        mxBean.setMaxThreadCount(numberOfThreads);\r
+\r
+        ObjectName threadFactoryON = transaction.createModule(NamingThreadFactoryModuleFactory.NAME, "naming");\r
+        NamingThreadFactoryModuleMXBean namingThreadFactoryModuleMXBean = transaction.newMXBeanProxy(threadFactoryON,\r
+                NamingThreadFactoryModuleMXBean.class);\r
+        namingThreadFactoryModuleMXBean.setNamePrefix("prefix");\r
+\r
+        mxBean.setThreadFactory(threadFactoryON);\r
+\r
+        return nameCreated;\r
+    }\r
+\r
+}\r
diff --git a/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/fixed/TestingFixedThreadPoolModule.java b/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/fixed/TestingFixedThreadPoolModule.java
new file mode 100644 (file)
index 0000000..00be5d8
--- /dev/null
@@ -0,0 +1,30 @@
+package org.opendaylight.controller.config.threadpool.fixed;\r
+\r
+import static org.mockito.Mockito.doNothing;\r
+import static org.mockito.Mockito.doReturn;\r
+import static org.mockito.Mockito.mock;\r
+\r
+import java.util.concurrent.ExecutorService;\r
+\r
+import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;\r
+import org.opendaylight.controller.config.api.ModuleIdentifier;\r
+import org.opendaylight.controller.config.manager.impl.AbstractMockedModule;\r
+import org.opendaylight.controller.config.spi.Module;\r
+import org.opendaylight.controller.config.threadpool.util.FixedThreadPoolWrapper;\r
+import org.opendaylight.controller.config.yang.threadpool.ThreadPoolServiceInterface;\r
+\r
+public class TestingFixedThreadPoolModule extends AbstractMockedModule implements ThreadPoolServiceInterface, Module {\r
+\r
+    public TestingFixedThreadPoolModule(DynamicMBeanWithInstance old, ModuleIdentifier id) {\r
+        super(old, id);\r
+    }\r
+\r
+    @Override\r
+    protected AutoCloseable prepareMockedInstance() throws Exception {\r
+        FixedThreadPoolWrapper pool = mock(FixedThreadPoolWrapper.class);\r
+        doNothing().when(pool).close();\r
+        doReturn(mock(ExecutorService.class)).when(pool).getExecutor();\r
+        return pool;\r
+    }\r
+\r
+}\r
diff --git a/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/flexible/FlexibleThreadPoolConfigBeanTest.java b/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/flexible/FlexibleThreadPoolConfigBeanTest.java
new file mode 100644 (file)
index 0000000..ee1de8f
--- /dev/null
@@ -0,0 +1,173 @@
+package org.opendaylight.controller.config.threadpool.flexible;\r
+\r
+import static org.junit.Assert.assertThat;\r
+import static org.junit.Assert.fail;\r
+import static org.junit.matchers.JUnitMatchers.containsString;\r
+\r
+import javax.management.InstanceAlreadyExistsException;\r
+import javax.management.InstanceNotFoundException;\r
+import javax.management.ObjectName;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.opendaylight.controller.config.api.ConflictingVersionException;\r
+import org.opendaylight.controller.config.api.ValidationException;\r
+import org.opendaylight.controller.config.api.jmx.CommitStatus;\r
+import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;\r
+import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;\r
+import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.FlexibleThreadPoolModuleFactory;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.FlexibleThreadPoolModuleMXBean;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleFactory;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleMXBean;\r
+\r
+public class FlexibleThreadPoolConfigBeanTest extends AbstractConfigTest {\r
+\r
+    private FlexibleThreadPoolModuleFactory flexibleFactory;\r
+    private final String instanceName = "flexible1";\r
+    private final String threadFactoryName = "threadFactoryName";\r
+\r
+    @Before\r
+    public void setUp() {\r
+\r
+        flexibleFactory = new FlexibleThreadPoolModuleFactory();\r
+        super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(flexibleFactory,\r
+                new NamingThreadFactoryModuleFactory()));\r
+    }\r
+\r
+    @Test\r
+    public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException,\r
+            ConflictingVersionException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+\r
+        createFlexible(transaction, instanceName, threadFactoryName, 1, 20, 20);\r
+        transaction.validateConfig();\r
+        CommitStatus status = transaction.commit();\r
+\r
+        assertBeanCount(1, flexibleFactory.getImplementationName());\r
+        assertStatus(status, 2, 0, 0);\r
+    }\r
+\r
+    @Test\r
+    public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException,\r
+            ValidationException {\r
+\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+        createFlexible(transaction, instanceName, threadFactoryName, 1, 20, 10);\r
+\r
+        transaction.commit();\r
+\r
+        assertBeanCount(1, flexibleFactory.getImplementationName());\r
+\r
+        transaction = configRegistryClient.createTransaction();\r
+        CommitStatus status = transaction.commit();\r
+\r
+        assertBeanCount(1, flexibleFactory.getImplementationName());\r
+        assertStatus(status, 0, 0, 2);\r
+\r
+    }\r
+\r
+    @Test\r
+    public void testInstanceAlreadyExistsException() throws ConflictingVersionException, ValidationException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+\r
+        try {\r
+            createFlexible(transaction, instanceName, threadFactoryName, 1, 1, 2);\r
+            transaction.commit();\r
+        } catch (InstanceAlreadyExistsException e1) {\r
+            fail();\r
+        }\r
+\r
+        transaction = configRegistryClient.createTransaction();\r
+        try {\r
+            createFlexible(transaction, instanceName, "threadFactoryName1", 2, 2, 2);\r
+            fail();\r
+        } catch (InstanceAlreadyExistsException e) {\r
+            assertThat(\r
+                    e.getMessage(),\r
+                    containsString("There is an instance registered with name ModuleIdentifier{factoryName='threadpool-flexible', instanceName='flexible1'}"));\r
+        }\r
+    }\r
+\r
+    @Test\r
+    public void testValidationException() throws InstanceAlreadyExistsException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+\r
+        createFlexible(transaction, instanceName, threadFactoryName, 0, 10, 10);\r
+\r
+        try {\r
+            transaction.validateConfig();\r
+            fail();\r
+        } catch (ValidationException e) {\r
+            assertThat(e.getMessage(), containsString("MinThreadCount must be greater than zero"));\r
+        }\r
+    }\r
+\r
+    @Test\r
+    public void testValidationException2() throws InstanceAlreadyExistsException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+\r
+        createFlexible(transaction, instanceName, threadFactoryName, 0, 0, 10);\r
+\r
+        try {\r
+            transaction.validateConfig();\r
+            fail();\r
+        } catch (ValidationException e) {\r
+            assertThat(e.getMessage(), containsString("KeepAliveMillis must be greater than zero"));\r
+        }\r
+    }\r
+\r
+    @Test\r
+    public void testValidationException3() throws InstanceAlreadyExistsException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+\r
+        createFlexible(transaction, instanceName, threadFactoryName, 10, 50, 0);\r
+\r
+        try {\r
+            transaction.validateConfig();\r
+            fail();\r
+        } catch (ValidationException e) {\r
+            assertThat(e.getMessage(), containsString("MaxThreadCount must be greater than zero"));\r
+        }\r
+    }\r
+\r
+    private ObjectName createFlexible(ConfigTransactionJMXClient transaction, String instanceName,\r
+            String threadFactoryName, int minThreadCount, long keepAliveMillis, int maxThreadCount)\r
+            throws InstanceAlreadyExistsException {\r
+\r
+        ObjectName threadFactoryON = transaction.createModule(NamingThreadFactoryModuleFactory.NAME, threadFactoryName);\r
+        NamingThreadFactoryModuleMXBean namingThreadFactoryModuleMXBean = transaction.newMXBeanProxy(threadFactoryON,\r
+                NamingThreadFactoryModuleMXBean.class);\r
+        namingThreadFactoryModuleMXBean.setNamePrefix("prefix");\r
+\r
+        ObjectName flexibleON = transaction.createModule(flexibleFactory.getImplementationName(), instanceName);\r
+        FlexibleThreadPoolModuleMXBean mxBean = transaction.newMBeanProxy(flexibleON,\r
+                FlexibleThreadPoolModuleMXBean.class);\r
+        mxBean.setKeepAliveMillis(keepAliveMillis);\r
+        mxBean.setMaxThreadCount(maxThreadCount);\r
+        mxBean.setMinThreadCount(minThreadCount);\r
+        mxBean.setThreadFactory(threadFactoryON);\r
+        return flexibleON;\r
+    }\r
+\r
+    @Test\r
+    public void testReconfigurationInstance() throws InstanceAlreadyExistsException, ValidationException,\r
+            ConflictingVersionException, InstanceNotFoundException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+        createFlexible(transaction, instanceName, threadFactoryName, 2, 2, 2);\r
+\r
+        transaction.commit();\r
+\r
+        transaction = configRegistryClient.createTransaction();\r
+        ObjectName databaseNew = transaction.lookupConfigBean(flexibleFactory.getImplementationName(), instanceName);\r
+        FlexibleThreadPoolModuleMXBean proxy = transaction.newMXBeanProxy(databaseNew,\r
+                FlexibleThreadPoolModuleMXBean.class);\r
+        proxy.setMaxThreadCount(99);\r
+\r
+        CommitStatus status = transaction.commit();\r
+\r
+        assertBeanCount(1, flexibleFactory.getImplementationName());\r
+        assertStatus(status, 0, 1, 1);\r
+    }\r
+\r
+}\r
diff --git a/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/naming/NamingThreadPoolFactoryConfigBeanTest.java b/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/naming/NamingThreadPoolFactoryConfigBeanTest.java
new file mode 100644 (file)
index 0000000..9e9565a
--- /dev/null
@@ -0,0 +1,136 @@
+package org.opendaylight.controller.config.threadpool.naming;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertThat;\r
+import static org.junit.Assert.assertTrue;\r
+import static org.junit.Assert.fail;\r
+import static org.junit.matchers.JUnitMatchers.containsString;\r
+\r
+import javax.management.InstanceAlreadyExistsException;\r
+import javax.management.InstanceNotFoundException;\r
+import javax.management.ObjectName;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.opendaylight.controller.config.api.ConflictingVersionException;\r
+import org.opendaylight.controller.config.api.ValidationException;\r
+import org.opendaylight.controller.config.api.jmx.CommitStatus;\r
+import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;\r
+import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;\r
+import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;\r
+import org.opendaylight.controller.config.yang.threadpool.ThreadFactoryServiceInterface;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleFactory;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleMXBean;\r
+\r
+public class NamingThreadPoolFactoryConfigBeanTest extends AbstractConfigTest {\r
+\r
+    private NamingThreadFactoryModuleFactory factory;\r
+    private final String instanceName = "named";\r
+\r
+    @Before\r
+    public void setUp() {\r
+\r
+        factory = new NamingThreadFactoryModuleFactory();\r
+        super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(factory));\r
+    }\r
+\r
+    @Test\r
+    public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException,\r
+            ConflictingVersionException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+\r
+        createNamed(transaction, instanceName, "prefixes");\r
+        transaction.validateConfig();\r
+        CommitStatus status = transaction.commit();\r
+\r
+        assertEquals(1, configRegistry.lookupConfigBeans(factory.getImplementationName()).size());\r
+        assertEquals(1, status.getNewInstances().size());\r
+        assertEquals(0, status.getRecreatedInstances().size());\r
+        assertEquals(0, status.getReusedInstances().size());\r
+    }\r
+\r
+    @Test\r
+    public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException,\r
+            ValidationException {\r
+\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+        createNamed(transaction, instanceName, "prefixes");\r
+\r
+        transaction.commit();\r
+\r
+        assertEquals(1, configRegistry.lookupConfigBeans(factory.getImplementationName()).size());\r
+\r
+        transaction = configRegistryClient.createTransaction();\r
+        CommitStatus status = transaction.commit();\r
+\r
+        assertEquals(1, configRegistry.lookupConfigBeans(factory.getImplementationName()).size());\r
+        assertEquals(0, status.getNewInstances().size());\r
+        assertEquals(0, status.getRecreatedInstances().size());\r
+        assertEquals(1, status.getReusedInstances().size());\r
+\r
+    }\r
+\r
+    @Test\r
+    public void testInstanceAlreadyExistsException() throws ConflictingVersionException, ValidationException,\r
+            InstanceAlreadyExistsException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+\r
+        createNamed(transaction, instanceName, "prefixes");\r
+        transaction.commit();\r
+\r
+        transaction = configRegistryClient.createTransaction();\r
+        try {\r
+            createNamed(transaction, instanceName, "prefixes1");\r
+            fail();\r
+        } catch (InstanceAlreadyExistsException e) {\r
+            assertThat(\r
+                    e.getMessage(),\r
+                    containsString("There is an instance registered with name ModuleIdentifier{factoryName='threadfactory-naming', instanceName='named'}"));\r
+        }\r
+    }\r
+\r
+    @Test\r
+    public void testValidationException() throws InstanceAlreadyExistsException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+\r
+        ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName);\r
+        transaction.newMXBeanProxy(nameCreated, ThreadFactoryServiceInterface.class);\r
+        try {\r
+            transaction.validateConfig();\r
+            fail();\r
+        } catch (ValidationException e) {\r
+            assertTrue(e.getFailedValidations().containsKey(factory.getImplementationName()));\r
+            assertEquals(1, e.getFailedValidations().get(factory.getImplementationName()).keySet().size());\r
+        }\r
+    }\r
+\r
+    @Test\r
+    public void testReconfigurationInstance() throws InstanceAlreadyExistsException, ValidationException,\r
+            ConflictingVersionException, InstanceNotFoundException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+        createNamed(transaction, instanceName, "pref");\r
+\r
+        transaction.commit();\r
+\r
+        transaction = configRegistryClient.createTransaction();\r
+        ObjectName databaseNew = transaction.lookupConfigBean(factory.getImplementationName(), instanceName);\r
+        NamingThreadFactoryModuleMXBean proxy = transaction.newMXBeanProxy(databaseNew,\r
+                NamingThreadFactoryModuleMXBean.class);\r
+        proxy.setNamePrefix("pref1");\r
+\r
+        CommitStatus status = transaction.commit();\r
+\r
+        assertBeanCount(1, factory.getImplementationName());\r
+        assertStatus(status, 0, 1, 0);\r
+    }\r
+\r
+    private ObjectName createNamed(ConfigTransactionJMXClient transaction, String instanceName, String prefixes)\r
+            throws InstanceAlreadyExistsException {\r
+        ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName);\r
+        NamingThreadFactoryModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated,\r
+                NamingThreadFactoryModuleMXBean.class);\r
+        mxBean.setNamePrefix(prefixes);\r
+        return nameCreated;\r
+    }\r
+\r
+}\r
diff --git a/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/naming/TestingNamingThreadPoolFactoryModule.java b/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/naming/TestingNamingThreadPoolFactoryModule.java
new file mode 100644 (file)
index 0000000..5c717cc
--- /dev/null
@@ -0,0 +1,59 @@
+package org.opendaylight.controller.config.threadpool.naming;\r
+\r
+import static org.mockito.Matchers.any;\r
+import static org.mockito.Mockito.doNothing;\r
+import static org.mockito.Mockito.doReturn;\r
+import static org.mockito.Mockito.mock;\r
+\r
+import java.io.Closeable;\r
+import java.io.IOException;\r
+\r
+import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;\r
+import org.opendaylight.controller.config.api.ModuleIdentifier;\r
+import org.opendaylight.controller.config.spi.Module;\r
+import org.opendaylight.controller.config.threadpool.util.NamingThreadPoolFactory;\r
+import org.opendaylight.controller.config.yang.threadpool.ThreadFactoryServiceInterface;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleMXBean;\r
+\r
+public class TestingNamingThreadPoolFactoryModule implements Module, ThreadFactoryServiceInterface,\r
+        NamingThreadFactoryModuleMXBean {\r
+\r
+    private final NamingThreadPoolFactory fact;\r
+\r
+    public TestingNamingThreadPoolFactoryModule() throws IOException {\r
+        fact = mock(NamingThreadPoolFactory.class);\r
+        Thread thread = mock(Thread.class);\r
+        doNothing().when(thread).start();\r
+        doReturn(thread).when(fact).newThread(any(Runnable.class));\r
+        doNothing().when(fact).close();\r
+    }\r
+\r
+    public TestingNamingThreadPoolFactoryModule(DynamicMBeanWithInstance old) {\r
+        fact = (NamingThreadPoolFactory) old.getInstance();\r
+    }\r
+\r
+    @Override\r
+    public ModuleIdentifier getIdentifier() {\r
+        return new ModuleIdentifier(TestingNamingThreadPoolFactoryModule.class.getCanonicalName(), "mock");\r
+    }\r
+\r
+    @Override\r
+    public String getNamePrefix() {\r
+        return null;\r
+    }\r
+\r
+    @Override\r
+    public void setNamePrefix(String arg) {\r
+        throw new UnsupportedOperationException();\r
+    }\r
+\r
+    @Override\r
+    public void validate() {\r
+    }\r
+\r
+    @Override\r
+    public Closeable getInstance() {\r
+        return fact;\r
+    }\r
+\r
+}\r
diff --git a/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/scheduled/ScheduledThreadPoolConfigBeanTest.java b/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/scheduled/ScheduledThreadPoolConfigBeanTest.java
new file mode 100644 (file)
index 0000000..b4b1b60
--- /dev/null
@@ -0,0 +1,154 @@
+package org.opendaylight.controller.config.threadpool.scheduled;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertThat;\r
+import static org.junit.Assert.assertTrue;\r
+import static org.junit.Assert.fail;\r
+import static org.junit.matchers.JUnitMatchers.containsString;\r
+\r
+import javax.management.InstanceAlreadyExistsException;\r
+import javax.management.InstanceNotFoundException;\r
+import javax.management.ObjectName;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.opendaylight.controller.config.api.ConflictingVersionException;\r
+import org.opendaylight.controller.config.api.ValidationException;\r
+import org.opendaylight.controller.config.api.jmx.CommitStatus;\r
+import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;\r
+import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;\r
+import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleFactory;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleMXBean;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.ScheduledThreadPoolModuleFactory;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.ScheduledThreadPoolModuleMXBean;\r
+\r
+public class ScheduledThreadPoolConfigBeanTest extends AbstractConfigTest {\r
+\r
+    private ScheduledThreadPoolModuleFactory factory;\r
+    private final String instanceName = "scheduled1";\r
+\r
+    @Before\r
+    public void setUp() {\r
+\r
+        factory = new ScheduledThreadPoolModuleFactory();\r
+        super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(factory,\r
+                new NamingThreadFactoryModuleFactory()));\r
+    }\r
+\r
+    @Test\r
+    public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException,\r
+            ConflictingVersionException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+\r
+        createScheduled(transaction, instanceName, 1);\r
+        transaction.validateConfig();\r
+        CommitStatus status = transaction.commit();\r
+\r
+        assertBeanCount(1, factory.getImplementationName());\r
+        assertStatus(status, 2, 0, 0);\r
+    }\r
+\r
+    @Test\r
+    public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException,\r
+            ValidationException {\r
+\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+        createScheduled(transaction, instanceName, 1);\r
+\r
+        transaction.commit();\r
+\r
+        assertBeanCount(1, factory.getImplementationName());\r
+\r
+        transaction = configRegistryClient.createTransaction();\r
+        CommitStatus status = transaction.commit();\r
+\r
+        assertBeanCount(1, factory.getImplementationName());\r
+        assertStatus(status, 0, 0, 2);\r
+    }\r
+\r
+    @Test\r
+    public void testReconfigurationInstance() throws InstanceAlreadyExistsException, ValidationException,\r
+            ConflictingVersionException, InstanceNotFoundException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+        createScheduled(transaction, instanceName, 1);\r
+\r
+        transaction.commit();\r
+\r
+        transaction = configRegistryClient.createTransaction();\r
+        ObjectName databaseNew = transaction.lookupConfigBean(factory.getImplementationName(), instanceName);\r
+        ScheduledThreadPoolModuleMXBean proxy = transaction.newMXBeanProxy(databaseNew,\r
+                ScheduledThreadPoolModuleMXBean.class);\r
+        proxy.setMaxThreadCount(99);\r
+\r
+        CommitStatus status = transaction.commit();\r
+\r
+        assertBeanCount(1, factory.getImplementationName());\r
+        assertStatus(status, 0, 1, 1);\r
+    }\r
+\r
+    @Test\r
+    public void testDestroy() throws InstanceAlreadyExistsException, ValidationException, ConflictingVersionException,\r
+            InstanceNotFoundException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+        createScheduled(transaction, instanceName, 1);\r
+\r
+        transaction.commit();\r
+\r
+        transaction = configRegistryClient.createTransaction();\r
+        transaction.destroyConfigBean(factory.getImplementationName(), instanceName);\r
+        CommitStatus status = transaction.commit();\r
+\r
+        assertBeanCount(0, factory.getImplementationName());\r
+        assertStatus(status, 0, 0, 1);\r
+    }\r
+\r
+    @Test\r
+    public void testInstanceAlreadyExistsException() throws ConflictingVersionException, ValidationException,\r
+            InstanceAlreadyExistsException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+        createScheduled(transaction, instanceName, 1);\r
+        transaction.commit();\r
+        transaction = configRegistryClient.createTransaction();\r
+        try {\r
+            createScheduled(transaction, instanceName, 2);\r
+            fail();\r
+        } catch (InstanceAlreadyExistsException e) {\r
+            assertThat(\r
+                    e.getMessage(),\r
+                    containsString("There is an instance registered with name ModuleIdentifier{factoryName='threadpool-scheduled', instanceName='scheduled1'}"));\r
+        }\r
+    }\r
+\r
+    @Test\r
+    public void testValidationException() throws InstanceAlreadyExistsException {\r
+        ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();\r
+        createScheduled(transaction, instanceName, 0);\r
+\r
+        try {\r
+            transaction.validateConfig();\r
+            fail();\r
+        } catch (ValidationException e) {\r
+            assertTrue(e.getFailedValidations().containsKey(factory.getImplementationName()));\r
+            assertEquals(1, e.getFailedValidations().get(factory.getImplementationName()).keySet().size());\r
+        }\r
+    }\r
+\r
+    private ObjectName createScheduled(ConfigTransactionJMXClient transaction, String instanceName, int maxThreadCount)\r
+            throws InstanceAlreadyExistsException {\r
+        ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName);\r
+        ScheduledThreadPoolModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated,\r
+                ScheduledThreadPoolModuleMXBean.class);\r
+        mxBean.setMaxThreadCount(maxThreadCount);\r
+\r
+        ObjectName threadFactoryON = transaction.createModule(NamingThreadFactoryModuleFactory.NAME, "naming");\r
+        NamingThreadFactoryModuleMXBean namingThreadFactoryModuleMXBean = transaction.newMXBeanProxy(threadFactoryON,\r
+                NamingThreadFactoryModuleMXBean.class);\r
+        namingThreadFactoryModuleMXBean.setNamePrefix("prefix");\r
+\r
+        mxBean.setThreadFactory(threadFactoryON);\r
+\r
+        return nameCreated;\r
+    }\r
+\r
+}\r
diff --git a/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/scheduled/TestingScheduledThreadPoolModule.java b/opendaylight/config/threadpool-config-impl/src/test/java/org/opendaylight/controller/config/threadpool/scheduled/TestingScheduledThreadPoolModule.java
new file mode 100644 (file)
index 0000000..27e60ee
--- /dev/null
@@ -0,0 +1,77 @@
+package org.opendaylight.controller.config.threadpool.scheduled;\r
+\r
+import static org.mockito.Matchers.any;\r
+import static org.mockito.Matchers.anyBoolean;\r
+import static org.mockito.Matchers.anyLong;\r
+import static org.mockito.Mockito.doNothing;\r
+import static org.mockito.Mockito.doReturn;\r
+import static org.mockito.Mockito.mock;\r
+\r
+import java.util.concurrent.ScheduledExecutorService;\r
+import java.util.concurrent.ScheduledFuture;\r
+import java.util.concurrent.TimeUnit;\r
+\r
+import javax.management.ObjectName;\r
+\r
+import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;\r
+import org.opendaylight.controller.config.api.ModuleIdentifier;\r
+import org.opendaylight.controller.config.manager.impl.AbstractMockedModule;\r
+import org.opendaylight.controller.config.spi.Module;\r
+import org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper;\r
+import org.opendaylight.controller.config.yang.threadpool.ScheduledThreadPoolServiceInterface;\r
+import org.opendaylight.controller.config.yang.threadpool.impl.ScheduledThreadPoolModuleMXBean;\r
+\r
+import com.google.common.util.concurrent.ListenableFutureTask;\r
+\r
+public class TestingScheduledThreadPoolModule extends AbstractMockedModule implements\r
+        ScheduledThreadPoolServiceInterface, Module, ScheduledThreadPoolModuleMXBean {\r
+\r
+    public TestingScheduledThreadPoolModule(DynamicMBeanWithInstance old, ModuleIdentifier id) {\r
+        super(old, id);\r
+    }\r
+\r
+    @Override\r
+    protected AutoCloseable prepareMockedInstance() throws Exception {\r
+        ScheduledThreadPoolWrapper instance = mock(ScheduledThreadPoolWrapper.class);\r
+        ScheduledExecutorService ses = mock(ScheduledExecutorService.class);\r
+        {// mockFuture\r
+            ScheduledFuture<?> future = mock(ScheduledFuture.class);\r
+            doReturn(false).when(future).cancel(anyBoolean());\r
+            try {\r
+                doReturn(mock(Object.class)).when(future).get();\r
+            } catch (Exception e) {\r
+                throw new RuntimeException(e);\r
+            }\r
+            doReturn(future).when(ses).schedule(any(Runnable.class), any(Long.class), any(TimeUnit.class));\r
+            doReturn(future).when(ses).scheduleWithFixedDelay(any(Runnable.class), anyLong(), anyLong(),\r
+                    any(TimeUnit.class));\r
+\r
+        }\r
+        doNothing().when(ses).execute(any(Runnable.class));\r
+        doNothing().when(ses).execute(any(ListenableFutureTask.class));\r
+        doReturn(ses).when(instance).getExecutor();\r
+        doNothing().when(instance).close();\r
+\r
+        doReturn(1).when(instance).getMaxThreadCount();\r
+        return instance;\r
+    }\r
+\r
+    @Override\r
+    public ObjectName getThreadFactory() {\r
+        return any(ObjectName.class);\r
+    }\r
+\r
+    @Override\r
+    public void setThreadFactory(ObjectName threadFactory) {\r
+    }\r
+\r
+    @Override\r
+    public Integer getMaxThreadCount() {\r
+        return 1;\r
+    }\r
+\r
+    @Override\r
+    public void setMaxThreadCount(Integer maxThreadCount) {\r
+    }\r
+\r
+}\r