import static org.mockito.ArgumentMatchers.any;
-import com.google.common.util.concurrent.FluentFuture;
-import com.google.common.util.concurrent.ListeningExecutorService;
-import com.google.common.util.concurrent.MoreExecutors;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-import org.eclipse.jdt.annotation.NonNull;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.opendaylight.mdsal.binding.api.MountPoint;
import org.opendaylight.mdsal.binding.api.MountPointService;
import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
-import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkBuilder;
@RunWith(MockitoJUnitRunner.class)
public class DeviceTransactionManagerTest {
- @Mock private MountPointService mountPointServiceMock;
- @Mock private MountPoint mountPointMock;
- @Mock private DataBroker dataBrokerMock;
- @Mock private ReadWriteTransaction rwTransactionMock;
+ @Mock
+ private MountPointService mountPointServiceMock;
+ @Mock
+ private MountPoint mountPointMock;
+ @Mock
+ private DataBroker dataBrokerMock;
+ @Mock
+ private ReadWriteTransaction rwTransactionMock;
+
private DeviceTransactionManagerImpl transactionManager;
private String defaultDeviceId = "device-id";
Mockito.verify(rwTransactionMock, Mockito.times(1)).commit();
}
- @Test
- @Ignore
- public void submitTxTimeoutTransactionTest() {
- Future<java.util.Optional<DeviceTransaction>> deviceTxFuture =
- transactionManager.getDeviceTransaction(defaultDeviceId);
- DeviceTransaction deviceTx;
- try {
- deviceTx = deviceTxFuture.get().get();
- } catch (InterruptedException | ExecutionException e) {
- Assert.fail("Exception catched! " + e);
- return;
- }
-
- deviceTx.put(defaultDatastore, defaultIid, defaultData);
-
- Exception throwedException = null;
-
- FluentFuture<? extends @NonNull CommitInfo> submitFuture = deviceTx.commit(200, defaultTimeUnit);
- try {
- submitFuture.get();
- } catch (InterruptedException e) {
- Assert.fail("Exception catched! " + e);
- } catch (ExecutionException e) {
- throwedException = e;
- }
-
- if (throwedException == null
- || !throwedException.getMessage().contains(TimeoutException.class.getName())) {
- Assert.fail("TimeoutException inside of should be thrown!");
- return;
- }
-
-
- Mockito.doReturn(FluentFutures.immediateNullFluentFuture()).when(rwTransactionMock.commit());
-
- try {
- putAndSubmit(transactionManager, defaultDeviceId, defaultDatastore, defaultIid, defaultData);
- } catch (InterruptedException | ExecutionException e) {
- Assert.fail("Exception catched! " + e);
- return;
- }
-
- Mockito.verify(rwTransactionMock, Mockito.times(2)).put(defaultDatastore, defaultIid, defaultData);
- Mockito.verify(rwTransactionMock, Mockito.times(2)).commit();
- ListeningExecutorService executor = MoreExecutors
- .listeningDecorator(Executors.newSingleThreadExecutor());
- executor.shutdown();
- }
-
private <T extends DataObject> void putAndSubmit(DeviceTransactionManagerImpl deviceTxManager, String deviceId,
LogicalDatastoreType store, InstanceIdentifier<T> path, T data)
throws ExecutionException, InterruptedException {
Assert.assertEquals("Failed", output.getResult());
}
- /*
- @Test
- public void testCalculateSpanlossBase() {
- CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput();
- //TODO
- Mockito.when(this.olmPowerServiceMock.calculateSpanlossBase(Mockito.any()))
- .thenReturn(new CalculateSpanlossBaseOutputBuilder().setResult("Failed").build());
- CalculateSpanlossBaseOutput output = this.olmPowerServiceMock.calculateSpanlossBase(input);
- Assert.assertEquals("Failed", output.getResult());
-
- }
- */
-
- /*
- @Test
- public void testCalculateSpanlossBase2() {
- NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
-<<<<<<< HEAD
- InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Networks.class)
- .child(Network.class, overlayTopologyKey)
-=======
- InstanceIdentifier<Network1> networkTopoIID = InstanceIdentifier.builder(Networks.class)
- .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
- .ietf.network.rev180226.networks.Network.class,
- overlayTopologyKey)
->>>>>>> 87d8bf0... Retrieve OLM modifs from change 80051
- .augmentation(Network1.class)
- .build();
- InstanceIdentifier<Network> networkIID = InstanceIdentifier.builder(Networks.class)
- .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
- .ietf.network.rev180226.networks.Network.class,
- overlayTopologyKey)
- .build();
- Network1 network = TransactionUtils.getNetwork();
- Network ietfNetwork = TransactionUtils.getOverLayNetwork();
- TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, ietfNetwork);
- TransactionUtils.writeTransaction(this.getDataBroker(), networkTopoIID, network);
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- LOG.error("Write transaction failed !",e);
- }
- CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput();
- //TODO
- Mockito.when(this.olmPowerServiceMock.calculateSpanlossBase(Mockito.any()))
- .thenReturn(new CalculateSpanlossBaseOutputBuilder().setResult("Failed").build());
- CalculateSpanlossBaseOutput output = this.olmPowerServiceMock.calculateSpanlossBase(input);
- Assert.assertEquals("Failed", output.getResult());
-
- }
- */
@Ignore
@Test
public void testCalculateSpanlossBase3() {
}
-// @Test
-// public void testCalculateSpanlossBase4() throws InterruptedException {
-// NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
-// InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
-// .augmentation(Network1.class)
-// .build();
-// Network1 network = TransactionUtils.getNetwork2();
-// TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
-//
-// Thread.sleep(500);
-//
-// List<NodeId> nodes = TransactionUtils.getNodes();
-// Node n;
-// SupportingNode sn;
-//
-// List<SupportingNode> snl;
-// NodeId n5 = new NodeId("node 5");
-// KeyedInstanceIdentifier<Node, NodeKey> mappedNodeII2 =
-// InstanceIdentifiers.UNDERLAY_NETWORK_II.child(Node.class, new NodeKey(n5));
-//
-// sn = new SupportingNodeBuilder().setNetworkRef(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))
-// .setNodeRef(n5).build();
-// snl = new ArrayList<>();
-// snl.add(sn);
-// n = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608
-// .network.NodeBuilder().setNodeId(n5).build();
-// TransactionUtils.writeTransaction(this.getDataBroker(), mappedNodeII2, n);
-// Thread.sleep(500);
-//
-// for(int i=0; i < nodes.size(); i++) {
-// KeyedInstanceIdentifier<Node, NodeKey> mappedNodeII =
-// InstanceIdentifiers.OVERLAY_NETWORK_II.child(Node.class, new NodeKey(nodes.get(i)));
-// if (i != 0){
-// sn = new SupportingNodeBuilder().setNetworkRef(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))
-// .setNodeRef(nodes.get(i-1)).build();
-// }else {
-// sn = new SupportingNodeBuilder().setNodeRef(n5).build();
-// }
-// snl = new ArrayList<>();
-// snl.add(sn);
-// n = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608
-// .network.NodeBuilder().setNodeId(nodes.get(i)).setSupportingNode(snl).build();
-// TransactionUtils.writeTransaction(this.getDataBroker(), mappedNodeII, n);
-// Thread.sleep(500);
-// }
-//
-// Thread.sleep(1000);
-//
-// CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
-// CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
-// Assert.assertEquals("Failed", output.getResult());
-//
-// }
-
@Test
public void testCalculateSpanlossCurrent1() {
CalculateSpanlossCurrentInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossCurrentInput();