Search in sources :

Example 51 with Close

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close in project openflowplugin by opendaylight.

the class TransactionChainManagerTest method testDeactivateTransactionChainManagerFailed.

@Test
public void testDeactivateTransactionChainManagerFailed() throws Exception {
    Mockito.when(writeTx.submit()).thenReturn(Futures.<Void, TransactionCommitFailedException>immediateFailedCheckedFuture(new TransactionCommitFailedException("mock")));
    final Node data = new NodeBuilder().setId(nodeId).build();
    txChainManager.writeToTransaction(LogicalDatastoreType.CONFIGURATION, path, data, false);
    txChainManager.deactivateTransactionManager();
    Mockito.verify(txChain).newReadWriteTransaction();
    Mockito.verify(writeTx).put(LogicalDatastoreType.CONFIGURATION, path, data, false);
    Mockito.verify(writeTx, Mockito.never()).submit();
    Mockito.verify(writeTx).cancel();
    Mockito.verify(txChain).close();
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder) Test(org.junit.Test)

Example 52 with Close

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close in project openflowplugin by opendaylight.

the class SystemNotificationsListenerImplTest method testOnDisconnectEvent2.

/**
 * Broken scenario - connection is on but fails to close.
 */
@Test
public void testOnDisconnectEvent2() throws Exception {
    Mockito.when(connectionAdapter.isAlive()).thenReturn(true);
    Mockito.when(connectionAdapter.disconnect()).thenReturn(Futures.immediateFuture(Boolean.FALSE));
    DisconnectEvent disconnectNotification = new DisconnectEventBuilder().setInfo("testing disconnect").build();
    systemNotificationsListener.onDisconnectEvent(disconnectNotification);
    verifyCommonInvocationsSubSet();
    Mockito.verify(connectionContext).onConnectionClosed();
    Mockito.verify(connectionContext).getConnectionAdapter();
    Mockito.verify(connectionContext, Mockito.atLeastOnce()).getSafeNodeIdForLOG();
}
Also used : DisconnectEventBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEventBuilder) DisconnectEvent(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEvent) Test(org.junit.Test)

Example 53 with Close

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close in project openflowplugin by opendaylight.

the class SystemNotificationsListenerImplTest method testOnDisconnectEvent4.

/**
 * Broken scenario - connection is on but throws error on close.
 */
@Test
public void testOnDisconnectEvent4() throws Exception {
    Mockito.when(connectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.RIP);
    Mockito.when(connectionAdapter.isAlive()).thenReturn(false);
    DisconnectEvent disconnectNotification = new DisconnectEventBuilder().setInfo("testing disconnect").build();
    systemNotificationsListener.onDisconnectEvent(disconnectNotification);
    verifyCommonInvocationsSubSet();
    Mockito.verify(connectionContext).onConnectionClosed();
    Mockito.verify(connectionContext).getConnectionAdapter();
    Mockito.verify(connectionContext, Mockito.atLeastOnce()).getSafeNodeIdForLOG();
}
Also used : DisconnectEventBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEventBuilder) DisconnectEvent(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEvent) Test(org.junit.Test)

Example 54 with Close

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close in project openflowplugin by opendaylight.

the class MultipartRequestOnTheFlyCallbackTest method testOnSuccessWithValidMultipart1.

/**
 * Not the last reply.
 */
@Test
public void testOnSuccessWithValidMultipart1() throws Exception {
    final MatchBuilder matchBuilder = new MatchBuilder().setMatchEntry(Collections.<MatchEntry>emptyList());
    final FlowStatsBuilder flowStatsBuilder = new FlowStatsBuilder().setTableId(tableId).setPriority(2).setCookie(BigInteger.ZERO).setByteCount(BigInteger.TEN).setPacketCount(BigInteger.ONE).setDurationSec(11L).setDurationNsec(12L).setMatch(matchBuilder.build()).setFlags(new FlowModFlags(true, false, false, false, false));
    final MultipartReplyFlowBuilder multipartReplyFlowBuilder = new MultipartReplyFlowBuilder().setFlowStats(Collections.singletonList(flowStatsBuilder.build()));
    final MultipartReplyFlowCaseBuilder multipartReplyFlowCaseBuilder = new MultipartReplyFlowCaseBuilder().setMultipartReplyFlow(multipartReplyFlowBuilder.build());
    final MultipartReplyMessageBuilder mpReplyMessage = new MultipartReplyMessageBuilder().setType(MultipartType.OFPMPFLOW).setFlags(new MultipartRequestFlags(true)).setMultipartReplyBody(multipartReplyFlowCaseBuilder.build()).setXid(21L);
    final InstanceIdentifier<FlowCapableNode> nodePath = mockedDeviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
    final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder();
    final TableBuilder tableDataBld = new TableBuilder();
    tableDataBld.setId(tableId);
    flowNodeBuilder.setTable(Collections.singletonList(tableDataBld.build()));
    final Optional<FlowCapableNode> flowNodeOpt = Optional.of(flowNodeBuilder.build());
    final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowNodeFuture = Futures.immediateCheckedFuture(flowNodeOpt);
    when(mockedReadOnlyTx.read(LogicalDatastoreType.OPERATIONAL, nodePath)).thenReturn(flowNodeFuture);
    when(mockedDeviceContext.getReadTransaction()).thenReturn(mockedReadOnlyTx);
    multipartRequestOnTheFlyCallback.onSuccess(mpReplyMessage.build());
    verify(mockedReadOnlyTx, times(0)).read(LogicalDatastoreType.OPERATIONAL, nodePath);
    verify(mockedReadOnlyTx, times(0)).close();
    verify(mockedDeviceContext, times(1)).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), Matchers.any(), Matchers.any());
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) MultipartRequestFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags) FlowCapableNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder) MultipartReplyFlowCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyFlowCaseBuilder) TableBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder) FlowStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.multipart.reply.flow.FlowStatsBuilder) MultipartReplyMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder) MultipartReplyFlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.flow._case.MultipartReplyFlowBuilder) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder) Test(org.junit.Test)

Example 55 with Close

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Close in project openflowplugin by opendaylight.

the class MultipartRequestOnTheFlyCallbackTest method initialization.

@Before
public void initialization() {
    when(mockedDeviceContext.getMessageSpy()).thenReturn(new MessageIntelligenceAgencyImpl());
    when(mockedNodeId.toString()).thenReturn(DUMMY_NODE_ID);
    when(mockedPrimaryConnection.getNodeId()).thenReturn(mockedNodeId);
    when(mockedPrimaryConnection.getFeatures()).thenReturn(mockedFeaturesReply);
    when(mockedFeaturesReply.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
    when(mockedFeaturesReply.getDatapathId()).thenReturn(BigInteger.valueOf(123L));
    when(mocketGetFeaturesOutput.getTables()).thenReturn(tableId);
    when(mocketGetFeaturesOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
    when(mocketGetFeaturesOutput.getDatapathId()).thenReturn(BigInteger.valueOf(123L));
    when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimaryConnection);
    when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(NODE_PATH);
    when(mockedDeviceInfo.getNodeId()).thenReturn(mockedNodeId);
    when(mockedDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
    when(mockedDeviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
    when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
    when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
    when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(mockedFlowRegistry);
    when(mockedFlowRegistry.retrieveDescriptor(Matchers.any(FlowRegistryKey.class))).thenReturn(mockedFlowDescriptor);
    final InstanceIdentifier<FlowCapableNode> nodePath = mockedDeviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
    final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder();
    flowNodeBuilder.setTable(Collections.<Table>emptyList());
    final Optional<FlowCapableNode> flowNodeOpt = Optional.of(flowNodeBuilder.build());
    final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowNodeFuture = Futures.immediateCheckedFuture(flowNodeOpt);
    when(mockedReadOnlyTx.read(LogicalDatastoreType.OPERATIONAL, nodePath)).thenReturn(flowNodeFuture);
    when(mockedDeviceContext.getReadTransaction()).thenReturn(mockedReadOnlyTx);
    dummyRequestContext = new AbstractRequestContext<List<MultipartReply>>(DUMMY_XID) {

        @Override
        public void close() {
        // NOOP
        }
    };
    final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
    multipartRequestOnTheFlyCallback = new MultiLayerFlowMultipartRequestOnTheFlyCallback<>(dummyRequestContext, String.class, mockedDeviceContext, dummyEventIdentifier, MultipartWriterProviderFactory.createDefaultProvider(mockedDeviceContext), convertorManager);
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) FlowRegistryKey(org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey) Optional(com.google.common.base.Optional) MessageIntelligenceAgencyImpl(org.opendaylight.openflowplugin.impl.statistics.ofpspecific.MessageIntelligenceAgencyImpl) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) FlowCapableNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder) List(java.util.List) ConvertorManager(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)23 InetSocketAddress (java.net.InetSocketAddress)12 Before (org.junit.Before)11 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)9 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)8 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters)8 TimeUnit (java.util.concurrent.TimeUnit)7 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)7 Optional (com.google.common.base.Optional)6 ChannelFuture (io.netty.channel.ChannelFuture)6 ChannelHandler (io.netty.channel.ChannelHandler)6 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)6 Notification (org.opendaylight.yangtools.yang.binding.Notification)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)4 Channel (io.netty.channel.Channel)4 List (java.util.List)4 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)4 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4