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.Before;
15 import org.junit.Test;
16 import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
17 import org.opendaylight.ovsdb.lib.operations.OperationResult;
18 import org.opendaylight.ovsdb.lib.schema.ATableSchema;
19 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
20 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
21 import org.opendaylight.ovsdb.lib.schema.TableSchema;
22 import org.opendaylight.ovsdb.plugin.OvsdbTestBase;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 import java.io.IOException;
27 import java.util.List;
29 import java.util.concurrent.ExecutionException;
30 import java.util.concurrent.ExecutorService;
31 import java.util.concurrent.Executors;
33 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
36 public class OvsDBClientTestIT extends OvsdbTestBase {
37 Logger logger = LoggerFactory.getLogger(OvsDBClientTestIT.class);
44 public void testTransact() throws IOException, InterruptedException, ExecutionException {
46 ListenableFuture<DatabaseSchema> schema = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true);
47 TableSchema<ATableSchema> bridge = schema.get().table("Bridge");
49 for (Map.Entry<String, ColumnSchema> names : bridge.getColumnSchemas().entrySet()) {
50 System.out.println("names = " + names.getKey());
51 System.out.println("names.getValue().getType() = " + names.getValue().getType().getBaseType());
54 ColumnSchema<ATableSchema, String> name = bridge.column("name", String.class);
55 ColumnSchema<ATableSchema, String> fail_mode = bridge.column("fail_mode", String.class);
57 ListenableFuture<List<OperationResult>> results = ovs.transactBuilder()
58 .add(op.insert(bridge).value(name, "br-int"))
59 .add(op.update(bridge)
60 .set(fail_mode, "secure")
61 .where(name.opEqual("br-int"))
62 //.and(name.opEqual("br-int"))
66 List<OperationResult> operationResults = results.get();
67 Assert.assertFalse(operationResults.isEmpty());
68 System.out.println("operationResults = " + operationResults);
72 public void testGetDBs() throws ExecutionException, InterruptedException {
73 ListenableFuture<List<String>> databases = ovs.getDatabases();
74 List<String> dbNames = databases.get();
75 Assert.assertNotNull(dbNames);
76 Assert.assertTrue(dbNames.size() > 0);
80 public void initalize() throws IOException {
84 TestObjects testConnection = getTestConnection();
85 OvsdbRPC rpc = testConnection.connectionService.getConnection(testConnection.node).getRpc();
87 ExecutorService executorService = Executors.newFixedThreadPool(3);
88 ovs = new OvsDBClientImpl(rpc, executorService);