Added more ignorable files to .gitignore
[ovsdb.git] / ovsdb / src / test / java / org / opendaylight / ovsdb / lib / OvsDBClientTestITTyped.java
1 /*
2  * Copyright (C) 2014 EBay Software Foundation
3  *
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
7  *
8  * Authors : Ashwin Raveendran
9  */
10 package org.opendaylight.ovsdb.lib;
11
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;
23
24 import java.io.IOException;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.concurrent.ExecutionException;
28 import java.util.concurrent.ExecutorService;
29 import java.util.concurrent.Executors;
30
31 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
32
33 public class OvsDBClientTestITTyped extends OvsdbTestBase {
34
35     Logger logger = LoggerFactory.getLogger(OvsDBClientTestITTyped.class);
36
37
38     static class Bridge extends TableSchema<Bridge> {
39
40         Bridge(String name, Map<String, ColumnSchema> columns) {
41             super(name, columns);
42         }
43
44         public ColumnSchema<Bridge, String> name() {
45             return column("name", String.class);
46         }
47
48         public ColumnSchema<Bridge, Integer> floodVlans() {
49             return column("flood_vlans", Integer.class);
50         }
51
52         public ColumnSchema<Bridge, String> status() {
53             return column("status", String.class);
54         }
55
56         public ColumnSchema<Bridge, Reference> netflow() {
57             return column("netflow", Reference.class);
58         }
59     }
60
61
62     @Test
63     public void test() throws IOException, InterruptedException, ExecutionException {
64         OvsDBClientImpl ovs = getVswitch();
65
66         Bridge bridge = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true).get().table("Bridge", Bridge.class);
67
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())
75                 .execute();
76
77         List<OperationResult> operationResults = results.get();
78         Assert.assertFalse(operationResults.isEmpty());
79         System.out.println("operationResults = " + operationResults);
80     }
81
82
83
84
85     private OvsDBClientImpl getVswitch() throws IOException, InterruptedException {
86         TestObjects testConnection = getTestConnection();
87         OvsdbRPC rpc = testConnection.connectionService.getConnection(testConnection.node).getRpc();
88
89         ExecutorService executorService = Executors.newFixedThreadPool(3);
90         OvsDBClientImpl ovs = new OvsDBClientImpl(rpc, executorService);
91
92         for (int i = 0; i < 100; i++) {
93            if (ovs.isReady(0)) {
94               break;
95            }
96            Thread.sleep(1000);
97         }
98         return ovs;
99     }
100
101 }