From f895b83b6ea2e6062862aee5846ca074224e2d12 Mon Sep 17 00:00:00 2001 From: Martin Bobak Date: Tue, 30 Sep 2014 09:33:43 +0200 Subject: [PATCH] Bug 1254 - added basic functionality test for OFRpcTaskUtil - removed unused method OFRpcTaskUtil#wrapBarrierErrors Change-Id: I6ad9cfdf22f12fd00fd6d8727e8cad730d788dae Signed-off-by: Martin Bobak --- .../openflow/md/core/sal/OFRpcTaskUtil.java | 11 +-- .../md/core/sal/OFRpcTaskUtilTest.java | 99 +++++++++++++++++++ 2 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskUtilTest.java diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskUtil.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskUtil.java index 47fef3db89..c8f045b790 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskUtil.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskUtil.java @@ -103,15 +103,6 @@ public abstract class OFRpcTaskUtil { return new RpcInputOutputTuple<>(barrierInput, output); } - /** - * @param result rpcResult with success = false, errors = given collection - * @param barrierErrors - */ - public static void wrapBarrierErrors(SettableFuture> result, - Collection barrierErrors) { - result.set(RpcResultBuilder.failed().withRpcErrors(barrierErrors).build()); - } - /** * @param task of rpc * @param originalResult @@ -154,7 +145,7 @@ public abstract class OFRpcTaskUtil { } /** - * @param task of rpc + * @param task of rpcl * @param originalResult * @param notificationProviderService * @param notificationComposer lazy notification composer diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskUtilTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskUtilTest.java new file mode 100644 index 0000000000..e13b60a3d9 --- /dev/null +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskUtilTest.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2014 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.openflow.md.core.sal; + +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.when; + +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import java.util.Collection; +import java.util.concurrent.Callable; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.openflowplugin.api.OFConstants; +import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher; +import org.opendaylight.openflowplugin.api.openflow.md.core.sal.NotificationComposer; +import org.opendaylight.openflowplugin.openflow.md.core.session.IMessageDispatchService; +import org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; +import org.opendaylight.yangtools.yang.common.RpcError; +import org.opendaylight.yangtools.yang.common.RpcResult; + +@RunWith(MockitoJUnitRunner.class) +public class OFRpcTaskUtilTest { + + @MockitoAnnotations.Mock + private OFRpcTaskContext taskContext; + @MockitoAnnotations.Mock + private SwitchConnectionDistinguisher connectionDistinguisher; + @MockitoAnnotations.Mock + private SessionContext sessionContext; + @MockitoAnnotations.Mock + private IMessageDispatchService messageDispatchService; + @MockitoAnnotations.Mock + private GetFeaturesOutput featuresOutput; + @MockitoAnnotations.Mock + private ListenableFuture> resultListenableFuture; + @MockitoAnnotations.Mock + private ListenableFuture> updateFlowRpcResultListenableFuture; + @MockitoAnnotations.Mock + private OFRpcTaskContext ofRpcTaskContext; + @MockitoAnnotations.Mock + private NotificationProviderService notificationProviderService; + @MockitoAnnotations.Mock + private NotificationComposer notificationComposer; + @MockitoAnnotations.Mock + ListeningExecutorService executorService; + + + @Before + public void setup() { + when(taskContext.getSession()).thenReturn(sessionContext); + when(taskContext.getMessageService()).thenReturn(messageDispatchService); + when(sessionContext.getNextXid()).thenReturn(new Long(10)); + when(sessionContext.getFeatures()).thenReturn(featuresOutput); + when(featuresOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); + when(messageDispatchService.barrier(Mockito.any(BarrierInput.class), Mockito.any(SwitchConnectionDistinguisher.class))).thenReturn(resultListenableFuture); + when(ofRpcTaskContext.getRpcPool()).thenReturn(executorService); + when(executorService.submit(Mockito.any(Callable.class))).thenReturn(updateFlowRpcResultListenableFuture); + } + + + @Test + public void testManageBarrier() throws Exception { + Collection rpcErrors = OFRpcTaskUtil.manageBarrier(taskContext, true, connectionDistinguisher); + assertNotNull(rpcErrors); + } + + @Test + public void testHookFutureNotification() throws Exception { + AddFlowInputBuilder flowInputBuilder = new AddFlowInputBuilder(); + OFRpcTask> addFlowInputRpcResultOFRpcTask = OFRpcTaskFactory.createAddFlowTask(ofRpcTaskContext, flowInputBuilder.build(), connectionDistinguisher); + OFRpcTaskUtil.hookFutureNotification(addFlowInputRpcResultOFRpcTask, updateFlowRpcResultListenableFuture, notificationProviderService, notificationComposer); + } + + @Test + public void testChainFutureBarrier() throws Exception { + AddFlowInputBuilder flowInputBuilder = new AddFlowInputBuilder(); + flowInputBuilder.setBarrier(true); + OFRpcTask> addFlowInputRpcResultOFRpcTask = OFRpcTaskFactory.createAddFlowTask(ofRpcTaskContext, flowInputBuilder.build(), connectionDistinguisher); + OFRpcTaskUtil.chainFutureBarrier(addFlowInputRpcResultOFRpcTask, updateFlowRpcResultListenableFuture); + } +} \ No newline at end of file -- 2.36.6