import com.google.common.util.concurrent.Futures;
import io.netty.util.HashedWheelTimer;
+import java.util.concurrent.ExecutorService;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration;
import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
+import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.OwnershipChangeListener;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig;
@RunWith(MockitoJUnitRunner.class)
public class ContextChainHolderImplTest {
@Mock
private ClusterSingletonServiceProvider singletonServicesProvider;
@Mock
+ private ExecutorService executorService;
+ @Mock
+ private ClusterSingletonServiceRegistration clusterSingletonServiceRegistration;
+ @Mock
private EntityOwnershipService entityOwnershipService;
+ @Mock
+ private EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
+ @Mock
+ private OwnershipChangeListener ownershipChangeListener;
+ @Mock
+ private OpenflowProviderConfig config;
private ContextChainHolderImpl contextChainHolder;
@Before
public void setUp() throws Exception {
- contextChainHolder = new ContextChainHolderImpl(timer);
- contextChainHolder.addManager(statisticsManager);
- contextChainHolder.addManager(rpcManager);
- contextChainHolder.addManager(deviceManager);
- contextChainHolder.addSingletonServicesProvider(singletonServicesProvider);
+ Mockito.doAnswer(invocation -> {
+ invocation.getArgumentAt(0, Runnable.class).run();
+ return null;
+ }).when(executorService).submit(Mockito.<Runnable>any());
+
+
Mockito.when(connectionContext.getDeviceInfo()).thenReturn(deviceInfo);
Mockito.when(deviceManager.createContext(connectionContext)).thenReturn(deviceContext);
- Mockito.when(rpcManager.createContext(
- deviceInfo,
- deviceContext))
- .thenReturn(rpcContext);
+ Mockito.when(rpcManager.createContext(deviceContext)).thenReturn(rpcContext);
Mockito.when(statisticsManager.createContext(deviceContext)).thenReturn(statisticsContext);
Mockito.when(deviceContext.makeDeviceSlave()).thenReturn(Futures.immediateFuture(null));
+ Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
+
+ Mockito.when(singletonServicesProvider.registerClusterSingletonService(Mockito.any()))
+ .thenReturn(clusterSingletonServiceRegistration);
+ Mockito.when(entityOwnershipService.registerListener(Mockito.any(), Mockito.any()))
+ .thenReturn(entityOwnershipListenerRegistration);
+ Mockito.when(config.isUsingReconciliationFramework()).thenReturn(false);
+
+ contextChainHolder = new ContextChainHolderImpl(
+ timer,
+ executorService,
+ singletonServicesProvider,
+ entityOwnershipService,
+ ownershipChangeListener,
+ config);
+ contextChainHolder.addManager(statisticsManager);
+ contextChainHolder.addManager(rpcManager);
+ contextChainHolder.addManager(deviceManager);
}
@Test
public void createContextChain() throws Exception {
contextChainHolder.createContextChain(connectionContext);
Mockito.verify(deviceManager).createContext(Mockito.any(ConnectionContext.class));
- Mockito.verify(rpcManager).createContext(Mockito.any(DeviceInfo.class), Mockito.any(DeviceContext.class));
+ Mockito.verify(rpcManager).createContext(Mockito.any(DeviceContext.class));
Mockito.verify(statisticsManager).createContext(Mockito.any(DeviceContext.class));
}