suibin zhang
Committed by Gerrit Code Review

fix push-test-intents with latch is 0 before countdown

Change-Id: Ie9891612490f82b5067e795592e577952838b988
...@@ -15,11 +15,7 @@ ...@@ -15,11 +15,7 @@
15 */ 15 */
16 package org.onosproject.cli.net; 16 package org.onosproject.cli.net;
17 17
18 -import java.util.EnumSet; 18 +import com.google.common.collect.Lists;
19 -import java.util.List;
20 -import java.util.concurrent.CountDownLatch;
21 -import java.util.concurrent.TimeUnit;
22 -
23 import org.apache.karaf.shell.commands.Argument; 19 import org.apache.karaf.shell.commands.Argument;
24 import org.apache.karaf.shell.commands.Command; 20 import org.apache.karaf.shell.commands.Command;
25 import org.apache.karaf.shell.commands.Option; 21 import org.apache.karaf.shell.commands.Option;
...@@ -41,7 +37,11 @@ import org.onosproject.net.intent.IntentService; ...@@ -41,7 +37,11 @@ import org.onosproject.net.intent.IntentService;
41 import org.onosproject.net.intent.Key; 37 import org.onosproject.net.intent.Key;
42 import org.onosproject.net.intent.PointToPointIntent; 38 import org.onosproject.net.intent.PointToPointIntent;
43 39
44 -import com.google.common.collect.Lists; 40 +import java.util.ArrayList;
41 +import java.util.EnumSet;
42 +import java.util.List;
43 +import java.util.concurrent.CountDownLatch;
44 +import java.util.concurrent.TimeUnit;
45 45
46 import static org.onosproject.net.DeviceId.deviceId; 46 import static org.onosproject.net.DeviceId.deviceId;
47 import static org.onosproject.net.PortNumber.portNumber; 47 import static org.onosproject.net.PortNumber.portNumber;
...@@ -90,6 +90,8 @@ public class IntentPushTestCommand extends AbstractShellCommand ...@@ -90,6 +90,8 @@ public class IntentPushTestCommand extends AbstractShellCommand
90 private int count; 90 private int count;
91 private int keyOffset; 91 private int keyOffset;
92 private boolean add; 92 private boolean add;
93 + List<Key> keysForInstall = new ArrayList<>();
94 + List<Key> keysForWithdraw = new ArrayList<>();
93 95
94 @Override 96 @Override
95 protected void execute() { 97 protected void execute() {
...@@ -144,14 +146,15 @@ public class IntentPushTestCommand extends AbstractShellCommand ...@@ -144,14 +146,15 @@ public class IntentPushTestCommand extends AbstractShellCommand
144 .ingressPoint(ingress) 146 .ingressPoint(ingress)
145 .egressPoint(egress) 147 .egressPoint(egress)
146 .build()); 148 .build());
147 - 149 + keysForInstall.add(Key.of(i + keyOffset, appId()));
148 - 150 + keysForWithdraw.add(Key.of(i + keyOffset, appId()));
149 } 151 }
150 return intents; 152 return intents;
151 } 153 }
152 154
153 private void submitIntents(List<Intent> intents) { 155 private void submitIntents(List<Intent> intents) {
154 latch = new CountDownLatch(count); 156 latch = new CountDownLatch(count);
157 + log.info("CountDownLatch is set with count of {}", count);
155 start = System.currentTimeMillis(); 158 start = System.currentTimeMillis();
156 for (Intent intent : intents) { 159 for (Intent intent : intents) {
157 if (add) { 160 if (add) {
...@@ -162,7 +165,7 @@ public class IntentPushTestCommand extends AbstractShellCommand ...@@ -162,7 +165,7 @@ public class IntentPushTestCommand extends AbstractShellCommand
162 } 165 }
163 166
164 try { 167 try {
165 - if (latch.await(500 + count * 30, TimeUnit.MILLISECONDS)) { 168 + if (latch.await(1000 + count * 30, TimeUnit.MILLISECONDS)) {
166 printResults(count); 169 printResults(count);
167 } else { 170 } else {
168 print("Failure: %d intents not installed", latch.getCount()); 171 print("Failure: %d intents not installed", latch.getCount());
...@@ -215,13 +218,17 @@ public class IntentPushTestCommand extends AbstractShellCommand ...@@ -215,13 +218,17 @@ public class IntentPushTestCommand extends AbstractShellCommand
215 return; 218 return;
216 } 219 }
217 Type expected = add ? Type.INSTALLED : Type.WITHDRAWN; 220 Type expected = add ? Type.INSTALLED : Type.WITHDRAWN;
218 - if (event.type() == expected) { 221 + List keylist = add ? keysForInstall : keysForWithdraw;
222 + log.debug("Event generated: {}", event);
223 + if (event.type() == expected && keylist.contains(event.subject().key())) {
219 end = Math.max(end, event.time()); 224 end = Math.max(end, event.time());
225 + keylist.remove(event.subject().key());
220 if (latch != null) { 226 if (latch != null) {
221 if (latch.getCount() == 0) { 227 if (latch.getCount() == 0) {
222 log.warn("Latch was already 0 before counting down?"); 228 log.warn("Latch was already 0 before counting down?");
223 } 229 }
224 latch.countDown(); 230 latch.countDown();
231 + log.debug("Latch count is {}", latch.getCount());
225 } else { 232 } else {
226 log.warn("install event latch is null"); 233 log.warn("install event latch is null");
227 } 234 }
......