2 * Copyright (C) 2014 EBay Software Foundation
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 : Ashwin Raveendran
10 package org.opendaylight.ovsdb.lib;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import junit.framework.Assert;
14 import org.junit.Test;
15 import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
16 import org.opendaylight.ovsdb.lib.operations.OperationResult;
17 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
18 import org.opendaylight.ovsdb.lib.schema.TableSchema;
19 import org.opendaylight.ovsdb.lib.schema.temp.Reference;
20 import org.opendaylight.ovsdb.plugin.OvsdbTestBase;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 import java.io.IOException;
25 import java.util.List;
27 import java.util.concurrent.ExecutionException;
28 import java.util.concurrent.ExecutorService;
29 import java.util.concurrent.Executors;
31 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
33 public class OvsDBClientTestITTyped extends OvsdbTestBase {
35 Logger logger = LoggerFactory.getLogger(OvsDBClientTestITTyped.class);
38 static class Bridge extends TableSchema<Bridge> {
40 Bridge(String name, Map<String, ColumnSchema> columns) {
44 public ColumnSchema<Bridge, String> name() {
45 return column("name", String.class);
48 public ColumnSchema<Bridge, Integer> floodVlans() {
49 return column("flood_vlans", Integer.class);
52 public ColumnSchema<Bridge, String> status() {
53 return column("status", String.class);
56 public ColumnSchema<Bridge, Reference> netflow() {
57 return column("netflow", Reference.class);
63 public void test() throws IOException, InterruptedException, ExecutionException {
64 OvsDBClientImpl ovs = getVswitch();
66 Bridge bridge = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true).get().table("Bridge", Bridge.class);
68 ListenableFuture<List<OperationResult>> results = ovs.transactBuilder()
69 .add(op.insert(bridge).value(bridge.name(), "br-int"))
70 .add(op.update(bridge)
71 .set(bridge.status(), "br-blah")
72 .set(bridge.floodVlans(), 34)
73 .where(bridge.name().opEqual("br-int"))
74 .and(bridge.name().opEqual("br-int")).operation())
77 List<OperationResult> operationResults = results.get();
78 Assert.assertFalse(operationResults.isEmpty());
79 System.out.println("operationResults = " + operationResults);
85 private OvsDBClientImpl getVswitch() throws IOException, InterruptedException {
86 TestObjects testConnection = getTestConnection();
87 OvsdbRPC rpc = testConnection.connectionService.getConnection(testConnection.node).getRpc();
89 ExecutorService executorService = Executors.newFixedThreadPool(3);
90 OvsDBClientImpl ovs = new OvsDBClientImpl(rpc, executorService);
92 for (int i = 0; i < 100; i++) {