2 * Copyright (c) 2016 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
9 package org.opendaylight.openflowplugin.applications.frsync.impl;
11 import com.google.common.util.concurrent.Futures;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15 import org.mockito.Matchers;
16 import org.mockito.Mock;
17 import org.mockito.Mockito;
18 import org.mockito.runners.MockitoJUnitRunner;
19 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
20 import org.opendaylight.openflowplugin.applications.frsync.util.RetryRegistry;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 * Test for {@link SyncReactorRetryDecorator}
31 @RunWith(MockitoJUnitRunner.class)
32 public class SyncReactorRetryDecoratorTest {
34 private static final NodeId NODE_ID = new NodeId("test-node");
35 private SyncReactorRetryDecorator reactor;
36 private InstanceIdentifier<FlowCapableNode> fcNodePath;
37 final LogicalDatastoreType dsType = LogicalDatastoreType.CONFIGURATION;
40 private SyncReactorImpl delegate;
42 private RetryRegistry retryRegistry;
44 private FlowCapableNode fcConfigNode;
46 private FlowCapableNode fcOperationalNode;
50 reactor = new SyncReactorRetryDecorator(delegate, retryRegistry);
51 InstanceIdentifier<Node> nodePath = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(NODE_ID));
52 fcNodePath = nodePath.augmentation(FlowCapableNode.class);
54 final Node operationalNode = Mockito.mock(Node.class);
55 Mockito.when(operationalNode.getId()).thenReturn(NODE_ID);
56 Mockito.when(operationalNode.getAugmentation(FlowCapableNode.class)).thenReturn(fcOperationalNode);
60 public void testSyncupSuccess() throws InterruptedException {
61 Mockito.when(delegate.syncup(Matchers.<InstanceIdentifier<FlowCapableNode>>any(), Matchers.<FlowCapableNode>any(),
62 Matchers.<FlowCapableNode>any(), Matchers.<LogicalDatastoreType>any())).thenReturn(Futures.immediateFuture(Boolean.TRUE));
64 reactor.syncup(fcNodePath, fcConfigNode, fcOperationalNode, dsType);
66 Mockito.verify(delegate).syncup(fcNodePath, fcConfigNode, fcOperationalNode, dsType);
67 Mockito.verifyNoMoreInteractions(delegate);
68 Mockito.verify(retryRegistry).unregisterIfRegistered(NODE_ID);
72 public void testSyncupFail() throws InterruptedException {
73 Mockito.when(delegate.syncup(Matchers.<InstanceIdentifier<FlowCapableNode>>any(), Matchers.<FlowCapableNode>any(),
74 Matchers.<FlowCapableNode>any(), Matchers.<LogicalDatastoreType>any())).thenReturn(Futures.immediateFuture(Boolean.FALSE));
76 reactor.syncup(fcNodePath, fcConfigNode, fcOperationalNode, dsType);
78 Mockito.verify(delegate).syncup(fcNodePath, fcConfigNode, fcOperationalNode, dsType);
79 Mockito.verifyNoMoreInteractions(delegate);
80 Mockito.verify(retryRegistry).register(NODE_ID);
84 public void testSyncupConfigIgnoreInRetry() throws InterruptedException {
85 Mockito.when(retryRegistry.isRegistered(NODE_ID)).thenReturn(true);
87 reactor.syncup(fcNodePath, fcConfigNode, fcOperationalNode, dsType);
89 Mockito.verifyZeroInteractions(delegate);