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 static org.opendaylight.ovsdb.lib.operations.Operations.op;
14 import java.io.IOException;
15 import java.util.List;
17 import java.util.concurrent.ExecutionException;
18 import java.util.concurrent.ExecutorService;
19 import java.util.concurrent.Executors;
21 import junit.framework.Assert;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
26 import org.opendaylight.ovsdb.lib.message.UpdateNotification;
27 import org.opendaylight.ovsdb.lib.operations.OperationResult;
28 import org.opendaylight.ovsdb.lib.schema.ATableSchema;
29 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
30 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
31 import org.opendaylight.ovsdb.lib.schema.TableSchema;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 import com.google.common.util.concurrent.ListenableFuture;
38 public class OvsDBClientTestIT extends OvsdbTestBase {
39 Logger logger = LoggerFactory.getLogger(OvsDBClientTestIT.class);
46 public void testTransact() throws IOException, InterruptedException, ExecutionException {
48 ListenableFuture<DatabaseSchema> schema = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true);
49 TableSchema<ATableSchema> bridge = schema.get().table("Bridge");
51 for (Map.Entry<String, ColumnSchema> names : bridge.getColumnSchemas().entrySet()) {
52 System.out.println("names = " + names.getKey());
53 System.out.println("names.getValue().getType() = " + names.getValue().getType().getBaseType());
56 ColumnSchema<ATableSchema, String> name = bridge.column("name", String.class);
57 ColumnSchema<ATableSchema, String> fail_mode = bridge.column("fail_mode", String.class);
59 ListenableFuture<List<OperationResult>> results = ovs.transactBuilder()
60 .add(op.insert(bridge).value(name, "br-int"))
61 .add(op.update(bridge)
62 .set(fail_mode, "secure")
63 .where(name.opEqual("br-int"))
64 //.and(name.opEqual("br-int"))
68 List<OperationResult> operationResults = results.get();
69 Assert.assertFalse(operationResults.isEmpty());
70 System.out.println("operationResults = " + operationResults);
74 public void testGetDBs() throws ExecutionException, InterruptedException {
75 ListenableFuture<List<String>> databases = ovs.getDatabases();
76 List<String> dbNames = databases.get();
77 Assert.assertNotNull(dbNames);
78 Assert.assertTrue(dbNames.size() > 0);
82 public void initalize() throws IOException {
86 OvsdbRPC rpc = getTestConnection();
88 System.out.println("Unable to Establish Test Connection");
90 ExecutorService executorService = Executors.newFixedThreadPool(3);
91 ovs = new OvsDBClientImpl(rpc, executorService);
96 public void update(Object node, UpdateNotification upadateNotification) {
97 // TODO Auto-generated method stub
101 public void locked(Object node, List<String> ids) {
102 // TODO Auto-generated method stub
106 public void stolen(Object node, List<String> ids) {
107 // TODO Auto-generated method stub