From 669ada41fd93f254f7fe438b51c754285b5aac27 Mon Sep 17 00:00:00 2001 From: andrea Date: Wed, 21 Oct 2015 09:03:50 -0700 Subject: [PATCH] Stc scenario for testing distributed primitives and onos-execute-expect command Change-Id: Iac949099bf072b71aedd85dbc2ee8cf613b01807 --- .../cli/SetTestAddCommand.java | 12 ++-- .../cli/SetTestGetCommand.java | 12 ++-- .../cli/SetTestRemoveCommand.java | 23 +++--- tools/test/bin/onos-execute-expect | 27 +++++++ tools/test/scenarios/dist-test-seq.xml | 67 ++++++++++++++++++ tools/test/scenarios/dist-test.xml | 70 +++++++++++++++++++ 6 files changed, 180 insertions(+), 31 deletions(-) create mode 100755 tools/test/bin/onos-execute-expect create mode 100644 tools/test/scenarios/dist-test-seq.xml create mode 100644 tools/test/scenarios/dist-test.xml diff --git a/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestAddCommand.java b/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestAddCommand.java index 204471c2e3..2d1aa0b8a2 100644 --- a/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestAddCommand.java +++ b/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestAddCommand.java @@ -23,7 +23,7 @@ import org.onosproject.store.serializers.KryoNamespaces; import org.onosproject.store.service.Serializer; import org.onosproject.store.service.StorageService; -import java.util.HashSet; +import java.util.Arrays; import java.util.Set; /** @@ -44,7 +44,6 @@ public class SetTestAddCommand extends AbstractShellCommand { String[] values = null; Set set; - Set toAdd = new HashSet<>(); Serializer serializer = Serializer.using( @@ -68,13 +67,10 @@ public class SetTestAddCommand extends AbstractShellCommand { } } else if (values.length >= 1) { // Add multiple elements to a set - for (String value : values) { - toAdd.add(value); - } - if (set.addAll(toAdd)) { - print("%s was added to the set %s", toAdd, setName); + if (set.addAll(Arrays.asList(values))) { + print("%s was added to the set %s", Arrays.asList(values), setName); } else { - print("%s was already in set %s", toAdd, setName); + print("%s was already in set %s", Arrays.asList(values), setName); } } } diff --git a/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestGetCommand.java b/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestGetCommand.java index fb36a06ab6..74c52c166b 100644 --- a/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestGetCommand.java +++ b/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestGetCommand.java @@ -24,7 +24,7 @@ import org.onosproject.store.serializers.KryoNamespaces; import org.onosproject.store.service.Serializer; import org.onosproject.store.service.StorageService; -import java.util.HashSet; +import java.util.Arrays; import java.util.Set; /** @@ -49,7 +49,6 @@ public class SetTestGetCommand extends AbstractShellCommand { String[] values = null; Set set; - Set toCheck = new HashSet<>(); String output = ""; Serializer serializer = Serializer.using( @@ -95,13 +94,10 @@ public class SetTestGetCommand extends AbstractShellCommand { } } else if (values.length > 1) { //containsAll - for (String value : values) { - toCheck.add(value); - } - if (set.containsAll(toCheck)) { - print("Set %s contains the the subset %s", setName, toCheck); + if (set.containsAll(Arrays.asList(values))) { + print("Set %s contains the the subset %s", setName, Arrays.asList(values)); } else { - print("Set %s did not contain the the subset %s", setName, toCheck); + print("Set %s did not contain the the subset %s", setName, Arrays.asList(values)); } } } diff --git a/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestRemoveCommand.java b/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestRemoveCommand.java index d1f81e422f..1fa073f32b 100644 --- a/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestRemoveCommand.java +++ b/apps/test/distributed-primitives/src/main/java/org/onosproject/distributedprimitives/cli/SetTestRemoveCommand.java @@ -24,7 +24,7 @@ import org.onosproject.store.serializers.KryoNamespaces; import org.onosproject.store.service.Serializer; import org.onosproject.store.service.StorageService; -import java.util.HashSet; +import java.util.Arrays; import java.util.Set; /** @@ -54,7 +54,6 @@ public class SetTestRemoveCommand extends AbstractShellCommand { String[] values = null; Set set; - Set givenValues = new HashSet<>(); Serializer serializer = Serializer.using( new KryoNamespace.Builder().register(KryoNamespaces.BASIC).build()); @@ -79,13 +78,10 @@ public class SetTestRemoveCommand extends AbstractShellCommand { } if (retain) { // Keep only the given values - for (String value : values) { - givenValues.add(value); - } - if (set.retainAll(givenValues)) { - print("%s was pruned to contain only elements of set %s", setName, givenValues); + if (set.retainAll(Arrays.asList(values))) { + print("%s was pruned to contain only elements of set %s", setName, Arrays.asList(values)); } else { - print("%s was not changed by retaining only elements of the set %s", setName, givenValues); + print("%s was not changed by retaining only elements of the set %s", setName, Arrays.asList(values)); } } else if (values.length == 1) { // Remove a single element from the set @@ -94,15 +90,12 @@ public class SetTestRemoveCommand extends AbstractShellCommand { } else { print("[%s] was not in set %s", values[0], setName); } - } else if (values.length >= 1) { + } else if (values.length > 1) { // Remove multiple elements from a set - for (String value : values) { - givenValues.add(value); - } - if (set.removeAll(givenValues)) { - print("%s was removed from the set %s", givenValues, setName); + if (set.removeAll(Arrays.asList(values))) { + print("%s was removed from the set %s", Arrays.asList(values), setName); } else { - print("No element of %s was in set %s", givenValues, setName); + print("No element of %s was in set %s", Arrays.asList(values), setName); } } } diff --git a/tools/test/bin/onos-execute-expect b/tools/test/bin/onos-execute-expect new file mode 100755 index 0000000000..6ad95699ec --- /dev/null +++ b/tools/test/bin/onos-execute-expect @@ -0,0 +1,27 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# Executes a command on the given ONOS instance and matches the output +# to the passed one. +# First argument is the IP address of the machine to run the command on, +# then you pass the command and it's arguments if needed, then --expect and +# after it the string of what the output should be. +# Example: +# onos-execute-expect 1.1.1.1 fooCommand fooParamenter --expect fooOutputString +# ----------------------------------------------------------------------------- + +[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 +. $ONOS_ROOT/tools/build/envDefaults + + +aux=/tmp/stc-$$.log +trap "rm -f $aux 2>/dev/null" EXIT +ip=$1 +cmd="" +for a in ${*:2}; do shift; if [ "$a" = "--expect" ]; then break; fi; cmd="$cmd $a"; done +expect="${@: -1}" +onos $ip $cmd > $aux +cat $aux +grep -q $expect $aux && echo "expected value found" && exit 0 +exit 1 + + diff --git a/tools/test/scenarios/dist-test-seq.xml b/tools/test/scenarios/dist-test-seq.xml new file mode 100644 index 0000000000..2e99fa27c5 --- /dev/null +++ b/tools/test/scenarios/dist-test-seq.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/test/scenarios/dist-test.xml b/tools/test/scenarios/dist-test.xml new file mode 100644 index 0000000000..5e7dab0b5c --- /dev/null +++ b/tools/test/scenarios/dist-test.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +