From 9999d34b9b827e5c9f1cffba232864297597d261 Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Wed, 28 May 2014 15:26:27 -0700 Subject: [PATCH] Removing the Open_vSwitch schema hardcoding in OvsDBClient. Though it is an harmless constant string, it goes against the motivation of the library redesign to be schema independent. Hence moving the schema string to a more appropriate place (to the applications), in this case, to the Integration Test files. Also, modified the initialize functionality to include a test to check for the list_dbs to contain Open_vSwitch schema as all the tests in this file are based on Open_vSwitch schema tables. Change-Id: I3210abf1fa18b5707a27b719f7d481b5de76d6be Signed-off-by: Madhu Venugopal --- .../org/opendaylight/ovsdb/lib/OvsDBClient.java | 10 +++------- .../ovsdb/lib/OvsDBClientTestIT.java | 17 ++++++++++++----- .../ovsdb/lib/OvsDBClientTestITTyped.java | 2 +- .../opendaylight/ovsdb/lib/OvsdbTestBase.java | 5 +++++ .../ovsdb/lib/schema/temp/SchemaObjs.java | 11 +++++------ 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/library/src/main/java/org/opendaylight/ovsdb/lib/OvsDBClient.java b/library/src/main/java/org/opendaylight/ovsdb/lib/OvsDBClient.java index 404f5e6b6..1ae226184 100644 --- a/library/src/main/java/org/opendaylight/ovsdb/lib/OvsDBClient.java +++ b/library/src/main/java/org/opendaylight/ovsdb/lib/OvsDBClient.java @@ -12,7 +12,8 @@ package org.opendaylight.ovsdb.lib; -import com.google.common.util.concurrent.ListenableFuture; +import java.util.List; + import org.opendaylight.ovsdb.lib.message.MonitorRequest; import org.opendaylight.ovsdb.lib.operations.Operation; import org.opendaylight.ovsdb.lib.operations.OperationResult; @@ -20,7 +21,7 @@ import org.opendaylight.ovsdb.lib.operations.TransactionBuilder; import org.opendaylight.ovsdb.lib.schema.DatabaseSchema; import org.opendaylight.ovsdb.lib.schema.TableSchema; -import java.util.List; +import com.google.common.util.concurrent.ListenableFuture; /** * The main interface to interact with a device speaking ovsdb protocol in an asynchronous fashion and hence most @@ -28,11 +29,6 @@ import java.util.List; */ public interface OvsDBClient { - /** - * Represents the Open Vswitch Schema - */ - String OPEN_VSWITCH_SCHEMA = "Open_vSwitch"; - /** * Gets the list of database names exposed by this ovsdb capable device * @return list of database names diff --git a/library/src/test/java/org/opendaylight/ovsdb/lib/OvsDBClientTestIT.java b/library/src/test/java/org/opendaylight/ovsdb/lib/OvsDBClientTestIT.java index 2a25b22a6..0980493c9 100644 --- a/library/src/test/java/org/opendaylight/ovsdb/lib/OvsDBClientTestIT.java +++ b/library/src/test/java/org/opendaylight/ovsdb/lib/OvsDBClientTestIT.java @@ -52,7 +52,7 @@ public class OvsDBClientTestIT extends OvsdbTestBase { @Test public void testTransact() throws IOException, InterruptedException, ExecutionException { - ListenableFuture schema = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true); + ListenableFuture schema = ovs.getSchema(OPEN_VSWITCH_SCHEMA, true); TableSchema bridge = schema.get().table("Bridge", GenericTableSchema.class); for (Map.Entry names : bridge.getColumnSchemas().entrySet()) { @@ -142,7 +142,7 @@ public class OvsDBClientTestIT extends OvsdbTestBase { @Test public void testMonitorRequest() throws ExecutionException, InterruptedException { - DatabaseSchema dbSchema = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true).get(); + DatabaseSchema dbSchema = ovs.getSchema(OPEN_VSWITCH_SCHEMA, true).get(); GenericTableSchema bridge = dbSchema.table("Bridge", GenericTableSchema.class); List> monitorRequests = Lists.newArrayList(); @@ -182,16 +182,22 @@ public class OvsDBClientTestIT extends OvsdbTestBase { Assert.assertNotNull(bridgeUpdate); } - @Test public void testGetDBs() throws ExecutionException, InterruptedException { ListenableFuture> databases = ovs.getDatabases(); List dbNames = databases.get(); Assert.assertNotNull(dbNames); - Assert.assertTrue(dbNames.size() > 0); + boolean hasOpenVswitchSchema = false; + for(String dbName : dbNames) { + if (dbName.equals(OPEN_VSWITCH_SCHEMA)) { + hasOpenVswitchSchema = true; + break; + } + } + Assert.assertTrue(OPEN_VSWITCH_SCHEMA+" schema is not supported by the switch", hasOpenVswitchSchema); } @Before - public void initalize() throws IOException { + public void initalize() throws IOException, ExecutionException, InterruptedException { if (ovs != null) { return; } @@ -201,6 +207,7 @@ public class OvsDBClientTestIT extends OvsdbTestBase { } ExecutorService executorService = Executors.newFixedThreadPool(3); ovs = new OvsDBClientImpl(rpc, executorService); + testGetDBs(); } diff --git a/library/src/test/java/org/opendaylight/ovsdb/lib/OvsDBClientTestITTyped.java b/library/src/test/java/org/opendaylight/ovsdb/lib/OvsDBClientTestITTyped.java index d52ae5932..d104ea62e 100644 --- a/library/src/test/java/org/opendaylight/ovsdb/lib/OvsDBClientTestITTyped.java +++ b/library/src/test/java/org/opendaylight/ovsdb/lib/OvsDBClientTestITTyped.java @@ -65,7 +65,7 @@ public class OvsDBClientTestITTyped extends OvsdbTestBase { public void test() throws IOException, InterruptedException, ExecutionException { OvsDBClientImpl ovs = getVswitch(); - Bridge bridge = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true).get().table("Bridge", Bridge.class); + Bridge bridge = ovs.getSchema(OPEN_VSWITCH_SCHEMA, true).get().table("Bridge", Bridge.class); ListenableFuture> results = ovs.transactBuilder() .add(op.insert(bridge).value(bridge.name(), "br-int")) diff --git a/library/src/test/java/org/opendaylight/ovsdb/lib/OvsdbTestBase.java b/library/src/test/java/org/opendaylight/ovsdb/lib/OvsdbTestBase.java index c70f79a05..7d7ba6390 100644 --- a/library/src/test/java/org/opendaylight/ovsdb/lib/OvsdbTestBase.java +++ b/library/src/test/java/org/opendaylight/ovsdb/lib/OvsdbTestBase.java @@ -42,6 +42,11 @@ public abstract class OvsdbTestBase implements OvsdbRPC.Callback{ private final static String SERVER_PORT = "ovsdbserver.port"; private final static String DEFAULT_SERVER_PORT = "6640"; + /** + * Represents the Open Vswitch Schema + */ + public final static String OPEN_VSWITCH_SCHEMA = "Open_vSwitch"; + public Properties loadProperties() { Properties props = new Properties(System.getProperties()); return props; diff --git a/library/src/test/java/org/opendaylight/ovsdb/lib/schema/temp/SchemaObjs.java b/library/src/test/java/org/opendaylight/ovsdb/lib/schema/temp/SchemaObjs.java index a93ba0bf3..7b114f5ab 100644 --- a/library/src/test/java/org/opendaylight/ovsdb/lib/schema/temp/SchemaObjs.java +++ b/library/src/test/java/org/opendaylight/ovsdb/lib/schema/temp/SchemaObjs.java @@ -9,17 +9,16 @@ */ package org.opendaylight.ovsdb.lib.schema.temp; -import org.opendaylight.ovsdb.lib.OvsDBClient; +import java.util.concurrent.ExecutionException; + import org.opendaylight.ovsdb.lib.OvsDBClientImpl; -import org.opendaylight.ovsdb.lib.schema.DatabaseSchema; +import org.opendaylight.ovsdb.lib.OvsdbTestBase; import org.opendaylight.ovsdb.lib.schema.ColumnSchema; +import org.opendaylight.ovsdb.lib.schema.DatabaseSchema; import org.opendaylight.ovsdb.lib.schema.TableSchema; -import java.util.concurrent.ExecutionException; - public class SchemaObjs { - public static class Bridge extends TableSchema { public static String NAME = "Bridge"; TableSchema target; @@ -54,7 +53,7 @@ public class SchemaObjs { public static void main(String[] args) throws ExecutionException, InterruptedException { OvsDBClientImpl ovs = new OvsDBClientImpl(null, null); - DatabaseSchema db = ovs.getSchema(OvsDBClient.OPEN_VSWITCH_SCHEMA, true).get(); + DatabaseSchema db = ovs.getSchema(OvsdbTestBase.OPEN_VSWITCH_SCHEMA, true).get(); Bridge bridge = db.table(Bridge.NAME, Bridge.class); Port port = db.table(Port.NAME, Port.class); -- 2.36.6