import config { prefix config; revision-date 2013-04-05; }
import netty { prefix netty; revision-date 2013-11-19; }
- import threadpool { prefix th; revision-date 2013-04-09; }
organization "Cisco Systems, Inc.";
status deprecated;
type uint16;
}
-
- container thread-factory {
- status deprecated;
- uses config:service-ref {
- refine type {
- mandatory false;
- config:required-identity th:threadfactory;
- }
- }
- }
}
}
-}
\ No newline at end of file
+}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.config.yang.netty.timer;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import io.netty.util.Timer;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-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.NamingThreadFactoryModuleFactory;
-import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleMXBean;
-import org.osgi.framework.Filter;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-
-public class HashedWheelTimerModuleTest extends AbstractConfigTest {
-
- private HashedWheelTimerModuleFactory factory;
- private NamingThreadFactoryModuleFactory threadFactory;
- private final String instanceName = "hashed-wheel-timer1";
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Before
- public void setUp() throws Exception {
- factory = new HashedWheelTimerModuleFactory();
- threadFactory = new NamingThreadFactoryModuleFactory();
- super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, factory, threadFactory));
-
- Filter mockFilter = mock(Filter.class);
- doReturn("mock").when(mockFilter).toString();
- doReturn(mockFilter).when(mockedContext).createFilter(anyString());
- doNothing().when(mockedContext).addServiceListener(any(ServiceListener.class), anyString());
- ServiceReference mockServiceRef = mock(ServiceReference.class);
- doReturn(new ServiceReference[]{mockServiceRef}).when(mockedContext).
- getServiceReferences(anyString(), anyString());
- doReturn(mock(Timer.class)).when(mockedContext).getService(mockServiceRef);
- }
-
- public void testValidationExceptionTickDuration() throws InstanceAlreadyExistsException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- try {
- createInstance(transaction, instanceName, 0L, 10, true);
- transaction.validateConfig();
- fail();
- } catch (final ValidationException e) {
- assertTrue(e.getMessage().contains("TickDuration value must be greater than 0"));
- }
- }
-
- public void testValidationExceptionTicksPerWheel() throws InstanceAlreadyExistsException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- try {
- createInstance(transaction, instanceName, 500L, 0, true);
- transaction.validateConfig();
- fail();
- } catch (final ValidationException e) {
- assertTrue(e.getMessage().contains("TicksPerWheel value must be greater than 0"));
- }
- }
-
- @Test
- public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException,
- ConflictingVersionException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-
- createInstance(transaction, instanceName, 500L, 10, true);
- createInstance(transaction, instanceName + 1, null, null, false);
- createInstance(transaction, instanceName + 2, 500L, 10, false);
- createInstance(transaction, instanceName + 3, 500L, null, false);
- transaction.validateConfig();
- CommitStatus status = transaction.commit();
-
- assertBeanCount(4, factory.getImplementationName());
- assertStatus(status, 5, 0, 0);
- }
-
- @Test
- public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException,
- ValidationException {
-
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- createInstance(transaction, instanceName, 500L, 10, true);
-
- transaction.commit();
-
- transaction = configRegistryClient.createTransaction();
- assertBeanCount(1, factory.getImplementationName());
- CommitStatus status = transaction.commit();
-
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 0, 0, 2);
- }
-
- @Test
- public void testReconfigure() throws InstanceAlreadyExistsException, ConflictingVersionException,
- ValidationException, InstanceNotFoundException {
-
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- createInstance(transaction, instanceName, 500L, 10, true);
- transaction.commit();
-
- transaction = configRegistryClient.createTransaction();
- assertBeanCount(1, factory.getImplementationName());
- HashedWheelTimerModuleMXBean mxBean = transaction.newMBeanProxy(
- transaction.lookupConfigBean(factory.getImplementationName(), instanceName),
- HashedWheelTimerModuleMXBean.class);
- mxBean.setTicksPerWheel(20);
- CommitStatus status = transaction.commit();
-
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 0, 1, 1);
- }
-
- private ObjectName createInstance(final ConfigTransactionJMXClient transaction, final String instanceName,
- final Long tickDuration, final Integer ticksPerWheel, final boolean hasThreadfactory)
- throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName);
- HashedWheelTimerModuleMXBean mxBean = transaction
- .newMBeanProxy(nameCreated, HashedWheelTimerModuleMXBean.class);
- mxBean.setTickDuration(tickDuration);
- mxBean.setTicksPerWheel(ticksPerWheel);
- if (hasThreadfactory) {
- mxBean.setThreadFactory(createThreadfactoryInstance(transaction, "thread-factory1", "th"));
- }
- return nameCreated;
- }
-
- private ObjectName createThreadfactoryInstance(final ConfigTransactionJMXClient transaction, final String instanceName,
- final String namePrefix) throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(threadFactory.getImplementationName(), instanceName);
- NamingThreadFactoryModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated,
- NamingThreadFactoryModuleMXBean.class);
- mxBean.setNamePrefix(namePrefix);
- return nameCreated;
- }
-
-}
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.controller</groupId>
- <artifactId>config-plugin-parent</artifactId>
+ <artifactId>config-subsystem</artifactId>
<version>0.7.0-SNAPSHOT</version>
- <relativePath>../config-plugin-parent</relativePath>
+ <relativePath>../</relativePath>
</parent>
<artifactId>threadpool-config-api</artifactId>
<packaging>bundle</packaging>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>config-api</artifactId>
- </dependency>
</dependencies>
<build>
+++ /dev/null
-// vi: set smarttab et sw=4 tabstop=4:
-module threadpool {
- yang-version 1;
- namespace "urn:opendaylight:params:xml:ns:yang:controller:threadpool";
- prefix "th";
-
- import config { prefix config; revision-date 2013-04-05; }
-
- organization "Cisco Systems, Inc.";
-
- contact "Robert Varga <rovarga@cisco.com>";
-
- description
- "This module contains the base YANG definitions for
- thread-related services.
-
- Copyright (c)2013 Cisco Systems, Inc. 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";
-
- revision "2013-04-09" {
- description
- "Added eventbus service.";
- }
-
- revision "2013-04-05" {
- description
- "Updated with YANG extension for Java class specification.";
- }
-
- revision "2013-04-03" {
- description
- "Initial revision by Anton Tkacik, Tomas Olvecky and
- Robert Varga.";
- }
-
- identity eventbus {
- description
- "Service representing an event bus. The service acts as message
- router between event producers and event consumers";
-
- base "config:service-type";
- config:java-class "com.google.common.eventbus.EventBus";
- }
-
- identity threadfactory {
- description
- "Service representing a ThreadFactory instance. It is directly
- useful in Java world, where various library pieces need to create
- threads and you may want to inject a customized thread
- implementation.";
-
- base "config:service-type";
- config:java-class "java.util.concurrent.ThreadFactory";
- }
-
- identity threadpool {
- description
- "A simple pool of threads able to execute work.";
-
- base "config:service-type";
- config:java-class "org.opendaylight.controller.config.threadpool.ThreadPool";
- }
-
- identity scheduled-threadpool {
- description
- "An extension of the simple pool of threads able to schedule
- work to be executed at some point in time.";
-
- base "threadpool";
- config:java-class "org.opendaylight.controller.config.threadpool.ScheduledThreadPool";
- }
-}
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.controller</groupId>
- <artifactId>config-plugin-parent</artifactId>
+ <artifactId>config-subsystem</artifactId>
<version>0.7.0-SNAPSHOT</version>
- <relativePath>../config-plugin-parent</relativePath>
+ <relativePath>../</relativePath>
</parent>
<artifactId>threadpool-config-impl</artifactId>
<packaging>bundle</packaging>
<name>${project.artifactId}</name>
<dependencies>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>config-api</artifactId>
- </dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>threadpool-config-api</artifactId>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
-
- <!--test dependencies -->
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>config-manager</artifactId>
- <type>test-jar</type>
- <scope>test</scope>
- </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>
</dependencies>
<build>
+++ /dev/null
-/*
- * Copyright (c) 2013 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.config.threadpool.util;
-
-import com.google.common.eventbus.AsyncEventBus;
-import com.google.common.eventbus.DeadEvent;
-import com.google.common.eventbus.Subscribe;
-import java.io.Closeable;
-import java.io.IOException;
-import org.opendaylight.controller.config.threadpool.ThreadPool;
-import org.opendaylight.controller.config.yang.threadpool.impl.AsyncEventBusRuntimeMXBean;
-import org.opendaylight.controller.config.yang.threadpool.impl.AsyncEventBusRuntimeRegistration;
-import org.opendaylight.controller.config.yang.threadpool.impl.AsyncEventBusRuntimeRegistrator;
-
-/**
- * Closeable version of {@link AsyncEventBus}.
- */
-/**
- * To be removed in Nitrogen
- */
-@Deprecated
-public class CloseableAsyncEventBus extends AsyncEventBus implements Closeable {
- private final ThreadPool threadPool;
- private final AsyncEventBusRuntimeRegistration rootRegistration;
-
- public CloseableAsyncEventBus(String identifier, ThreadPool threadPool,
- AsyncEventBusRuntimeRegistrator rootRegistrator) {
- super(identifier, threadPool.getExecutor());
- this.threadPool = threadPool;
- rootRegistration = rootRegistrator.register(new AsyncEventBusRuntimeMXBean() {
- private long deadEventsCounter = 0;
-
- @Subscribe
- public void increaseDeadEvents(DeadEvent deadEvent) {
- deadEventsCounter++;
- }
-
- @Override
- public Long countDeadEvents() {
- return deadEventsCounter;
- }
-
- });
- }
-
- public ThreadPool getThreadPool() {
- return threadPool;
- }
-
- @Override
- public void close() throws IOException {
- rootRegistration.close();
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.config.threadpool.util;
-
-import com.google.common.eventbus.DeadEvent;
-import com.google.common.eventbus.EventBus;
-import com.google.common.eventbus.Subscribe;
-import java.io.Closeable;
-import org.opendaylight.controller.config.yang.threadpool.impl.EventBusRuntimeMXBean;
-import org.opendaylight.controller.config.yang.threadpool.impl.EventBusRuntimeRegistration;
-import org.opendaylight.controller.config.yang.threadpool.impl.EventBusRuntimeRegistrator;
-
-/**
- * Closeable {@link EventBus}.
- */
-/**
- * To be removed in Nitrogen
- */
-@Deprecated
-public class CloseableEventBus extends EventBus implements Closeable {
-
- private final EventBusRuntimeRegistration rootRegistration;
-
- public CloseableEventBus(String identifier, EventBusRuntimeRegistrator rootRegistrator) {
- super(identifier);
- rootRegistration = rootRegistrator.register(new EventBusRuntimeMXBean() {
- private long deadEventsCounter = 0;
-
- @Subscribe
- public void increaseDeadEvents(DeadEvent deadEvent) {
- deadEventsCounter++;
- }
-
- @Override
- public Long countDeadEvents() {
- return deadEventsCounter;
- }
- });
-
- }
-
- @Override
- public void close() {
- rootRegistration.close();
-
- }
-}
* Implementation of {@link ThreadPool} using fixed number of threads wraps
* {@link ExecutorService}.
*/
-/**
- * To be removed in Nitrogen
- */
-@Deprecated
public class FixedThreadPoolWrapper implements ThreadPool, Closeable {
private final ThreadPoolExecutor executor;
+++ /dev/null
-/*
- * Copyright (c) 2013 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
- */
-
-/**
- * Generated file
-
- * Generated from: yang module name: threadpool-impl yang module local name: async-eventbus
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Tue Nov 05 15:40:46 CET 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
-package org.opendaylight.controller.config.yang.threadpool.impl;
-
-import org.opendaylight.controller.config.threadpool.util.CloseableAsyncEventBus;
-
-/**
-* To be removed in Nitrogen
-*/
-@Deprecated
-public final class AsyncEventBusModule extends
- org.opendaylight.controller.config.yang.threadpool.impl.AbstractAsyncEventBusModule {
-
- public AsyncEventBusModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
- org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
- super(identifier, dependencyResolver);
- }
-
- public AsyncEventBusModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
- org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
- AsyncEventBusModule oldModule, java.lang.AutoCloseable oldInstance) {
- super(identifier, dependencyResolver, oldModule, oldInstance);
- }
-
- @Override
- public void validate() {
- super.validate();
- // Add custom validation for module attributes here.
- }
-
- @Override
- public java.lang.AutoCloseable createInstance() {
- return new CloseableAsyncEventBus(getIdentifier().toString(), getThreadpoolDependency(),
- getRootRuntimeBeanRegistratorWrapper());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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
- */
-
-/**
- * Generated file
-
- * Generated from: yang module name: threadpool-impl yang module local name: async-eventbus
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Tue Nov 05 15:40:46 CET 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
-package org.opendaylight.controller.config.yang.threadpool.impl;
-
-/**
- * To be removed in Nitrogen
- */
-@Deprecated
-public class AsyncEventBusModuleFactory extends
- org.opendaylight.controller.config.yang.threadpool.impl.AbstractAsyncEventBusModuleFactory {
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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
- */
-
-/**
- * Generated file
-
- * Generated from: yang module name: threadpool-impl yang module local name: eventbus
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Tue Nov 05 15:40:46 CET 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
-package org.opendaylight.controller.config.yang.threadpool.impl;
-
-import org.opendaylight.controller.config.threadpool.util.CloseableEventBus;
-
-/**
- * To be removed in Nitrogen
- */
-@Deprecated
-public final class EventBusModule extends
- org.opendaylight.controller.config.yang.threadpool.impl.AbstractEventBusModule {
-
- public EventBusModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
- org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
- super(identifier, dependencyResolver);
- }
-
- public EventBusModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
- org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, EventBusModule oldModule,
- java.lang.AutoCloseable oldInstance) {
- super(identifier, dependencyResolver, oldModule, oldInstance);
- }
-
- @Override
- public void validate() {
- super.validate();
- // Add custom validation for module attributes here.
- }
-
- @Override
- public java.lang.AutoCloseable createInstance() {
- return new CloseableEventBus(getIdentifier().toString(), getRootRuntimeBeanRegistratorWrapper());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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
- */
-
-/**
- * Generated file
-
- * Generated from: yang module name: threadpool-impl yang module local name: eventbus
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Tue Nov 05 15:40:46 CET 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
-package org.opendaylight.controller.config.yang.threadpool.impl;
-
-/**
- * To be removed in Nitrogen
- */
-@Deprecated
-public class EventBusModuleFactory extends
- org.opendaylight.controller.config.yang.threadpool.impl.AbstractEventBusModuleFactory {
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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
- */
-
-/**
- * Generated file
-
- * Generated from: yang module name: threadpool-impl yang module local name: threadfactory-naming
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Wed Nov 06 16:19:33 CET 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
-package org.opendaylight.controller.config.yang.threadpool.impl;
-
-import org.opendaylight.controller.config.api.JmxAttributeValidationException;
-import org.opendaylight.controller.config.threadpool.util.NamingThreadPoolFactory;
-
-/**
-*
-*/
-public final class NamingThreadFactoryModule extends
- org.opendaylight.controller.config.yang.threadpool.impl.AbstractNamingThreadFactoryModule {
-
- public NamingThreadFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
- org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
- super(identifier, dependencyResolver);
- }
-
- public NamingThreadFactoryModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
- org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
- NamingThreadFactoryModule oldModule, java.lang.AutoCloseable oldInstance) {
- super(identifier, dependencyResolver, oldModule, oldInstance);
- }
-
- @Override
- public void validate() {
- super.validate();
- JmxAttributeValidationException.checkNotNull(getNamePrefix(), namePrefixJmxAttribute);
- }
-
- @Override
- public java.lang.AutoCloseable createInstance() {
- return new NamingThreadPoolFactory(getNamePrefix());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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
- */
-
-/**
- * Generated file
-
- * Generated from: yang module name: threadpool-impl yang module local name: threadfactory-naming
- * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
- * Generated at: Wed Nov 06 16:19:33 CET 2013
- *
- * Do not modify this file unless it is present under src/main directory
- */
-package org.opendaylight.controller.config.yang.threadpool.impl;
-
-/**
-*
-*/
-public class NamingThreadFactoryModuleFactory extends
- org.opendaylight.controller.config.yang.threadpool.impl.AbstractNamingThreadFactoryModuleFactory {
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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
- */
-
-/**
-* Generated file
-
-* Generated from: yang module name: threadpool-impl-fixed yang module local name: threadpool-fixed
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Sun Dec 01 17:13:32 CET 2013
-*
-* Do not modify this file unless it is present under src/main directory
-*/
-package org.opendaylight.controller.config.yang.threadpool.impl.fixed;
-
-import org.opendaylight.controller.config.api.JmxAttributeValidationException;
-import org.opendaylight.controller.config.threadpool.util.FixedThreadPoolWrapper;
-
-/**
- * To be removed in Nitrogen
- */
-@Deprecated
-public final class FixedThreadPoolModule extends org.opendaylight.controller.config.yang.threadpool.impl.fixed.AbstractFixedThreadPoolModule
-{
-
- public FixedThreadPoolModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
- super(identifier, dependencyResolver);
- }
-
- public FixedThreadPoolModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, FixedThreadPoolModule oldModule, java.lang.AutoCloseable oldInstance) {
- super(identifier, dependencyResolver, oldModule, oldInstance);
- }
-
- @Override
- public void validate(){
- super.validate();
-
- JmxAttributeValidationException.checkNotNull(getMaxThreadCount(), maxThreadCountJmxAttribute);
- JmxAttributeValidationException.checkCondition(getMaxThreadCount() > 0, "must be greater than zero",
- maxThreadCountJmxAttribute);
- }
-
- @Override
- public java.lang.AutoCloseable createInstance() {
- return new FixedThreadPoolWrapper(getMaxThreadCount(), getThreadFactoryDependency());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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
- */
-
-/**
-* Generated file
-
-* Generated from: yang module name: threadpool-impl-fixed yang module local name: threadpool-fixed
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Sun Dec 01 17:13:32 CET 2013
-*
-* Do not modify this file unless it is present under src/main directory
-*/
-package org.opendaylight.controller.config.yang.threadpool.impl.fixed;
-
-/**
- * To be removed in Nitrogen
- */
-@Deprecated
-public class FixedThreadPoolModuleFactory extends org.opendaylight.controller.config.yang.threadpool.impl.fixed.AbstractFixedThreadPoolModuleFactory
-{
-
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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
- */
-
-/**
-* Generated file
-
-* Generated from: yang module name: threadpool-impl-flexible yang module local name: threadpool-flexible
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Sun Dec 01 17:13:32 CET 2013
-*
-* Do not modify this file unless it is present under src/main directory
-*/
-package org.opendaylight.controller.config.yang.threadpool.impl.flexible;
-
-import com.google.common.base.Optional;
-import java.util.concurrent.TimeUnit;
-import org.opendaylight.controller.config.api.JmxAttributeValidationException;
-import org.opendaylight.controller.config.threadpool.util.FlexibleThreadPoolWrapper;
-
-/**
-*
-*/
-public final class FlexibleThreadPoolModule extends org.opendaylight.controller.config.yang.threadpool.impl.flexible.AbstractFlexibleThreadPoolModule
-{
-
- public FlexibleThreadPoolModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
- super(identifier, dependencyResolver);
- }
-
- public FlexibleThreadPoolModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, FlexibleThreadPoolModule oldModule, java.lang.AutoCloseable oldInstance) {
- super(identifier, dependencyResolver, oldModule, oldInstance);
- }
-
- @Override
- public void validate(){
- super.validate();
- JmxAttributeValidationException.checkNotNull(getKeepAliveMillis(), keepAliveMillisJmxAttribute);
- JmxAttributeValidationException.checkCondition(getKeepAliveMillis() > 0, "must be greater than zero",
- keepAliveMillisJmxAttribute);
-
- JmxAttributeValidationException.checkNotNull(getMinThreadCount(), minThreadCountJmxAttribute);
- JmxAttributeValidationException.checkCondition(getMinThreadCount() > 0, "must be greater than zero",
- minThreadCountJmxAttribute);
-
- JmxAttributeValidationException.checkNotNull(getMaxThreadCount(), maxThreadCountJmxAttribute);
- JmxAttributeValidationException.checkCondition(getMaxThreadCount() > 0, "must be greater than zero",
- maxThreadCountJmxAttribute);
-
- if(getQueueCapacity() != null) {
- JmxAttributeValidationException.checkCondition(getQueueCapacity() > 0, "Queue capacity cannot be < 1", queueCapacityJmxAttribute);
- }
- }
-
- @Override
- public java.lang.AutoCloseable createInstance() {
- return new FlexibleThreadPoolWrapper(getMinThreadCount(), getMaxThreadCount(), getKeepAliveMillis(),
- TimeUnit.MILLISECONDS, getThreadFactoryDependency(), Optional.fromNullable(getQueueCapacity()));
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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
- */
-
-/**
-* Generated file
-
-* Generated from: yang module name: threadpool-impl-flexible yang module local name: threadpool-flexible
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Sun Dec 01 17:13:32 CET 2013
-*
-* Do not modify this file unless it is present under src/main directory
-*/
-package org.opendaylight.controller.config.yang.threadpool.impl.flexible;
-
-/**
-*
-*/
-public class FlexibleThreadPoolModuleFactory extends org.opendaylight.controller.config.yang.threadpool.impl.flexible.AbstractFlexibleThreadPoolModuleFactory
-{
-
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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
- */
-
-/**
-* Generated file
-
-* Generated from: yang module name: threadpool-impl-scheduled yang module local name: threadpool-scheduled
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Sun Dec 01 17:13:32 CET 2013
-*
-* Do not modify this file unless it is present under src/main directory
-*/
-package org.opendaylight.controller.config.yang.threadpool.impl.scheduled;
-
-import org.opendaylight.controller.config.api.JmxAttributeValidationException;
-import org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper;
-
-/**
-*
-*/
-public final class ScheduledThreadPoolModule extends org.opendaylight.controller.config.yang.threadpool.impl.scheduled.AbstractScheduledThreadPoolModule
-{
-
- public ScheduledThreadPoolModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
- super(identifier, dependencyResolver);
- }
-
- public ScheduledThreadPoolModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, ScheduledThreadPoolModule oldModule, java.lang.AutoCloseable oldInstance) {
- super(identifier, dependencyResolver, oldModule, oldInstance);
- }
-
- @Override
- public void validate(){
- super.validate();
- JmxAttributeValidationException.checkNotNull(getMaxThreadCount(), maxThreadCountJmxAttribute);
- JmxAttributeValidationException.checkCondition(getMaxThreadCount() > 0, "must be greater than zero",
- maxThreadCountJmxAttribute);
- }
-
- @Override
- public java.lang.AutoCloseable createInstance() {
- return new ScheduledThreadPoolWrapper(getMaxThreadCount(), getThreadFactoryDependency());
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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
- */
-
-/**
-* Generated file
-
-* Generated from: yang module name: threadpool-impl-scheduled yang module local name: threadpool-scheduled
-* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Sun Dec 01 17:13:32 CET 2013
-*
-* Do not modify this file unless it is present under src/main directory
-*/
-package org.opendaylight.controller.config.yang.threadpool.impl.scheduled;
-
-/**
-*
-*/
-public class ScheduledThreadPoolModuleFactory extends org.opendaylight.controller.config.yang.threadpool.impl.scheduled.AbstractScheduledThreadPoolModuleFactory
-{
-
-
-}
+++ /dev/null
-module threadpool-impl-fixed {
- yang-version 1;
- namespace "urn:opendaylight:params:xml:ns:yang:controller:threadpool:impl:fixed";
- prefix "th-java-fixed";
-
- import threadpool { prefix th; revision-date 2013-04-09; }
- import config { prefix config; revision-date 2013-04-05; }
- import rpc-context { prefix rpcx; revision-date 2013-06-17; }
-
- organization "Cisco Systems, Inc.";
-
- contact "Robert Varga <rovarga@cisco.com>";
-
- description
- "This module contains the base YANG definitions for
- thread services pure Java implementation.
-
- Copyright (c)2013 Cisco Systems, Inc. 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";
-
- revision "2013-12-01" {
- description
- "Initial revision";
- }
-
-
- identity threadpool-fixed {
- status deprecated;
- base config:module-type;
- config:provided-service th:threadpool;
- config:java-name-prefix FixedThreadPool;
- }
-
- augment "/config:modules/config:module/config:configuration" {
- status deprecated;
- case threadpool-fixed {
- when "/config:modules/config:module/config:type = 'threadpool-fixed'";
- leaf max-thread-count {
- type uint16;
- }
-
- container threadFactory {
- uses config:service-ref {
- refine type {
- //mandatory true;
- config:required-identity th:threadfactory;
- }
- }
- }
- }
- }
-}
-
+++ /dev/null
-module threadpool-impl-flexible {
- yang-version 1;
- namespace "urn:opendaylight:params:xml:ns:yang:controller:threadpool:impl:flexible";
- prefix "th-java-flexible";
-
- import threadpool { prefix th; revision-date 2013-04-09; }
- import config { prefix config; revision-date 2013-04-05; }
- import rpc-context { prefix rpcx; revision-date 2013-06-17; }
-
- organization "Cisco Systems, Inc.";
-
- contact "Robert Varga <rovarga@cisco.com>";
-
- description
- "This module contains the base YANG definitions for
- thread services pure Java implementation.
-
- Copyright (c)2013 Cisco Systems, Inc. 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";
-
- revision "2013-12-01" {
- description
- "Initial revision";
- }
-
- identity threadpool-flexible {
- base config:module-type;
- config:provided-service th:threadpool;
- config:java-name-prefix FlexibleThreadPool;
- }
-
- augment "/config:modules/config:module/config:configuration" {
- case threadpool-flexible {
- when "/config:modules/config:module/config:type = 'threadpool-flexible'";
- leaf max-thread-count {
- type uint16;
- }
- leaf minThreadCount {
- type uint16;
- }
- leaf keepAliveMillis {
- type uint32;
- }
-
- leaf queueCapacity {
- type uint16;
- mandatory false;
- description "Capacity of queue that holds waiting tasks";
- }
-
- container threadFactory {
- uses config:service-ref {
- refine type {
- // mandatory true;
- config:required-identity th:threadfactory;
- }
- }
- }
- }
- }
-}
+++ /dev/null
-module threadpool-impl-scheduled {
- yang-version 1;
- namespace "urn:opendaylight:params:xml:ns:yang:controller:threadpool:impl:scheduled";
- prefix "th-java-scheduled";
-
- import threadpool { prefix th; revision-date 2013-04-09; }
- import config { prefix config; revision-date 2013-04-05; }
- import rpc-context { prefix rpcx; revision-date 2013-06-17; }
-
- organization "Cisco Systems, Inc.";
-
- contact "Robert Varga <rovarga@cisco.com>";
-
- description
- "This module contains the base YANG definitions for
- thread services pure Java implementation.
-
- Copyright (c)2013 Cisco Systems, Inc. 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";
-
- revision "2013-12-01" {
- description
- "Initial revision";
- }
-
- identity threadpool-scheduled {
- base config:module-type;
- config:provided-service th:scheduled-threadpool;
- config:java-name-prefix ScheduledThreadPool;
- }
-
- augment "/config:modules/config:module/config:configuration" {
- case threadpool-scheduled {
- when "/config:modules/config:module/config:type = 'threadpool-scheduled'";
- leaf max-thread-count {
- type uint16;
- }
-
- container threadFactory {
- uses config:service-ref {
- refine type {
- // mandatory true;
- config:required-identity th:threadfactory;
- }
- }
- }
- }
- }
-}
+++ /dev/null
-module threadpool-impl {
- yang-version 1;
- namespace "urn:opendaylight:params:xml:ns:yang:controller:threadpool:impl";
- prefix "th-java";
-
- import threadpool { prefix th; revision-date 2013-04-09; }
- import config { prefix config; revision-date 2013-04-05; }
- import rpc-context { prefix rpcx; revision-date 2013-06-17; }
-
- organization "Cisco Systems, Inc.";
-
- contact "Robert Varga <rovarga@cisco.com>";
-
- description
- "This module contains the base YANG definitions for
- thread services pure Java implementation.
-
- Copyright (c)2013 Cisco Systems, Inc. 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";
-
- revision "2013-04-05" {
- description
- "Updated to work with new anchors.";
- }
-
- revision "2013-04-03" {
- description
- "Initial revision by Anton Tkacik, Tomas Olvecky and
- Robert Varga.";
- }
-
- identity eventbus {
- base config:module-type;
- config:provided-service th:eventbus;
- config:java-name-prefix EventBus;
- status deprecated;
- }
-
- augment "/config:modules/config:module/config:configuration" {
- status deprecated;
- case eventbus {
- when "/config:modules/config:module/config:type = 'eventbus'";
- // No real configuration
- }
- }
-
- augment "/config:modules/config:module/config:state" {
- status deprecated;
- case eventbus {
- when "/config:modules/config:module/config:type = 'eventbus'";
- rpcx:rpc-context-instance "event-bus-rpc";
- }
- }
-
- identity event-bus-rpc;
-
- identity async-eventbus {
- base config:module-type;
- config:provided-service th:eventbus;
- config:java-name-prefix AsyncEventBus;
- status deprecated;
- }
-
- augment "/config:modules/config:module/config:configuration" {
- status deprecated;
- case async-eventbus {
- when "/config:modules/config:module/config:type = 'async-eventbus'";
- container threadpool {
- uses config:service-ref {
- refine type {
- //mandatory true;
- config:required-identity th:threadpool;
- }
- }
- }
- }
- }
-
- augment "/config:modules/config:module/config:state" {
- status deprecated;
- case async-eventbus {
- when "/config:modules/config:module/config:type = 'async-eventbus'";
- rpcx:rpc-context-instance "event-bus-rpc";
- }
- }
-
- rpc get-dead-events-count {
- config:java-name-prefix countDeadEvents;
- input {
- uses rpcx:rpc-context-ref {
- refine context-instance {
- rpcx:rpc-context-instance event-bus-rpc;
- }
- }
- }
- output {
- leaf result {
- type uint32;
- }
- }
- }
-
- identity threadfactory-naming {
- base config:module-type;
- config:provided-service th:threadfactory;
- config:java-name-prefix NamingThreadFactory;
- }
-
- augment "/config:modules/config:module/config:configuration" {
- case threadfactory-naming {
- when "/config:modules/config:module/config:type = 'threadfactory-naming'";
- leaf name-prefix {
- type string;
- }
- }
- }
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2013 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.config.threadpool.async;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-
-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.ClassBasedModuleFactory;
-import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
-import org.opendaylight.controller.config.threadpool.scheduled.TestingScheduledThreadPoolModule;
-import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
-import org.opendaylight.controller.config.yang.threadpool.impl.AsyncEventBusModuleFactory;
-import org.opendaylight.controller.config.yang.threadpool.impl.AsyncEventBusModuleMXBean;
-
-public class AsyncEventBusConfigBeanTest extends AbstractConfigTest {
-
- private AsyncEventBusModuleFactory factory;
- private final String instanceName = "async1";
- private final String poolImplName = "fixed1";
-
- @Before
- public void setUp() {
-
- ClassBasedModuleFactory scheduledThreadPoolConfigFactory = createClassBasedCBF(
- TestingScheduledThreadPoolModule.class, poolImplName);
-
- factory = new AsyncEventBusModuleFactory();
- super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext,factory,
- scheduledThreadPoolConfigFactory));
- }
-
- @Test
- public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException,
- ConflictingVersionException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-
- createAsynced(transaction, instanceName, transaction.createModule(poolImplName, "pool-test"));
- transaction.validateConfig();
- CommitStatus status = transaction.commit();
-
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 2, 0, 0);
- }
-
- @Test
- public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException,
- ValidationException {
-
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- createAsynced(transaction, instanceName, transaction.createModule(poolImplName, "pool-test"));
-
- transaction.commit();
-
- assertBeanCount(1, factory.getImplementationName());
-
- transaction = configRegistryClient.createTransaction();
- CommitStatus status = transaction.commit();
-
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 0, 0, 2);
-
- }
-
- @Test
- public void testInstanceAlreadyExistsException() throws ConflictingVersionException, ValidationException,
- InstanceAlreadyExistsException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-
- ObjectName poolCB = transaction.createModule(poolImplName, "pool-test");
- createAsynced(transaction, instanceName, poolCB);
- transaction.commit();
-
- transaction = configRegistryClient.createTransaction();
- try {
- createAsynced(transaction, instanceName, poolCB);
- fail();
- } catch (InstanceAlreadyExistsException e) {
- assertThat(
- e.getMessage(),
- containsString("There is an instance registered with name ModuleIdentifier{factoryName='async-eventbus', instanceName='async1'}"));
- }
- }
-
- private ObjectName createAsynced(ConfigTransactionJMXClient transaction, String instanceName, ObjectName threadPool)
- throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName);
- AsyncEventBusModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated, AsyncEventBusModuleMXBean.class);
- mxBean.setThreadpool(threadPool);
- return nameCreated;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.config.threadpool.eventbus;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-
-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(mockedContext,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;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.config.threadpool.eventbus;
-
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
-
-import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.config.manager.impl.AbstractMockedModule;
-import org.opendaylight.controller.config.spi.Module;
-import org.opendaylight.controller.config.threadpool.util.CloseableEventBus;
-import org.opendaylight.controller.config.yang.threadpool.EventBusServiceInterface;
-import org.opendaylight.controller.config.yang.threadpool.impl.EventBusModuleMXBean;
-
-public class TestingEventBusModule extends AbstractMockedModule implements Module, EventBusServiceInterface,
- EventBusModuleMXBean {
-
- public TestingEventBusModule(DynamicMBeanWithInstance old, ModuleIdentifier id) {
- super(old, id);
- }
-
- @Override
- protected AutoCloseable prepareMockedInstance() throws Exception {
- CloseableEventBus bus = mock(CloseableEventBus.class);
- doNothing().when(bus).close();
- return bus;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.config.threadpool.fixed;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-
-import java.lang.management.ManagementFactory;
-import java.lang.management.ThreadInfo;
-import java.lang.management.ThreadMXBean;
-import java.util.ArrayList;
-import java.util.List;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-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.NamingThreadFactoryModuleFactory;
-import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleMXBean;
-import org.opendaylight.controller.config.yang.threadpool.impl.fixed.FixedThreadPoolModuleFactory;
-import org.opendaylight.controller.config.yang.threadpool.impl.fixed.FixedThreadPoolModuleMXBean;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class FixedThreadPoolConfigBeanTest extends AbstractConfigTest {
- private static final Logger LOG = LoggerFactory.getLogger(FixedThreadPoolConfigBeanTest.class);
-
- private FixedThreadPoolModuleFactory factory;
- private final String nameInstance = "fixedInstance";
- private ObjectName threadFactoryON;
-
- @Before
- public void setUp() {
- factory = new FixedThreadPoolModuleFactory();
- super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, factory,
- new NamingThreadFactoryModuleFactory()));
- }
-
- @Test
- public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException,
- ConflictingVersionException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- createFixed(transaction, nameInstance, 2, nameInstance);
-
- transaction.validateConfig();
- CommitStatus status = transaction.commit();
-
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 2, 0, 0);
- }
-
- @Test
- public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException,
- ValidationException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- createFixed(transaction, nameInstance, 4, nameInstance);
-
- transaction.validateConfig();
- transaction.commit();
-
- assertBeanCount(1, factory.getImplementationName());
-
- transaction = configRegistryClient.createTransaction();
- NamingThreadFactoryModuleMXBean namingThreadFactoryModuleMXBean = transaction.newMXBeanProxy(threadFactoryON, NamingThreadFactoryModuleMXBean.class);
- namingThreadFactoryModuleMXBean.setNamePrefix("newPrefix");
- CommitStatus status = transaction.commit();
-
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 0, 2, 0);
- }
-
- @Test
- public void testNegative() throws ConflictingVersionException, ValidationException, InstanceAlreadyExistsException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-
- createFixed(transaction, nameInstance, 5, nameInstance);
- transaction.commit();
-
- transaction = configRegistryClient.createTransaction();
- try {
- createFixed(transaction, nameInstance, 0, nameInstance);
- fail();
- } catch (InstanceAlreadyExistsException e) {
- assertThat(
- e.getMessage(),
- containsString("There is an instance registered with name ModuleIdentifier{factoryName='threadpool-fixed', instanceName='fixedInstance'}"));
- }
- }
-
- private int countThreadsByPrefix(String prefix) {
- ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
- int result = 0;
- List<String> names = new ArrayList<>();
- for (ThreadInfo threadInfo : threadMXBean.dumpAllThreads(false, false)) {
- names.add(threadInfo.getThreadName());
- if (threadInfo.getThreadName().startsWith(prefix)) {
- result++;
- }
- }
- LOG.info("Current threads {}", names);
- return result;
- }
-
- @Test
- public void testDestroy() throws InstanceAlreadyExistsException, ValidationException, ConflictingVersionException,
- InstanceNotFoundException, InterruptedException {
-
- String prefix = org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(10);
-
- int numberOfThreads = 100;
- int threadCount1 = countThreadsByPrefix(prefix);
- assertEquals(0, threadCount1);
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-
- createFixed(transaction, nameInstance, numberOfThreads, prefix);
- transaction.commit();
- int threadCount2 = countThreadsByPrefix(prefix);
- assertEquals(numberOfThreads, threadCount2);
-
- transaction = configRegistryClient.createTransaction();
- transaction.destroyModule(factory.getImplementationName(), nameInstance);
- CommitStatus status = transaction.commit();
-
- assertBeanCount(0, factory.getImplementationName());
- assertStatus(status, 0, 0, 1);
-
- for (int i = 0; i < 60; i++) {
- if (countThreadsByPrefix(prefix) == 0) {
- return;
- }
- Thread.sleep(1000);
- }
- assertEquals(0, countThreadsByPrefix(prefix));
- }
-
- @Test
- public void testValidationException() throws InstanceAlreadyExistsException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- createFixed(transaction, nameInstance, -1, nameInstance);
- try {
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertThat(e.getMessage(), containsString("MaxThreadCount must be greater than zero"));
- }
- }
-
- private ObjectName createFixed(ConfigTransactionJMXClient transaction, String name, int numberOfThreads, String prefix)
- throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), name);
- FixedThreadPoolModuleMXBean mxBean = transaction.newMXBeanProxy(nameCreated, FixedThreadPoolModuleMXBean.class);
- mxBean.setMaxThreadCount(numberOfThreads);
-
- threadFactoryON = transaction.createModule(NamingThreadFactoryModuleFactory.NAME, "naming");
- NamingThreadFactoryModuleMXBean namingThreadFactoryModuleMXBean = transaction.newMXBeanProxy(threadFactoryON,
- NamingThreadFactoryModuleMXBean.class);
- namingThreadFactoryModuleMXBean.setNamePrefix(prefix);
-
- mxBean.setThreadFactory(threadFactoryON);
-
- return nameCreated;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.config.threadpool.fixed;
-
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-import java.util.concurrent.ExecutorService;
-import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.config.manager.impl.AbstractMockedModule;
-import org.opendaylight.controller.config.spi.Module;
-import org.opendaylight.controller.config.threadpool.util.FixedThreadPoolWrapper;
-import org.opendaylight.controller.config.yang.threadpool.ThreadPoolServiceInterface;
-
-public class TestingFixedThreadPoolModule extends AbstractMockedModule implements ThreadPoolServiceInterface, Module {
-
- public TestingFixedThreadPoolModule(DynamicMBeanWithInstance old, ModuleIdentifier id) {
- super(old, id);
- }
-
- @Override
- protected AutoCloseable prepareMockedInstance() throws Exception {
- FixedThreadPoolWrapper pool = mock(FixedThreadPoolWrapper.class);
- doNothing().when(pool).close();
- doReturn(mock(ExecutorService.class)).when(pool).getExecutor();
- return pool;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.config.threadpool.flexible;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-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.NamingThreadFactoryModuleFactory;
-import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleMXBean;
-import org.opendaylight.controller.config.yang.threadpool.impl.flexible.FlexibleThreadPoolModuleFactory;
-import org.opendaylight.controller.config.yang.threadpool.impl.flexible.FlexibleThreadPoolModuleMXBean;
-
-public class FlexibleThreadPoolConfigBeanTest extends AbstractConfigTest {
-
- private FlexibleThreadPoolModuleFactory flexibleFactory;
- private final String instanceName = "flexible1";
- private final String threadFactoryName = "threadFactoryName";
-
- @Before
- public void setUp() {
-
- flexibleFactory = new FlexibleThreadPoolModuleFactory();
- super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext,flexibleFactory,
- new NamingThreadFactoryModuleFactory()));
- }
-
- @Test
- public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException,
- ConflictingVersionException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-
- createFlexible(transaction, instanceName, threadFactoryName, 1, 20, 20);
- transaction.validateConfig();
- CommitStatus status = transaction.commit();
-
- assertBeanCount(1, flexibleFactory.getImplementationName());
- assertStatus(status, 2, 0, 0);
- }
-
- @Test
- public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException,
- ValidationException {
-
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- createFlexible(transaction, instanceName, threadFactoryName, 1, 20, 10);
-
- transaction.commit();
-
- assertBeanCount(1, flexibleFactory.getImplementationName());
-
- transaction = configRegistryClient.createTransaction();
- CommitStatus status = transaction.commit();
-
- assertBeanCount(1, flexibleFactory.getImplementationName());
- assertStatus(status, 0, 0, 2);
-
- }
-
- @Test
- public void testInstanceAlreadyExistsException() throws ConflictingVersionException, ValidationException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-
- try {
- createFlexible(transaction, instanceName, threadFactoryName, 1, 1, 2);
- transaction.commit();
- } catch (InstanceAlreadyExistsException e1) {
- fail();
- }
-
- transaction = configRegistryClient.createTransaction();
- try {
- createFlexible(transaction, instanceName, "threadFactoryName1", 2, 2, 2);
- fail();
- } catch (InstanceAlreadyExistsException e) {
- assertThat(
- e.getMessage(),
- containsString("There is an instance registered with name ModuleIdentifier{factoryName='threadpool-flexible', instanceName='flexible1'}"));
- }
- }
-
- @Test
- public void testValidationException() throws InstanceAlreadyExistsException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-
- createFlexible(transaction, instanceName, threadFactoryName, 0, 10, 10);
-
- try {
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertThat(e.getMessage(), containsString("MinThreadCount must be greater than zero"));
- }
- }
-
- @Test
- public void testValidationException2() throws InstanceAlreadyExistsException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-
- createFlexible(transaction, instanceName, threadFactoryName, 0, 0, 10);
-
- try {
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertThat(e.getMessage(), containsString("KeepAliveMillis must be greater than zero"));
- }
- }
-
- @Test
- public void testValidationException3() throws InstanceAlreadyExistsException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-
- createFlexible(transaction, instanceName, threadFactoryName, 10, 50, 0);
-
- try {
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertThat(e.getMessage(), containsString("MaxThreadCount must be greater than zero"));
- }
- }
-
- private ObjectName createFlexible(ConfigTransactionJMXClient transaction, String instanceName,
- String threadFactoryName, int minThreadCount, long keepAliveMillis, int maxThreadCount)
- throws InstanceAlreadyExistsException {
-
- ObjectName threadFactoryON = transaction.createModule(NamingThreadFactoryModuleFactory.NAME, threadFactoryName);
- NamingThreadFactoryModuleMXBean namingThreadFactoryModuleMXBean = transaction.newMXBeanProxy(threadFactoryON,
- NamingThreadFactoryModuleMXBean.class);
- namingThreadFactoryModuleMXBean.setNamePrefix("prefix");
-
- ObjectName flexibleON = transaction.createModule(flexibleFactory.getImplementationName(), instanceName);
- FlexibleThreadPoolModuleMXBean mxBean = transaction.newMBeanProxy(flexibleON,
- FlexibleThreadPoolModuleMXBean.class);
- mxBean.setKeepAliveMillis(keepAliveMillis);
- mxBean.setMaxThreadCount(maxThreadCount);
- mxBean.setMinThreadCount(minThreadCount);
- mxBean.setThreadFactory(threadFactoryON);
- return flexibleON;
- }
-
- @Test
- public void testReconfigurationInstance() throws InstanceAlreadyExistsException, ValidationException,
- ConflictingVersionException, InstanceNotFoundException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- createFlexible(transaction, instanceName, threadFactoryName, 2, 2, 2);
-
- transaction.commit();
-
- transaction = configRegistryClient.createTransaction();
- ObjectName databaseNew = transaction.lookupConfigBean(flexibleFactory.getImplementationName(), instanceName);
- FlexibleThreadPoolModuleMXBean proxy = transaction.newMXBeanProxy(databaseNew,
- FlexibleThreadPoolModuleMXBean.class);
- proxy.setMaxThreadCount(99);
-
- CommitStatus status = transaction.commit();
-
- assertBeanCount(1, flexibleFactory.getImplementationName());
- assertStatus(status, 0, 1, 1);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.config.threadpool.naming;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-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.ThreadFactoryServiceInterface;
-import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleFactory;
-import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleMXBean;
-
-public class NamingThreadPoolFactoryConfigBeanTest extends AbstractConfigTest {
-
- private NamingThreadFactoryModuleFactory factory;
- private final String instanceName = "named";
-
- @Before
- public void setUp() {
-
- factory = new NamingThreadFactoryModuleFactory();
- super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, factory));
- }
-
- @Test
- public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException,
- ConflictingVersionException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-
- createNamed(transaction, instanceName, "prefixes");
- 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());
- }
-
- @Test
- public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException,
- ValidationException {
-
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- createNamed(transaction, instanceName, "prefixes");
-
- 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,
- InstanceAlreadyExistsException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-
- createNamed(transaction, instanceName, "prefixes");
- transaction.commit();
-
- transaction = configRegistryClient.createTransaction();
- try {
- createNamed(transaction, instanceName, "prefixes1");
- fail();
- } catch (InstanceAlreadyExistsException e) {
- assertThat(
- e.getMessage(),
- containsString("There is an instance registered with name ModuleIdentifier{factoryName='threadfactory-naming', instanceName='named'}"));
- }
- }
-
- @Test
- public void testValidationException() throws InstanceAlreadyExistsException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-
- ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName);
- transaction.newMXBeanProxy(nameCreated, ThreadFactoryServiceInterface.class);
- try {
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertTrue(e.getFailedValidations().containsKey(factory.getImplementationName()));
- assertEquals(1, e.getFailedValidations().get(factory.getImplementationName()).keySet().size());
- }
- }
-
- @Test
- public void testReconfigurationInstance() throws InstanceAlreadyExistsException, ValidationException,
- ConflictingVersionException, InstanceNotFoundException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- createNamed(transaction, instanceName, "pref");
-
- transaction.commit();
-
- transaction = configRegistryClient.createTransaction();
- ObjectName databaseNew = transaction.lookupConfigBean(factory.getImplementationName(), instanceName);
- NamingThreadFactoryModuleMXBean proxy = transaction.newMXBeanProxy(databaseNew,
- NamingThreadFactoryModuleMXBean.class);
- proxy.setNamePrefix("pref1");
-
- CommitStatus status = transaction.commit();
-
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 0, 1, 0);
- }
-
- private ObjectName createNamed(ConfigTransactionJMXClient transaction, String instanceName, String prefixes)
- throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName);
- NamingThreadFactoryModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated,
- NamingThreadFactoryModuleMXBean.class);
- mxBean.setNamePrefix(prefixes);
- return nameCreated;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.config.threadpool.naming;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-import java.io.Closeable;
-import java.io.IOException;
-import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.config.spi.Module;
-import org.opendaylight.controller.config.threadpool.util.NamingThreadPoolFactory;
-import org.opendaylight.controller.config.yang.threadpool.ThreadFactoryServiceInterface;
-import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleMXBean;
-
-public class TestingNamingThreadPoolFactoryModule implements Module, ThreadFactoryServiceInterface,
- NamingThreadFactoryModuleMXBean {
-
- private final NamingThreadPoolFactory fact;
-
- public TestingNamingThreadPoolFactoryModule() throws IOException {
- fact = mock(NamingThreadPoolFactory.class);
- Thread thread = mock(Thread.class);
- doNothing().when(thread).start();
- doReturn(thread).when(fact).newThread(any(Runnable.class));
- doNothing().when(fact).close();
- }
-
- public TestingNamingThreadPoolFactoryModule(DynamicMBeanWithInstance old) {
- fact = (NamingThreadPoolFactory) old.getInstance();
- }
-
- @Override
- public ModuleIdentifier getIdentifier() {
- return new ModuleIdentifier(TestingNamingThreadPoolFactoryModule.class.getCanonicalName(), "mock");
- }
-
- @Override
- public String getNamePrefix() {
- return null;
- }
-
- @Override
- public void setNamePrefix(String arg) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void validate() {
- }
-
- @Override
- public Closeable getInstance() {
- return fact;
- }
-
- @Override
- public boolean canReuse(Module oldModule) {
- return false;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.config.threadpool.scheduled;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
-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.NamingThreadFactoryModuleFactory;
-import org.opendaylight.controller.config.yang.threadpool.impl.NamingThreadFactoryModuleMXBean;
-import org.opendaylight.controller.config.yang.threadpool.impl.scheduled.ScheduledThreadPoolModuleFactory;
-import org.opendaylight.controller.config.yang.threadpool.impl.scheduled.ScheduledThreadPoolModuleMXBean;
-
-public class ScheduledThreadPoolConfigBeanTest extends AbstractConfigTest {
-
- private ScheduledThreadPoolModuleFactory factory;
- private final String instanceName = "scheduled1";
-
- @Before
- public void setUp() {
-
- factory = new ScheduledThreadPoolModuleFactory();
- super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, factory,
- new NamingThreadFactoryModuleFactory()));
- }
-
- @Test
- public void testCreateBean() throws InstanceAlreadyExistsException, ValidationException,
- ConflictingVersionException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
-
- createScheduled(transaction, instanceName, 1);
- transaction.validateConfig();
- CommitStatus status = transaction.commit();
-
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 2, 0, 0);
- }
-
- @Test
- public void testReusingOldInstance() throws InstanceAlreadyExistsException, ConflictingVersionException,
- ValidationException {
-
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- createScheduled(transaction, instanceName, 1);
-
- transaction.commit();
-
- assertBeanCount(1, factory.getImplementationName());
-
- transaction = configRegistryClient.createTransaction();
- CommitStatus status = transaction.commit();
-
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 0, 0, 2);
- }
-
- @Test
- public void testReconfigurationInstance() throws InstanceAlreadyExistsException, ValidationException,
- ConflictingVersionException, InstanceNotFoundException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- createScheduled(transaction, instanceName, 1);
-
- transaction.commit();
-
- transaction = configRegistryClient.createTransaction();
- ObjectName databaseNew = transaction.lookupConfigBean(factory.getImplementationName(), instanceName);
- ScheduledThreadPoolModuleMXBean proxy = transaction.newMXBeanProxy(databaseNew,
- ScheduledThreadPoolModuleMXBean.class);
- proxy.setMaxThreadCount(99);
-
- CommitStatus status = transaction.commit();
-
- assertBeanCount(1, factory.getImplementationName());
- assertStatus(status, 0, 1, 1);
- }
-
- @Test
- public void testDestroy() throws InstanceAlreadyExistsException, ValidationException, ConflictingVersionException,
- InstanceNotFoundException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- createScheduled(transaction, instanceName, 1);
-
- transaction.commit();
-
- transaction = configRegistryClient.createTransaction();
- transaction.destroyModule(factory.getImplementationName(), instanceName);
- CommitStatus status = transaction.commit();
-
- assertBeanCount(0, factory.getImplementationName());
- assertStatus(status, 0, 0, 1);
- }
-
- @Test
- public void testInstanceAlreadyExistsException() throws ConflictingVersionException, ValidationException,
- InstanceAlreadyExistsException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- createScheduled(transaction, instanceName, 1);
- transaction.commit();
- transaction = configRegistryClient.createTransaction();
- try {
- createScheduled(transaction, instanceName, 2);
- fail();
- } catch (InstanceAlreadyExistsException e) {
- assertThat(
- e.getMessage(),
- containsString("There is an instance registered with name ModuleIdentifier{factoryName='threadpool-scheduled', instanceName='scheduled1'}"));
- }
- }
-
- @Test
- public void testValidationException() throws InstanceAlreadyExistsException {
- ConfigTransactionJMXClient transaction = configRegistryClient.createTransaction();
- createScheduled(transaction, instanceName, 0);
-
- try {
- transaction.validateConfig();
- fail();
- } catch (ValidationException e) {
- assertTrue(e.getFailedValidations().containsKey(factory.getImplementationName()));
- assertEquals(1, e.getFailedValidations().get(factory.getImplementationName()).keySet().size());
- }
- }
-
- private ObjectName createScheduled(ConfigTransactionJMXClient transaction, String instanceName, int maxThreadCount)
- throws InstanceAlreadyExistsException {
- ObjectName nameCreated = transaction.createModule(factory.getImplementationName(), instanceName);
- ScheduledThreadPoolModuleMXBean mxBean = transaction.newMBeanProxy(nameCreated,
- ScheduledThreadPoolModuleMXBean.class);
- mxBean.setMaxThreadCount(maxThreadCount);
-
- ObjectName threadFactoryON = transaction.createModule(NamingThreadFactoryModuleFactory.NAME, "naming");
- NamingThreadFactoryModuleMXBean namingThreadFactoryModuleMXBean = transaction.newMXBeanProxy(threadFactoryON,
- NamingThreadFactoryModuleMXBean.class);
- namingThreadFactoryModuleMXBean.setNamePrefix("prefix");
-
- mxBean.setThreadFactory(threadFactoryON);
-
- return nameCreated;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.config.threadpool.scheduled;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-
-import com.google.common.util.concurrent.ListenableFutureTask;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
-import javax.management.ObjectName;
-import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
-import org.opendaylight.controller.config.api.ModuleIdentifier;
-import org.opendaylight.controller.config.manager.impl.AbstractMockedModule;
-import org.opendaylight.controller.config.spi.Module;
-import org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper;
-import org.opendaylight.controller.config.yang.threadpool.ScheduledThreadPoolServiceInterface;
-import org.opendaylight.controller.config.yang.threadpool.impl.scheduled.ScheduledThreadPoolModuleMXBean;
-
-public class TestingScheduledThreadPoolModule extends AbstractMockedModule implements
- ScheduledThreadPoolServiceInterface, Module, ScheduledThreadPoolModuleMXBean {
-
- public TestingScheduledThreadPoolModule(DynamicMBeanWithInstance old, ModuleIdentifier id) {
- super(old, id);
- }
-
- @Override
- protected AutoCloseable prepareMockedInstance() throws Exception {
- ScheduledThreadPoolWrapper instance = mock(ScheduledThreadPoolWrapper.class);
- ScheduledExecutorService ses = mock(ScheduledExecutorService.class);
- {// mockFuture
- ScheduledFuture<?> future = mock(ScheduledFuture.class);
- doReturn(false).when(future).cancel(anyBoolean());
- try {
- doReturn(mock(Object.class)).when(future).get();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- doReturn(future).when(ses).schedule(any(Runnable.class), any(Long.class), any(TimeUnit.class));
- doReturn(future).when(ses).scheduleWithFixedDelay(any(Runnable.class), anyLong(), anyLong(),
- any(TimeUnit.class));
-
- }
- doNothing().when(ses).execute(any(Runnable.class));
- doNothing().when(ses).execute(any(ListenableFutureTask.class));
- doReturn(ses).when(instance).getExecutor();
- doNothing().when(instance).close();
-
- doReturn(1).when(instance).getMaxThreadCount();
- return instance;
- }
-
- @Override
- public ObjectName getThreadFactory() {
- return any(ObjectName.class);
- }
-
- @Override
- public void setThreadFactory(ObjectName threadFactory) {
- }
-
- @Override
- public Integer getMaxThreadCount() {
- return 1;
- }
-
- @Override
- public void setMaxThreadCount(Integer maxThreadCount) {
- }
-
-}
</configuration>
<required-capabilities>
<capability>urn:opendaylight:params:xml:ns:yang:controller:netty:eventexecutor?module=netty-event-executor&revision=2013-11-12</capability>
- <capability>urn:opendaylight:params:xml:ns:yang:controller:threadpool?module=threadpool&revision=2013-04-09</capability>
<capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding?module=opendaylight-md-sal-binding&revision=2013-10-28</capability>
<capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom?module=opendaylight-md-sal-dom&revision=2013-10-28</capability>
<capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding:impl?module=opendaylight-sal-binding-broker-impl&revision=2013-10-28</capability>