BUG-650: Split out CommitCoordinationTask
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / testingservices / parallelapsp / TestingParallelAPSPModule.java
index 81ba49e1aaad9ac6ef53d82404cfe8f9b481f027..5c320ae2c159b6bdd132ad6fd1e5a15d4db33bd3 100644 (file)
@@ -10,24 +10,22 @@ package org.opendaylight.controller.config.manager.testingservices.parallelapsp;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 
+import com.google.common.base.Strings;
 import java.io.Closeable;
-
 import javax.annotation.Nullable;
 import javax.annotation.concurrent.NotThreadSafe;
 import javax.management.ObjectName;
-
 import org.opendaylight.controller.config.api.DependencyResolver;
 import org.opendaylight.controller.config.api.JmxAttribute;
 import org.opendaylight.controller.config.api.ModuleIdentifier;
 import org.opendaylight.controller.config.api.annotations.RequireInterface;
 import org.opendaylight.controller.config.manager.testingservices.seviceinterface.TestingThreadPoolServiceInterface;
+import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingThreadPoolConfigMXBean;
 import org.opendaylight.controller.config.manager.testingservices.threadpool.TestingThreadPoolIfc;
 import org.opendaylight.controller.config.spi.Module;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Strings;
-
 /**
  * Represents service that has dependency to thread pool.
  */
@@ -40,26 +38,21 @@ public class TestingParallelAPSPModule implements Module,
     private final DependencyResolver dependencyResolver;
     private final AutoCloseable oldCloseable;
     private final TestingParallelAPSPImpl oldInstance;
-    private final ModuleIdentifier name;
+    private final ModuleIdentifier identifier;
     private ObjectName threadPoolON;
     private TestingParallelAPSPImpl instance;
     private String someParam;
 
-    public TestingParallelAPSPModule(ModuleIdentifier name,
+    public TestingParallelAPSPModule(ModuleIdentifier identifier,
             DependencyResolver dependencyResolver,
             @Nullable AutoCloseable oldCloseable,
             @Nullable TestingParallelAPSPImpl oldInstance) {
-        this.name = name;
+        this.identifier = identifier;
         this.dependencyResolver = dependencyResolver;
         this.oldCloseable = oldCloseable;
         this.oldInstance = oldInstance;
     }
 
-    @Override
-    public ModuleIdentifier getName() {
-        return name;
-    }
-
     @Override
     public ObjectName getThreadPool() {
         return threadPoolON;
@@ -109,6 +102,17 @@ public class TestingParallelAPSPModule implements Module,
             checkState("Commit was not triggered".equals(e.getMessage()),
                     e.getMessage());
         }
+
+        // test retrieving dependent module's attribute
+        int threadCount;
+        try {
+            threadCount = (Integer)dependencyResolver.getAttribute(threadPoolON, "ThreadCount");
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+        checkState(threadCount > 0);
+        TestingThreadPoolConfigMXBean proxy = dependencyResolver.newMXBeanProxy(threadPoolON, TestingThreadPoolConfigMXBean.class);
+        checkState(threadCount == proxy.getThreadCount());
     }
 
     @Override
@@ -119,8 +123,7 @@ public class TestingParallelAPSPModule implements Module,
 
             if (oldInstance != null) {
                 // changing thread pool is not supported
-                boolean reuse = threadPoolInstance.equals(oldInstance
-                        .getThreadPool());
+                boolean reuse = threadPoolInstance == oldInstance.getThreadPool();
                 if (reuse) {
                     logger.debug("Reusing old instance");
                     instance = oldInstance;
@@ -142,4 +145,11 @@ public class TestingParallelAPSPModule implements Module,
         }
         return instance;
     }
+
+    @Override
+    public ModuleIdentifier getIdentifier() {
+        return identifier;
+    }
+
+
 }