Skip to content

Commit 8c69fe4

Browse files
author
Tilmann Zäschke
committed
Refactoring and fixes
1 parent 3ccd549 commit 8c69fe4

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/main/java/org/scion/multiping/PingAll.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.concurrent.ConcurrentHashMap;
2525
import java.util.concurrent.CountDownLatch;
2626
import java.util.concurrent.TimeUnit;
27+
import java.util.concurrent.atomic.AtomicInteger;
2728
import java.util.stream.Collectors;
2829
import org.scion.jpan.*;
2930
import org.scion.jpan.internal.PathRawParser;
@@ -308,6 +309,7 @@ private Scmp.TracerouteMessage findFastestTR(List<Path> paths, Ref<Path> refBest
308309
private Scmp.TracerouteMessage findFastestTRasync(List<Path> paths, Ref<Path> refBest) {
309310
ConcurrentHashMap<Integer, Scmp.TimedMessage> messages = new ConcurrentHashMap<>();
310311
CountDownLatch barrier = new CountDownLatch(paths.size());
312+
AtomicInteger errors = new AtomicInteger();
311313
ScmpSenderAsync.ResponseHandler handler =
312314
new ScmpSenderAsync.ResponseHandler() {
313315
@Override
@@ -324,13 +326,13 @@ public void onTimeout(Scmp.TimedMessage msg) {
324326

325327
@Override
326328
public void onError(Scmp.ErrorMessage msg) {
327-
summary.incAsError();
329+
errors.incrementAndGet();
328330
barrier.countDown();
329331
}
330332

331333
@Override
332334
public void onException(Throwable t) {
333-
summary.incAsError();
335+
errors.incrementAndGet();
334336
barrier.countDown();
335337
}
336338
};
@@ -356,6 +358,11 @@ public void onException(Throwable t) {
356358
throw new IllegalStateException(e);
357359
}
358360

361+
if (errors.get() > 0 && messages.isEmpty()) {
362+
summary.incAsError();
363+
return null;
364+
}
365+
359366
Scmp.TracerouteMessage best = null;
360367
for (Scmp.TimedMessage tm : messages.values()) {
361368
Scmp.TracerouteMessage msg = (Scmp.TracerouteMessage) tm;

src/test/java/org/scion/multiping/PingAllTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,11 @@ class MyWithHandler extends WithHandler {
161161
PingAll ping = new PingAll(PingAll.Policy.FASTEST_TR_ASYNC, p);
162162
ResultSummary summary = ping.run();
163163
assertEquals(0, summary.getMaxPaths().getPathCount());
164-
assertEquals(9, summary.getAsErrors());
164+
assertEquals(3, summary.getAsErrors());
165165
}
166166

167167
@Test
168168
void testPingSendingError() throws IOException {
169-
List<Path> paths = PathHelper.createPaths(3);
170169
class MyWithHandler extends WithIOError {
171170
MyWithHandler(ScmpSenderAsync.ResponseHandler handler) {
172171
super(handler, hdl -> {});

0 commit comments

Comments
 (0)