Skip to content

Commit

Permalink
Fix tests about Dynamic IP using ReverseProxy...
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Oct 15, 2024
1 parent 88f161a commit 1a3f280
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.leshan.core.util.TestToolBox.uriHandler;
import static org.eclipse.leshan.integration.tests.util.assertion.Assertions.assertArg;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNotNull;
import static org.mockito.ArgumentMatchers.notNull;
Expand Down Expand Up @@ -140,10 +141,10 @@ public void waitForRegistrationTo(LeshanTestServer server) {

public void waitForRegistrationTo(LeshanTestServer server, long timeout, TimeUnit unit) {
inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onRegistrationStarted(assertArg( //
s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), //
s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), //
isNotNull());
inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onRegistrationSuccess(assertArg( //
s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), //
s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), //
isNotNull(), isNotNull());
inOrder.verifyNoMoreInteractions();
}
Expand All @@ -157,10 +158,10 @@ public Failure waitForRegistrationFailureTo(LeshanTestServer server, long timeou
final ArgumentCaptor<ResponseCode> cCode = ArgumentCaptor.forClass(ResponseCode.class);

inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onRegistrationStarted(assertArg( //
s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), //
s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), //
isNotNull());
inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onRegistrationFailure(assertArg( //
s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), //
s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), //
notNull(), cCode.capture(), any(), cExp.capture());
inOrder.verifyNoMoreInteractions();

Expand All @@ -169,10 +170,10 @@ public Failure waitForRegistrationFailureTo(LeshanTestServer server, long timeou

public void waitForUpdateTo(LeshanTestServer server, long timeout, TimeUnit unit) {
inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onUpdateStarted(assertArg( //
s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), //
s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), //
notNull());
inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onUpdateSuccess(assertArg( //
s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), //
s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), //
notNull());
inOrder.verifyNoMoreInteractions();
}
Expand All @@ -183,10 +184,10 @@ public void waitForDeregistrationTo(LeshanTestServer server) {

public void waitForDeregistrationTo(LeshanTestServer server, long timeout, TimeUnit unit) {
inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onDeregistrationStarted(assertArg( //
s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), //
s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), //
isNotNull());
inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onDeregistrationSuccess(assertArg( //
s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), //
s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), //
isNotNull());
inOrder.verifyNoMoreInteractions();
}
Expand All @@ -197,11 +198,11 @@ public void waitForUpdateTimeoutTo(LeshanTestServer server) {

public void waitForUpdateTimeoutTo(LeshanTestServer server, long timeout, TimeUnit unit) {
inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onUpdateStarted(assertArg( //
s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), //
s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), //
notNull());

inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onUpdateTimeout(assertArg( //
s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), //
s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), //
notNull());
// if client update timeout, it will retry again then try a register so all events can not be consume by inOrder
// ...
Expand All @@ -213,10 +214,10 @@ public void waitForUpdateFailureTo(LeshanTestServer server) {

public void waitForUpdateFailureTo(LeshanTestServer server, long timeout, TimeUnit unit) {
inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onUpdateStarted(assertArg( //
s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), //
s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), //
notNull());
inOrder.verify(clientObserver, timeout(unit.toMillis(timeout)).times(1)).onUpdateFailure(assertArg( //
s -> assertThat(isServerIdentifiedByUri(server, s.getUri()))), //
s -> assertTrue(isServerIdentifiedByUri(server, s.getUri()))), //
notNull(), //
notNull(), // TODO we should be able to check response code
any(), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,7 @@ public InetSocketAddress getClientSideProxyAddress() {
* @return address of server to proxified
*/
public InetSocketAddress getServerAddress() {
try {
return (InetSocketAddress) clientToProxyChannel.getLocalAddress();
} catch (IOException e) {
throw new IllegalStateException(e);
}
return serverAddress;
}

/**
Expand Down

0 comments on commit 1a3f280

Please sign in to comment.