7fec593c2f822b366ca68ab177adb377ca8dd53b
[ovsdb.git] / library / 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 static org.opendaylight.ovsdb.lib.operations.Operations.op;
13
14 import java.io.IOException;
15 import java.util.List;
16 import java.util.Map;
17 import java.util.concurrent.ExecutionException;
18 import java.util.concurrent.ExecutorService;
19 import java.util.concurrent.Executors;
20
21 import junit.framework.Assert;
22
23 import org.junit.Test;
24 import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
25 import org.opendaylight.ovsdb.lib.message.UpdateNotification;
26 import org.opendaylight.ovsdb.lib.operations.OperationResult;
27 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
28 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
29 import org.opendaylight.ovsdb.lib.schema.TableSchema;
30 import org.opendaylight.ovsdb.lib.schema.temp.Reference;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 import com.google.common.util.concurrent.ListenableFuture;
35
36 public class OvsDBClientTestITTyped extends OvsdbTestBase {
37
38     Logger logger = LoggerFactory.getLogger(OvsDBClientTestITTyped.class);
39
40
41     static class Bridge extends TableSchema<Bridge> {
42
43         Bridge(String name, Map<String, ColumnSchema> columns) {
44             super(name, columns);
45         }
46
47         public ColumnSchema<Bridge, String> name() {
48             return column("name", String.class);
49         }
50
51         public ColumnSchema<Bridge, Integer> floodVlans() {
52             return column("flood_vlans", Integer.class);
53         }
54
55         public ColumnSchema<Bridge, String> status() {
56             return column("status", String.class);
57         }
58
59         public ColumnSchema<Bridge, Reference> netflow() {
60             return column("netflow", Reference.class);
61         }
62
63     }
64
65
66     @Test
67     public void test() throws IOException, InterruptedException, ExecutionException {
68         OvsDBClientImpl ovs = getVswitch();
69
70         Bridge bridge = ovs.getSchema("Open_vSwitch", true).get().table("Bridge", Bridge.class);
71         GenericTableSchema anytable = null;
72
73
74
75         ListenableFuture<List<OperationResult>> results = ovs.transactBuilder()
76                 .add(op.insert(bridge).value(bridge.name(), "br-int"))
77                 .add(op.update(bridge)
78                         .set(bridge.status(), "br-blah")
79                         .set(bridge.floodVlans(), 34)
80                         .where(bridge.name().opEqual("br-int"))
81                         .and(bridge.name().opEqual("br-int")).build())
82                 .execute();
83
84         List<OperationResult> operationResults = results.get();
85         Assert.assertFalse(operationResults.isEmpty());
86         System.out.println("operationResults = " + operationResults);
87     }
88
89     private OvsDBClientImpl getVswitch() throws IOException, InterruptedException {
90         OvsdbRPC rpc = getTestConnection();
91         if (rpc == null) {
92             System.out.println("Unable to Establish Test Connection");
93         }
94
95         ExecutorService executorService = Executors.newFixedThreadPool(3);
96         OvsDBClientImpl ovs = new OvsDBClientImpl(rpc, executorService);
97
98         for (int i = 0; i < 100; i++) {
99            if (ovs.isReady(0)) {
100               break;
101            }
102            Thread.sleep(1000);
103         }
104         return ovs;
105     }
106
107
108     @Override
109     public void update(Object node, UpdateNotification upadateNotification) {
110         // TODO Auto-generated method stub
111
112     }
113     @Override
114     public void locked(Object node, List<String> ids) {
115         // TODO Auto-generated method stub
116
117     }
118     @Override
119     public void stolen(Object node, List<String> ids) {
120         // TODO Auto-generated method stub
121
122     }
123
124 }