* 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;
}
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);
@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
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;
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);
}
this.messageIntelligenceAgency = messageIntelligenceAgency;
- this.switchFeaturesMandatory = switchFeaturesMandatory;
deviceTransactionChainManagerProvider = new DeviceTransactionChainManagerProvider(dataBroker);
}
}
@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();
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);
deviceContext.close();
return;
}
+
((ExtensionConverterProviderKeeper) deviceContext).setExtensionConverterProvider(extensionConverterProvider);
deviceContext.setNotificationService(notificationService);
deviceContext.setNotificationPublishService(notificationPublishService);
- deviceContexts.add(deviceContext);
updatePacketInRateLimiters();
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();
freshNotificationLimit = 100;
}
LOG.debug("fresh notification limit = {}", freshNotificationLimit);
- for (DeviceContext deviceContext : deviceContexts) {
+ for (final DeviceContext deviceContext : deviceContexts.values()) {
deviceContext.updatePacketInRateLimit(freshNotificationLimit);
}
}
@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();
}
+++ /dev/null
-/*
- * 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 <mbobak@cisco.com> on 2.6.2015.
- */
-public interface ReadyForNewTransactionChainHandler {
-
- void onReadyForNewTransactionChain();
-}
+++ /dev/null
-/*
- * 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 <mbobak@cisco.com> 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);
- }
-}
return transactionChainManagerStatus;
}
- private TransactionChainManagerStatus transactionChainManagerStatus;
- private ReadyForNewTransactionChainHandler readyForNewTransactionChainHandler;
+ private volatile TransactionChainManagerStatus transactionChainManagerStatus;
private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
private volatile Registration managerRegistration;
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) {
LOG.warn("Failed to close transaction chain manager's registration.", e);
}
managerRegistration = null;
- if (null != readyForNewTransactionChainHandler) {
- readyForNewTransactionChainHandler.onReadyForNewTransactionChain();
- }
}
txChainFactory.close();
txChainFactory = null;
* @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());
* @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());
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;
private ConnectionAdapter mockedConnectionAdapter;
@Mock
private DeviceContextImpl mockedDeviceContext;
+ @Mock
+ private NodeId mockedNodeId;
@Before
public void setUp() throws Exception {
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);
}
@Test
- public void deviceConnectedTest() {
+ public void deviceConnectedTest() throws Exception{
DeviceManagerImpl deviceManager = prepareDeviceManager();
injectMockTranslatorLibrary(deviceManager);
ConnectionContext mockConnectionContext = buildMockConnectionContext(OFConstants.OFP_VERSION_1_3);
}
@Test
- public void deviceConnectedV10Test() {
+ public void deviceConnectedV10Test() throws Exception{
DeviceManagerImpl deviceManager = prepareDeviceManager();
injectMockTranslatorLibrary(deviceManager);
ConnectionContext mockConnectionContext = buildMockConnectionContext(OFConstants.OFP_VERSION_1_0);
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();
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);
}
}
+++ /dev/null
-/*
- * 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
+++ /dev/null
-/*
- * 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
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;
HashedWheelTimer timer;
@Mock
Registration registration;
- @Mock
- private ReadyForNewTransactionChainHandler readyForNewTransactionChainHandler;
@Mock
private KeyedInstanceIdentifier<Node, NodeKey> nodeKeyIdent;
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