Committed by
Gerrit Code Review
Stc scenario for testing distributed primitives and onos-execute-expect command
Change-Id: Iac949099bf072b71aedd85dbc2ee8cf613b01807
Showing
6 changed files
with
180 additions
and
31 deletions
... | @@ -23,7 +23,7 @@ import org.onosproject.store.serializers.KryoNamespaces; | ... | @@ -23,7 +23,7 @@ import org.onosproject.store.serializers.KryoNamespaces; |
23 | import org.onosproject.store.service.Serializer; | 23 | import org.onosproject.store.service.Serializer; |
24 | import org.onosproject.store.service.StorageService; | 24 | import org.onosproject.store.service.StorageService; |
25 | 25 | ||
26 | -import java.util.HashSet; | 26 | +import java.util.Arrays; |
27 | import java.util.Set; | 27 | import java.util.Set; |
28 | 28 | ||
29 | /** | 29 | /** |
... | @@ -44,7 +44,6 @@ public class SetTestAddCommand extends AbstractShellCommand { | ... | @@ -44,7 +44,6 @@ public class SetTestAddCommand extends AbstractShellCommand { |
44 | String[] values = null; | 44 | String[] values = null; |
45 | 45 | ||
46 | Set<String> set; | 46 | Set<String> set; |
47 | - Set<String> toAdd = new HashSet<>(); | ||
48 | 47 | ||
49 | 48 | ||
50 | Serializer serializer = Serializer.using( | 49 | Serializer serializer = Serializer.using( |
... | @@ -68,13 +67,10 @@ public class SetTestAddCommand extends AbstractShellCommand { | ... | @@ -68,13 +67,10 @@ public class SetTestAddCommand extends AbstractShellCommand { |
68 | } | 67 | } |
69 | } else if (values.length >= 1) { | 68 | } else if (values.length >= 1) { |
70 | // Add multiple elements to a set | 69 | // Add multiple elements to a set |
71 | - for (String value : values) { | 70 | + if (set.addAll(Arrays.asList(values))) { |
72 | - toAdd.add(value); | 71 | + print("%s was added to the set %s", Arrays.asList(values), setName); |
73 | - } | ||
74 | - if (set.addAll(toAdd)) { | ||
75 | - print("%s was added to the set %s", toAdd, setName); | ||
76 | } else { | 72 | } else { |
77 | - print("%s was already in set %s", toAdd, setName); | 73 | + print("%s was already in set %s", Arrays.asList(values), setName); |
78 | } | 74 | } |
79 | } | 75 | } |
80 | } | 76 | } | ... | ... |
... | @@ -24,7 +24,7 @@ import org.onosproject.store.serializers.KryoNamespaces; | ... | @@ -24,7 +24,7 @@ import org.onosproject.store.serializers.KryoNamespaces; |
24 | import org.onosproject.store.service.Serializer; | 24 | import org.onosproject.store.service.Serializer; |
25 | import org.onosproject.store.service.StorageService; | 25 | import org.onosproject.store.service.StorageService; |
26 | 26 | ||
27 | -import java.util.HashSet; | 27 | +import java.util.Arrays; |
28 | import java.util.Set; | 28 | import java.util.Set; |
29 | 29 | ||
30 | /** | 30 | /** |
... | @@ -49,7 +49,6 @@ public class SetTestGetCommand extends AbstractShellCommand { | ... | @@ -49,7 +49,6 @@ public class SetTestGetCommand extends AbstractShellCommand { |
49 | String[] values = null; | 49 | String[] values = null; |
50 | 50 | ||
51 | Set<String> set; | 51 | Set<String> set; |
52 | - Set<String> toCheck = new HashSet<>(); | ||
53 | String output = ""; | 52 | String output = ""; |
54 | 53 | ||
55 | Serializer serializer = Serializer.using( | 54 | Serializer serializer = Serializer.using( |
... | @@ -95,13 +94,10 @@ public class SetTestGetCommand extends AbstractShellCommand { | ... | @@ -95,13 +94,10 @@ public class SetTestGetCommand extends AbstractShellCommand { |
95 | } | 94 | } |
96 | } else if (values.length > 1) { | 95 | } else if (values.length > 1) { |
97 | //containsAll | 96 | //containsAll |
98 | - for (String value : values) { | 97 | + if (set.containsAll(Arrays.asList(values))) { |
99 | - toCheck.add(value); | 98 | + print("Set %s contains the the subset %s", setName, Arrays.asList(values)); |
100 | - } | ||
101 | - if (set.containsAll(toCheck)) { | ||
102 | - print("Set %s contains the the subset %s", setName, toCheck); | ||
103 | } else { | 99 | } else { |
104 | - print("Set %s did not contain the the subset %s", setName, toCheck); | 100 | + print("Set %s did not contain the the subset %s", setName, Arrays.asList(values)); |
105 | } | 101 | } |
106 | } | 102 | } |
107 | } | 103 | } | ... | ... |
... | @@ -24,7 +24,7 @@ import org.onosproject.store.serializers.KryoNamespaces; | ... | @@ -24,7 +24,7 @@ import org.onosproject.store.serializers.KryoNamespaces; |
24 | import org.onosproject.store.service.Serializer; | 24 | import org.onosproject.store.service.Serializer; |
25 | import org.onosproject.store.service.StorageService; | 25 | import org.onosproject.store.service.StorageService; |
26 | 26 | ||
27 | -import java.util.HashSet; | 27 | +import java.util.Arrays; |
28 | import java.util.Set; | 28 | import java.util.Set; |
29 | 29 | ||
30 | /** | 30 | /** |
... | @@ -54,7 +54,6 @@ public class SetTestRemoveCommand extends AbstractShellCommand { | ... | @@ -54,7 +54,6 @@ public class SetTestRemoveCommand extends AbstractShellCommand { |
54 | String[] values = null; | 54 | String[] values = null; |
55 | 55 | ||
56 | Set<String> set; | 56 | Set<String> set; |
57 | - Set<String> givenValues = new HashSet<>(); | ||
58 | Serializer serializer = Serializer.using( | 57 | Serializer serializer = Serializer.using( |
59 | new KryoNamespace.Builder().register(KryoNamespaces.BASIC).build()); | 58 | new KryoNamespace.Builder().register(KryoNamespaces.BASIC).build()); |
60 | 59 | ||
... | @@ -79,13 +78,10 @@ public class SetTestRemoveCommand extends AbstractShellCommand { | ... | @@ -79,13 +78,10 @@ public class SetTestRemoveCommand extends AbstractShellCommand { |
79 | } | 78 | } |
80 | 79 | ||
81 | if (retain) { // Keep only the given values | 80 | if (retain) { // Keep only the given values |
82 | - for (String value : values) { | 81 | + if (set.retainAll(Arrays.asList(values))) { |
83 | - givenValues.add(value); | 82 | + print("%s was pruned to contain only elements of set %s", setName, Arrays.asList(values)); |
84 | - } | ||
85 | - if (set.retainAll(givenValues)) { | ||
86 | - print("%s was pruned to contain only elements of set %s", setName, givenValues); | ||
87 | } else { | 83 | } else { |
88 | - print("%s was not changed by retaining only elements of the set %s", setName, givenValues); | 84 | + print("%s was not changed by retaining only elements of the set %s", setName, Arrays.asList(values)); |
89 | } | 85 | } |
90 | } else if (values.length == 1) { | 86 | } else if (values.length == 1) { |
91 | // Remove a single element from the set | 87 | // Remove a single element from the set |
... | @@ -94,15 +90,12 @@ public class SetTestRemoveCommand extends AbstractShellCommand { | ... | @@ -94,15 +90,12 @@ public class SetTestRemoveCommand extends AbstractShellCommand { |
94 | } else { | 90 | } else { |
95 | print("[%s] was not in set %s", values[0], setName); | 91 | print("[%s] was not in set %s", values[0], setName); |
96 | } | 92 | } |
97 | - } else if (values.length >= 1) { | 93 | + } else if (values.length > 1) { |
98 | // Remove multiple elements from a set | 94 | // Remove multiple elements from a set |
99 | - for (String value : values) { | 95 | + if (set.removeAll(Arrays.asList(values))) { |
100 | - givenValues.add(value); | 96 | + print("%s was removed from the set %s", Arrays.asList(values), setName); |
101 | - } | ||
102 | - if (set.removeAll(givenValues)) { | ||
103 | - print("%s was removed from the set %s", givenValues, setName); | ||
104 | } else { | 97 | } else { |
105 | - print("No element of %s was in set %s", givenValues, setName); | 98 | + print("No element of %s was in set %s", Arrays.asList(values), setName); |
106 | } | 99 | } |
107 | } | 100 | } |
108 | } | 101 | } | ... | ... |
tools/test/bin/onos-execute-expect
0 → 100755
1 | +#!/bin/bash | ||
2 | +# ----------------------------------------------------------------------------- | ||
3 | +# Executes a command on the given ONOS instance and matches the output | ||
4 | +# to the passed one. | ||
5 | +# First argument is the IP address of the machine to run the command on, | ||
6 | +# then you pass the command and it's arguments if needed, then --expect and | ||
7 | +# after it the string of what the output should be. | ||
8 | +# Example: | ||
9 | +# onos-execute-expect 1.1.1.1 fooCommand fooParamenter --expect fooOutputString | ||
10 | +# ----------------------------------------------------------------------------- | ||
11 | + | ||
12 | +[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 | ||
13 | +. $ONOS_ROOT/tools/build/envDefaults | ||
14 | + | ||
15 | + | ||
16 | +aux=/tmp/stc-$$.log | ||
17 | +trap "rm -f $aux 2>/dev/null" EXIT | ||
18 | +ip=$1 | ||
19 | +cmd="" | ||
20 | +for a in ${*:2}; do shift; if [ "$a" = "--expect" ]; then break; fi; cmd="$cmd $a"; done | ||
21 | +expect="${@: -1}" | ||
22 | +onos $ip $cmd > $aux | ||
23 | +cat $aux | ||
24 | +grep -q $expect $aux && echo "expected value found" && exit 0 | ||
25 | +exit 1 | ||
26 | + | ||
27 | + |
tools/test/scenarios/dist-test-seq.xml
0 → 100644
1 | +<!-- | ||
2 | + ~ Copyright 20${OCI}5 Open Networking Laboratory | ||
3 | + ~ | ||
4 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + ~ you may not use this file except in compliance with the License. | ||
6 | + ~ You may obtain a copy of the License at | ||
7 | + ~ | ||
8 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + ~ | ||
10 | + ~ Unless required by applicable law or agreed to in writing, software | ||
11 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + ~ See the License for the specific language governing permissions and | ||
14 | + ~ limitations under the License. | ||
15 | + --> | ||
16 | + | ||
17 | +<scenario name="dist-test" | ||
18 | + description="ONOS distributed primitives setup"> | ||
19 | + <group name="Distributed-Primitives"> | ||
20 | + <!--<import file="${ONOS_SCENARIOS}/prerequisites.xml"/>--> | ||
21 | + | ||
22 | + <!--<import file="${ONOS_SCENARIOS}/setup.xml"/> | ||
23 | + <dependency name="Setup" requires="Prerequisites"/>--> | ||
24 | + | ||
25 | + <sequential var="${OC#}" starts="Distributed-App-${#}" ends="Check-Distributed-Exceptions-${#-1}"> | ||
26 | + <step name="Distributed-App-${#}" | ||
27 | + requires="Setup" | ||
28 | + exec="onos ${OC#} app activate org.onosproject.distributedprimitives"/> | ||
29 | + | ||
30 | + <step name="Test-Counter-Increment-${#}" | ||
31 | + requires="Distributed-App-${#}" | ||
32 | + exec="onos-execute-expect ${OC#} counter-test-increment fooCounter 5 --expect updated"/> | ||
33 | + | ||
34 | + <step name="Test-Add-${#}" | ||
35 | + requires="Distributed-App-${#}" | ||
36 | + exec="onos-execute-expect ${OC#} set-test-add fooSet foo --expect added"/> | ||
37 | + | ||
38 | + <step name="Test-Get-${#}" | ||
39 | + requires="Test-Add-${#}" | ||
40 | + exec="onos-execute-expect ${OC#} set-test-get fooSet foo --expect contains"/> | ||
41 | + | ||
42 | + <step name="Test-Remove-${#}" | ||
43 | + requires="Test-Get-${#}" | ||
44 | + exec="onos-execute-expect ${OC#} set-test-remove fooSet foo --expect removed"/> | ||
45 | + | ||
46 | + <step name="Test-Add-Multiple-${#}" | ||
47 | + requires="Test-Remove-${#}" | ||
48 | + exec="onos-execute-expect ${OC#} set-test-add fooSet foo foo2 foo3 --expect added"/> | ||
49 | + | ||
50 | + <step name="Test-Get-Multiple-${#}" | ||
51 | + requires="Test-Add-Multiple-${#}" | ||
52 | + exec="onos-execute-expect ${OC#} set-test-get fooSet foo foo2 foo3 --expect contains"/> | ||
53 | + | ||
54 | + <step name="Test-Remove-Multiple-${#}" | ||
55 | + requires="Test-Get-Multiple-${#}" | ||
56 | + exec="onos-execute-expect ${OC#} set-test-remove fooSet foo foo2 foo3 --expect removed"/> | ||
57 | + | ||
58 | + <step name="Sleep-${#}" | ||
59 | + exec="sleep 2" | ||
60 | + requires="Test-Remove-Multiple-${#}"/> | ||
61 | + <!--Check with check logs--> | ||
62 | + <step name="Check-Distributed-Exceptions-${#}" | ||
63 | + exec="onos-check-logs ${OC#}" | ||
64 | + requires="Sleep-${#}"/> | ||
65 | + </sequential> | ||
66 | + </group> | ||
67 | +</scenario> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
tools/test/scenarios/dist-test.xml
0 → 100644
1 | +<!-- | ||
2 | + ~ Copyright 2015 Open Networking Laboratory | ||
3 | + ~ | ||
4 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + ~ you may not use this file except in compliance with the License. | ||
6 | + ~ You may obtain a copy of the License at | ||
7 | + ~ | ||
8 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + ~ | ||
10 | + ~ Unless required by applicable law or agreed to in writing, software | ||
11 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + ~ See the License for the specific language governing permissions and | ||
14 | + ~ limitations under the License. | ||
15 | +--> | ||
16 | + | ||
17 | +<scenario name="dist-test" | ||
18 | + description="ONOS distributed primitives setup"> | ||
19 | + <group name="Distributed-Primitives"> | ||
20 | + | ||
21 | + <!--<import file="${ONOS_SCENARIOS}/setup.xml"/> | ||
22 | + <dependency name="Setup" requires="Prerequisites"/>--> | ||
23 | + | ||
24 | + <step name="Distributed-App" | ||
25 | + requires="Setup" | ||
26 | + exec="onos ${OCI} app activate org.onosproject.distributedprimitives"/> | ||
27 | + | ||
28 | + <step name="Test-Counter-Increment" | ||
29 | + requires="Distributed-App" | ||
30 | + exec="onos-execute-expect ${OCI} counter-test-increment fooCounter 5 --expect updated"/> | ||
31 | + | ||
32 | + <step name="Test-Add" | ||
33 | + requires="Distributed-App" | ||
34 | + exec="onos-execute-expect ${OCI} set-test-add fooSet foo --expect added"/> | ||
35 | + | ||
36 | + <step name="Test-Get" | ||
37 | + requires="Test-Add" | ||
38 | + exec="onos-execute-expect ${OCI} set-test-get fooSet foo --expect contains"/> | ||
39 | + | ||
40 | + <step name="Test-Remove" | ||
41 | + requires="Test-Get" | ||
42 | + exec="onos-execute-expect ${OCI} set-test-remove fooSet foo --expect removed"/> | ||
43 | + | ||
44 | + <step name="Test-Add-Multiple" | ||
45 | + requires="Test-Remove" | ||
46 | + exec="onos-execute-expect ${OCI} set-test-add fooSet foo foo2 foo3 --expect added"/> | ||
47 | + | ||
48 | + <step name="Test-Get-Multiple" | ||
49 | + requires="Test-Add-Multiple" | ||
50 | + exec="onos-execute-expect ${OCI} set-test-get fooSet foo foo2 foo3 --expect contains"/> | ||
51 | + | ||
52 | + <step name="Test-Remove-Multiple" | ||
53 | + requires="Test-Get-Multiple" | ||
54 | + exec="onos-execute-expect ${OCI} set-test-remove fooSet foo foo2 foo3 --expect removed"/> | ||
55 | + | ||
56 | + <step name="Test-Map-Put" | ||
57 | + requires="Distributed-App" | ||
58 | + exec="onos-execute-expect ${OCI} transactional-map-test-put 1 foo --expect Created"/> | ||
59 | + | ||
60 | + <step name="Test-Map-Get" | ||
61 | + requires="Test-Map-Put" | ||
62 | + exec="onos-execute-expect ${OCI} transactional-map-test-get Key1 --expect Key-value"/> | ||
63 | + | ||
64 | + <!--Check with check logs--> | ||
65 | + <step name="Check-Distributed-Exceptions" | ||
66 | + exec="onos-check-logs ${OCI}" | ||
67 | + requires="Test-Map-Get"/> | ||
68 | + </group> | ||
69 | +</scenario> | ||
70 | + |
-
Please register or login to post a comment