Skip to content

Commit

Permalink
Cleanup advanced handshake tests.
Browse files Browse the repository at this point in the history
Assert intended session states.

Signed-off-by: Achim Kraus <achim.kraus@bosch.io>
  • Loading branch information
Achim Kraus committed Sep 4, 2020
1 parent 1c0e572 commit 719598f
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -570,10 +570,15 @@ public List<Record> assertFlight(int size, long timeout, TimeUnit unit) throws I

};

static class LatchSessionListener extends SessionAdapter {
public static enum SessionState {
ESTABLISHED, COMPLETED, FAILED
}

public static class LatchSessionListener extends SessionAdapter {

private CountDownLatch finished = new CountDownLatch(1);
private AtomicBoolean established = new AtomicBoolean();
private CountDownLatch completed = new CountDownLatch(1);
private AtomicReference<Throwable> error = new AtomicReference<Throwable>();

@Override
Expand All @@ -583,6 +588,11 @@ public void sessionEstablished(Handshaker handshaker, DTLSSession establishedSes
finished.countDown();
}

@Override
public void handshakeCompleted(Handshaker handshaker) {
completed.countDown();
}

@Override
public void handshakeFailed(Handshaker handshaker, Throwable error) {
this.error.set(error);
Expand All @@ -593,6 +603,13 @@ public boolean waitForSessionEstablished(long timeout, TimeUnit unit) throws Int
return finished.await(timeout, unit) && established.get();
}

public boolean waitForSessionCompleted(long timeout, TimeUnit unit) throws InterruptedException {
if (waitForSessionEstablished(timeout, unit)) {
return completed.await(timeout, unit);
}
return false;
}

public Throwable waitForSessionFailed(long timeout, TimeUnit unit) throws InterruptedException {
if (finished.await(timeout, unit)) {
return error.get();
Expand Down
Loading

0 comments on commit 719598f

Please sign in to comment.