From cd3717fdd24b892c9e6d266c725349fbcacc2687 Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Sat, 14 Jun 2014 21:27:23 -0700 Subject: [PATCH] Fixed the broken Typed IT tests & included it to run as part of failsafe maven plugin. Change-Id: I269c200646b83c336b253d2dfa9a089e0e0595eb Signed-off-by: Madhu Venugopal --- library/pom.xml | 5 +- .../ovsdb/lib/OvsDBClientTestITTyped.java | 112 +++++++++++++----- 2 files changed, 87 insertions(+), 30 deletions(-) diff --git a/library/pom.xml b/library/pom.xml index 5270dbe1c..099054923 100755 --- a/library/pom.xml +++ b/library/pom.xml @@ -136,6 +136,9 @@ maven-failsafe-plugin ${skip.integrationtest} + + **/*IT* + @@ -145,7 +148,7 @@ - **/*IT + **/*IT* 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 7fec593c2..0913883b5 100644 --- a/library/src/test/java/org/opendaylight/ovsdb/lib/OvsDBClientTestITTyped.java +++ b/library/src/test/java/org/opendaylight/ovsdb/lib/OvsDBClientTestITTyped.java @@ -5,7 +5,7 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html * - * Authors : Ashwin Raveendran + * Authors : Ashwin Raveendran, Madhu Venugopal */ package org.opendaylight.ovsdb.lib; @@ -14,33 +14,50 @@ import static org.opendaylight.ovsdb.lib.operations.Operations.op; import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import junit.framework.Assert; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import org.opendaylight.ovsdb.lib.message.OvsdbRPC; import org.opendaylight.ovsdb.lib.message.UpdateNotification; +import org.opendaylight.ovsdb.lib.notation.Mutator; +import org.opendaylight.ovsdb.lib.notation.UUID; import org.opendaylight.ovsdb.lib.operations.OperationResult; +import org.opendaylight.ovsdb.lib.operations.TransactionBuilder; import org.opendaylight.ovsdb.lib.schema.ColumnSchema; +import org.opendaylight.ovsdb.lib.schema.DatabaseSchema; import org.opendaylight.ovsdb.lib.schema.GenericTableSchema; import org.opendaylight.ovsdb.lib.schema.TableSchema; import org.opendaylight.ovsdb.lib.schema.temp.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import com.google.common.util.concurrent.ListenableFuture; public class OvsDBClientTestITTyped extends OvsdbTestBase { Logger logger = LoggerFactory.getLogger(OvsDBClientTestITTyped.class); + OvsDBClientImpl ovs; + DatabaseSchema dbSchema = null; + static String testBridgeName = "br-test"; + static UUID testBridgeUuid = null; + public static class Bridge extends TableSchema { - static class Bridge extends TableSchema { + public Bridge (TableSchema tableSchema) { + super("Bridge", tableSchema.getColumnSchemas()); + } - Bridge(String name, Map columns) { + public Bridge(String name, Map columns) { super(name, columns); } @@ -52,58 +69,95 @@ public class OvsDBClientTestITTyped extends OvsdbTestBase { return column("flood_vlans", Integer.class); } - public ColumnSchema status() { - return column("status", String.class); + public ColumnSchema status() { + return column("status", Map.class); } public ColumnSchema netflow() { return column("netflow", Reference.class); } - } @Test - public void test() throws IOException, InterruptedException, ExecutionException { - OvsDBClientImpl ovs = getVswitch(); + public void testTypedBridgeCreate() throws IOException, InterruptedException, ExecutionException { + Bridge bridge = dbSchema.table("Bridge", Bridge.class); + GenericTableSchema ovsTable = dbSchema.table("Open_vSwitch", GenericTableSchema.class); + ColumnSchema> bridges = ovsTable.multiValuedColumn("bridges", UUID.class); - Bridge bridge = ovs.getSchema("Open_vSwitch", true).get().table("Bridge", Bridge.class); GenericTableSchema anytable = null; + String namedUuid = "br_test"; + int insertOperationIndex = 0; - - - ListenableFuture> results = ovs.transactBuilder() - .add(op.insert(bridge).value(bridge.name(), "br-int")) + TransactionBuilder transactionBuilder = ovs.transactBuilder() + .add(op.insert(bridge) + .withId(namedUuid) + .value(bridge.name(), testBridgeName)) .add(op.update(bridge) - .set(bridge.status(), "br-blah") + .set(bridge.status(), Maps.newHashMap(ImmutableMap.of("key","value"))) .set(bridge.floodVlans(), 34) - .where(bridge.name().opEqual("br-int")) - .and(bridge.name().opEqual("br-int")).build()) - .execute(); + .where(bridge.name().opEqual(testBridgeName)) + .and(bridge.name().opEqual(testBridgeName)).build()) + .add(op.mutate(ovsTable) + .addMutation(bridges, Mutator.INSERT, Sets.newHashSet(new UUID(namedUuid)))); + ListenableFuture> results = transactionBuilder.execute(); List operationResults = results.get(); Assert.assertFalse(operationResults.isEmpty()); - System.out.println("operationResults = " + operationResults); + // Check if Results matches the number of operations in transaction + Assert.assertEquals(transactionBuilder.getOperations().size(), operationResults.size()); + System.out.println("Insert & Update operation results = " + operationResults); + testBridgeUuid = operationResults.get(insertOperationIndex).getUuid(); } - private OvsDBClientImpl getVswitch() throws IOException, InterruptedException { + public void testGetDBs() throws ExecutionException, InterruptedException { + ListenableFuture> databases = ovs.getDatabases(); + List dbNames = databases.get(); + Assert.assertNotNull(dbNames); + 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 setUp() throws IOException, ExecutionException, InterruptedException { + if (ovs != null) { + return; + } OvsdbRPC rpc = getTestConnection(); if (rpc == null) { System.out.println("Unable to Establish Test Connection"); } - ExecutorService executorService = Executors.newFixedThreadPool(3); - OvsDBClientImpl ovs = new OvsDBClientImpl(rpc, executorService); - - for (int i = 0; i < 100; i++) { - if (ovs.isReady(0)) { - break; - } - Thread.sleep(1000); - } - return ovs; + ovs = new OvsDBClientImpl(rpc, executorService); + testGetDBs(); + dbSchema = ovs.getSchema(OPEN_VSWITCH_SCHEMA, true).get(); } + @After + public void tearDown() throws InterruptedException, ExecutionException { + TableSchema bridge = dbSchema.table("Bridge", GenericTableSchema.class); + ColumnSchema name = bridge.column("name", String.class); + GenericTableSchema ovsTable = dbSchema.table("Open_vSwitch", GenericTableSchema.class); + ColumnSchema> bridges = ovsTable.multiValuedColumn("bridges", UUID.class); + + ListenableFuture> results = ovs.transactBuilder() + .add(op.delete(bridge) + .where(name.opEqual(testBridgeName)) + .build()) + .add(op.mutate(ovsTable) + .addMutation(bridges, Mutator.DELETE, Sets.newHashSet(testBridgeUuid))) + .add(op.commit(true)) + .execute(); + + List operationResults = results.get(); + System.out.println("Delete operation results = " + operationResults); + } @Override public void update(Object node, UpdateNotification upadateNotification) { -- 2.36.6