Merge "Bug 4957 TxChainManager lifecycle startup cleaning"
authormichal rehak <mirehak@cisco.com>
Tue, 9 Feb 2016 09:20:27 +0000 (09:20 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 9 Feb 2016 09:20:27 +0000 (09:20 +0000)
12 files changed:
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/handlers/DeviceConnectedHandler.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/HandshakeListenerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/ReadyForNewTransactionChainHandler.java [deleted file]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/ReadyForNewTransactionChainHandlerImpl.java [deleted file]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/TransactionChainManager.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/ConnectionManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceTransactionChainManagerProviderTest.java [deleted file]
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/ReadyForNewTransactionChainHandlerImplTest.java [deleted file]
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/TransactionChainManagerTest.java

index 24b893f6fb0dd85b82cf5031958ff5ee82516976..005a2de0583ec4ab543e34323a417f6bf721b61d 100644 (file)
@@ -19,6 +19,6 @@ public interface DeviceConnectedHandler {
      * Method is used to propagate information about established connection with device.
      * It propagates connected device's connection context.
      */
-    void deviceConnected(ConnectionContext connectionContext);
+    void deviceConnected(ConnectionContext connectionContext) throws Exception;
 
 }
index 4908331a52c274ff284839b3dd4ae0edc1019a13..7b712904f0973ff0e359fe5463c68cebdd66f402 100644 (file)
@@ -170,7 +170,7 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
 
         registerMXBean(messageIntelligenceAgency);
 
-        deviceManager = new DeviceManagerImpl(dataBroker, messageIntelligenceAgency, switchFeaturesMandatory, globalNotificationQuota);
+        deviceManager = new DeviceManagerImpl(dataBroker, messageIntelligenceAgency, globalNotificationQuota);
         ((ExtensionConverterProviderKeeper) deviceManager).setExtensionConverterProvider(extensionConverterManager);
         roleManager = new RoleManagerImpl(rpcProviderRegistry, entityOwnershipService, switchFeaturesMandatory);
         statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, isStatisticsPollingOff);
index c8f0600edf866903a2f4bfc45545e7c8e304d53e..3ea654fe22364c722947a7f8c553f3f45b9f1380 100644 (file)
@@ -61,9 +61,16 @@ public class HandshakeListenerImpl implements HandshakeListener {
             @Override
             public void onSuccess(@Nullable final RpcResult<BarrierOutput> result) {
                 LOG.debug("succeeded by getting sweep barrier after posthandshake for device {}", connectionContext.getNodeId());
-                deviceConnectedHandler.deviceConnected(connectionContext);
-                SessionStatistics.countEvent(connectionContext.getNodeId().toString(),
-                        SessionStatistics.ConnectionStatus.CONNECTION_CREATED);
+                try {
+                    deviceConnectedHandler.deviceConnected(connectionContext);
+                    SessionStatistics.countEvent(connectionContext.getNodeId().toString(),
+                            SessionStatistics.ConnectionStatus.CONNECTION_CREATED);
+                } catch (Exception e) {
+                    LOG.info("ConnectionContext initial processing failed: {}", e.getMessage());
+                    SessionStatistics.countEvent(connectionContext.getNodeId().toString(),
+                            SessionStatistics.ConnectionStatus.CONNECTION_DISCONNECTED_BY_OFP);
+                    connectionContext.closeConnection(false);
+                }
             }
 
             @Override
index b5a99013b7ea988a08800e7a08cb60afb88b0f47..0c42b68d5f12d0e233287b0887d992dd0ef659a5 100644 (file)
@@ -10,13 +10,12 @@ package org.opendaylight.openflowplugin.impl.device;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import java.util.Collections;
-import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Sets;
 import io.netty.util.HashedWheelTimer;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
@@ -65,18 +64,16 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
     private NotificationService notificationService;
     private NotificationPublishService notificationPublishService;
 
-    private final Set<DeviceContext> deviceContexts = Sets.newConcurrentHashSet();
+    private final ConcurrentHashMap<NodeId, DeviceContext> deviceContexts = new ConcurrentHashMap<>();
     private final MessageIntelligenceAgency messageIntelligenceAgency;
 
     private final long barrierNanos = TimeUnit.MILLISECONDS.toNanos(500);
     private final int maxQueueDepth = 25600;
-    private final boolean switchFeaturesMandatory;
     private final DeviceTransactionChainManagerProvider deviceTransactionChainManagerProvider;
     private ExtensionConverterProvider extensionConverterProvider;
 
     public DeviceManagerImpl(@Nonnull final DataBroker dataBroker,
                              @Nonnull final MessageIntelligenceAgency messageIntelligenceAgency,
-                             final boolean switchFeaturesMandatory,
                              final long globalNotificationQuota) {
         this.globalNotificationQuota = globalNotificationQuota;
         this.dataBroker = Preconditions.checkNotNull(dataBroker);
@@ -95,7 +92,6 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
         }
 
         this.messageIntelligenceAgency = messageIntelligenceAgency;
-        this.switchFeaturesMandatory = switchFeaturesMandatory;
         deviceTransactionChainManagerProvider = new DeviceTransactionChainManagerProvider(dataBroker);
     }
 
@@ -138,17 +134,14 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
     }
 
     @Override
-    public void deviceConnected(@CheckForNull final ConnectionContext connectionContext) {
+    public void deviceConnected(@CheckForNull final ConnectionContext connectionContext) throws Exception {
         Preconditions.checkArgument(connectionContext != null);
-        try {
-            initializeDeviceContext(connectionContext);
-        } catch (Exception e) {
-            LOG.warn("Exception during initialization phase.", e);
-        }
-    }
+        Preconditions.checkState(!deviceContexts.containsKey(connectionContext.getNodeId()),
+                "Rejecting connection from node which is already connected and there exist deviceContext for it: {}",
+                connectionContext.getNodeId()
+        );
+        LOG.info("Initializing New Connection DeviceContext for node:{}", connectionContext.getNodeId());
 
-    private void initializeDeviceContext(final ConnectionContext connectionContext) throws Exception{
-        LOG.info("Initializing New Connection DeviceContext for node:{}",  connectionContext.getNodeId());
         // Cache this for clarity
         final ConnectionAdapter connectionAdapter = connectionContext.getConnectionAdapter();
 
@@ -163,13 +156,13 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
                 connectionAdapter.registerOutboundQueueHandler(outboundQueueProvider, maxQueueDepth, barrierNanos);
         connectionContext.setOutboundQueueHandleRegistration(outboundQueueHandlerRegistration);
 
-        final NodeId nodeId = connectionContext.getNodeId();
-        final DeviceState deviceState = new DeviceStateImpl(connectionContext.getFeatures(), nodeId);
-
+        final DeviceState deviceState = createDeviceState(connectionContext);
         final DeviceContext deviceContext = new DeviceContextImpl(connectionContext, deviceState, dataBroker,
                 hashedWheelTimer, messageIntelligenceAgency, outboundQueueProvider, translatorLibrary);
 
         deviceContext.addDeviceContextClosedHandler(this);
+        deviceContexts.put(connectionContext.getNodeId(), deviceContext);
+
         // We would like to crete/register TxChainManager after
         final DeviceTransactionChainManagerProvider.TransactionChainManagerRegistration txChainManagerReg = deviceTransactionChainManagerProvider
                 .provideTransactionChainManager(connectionContext);
@@ -181,11 +174,11 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
             deviceContext.close();
             return;
         }
+
         ((ExtensionConverterProviderKeeper) deviceContext).setExtensionConverterProvider(extensionConverterProvider);
         deviceContext.setNotificationService(notificationService);
         deviceContext.setNotificationPublishService(notificationPublishService);
 
-        deviceContexts.add(deviceContext);
 
         updatePacketInRateLimiters();
 
@@ -196,6 +189,10 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
         deviceCtxLevelUp(deviceContext);
     }
 
+    private static DeviceStateImpl createDeviceState(final @Nonnull ConnectionContext connectionContext) {
+        return new DeviceStateImpl(connectionContext.getFeatures(), connectionContext.getNodeId());
+    }
+
     private void updatePacketInRateLimiters() {
         synchronized (deviceContexts) {
             final int deviceContextsSize = deviceContexts.size();
@@ -205,7 +202,7 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
                     freshNotificationLimit = 100;
                 }
                 LOG.debug("fresh notification limit = {}", freshNotificationLimit);
-                for (DeviceContext deviceContext : deviceContexts) {
+                for (final DeviceContext deviceContext : deviceContexts.values()) {
                     deviceContext.updatePacketInRateLimit(freshNotificationLimit);
                 }
             }
@@ -240,14 +237,15 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
 
     @Override
     public void close() throws Exception {
-        for (final DeviceContext deviceContext : deviceContexts) {
+        for (final DeviceContext deviceContext : deviceContexts.values()) {
             deviceContext.close();
         }
     }
 
     @Override
     public void onDeviceContextClosed(final DeviceContext deviceContext) {
-        deviceContexts.remove(deviceContext);
+        LOG.trace("onDeviceContextClosed for Node {}", deviceContext.getDeviceState().getNodeId());
+        deviceContexts.remove(deviceContext.getPrimaryConnectionContext().getNodeId());
         updatePacketInRateLimiters();
     }
 
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/ReadyForNewTransactionChainHandler.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/ReadyForNewTransactionChainHandler.java
deleted file mode 100644 (file)
index 255e4cf..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Copyright (c) 2015 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.openflowplugin.impl.device;
-
-/**
- * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 2.6.2015.
- */
-public interface ReadyForNewTransactionChainHandler {
-
-    void onReadyForNewTransactionChain();
-}
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/ReadyForNewTransactionChainHandlerImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/ReadyForNewTransactionChainHandlerImpl.java
deleted file mode 100644 (file)
index 76ead2f..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2015 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.openflowplugin.impl.device;
-
-import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
-
-/**
- * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 5.6.2015.
- */
-public class ReadyForNewTransactionChainHandlerImpl implements ReadyForNewTransactionChainHandler {
-
-    private final DeviceManager deviceManager;
-    private final ConnectionContext connectionContext;
-
-    public ReadyForNewTransactionChainHandlerImpl(final DeviceManager deviceManager, final ConnectionContext connectionContext) {
-        this.deviceManager = deviceManager;
-        this.connectionContext = connectionContext;
-    }
-
-    @Override
-    public void onReadyForNewTransactionChain() {
-        deviceManager.deviceConnected(connectionContext);
-    }
-}
index ce1f0368ce8203f02f62cd2b7e58695d3a801dd1..9f3450e449daa7dde55cbc304a8927eff5016cb1 100644 (file)
@@ -59,8 +59,7 @@ class TransactionChainManager implements TransactionChainListener, AutoCloseable
         return transactionChainManagerStatus;
     }
 
-    private TransactionChainManagerStatus transactionChainManagerStatus;
-    private ReadyForNewTransactionChainHandler readyForNewTransactionChainHandler;
+    private volatile TransactionChainManagerStatus transactionChainManagerStatus;
     private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
     private volatile Registration managerRegistration;
 
@@ -84,18 +83,6 @@ class TransactionChainManager implements TransactionChainListener, AutoCloseable
         submitWriteTransaction();
     }
 
-    public synchronized boolean attemptToRegisterHandler(final ReadyForNewTransactionChainHandler readyForNewTransactionChainHandler) {
-        if (TransactionChainManagerStatus.SHUTTING_DOWN.equals(this.transactionChainManagerStatus)
-                && null == this.readyForNewTransactionChainHandler) {
-            this.readyForNewTransactionChainHandler = readyForNewTransactionChainHandler;
-            if (managerRegistration == null) {
-                this.readyForNewTransactionChainHandler.onReadyForNewTransactionChain();
-            }
-            return true;
-        } else {
-            return false;
-        }
-    }
 
     boolean submitWriteTransaction() {
         if (!submitIsEnabled) {
@@ -248,9 +235,6 @@ class TransactionChainManager implements TransactionChainListener, AutoCloseable
                 LOG.warn("Failed to close transaction chain manager's registration.", e);
             }
             managerRegistration = null;
-            if (null != readyForNewTransactionChainHandler) {
-                readyForNewTransactionChainHandler.onReadyForNewTransactionChain();
-            }
         }
         txChainFactory.close();
         txChainFactory = null;
index 0f228516affb5d98396a2ce78820b7af0413e737..3c3f5c1bde3fbda6015ac6cd43c7a392dca9d701 100644 (file)
@@ -90,7 +90,7 @@ public class ConnectionManagerImplTest {
      * @throws InterruptedException
      */
     @Test
-    public void testOnSwitchConnected1() throws InterruptedException {
+    public void testOnSwitchConnected1() throws Exception {
         connectionManagerImpl.onSwitchConnected(connection);
         Mockito.verify(connection).setConnectionReadyListener(connectionReadyListenerAC.capture());
         Mockito.verify(connection).setMessageListener(ofpListenerAC.capture());
@@ -141,7 +141,7 @@ public class ConnectionManagerImplTest {
      * @throws InterruptedException
      */
     @Test
-    public void testOnSwitchConnected2() throws InterruptedException {
+    public void testOnSwitchConnected2() throws Exception {
         connectionManagerImpl.onSwitchConnected(connection);
         Mockito.verify(connection).setConnectionReadyListener(connectionReadyListenerAC.capture());
         Mockito.verify(connection).setMessageListener(ofpListenerAC.capture());
index e2d969712dd62e96415d917e10ecaf799316ce64..94ef781bcad22c4c68eba75298c22381a11c4a4b 100644 (file)
@@ -21,7 +21,7 @@ import static org.mockito.Mockito.when;
 import java.lang.reflect.Field;
 import java.math.BigInteger;
 import java.util.Collections;
-import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
@@ -98,6 +98,8 @@ public class DeviceManagerImplTest {
     private ConnectionAdapter mockedConnectionAdapter;
     @Mock
     private DeviceContextImpl mockedDeviceContext;
+    @Mock
+    private NodeId mockedNodeId;
 
     @Before
     public void setUp() throws Exception {
@@ -143,7 +145,7 @@ public class DeviceManagerImplTest {
         when(mockedWriteTransaction.submit()).thenReturn(mockedFuture);
 
         MessageIntelligenceAgency mockedMessageIntelligenceAgency = mock(MessageIntelligenceAgency.class);
-        DeviceManagerImpl deviceManager = new DeviceManagerImpl(mockedDataBroker, mockedMessageIntelligenceAgency, TEST_VALUE_SWITCH_FEATURE_MANDATORY,
+        DeviceManagerImpl deviceManager = new DeviceManagerImpl(mockedDataBroker, mockedMessageIntelligenceAgency,
                 TEST_VALUE_GLOBAL_NOTIFICATION_QUOTA);
         deviceManager.setDeviceInitializationPhaseHandler(deviceInitPhaseHandler);
 
@@ -170,7 +172,7 @@ public class DeviceManagerImplTest {
     }
 
     @Test
-    public void deviceConnectedTest() {
+    public void deviceConnectedTest() throws Exception{
         DeviceManagerImpl deviceManager = prepareDeviceManager();
         injectMockTranslatorLibrary(deviceManager);
         ConnectionContext mockConnectionContext = buildMockConnectionContext(OFConstants.OFP_VERSION_1_3);
@@ -187,7 +189,7 @@ public class DeviceManagerImplTest {
     }
 
     @Test
-    public void deviceConnectedV10Test() {
+    public void deviceConnectedV10Test() throws Exception{
         DeviceManagerImpl deviceManager = prepareDeviceManager();
         injectMockTranslatorLibrary(deviceManager);
         ConnectionContext mockConnectionContext = buildMockConnectionContext(OFConstants.OFP_VERSION_1_0);
@@ -247,8 +249,8 @@ public class DeviceManagerImplTest {
     public void testClose() throws Exception {
         DeviceContext deviceContext = Mockito.mock(DeviceContext.class);
         final DeviceManagerImpl deviceManager = prepareDeviceManager();
-        final Set<DeviceContext> deviceContexts = getContextsCollection(deviceManager);
-        deviceContexts.add(deviceContext);
+        final ConcurrentHashMap<NodeId, DeviceContext> deviceContexts = getContextsCollection(deviceManager);
+        deviceContexts.put(mockedNodeId, deviceContext);
         Assert.assertEquals(1, deviceContexts.size());
 
         deviceManager.close();
@@ -256,12 +258,12 @@ public class DeviceManagerImplTest {
         Mockito.verify(deviceContext).close();
     }
 
-    private static Set<DeviceContext> getContextsCollection(DeviceManagerImpl deviceManager) throws NoSuchFieldException, IllegalAccessException {
+    private static ConcurrentHashMap<NodeId, DeviceContext> getContextsCollection(DeviceManagerImpl deviceManager) throws NoSuchFieldException, IllegalAccessException {
         // HACK: contexts collection for testing shall be accessed in some more civilized way
         final Field contextsField = DeviceManagerImpl.class.getDeclaredField("deviceContexts");
         Assert.assertNotNull(contextsField);
         contextsField.setAccessible(true);
-        return (Set<DeviceContext>) contextsField.get(deviceManager);
+        return (ConcurrentHashMap<NodeId, DeviceContext>) contextsField.get(deviceManager);
     }
 
 }
diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceTransactionChainManagerProviderTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceTransactionChainManagerProviderTest.java
deleted file mode 100644 (file)
index e4691fd..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (c) 2015 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.openflowplugin.impl.device;
-
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.SettableFuture;
-import javax.annotation.Nullable;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Matchers;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-
-@RunWith(MockitoJUnitRunner.class)
-public class DeviceTransactionChainManagerProviderTest {
-
-
-    @Mock
-    DataBroker dataBroker;
-    @Mock
-    ConnectionContext connectionContext;
-    @Mock
-    ConnectionContext concurrentConnectionContex;
-    @Mock
-    private BindingTransactionChain txChain;
-    @Mock
-    DeviceManager deviceManager;
-    @Mock
-    private WriteTransaction writeTx;
-    @Mock
-    private ReadyForNewTransactionChainHandler readyForNewTransactionChainHandler;
-
-    private static final NodeId nodeId = new NodeId("OPF:TEST");
-    private DeviceTransactionChainManagerProvider deviceTransactionChainManagerProvider;
-
-    @Before
-    public void setup() {
-        deviceTransactionChainManagerProvider = new DeviceTransactionChainManagerProvider(dataBroker);
-        Mockito.when(connectionContext.getNodeId()).thenReturn(nodeId);
-        Mockito.when(concurrentConnectionContex.getNodeId()).thenReturn(nodeId);
-
-        final ReadOnlyTransaction readOnlyTx = Mockito.mock(ReadOnlyTransaction.class);
-        //final CheckedFuture<Optional<Node>, ReadFailedException> noExistNodeFuture = Futures.immediateCheckedFuture(Optional.<Node>absent());
-//        Mockito.when(readOnlyTx.read(LogicalDatastoreType.OPERATIONAL, nodeKeyIdent)).thenReturn(noExistNodeFuture);
-        Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTx);
-        Mockito.when(dataBroker.createTransactionChain(Matchers.any(TransactionChainListener.class)))
-                .thenReturn(txChain);
-
-//        nodeKeyIdent = DeviceStateUtil.createNodeInstanceIdentifier(nodeId);
-//        txChainManager = new TransactionChainManager(dataBroker, nodeKeyIdent, registration);
-        Mockito.when(txChain.newWriteOnlyTransaction()).thenReturn(writeTx);
-
-//        path = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
-//        Mockito.when(writeTx.submit()).thenReturn(Futures.<Void, TransactionCommitFailedException>immediateCheckedFuture(null));
-    }
-
-    /**
-     * This test verifies code path for registering new connection when no {@link org.opendaylight.openflowplugin.impl.device.TransactionChainManager}
-     * is present in registry.
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testProvideTransactionChainManagerOrWaitForNotification1() throws Exception {
-        DeviceTransactionChainManagerProvider.TransactionChainManagerRegistration transactionChainManagerRegistration = deviceTransactionChainManagerProvider.provideTransactionChainManager(connectionContext);
-        final TransactionChainManager txChainManager = transactionChainManagerRegistration.getTransactionChainManager();
-
-        Assert.assertTrue(transactionChainManagerRegistration.ownedByInvokingConnectionContext());
-        Assert.assertNotNull(txChainManager);
-        Assert.assertEquals(TransactionChainManager.TransactionChainManagerStatus.WORKING, txChainManager.getTransactionChainManagerStatus());
-    }
-
-    /**
-     * This test verifies code path for registering new connection when {@link org.opendaylight.openflowplugin.impl.device.TransactionChainManager}
-     * is present in registry.
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testProvideTransactionChainManagerOrWaitForNotification2() throws Exception {
-        DeviceTransactionChainManagerProvider.TransactionChainManagerRegistration transactionChainManagerRegistration_1 = deviceTransactionChainManagerProvider.provideTransactionChainManager(connectionContext);
-        Assert.assertEquals(TransactionChainManager.TransactionChainManagerStatus.WORKING, transactionChainManagerRegistration_1.getTransactionChainManager().getTransactionChainManagerStatus());
-        DeviceTransactionChainManagerProvider.TransactionChainManagerRegistration transactionChainManagerRegistration_2 = deviceTransactionChainManagerProvider.provideTransactionChainManager(concurrentConnectionContex);
-        Assert.assertFalse(transactionChainManagerRegistration_2.ownedByInvokingConnectionContext());
-    }
-
-    /**
-     * This test verifies code path for registering new connection when {@link org.opendaylight.openflowplugin.impl.device.TransactionChainManager}
-     * is present in registry and in SHUTTING_DOWN state (finished).
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testProvideTransactionChainManagerRecreate1() throws Exception {
-        DeviceTransactionChainManagerProvider.TransactionChainManagerRegistration txChainManagerRegistration_1 = deviceTransactionChainManagerProvider.provideTransactionChainManager(connectionContext);
-        final TransactionChainManager txChainManager = txChainManagerRegistration_1.getTransactionChainManager();
-        Assert.assertTrue(txChainManagerRegistration_1.ownedByInvokingConnectionContext());
-        Assert.assertNotNull(txChainManager);
-        Assert.assertEquals(TransactionChainManager.TransactionChainManagerStatus.WORKING,
-                txChainManagerRegistration_1.getTransactionChainManager().getTransactionChainManagerStatus());
-
-        CheckedFuture<Void, TransactionCommitFailedException> checkedSubmitCleanFuture = Futures.immediateCheckedFuture(null);
-        Mockito.when(writeTx.submit()).thenReturn(checkedSubmitCleanFuture);
-        txChainManager.close();
-        Assert.assertEquals(TransactionChainManager.TransactionChainManagerStatus.SHUTTING_DOWN,
-                txChainManagerRegistration_1.getTransactionChainManager().getTransactionChainManagerStatus());
-        txChainManager.attemptToRegisterHandler(readyForNewTransactionChainHandler);
-        Mockito.verify(readyForNewTransactionChainHandler).onReadyForNewTransactionChain();
-    }
-
-
-    /**
-     * This test verifies code path for registering new connection when {@link org.opendaylight.openflowplugin.impl.device.TransactionChainManager}
-     * is present in registry and in SHUTTING_DOWN state (unfinished).
-     *
-     * @throws Exception
-     */
-    @Test
-    public void testProvideTransactionChainManagerRecreate2() throws Exception {
-        DeviceTransactionChainManagerProvider.TransactionChainManagerRegistration txChainManagerRegistration_1 = deviceTransactionChainManagerProvider.provideTransactionChainManager(connectionContext);
-        final TransactionChainManager txChainManager = txChainManagerRegistration_1.getTransactionChainManager();
-        Assert.assertTrue(txChainManagerRegistration_1.ownedByInvokingConnectionContext());
-        Assert.assertNotNull(txChainManager);
-        Assert.assertEquals(TransactionChainManager.TransactionChainManagerStatus.WORKING,
-                txChainManagerRegistration_1.getTransactionChainManager().getTransactionChainManagerStatus());
-
-        SettableFuture<Void> submitCleanFuture = SettableFuture.create();
-        CheckedFuture<Void, TransactionCommitFailedException> checkedSubmitCleanFuture =
-                Futures.makeChecked(submitCleanFuture, new Function<Exception, TransactionCommitFailedException>() {
-                    @Nullable
-                    @Override
-                    public TransactionCommitFailedException apply(Exception input) {
-                        return new TransactionCommitFailedException("tx failed..", input);
-                    }
-                });
-        Mockito.when(writeTx.submit()).thenReturn(checkedSubmitCleanFuture);
-        txChainManager.cleanupPostClosure();
-        Assert.assertEquals(TransactionChainManager.TransactionChainManagerStatus.SHUTTING_DOWN,
-                txChainManagerRegistration_1.getTransactionChainManager().getTransactionChainManagerStatus());
-        txChainManager.attemptToRegisterHandler(readyForNewTransactionChainHandler);
-        Mockito.verify(readyForNewTransactionChainHandler, Mockito.never()).onReadyForNewTransactionChain();
-
-        submitCleanFuture.set(null);
-        Mockito.verify(readyForNewTransactionChainHandler).onReadyForNewTransactionChain();
-    }
-
-}
\ No newline at end of file
diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/ReadyForNewTransactionChainHandlerImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/ReadyForNewTransactionChainHandlerImplTest.java
deleted file mode 100644 (file)
index ef27785..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2015 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.openflowplugin.impl.device;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
-
-/**
- * Test for {@link ReadyForNewTransactionChainHandlerImpl}.
- */
-@RunWith(MockitoJUnitRunner.class)
-public class ReadyForNewTransactionChainHandlerImplTest {
-
-    @Mock
-    private DeviceManager deviceManager;
-    @Mock
-    private ConnectionContext connectionContext;
-
-    private ReadyForNewTransactionChainHandlerImpl chainHandler;
-
-    @Before
-    public void setUp() throws Exception {
-        chainHandler = new ReadyForNewTransactionChainHandlerImpl(deviceManager, connectionContext);
-    }
-
-    @After
-    public void tearDown() throws Exception {
-        Mockito.verifyNoMoreInteractions(deviceManager, connectionContext);
-    }
-
-    @Test
-    public void testOnReadyForNewTransactionChain() throws Exception {
-        chainHandler.onReadyForNewTransactionChain();
-        Mockito.verify(deviceManager).deviceConnected(connectionContext);
-    }
-}
\ No newline at end of file
index 7909a3637a80bab91b7c81d7c9b686fd7156033a..da2d438633f8e1f4aeb0da2a35a197397b9321b4 100644 (file)
@@ -17,7 +17,6 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.mockito.InOrder;
 import org.mockito.Matchers;
 import org.mockito.Mock;
 import org.mockito.Mockito;
@@ -63,8 +62,6 @@ public class TransactionChainManagerTest {
     HashedWheelTimer timer;
     @Mock
     Registration registration;
-    @Mock
-    private ReadyForNewTransactionChainHandler readyForNewTransactionChainHandler;
 
     @Mock
     private KeyedInstanceIdentifier<Node, NodeKey> nodeKeyIdent;
@@ -155,29 +152,4 @@ public class TransactionChainManagerTest {
         Mockito.verify(txChain).newWriteOnlyTransaction();
         Mockito.verify(writeTx).delete(LogicalDatastoreType.CONFIGURATION, path);
     }
-
-    @Test
-    public void testAttemptToRegisterHandler1() throws Exception {
-        boolean attemptResult = txChainManager.attemptToRegisterHandler(readyForNewTransactionChainHandler);
-        Assert.assertFalse(attemptResult);
-    }
-
-    @Test
-    public void testAttemptToRegisterHandler2() throws Exception {
-        final InOrder inOrder = Mockito.inOrder(writeTx, txChain);
-
-        txChainManager.cleanupPostClosure();
-        Assert.assertEquals(TransactionChainManager.TransactionChainManagerStatus.SHUTTING_DOWN, txChainManager.getTransactionChainManagerStatus());
-
-        boolean attemptResult = txChainManager.attemptToRegisterHandler(readyForNewTransactionChainHandler);
-        Assert.assertTrue(attemptResult);
-
-        inOrder.verify(txChain).newWriteOnlyTransaction();
-        inOrder.verify(writeTx).delete(LogicalDatastoreType.OPERATIONAL, path);
-        inOrder.verify(writeTx).submit();
-        inOrder.verify(txChain).close();
-
-        attemptResult = txChainManager.attemptToRegisterHandler(readyForNewTransactionChainHandler);
-        Assert.assertFalse(attemptResult);
-    }
 }
\ No newline at end of file