*/
package org.opendaylight.controller.config.manager.impl;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+
import com.google.common.base.Preconditions;
+import java.io.File;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Dictionary;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.RuntimeMBeanException;
import org.junit.After;
import org.junit.Before;
import org.mockito.Matchers;
import org.opendaylight.controller.config.manager.impl.jmx.BaseJMXRegistrator;
import org.opendaylight.controller.config.manager.impl.jmx.ConfigRegistryJMXRegistrator;
import org.opendaylight.controller.config.manager.impl.jmx.InternalJMXRegistrator;
+import org.opendaylight.controller.config.manager.impl.jmx.JMXNotifierConfigRegistry;
+import org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider;
import org.opendaylight.controller.config.manager.testingservices.scheduledthreadpool.TestingScheduledThreadPoolImpl;
import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingFixedThreadPool;
import org.opendaylight.controller.config.spi.Module;
import org.opendaylight.controller.config.util.ConfigRegistryJMXClient;
import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
-import org.opendaylight.yangtools.yang.data.impl.codec.CodecRegistry;
+import org.opendaylight.yangtools.sal.binding.generator.api.ClassLoadingStrategy;
+import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.management.RuntimeMBeanException;
-import java.lang.management.ManagementFactory;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.Dictionary;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
-
/**
* Each test that relies on
* {@link org.opendaylight.controller.config.manager.impl.ConfigRegistryImpl}
AbstractLockedPlatformMBeanServerTest {
protected ConfigRegistryJMXRegistrator configRegistryJMXRegistrator;
protected ConfigRegistryImpl configRegistry;
+ private JMXNotifierConfigRegistry notifyingConfigRegistry;
protected ConfigRegistryJMXClient configRegistryClient;
protected BaseJMXRegistrator baseJmxRegistrator;
protected InternalJMXRegistrator internalJmxRegistrator;
internalJmxRegistrator = new InternalJMXRegistrator(platformMBeanServer);
baseJmxRegistrator = new BaseJMXRegistrator(internalJmxRegistrator);
- configRegistry = new ConfigRegistryImpl(resolver,
- platformMBeanServer, baseJmxRegistrator, getCodecRegistry());
+ configRegistry = new ConfigRegistryImpl(resolver, platformMBeanServer, baseJmxRegistrator, new BindingContextProvider() {
+ @Override
+ public synchronized void update(final ClassLoadingStrategy classLoadingStrategy, final SchemaContextProvider ctxProvider) {
+ // NOOP
+ }
+
+ @Override
+ public synchronized BindingRuntimeContext getBindingContext() {
+ return getBindingRuntimeContext();
+ }
+ });
+ notifyingConfigRegistry = new JMXNotifierConfigRegistry(this.configRegistry, platformMBeanServer);
try {
- configRegistryJMXRegistrator.registerToJMX(configRegistry);
+ configRegistryJMXRegistrator.registerToJMXNoNotifications(configRegistry);
+ configRegistryJMXRegistrator.registerToJMX(notifyingConfigRegistry);
} catch (InstanceAlreadyExistsException e) {
throw new RuntimeException(e);
}
@After
public final void cleanUpConfigTransactionManagerImpl() {
configRegistryJMXRegistrator.close();
+ notifyingConfigRegistry.close();
configRegistry.close();
TestingFixedThreadPool.cleanUp();
TestingScheduledThreadPoolImpl.cleanUp();
return new ClassBasedModuleFactory(implementationName, configBeanClass);
}
- protected CodecRegistry getCodecRegistry() {
- return mock(CodecRegistry.class);
+ protected BindingRuntimeContext getBindingRuntimeContext() {
+ return mock(BindingRuntimeContext.class);
}
public static interface BundleContextServiceRegistrationHandler {
- void handleServiceRegistration(Class<?> clazz, Object serviceInstance, Dictionary<String, ?> props);
+ void handleServiceRegistration(Class<?> clazz, Object serviceInstance, Dictionary<String, ?> props);
}
Object serviceTypeRaw = args[0];
Object serviceInstance = args[1];
- Dictionary<String, ?> props = (Dictionary) args[2];
+ Dictionary<String, ?> props = (Dictionary<String, ?>) args[2];
if (serviceTypeRaw instanceof Class) {
Class<?> serviceType = (Class<?>) serviceTypeRaw;
Object proxy = Proxy.newProxyInstance(innerObject.getClass().getClassLoader(),
innerObject.getClass().getInterfaces(), new InvocationHandler() {
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- try {
- return method.invoke(innerObject, args);
- } catch (InvocationTargetException e) {
- try {
- throw e.getTargetException();
- } catch (RuntimeMBeanException e2) {
- throw e2.getTargetException();
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ try {
+ return method.invoke(innerObject, args);
+ } catch (InvocationTargetException e) {
+ try {
+ throw e.getTargetException();
+ } catch (RuntimeMBeanException e2) {
+ throw e2.getTargetException();
+ }
+ }
+ }
}
- }
- }
- });
+ );
return (T) proxy;
}
+ /**
+ * removes contents of the directory
+ * @param dir to be cleaned
+ * @throws IOException
+ */
+ protected void cleanDirectory(File dir) throws IOException {
+ if (!dir.isDirectory()) {
+ throw new IllegalStateException("dir must be a directory");
+ }
+
+ final File[] files = dir.listFiles();
+ if (files == null) {
+ throw new IOException("Failed to list contents of " + dir);
+ }
+
+ for (File file : files) {
+ if (file.isDirectory()) {
+ cleanDirectory(dir);
+ }
+ file.delete();
+ }
+ }
+
}