2 * Copyright (C) 2014 Red Hat, Inc.
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 * Authors : Madhu Venugopal, Dave Tucker
11 package org.opendaylight.ovsdb.schema.openvswitch;
13 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
15 import java.io.IOException;
16 import java.lang.reflect.InvocationTargetException;
17 import java.util.List;
18 import java.util.concurrent.ExecutionException;
19 import java.util.concurrent.TimeoutException;
21 import junit.framework.Assert;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.opendaylight.ovsdb.lib.message.UpdateNotification;
26 import org.opendaylight.ovsdb.lib.notation.Mutator;
27 import org.opendaylight.ovsdb.lib.notation.Row;
28 import org.opendaylight.ovsdb.lib.notation.UUID;
29 import org.opendaylight.ovsdb.lib.operations.OperationResult;
30 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 import com.google.common.collect.Sets;
35 import com.google.common.util.concurrent.ListenableFuture;
37 public class ControllerTestCases extends OpenVswitchSchemaTestBase {
38 Logger logger = LoggerFactory.getLogger(ControllerTestCases.class);
42 public void setUp() throws ExecutionException, InterruptedException, TimeoutException, IOException {
47 public void createTypedController() throws IOException, InterruptedException, ExecutionException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
48 Controller controller1 = ovs.createTypedRowWrapper(Controller.class);
49 controller1.setTarget("tcp:1.1.1.1:6640");
50 Controller controller2 = ovs.createTypedRowWrapper(Controller.class);
51 controller2.setTarget("tcp:2.2.2.2:6640");
53 Bridge bridge = ovs.getTypedRowWrapper(Bridge.class, null);
55 String transactionUuidStr = "controller";
56 TransactionBuilder transactionBuilder = ovs.transactBuilder()
57 .add(op.insert(controller1.getSchema())
58 .withId(transactionUuidStr)
59 .value(controller1.getTargetColumn()))
60 .add(op.mutate(bridge.getSchema())
61 .addMutation(bridge.getControllerColumn().getSchema(), Mutator.INSERT,
62 Sets.newHashSet(new UUID(transactionUuidStr)))
63 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
66 ListenableFuture<List<OperationResult>> results = transactionBuilder.execute();
67 List<OperationResult> operationResults = results.get();
68 Assert.assertFalse(operationResults.isEmpty());
69 // Check if Results matches the number of operations in transaction
70 Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
71 logger.info("Insert & Mutate operation results for controller1 = " + operationResults);
72 // Check for any errors
73 for (OperationResult result : operationResults) {
74 Assert.assertNull(result.getError());
77 Thread.sleep(3000); // Wait for cache to catchup
78 Row bridgeRow = OpenVswitchSchemaSuiteIT.getTableCache().get(bridge.getSchema().getName()).get(OpenVswitchSchemaSuiteIT.getTestBridgeUuid());
79 Bridge monitoredBridge = ovs.getTypedRowWrapper(Bridge.class, bridgeRow);
80 Assert.assertEquals(1, monitoredBridge.getControllerColumn().getData().size());
82 transactionBuilder = ovs.transactBuilder()
83 .add(op.insert(controller2.getSchema())
84 .withId(transactionUuidStr)
85 .value(controller2.getTargetColumn()))
86 .add(op.mutate(bridge.getSchema())
87 .addMutation(bridge.getControllerColumn().getSchema(), Mutator.INSERT,
88 Sets.newHashSet(new UUID(transactionUuidStr)))
89 .where(bridge.getNameColumn().getSchema().opEqual(TEST_BRIDGE_NAME))
92 results = transactionBuilder.execute();
93 operationResults = results.get();
94 Assert.assertFalse(operationResults.isEmpty());
95 // Check if Results matches the number of operations in transaction
96 Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size());
97 logger.info("Insert & Mutate operation results for controller2 = " + operationResults);
98 // Check for any errors
99 for (OperationResult result : operationResults) {
100 Assert.assertNull(result.getError());
102 Thread.sleep(3000); // Wait for cache to catchup
103 bridgeRow = OpenVswitchSchemaSuiteIT.getTableCache().get(bridge.getSchema().getName()).get(OpenVswitchSchemaSuiteIT.getTestBridgeUuid());
104 monitoredBridge = ovs.getTypedRowWrapper(Bridge.class, bridgeRow);
105 Assert.assertEquals(2, monitoredBridge.getControllerColumn().getData().size());
109 public void update(Object context, UpdateNotification upadateNotification) {
114 public void locked(Object context, List<String> ids) {
119 public void stolen(Object context, List<String> ids) {