2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.api.openflow.device;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
15 import java.util.Iterator;
16 import java.util.concurrent.Future;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.Mock;
21 import org.mockito.runners.MockitoJUnitRunner;
22 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
23 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
24 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
25 import org.opendaylight.openflowplugin.impl.rpc.RpcContextImpl;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
33 import org.opendaylight.yangtools.yang.common.RpcError;
34 import org.opendaylight.yangtools.yang.common.RpcResult;
39 @RunWith(MockitoJUnitRunner.class)
40 public class RpcContextImplTest {
43 private BindingAwareBroker.ProviderContext mockedRpcProviderRegistry;
46 private DeviceContext deviceContext;
48 private MessageSpy messageSpy;
50 private RpcContext rpcContext;
52 private static final String QUEUE_IS_FULL = "Device's request queue is full.";
56 NodeId nodeId = new NodeId("openflow:1");
57 KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
59 rpcContext = new RpcContextImpl(messageSpy, mockedRpcProviderRegistry, nodeInstanceIdentifier);
63 public void invokeRpcTest() {
68 public void testStoreOrFail() throws Exception {
69 RequestContext requestContext = rpcContext.createRequestContext();
70 rpcContext.setRequestContextQuota(100);
71 Future<RpcResult<UpdateFlowOutput>> resultFuture = rpcContext.storeOrFail(requestContext);
72 assertNotNull(resultFuture);
73 assertFalse(resultFuture.isDone());
77 public void testStoreOrFailThatFails() throws Exception {
78 RequestContext requestContext = rpcContext.createRequestContext();
79 rpcContext.setRequestContextQuota(0);
80 Future<RpcResult<UpdateFlowOutput>> resultFuture = rpcContext.storeOrFail(requestContext);
81 assertNotNull(resultFuture);
82 assertTrue(resultFuture.isDone());
83 RpcResult<UpdateFlowOutput> updateFlowOutputRpcResult = resultFuture.get();
84 assertNotNull(updateFlowOutputRpcResult);
85 assertEquals(1, updateFlowOutputRpcResult.getErrors().size());
86 Iterator<RpcError> iterator = updateFlowOutputRpcResult.getErrors().iterator();
87 assertEquals(QUEUE_IS_FULL, iterator.next().getMessage());