+ /**
+ * 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.close();
+ 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();
+ }
+