Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-v committed Sep 1, 2023
1 parent 16fe20e commit 837d09e
Showing 1 changed file with 42 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,21 @@ class TransportWrapperTest {
.data("" + System.currentTimeMillis())
.build();

private final Transport transport;
private final TransportWrapper transportWrapper;

public TransportWrapperTest() {
transport = mock(Transport.class);
transportWrapper = new TransportWrapper(transport);
}

@Nested
class RequestResponseTests {

@Test
void requestResponseShouldWork() {
final List<Address> addresses = Collections.singletonList(Address.from("test:0"));
final Member member = new Member("test", null, addresses, "namespace");
final Transport transport = mock(Transport.class);
final TransportWrapper transportWrapper = new TransportWrapper(transport);

when(transport.requestResponse(addresses.get(0), request)).thenReturn(Mono.just(response));

Expand All @@ -57,12 +63,29 @@ void requestResponseShouldWork() {
.verify();
}

@Test
void requestResponseShouldWorkThenFail() {
final List<Address> addresses = Collections.singletonList(Address.from("test:0"));
final Member member = new Member("test", null, addresses, "namespace");

when(transport.requestResponse(addresses.get(0), request))
.thenReturn(Mono.just(response))
.thenReturn(Mono.error(new RuntimeException("Error")));

StepVerifier.create(transportWrapper.requestResponse(member, request))
.assertNext(message -> Assertions.assertSame(response, message, "response"))
.thenCancel()
.verify();

StepVerifier.create(transportWrapper.requestResponse(member, request))
.verifyErrorSatisfies(
throwable -> Assertions.assertEquals("Error", throwable.getMessage()));
}

@Test
void requestResponseShouldWorkMemberSingleAddress() {
final List<Address> addresses = Collections.singletonList(Address.from("test:0"));
final Member member = new Member("test", null, addresses, "namespace");
final Transport transport = mock(Transport.class);
final TransportWrapper transportWrapper = new TransportWrapper(transport);

when(transport.requestResponse(addresses.get(0), request)).thenReturn(Mono.just(response));

Expand All @@ -76,8 +99,6 @@ void requestResponseShouldWorkMemberSingleAddress() {
void requestResponseShouldWorkMemberTwoAddresses() {
final List<Address> addresses = Arrays.asList(Address.from("test:0"), Address.from("test:1"));
final Member member = new Member("test", null, addresses, "namespace");
final Transport transport = mock(Transport.class);
final TransportWrapper transportWrapper = new TransportWrapper(transport);

when(transport.requestResponse(addresses.get(0), request))
.thenReturn(Mono.error(new RuntimeException("Error")));
Expand All @@ -94,8 +115,6 @@ void requestResponseShouldWorkMemberThreeAddresses() {
final List<Address> addresses =
Arrays.asList(Address.from("test:0"), Address.from("test:1"), Address.from("test:2"));
final Member member = new Member("test", null, addresses, "namespace");
final Transport transport = mock(Transport.class);
final TransportWrapper transportWrapper = new TransportWrapper(transport);

when(transport.requestResponse(addresses.get(0), request))
.thenReturn(Mono.error(new RuntimeException("Error")));
Expand All @@ -113,8 +132,6 @@ void requestResponseShouldWorkMemberThreeAddresses() {
void requestResponseShouldFailMemberSingleAddress() {
final List<Address> addresses = Collections.singletonList(Address.from("test:0"));
final Member member = new Member("test", null, addresses, "namespace");
final Transport transport = mock(Transport.class);
final TransportWrapper transportWrapper = new TransportWrapper(transport);

when(transport.requestResponse(addresses.get(0), request))
.thenReturn(Mono.error(new RuntimeException("Error")));
Expand All @@ -128,8 +145,6 @@ void requestResponseShouldFailMemberSingleAddress() {
void requestResponseShouldFailMemberTwoAddresses() {
final List<Address> addresses = Arrays.asList(Address.from("test:0"), Address.from("test:1"));
final Member member = new Member("test", null, addresses, "namespace");
final Transport transport = mock(Transport.class);
final TransportWrapper transportWrapper = new TransportWrapper(transport);

when(transport.requestResponse(addresses.get(0), request))
.thenReturn(Mono.error(new RuntimeException("Error - 0")));
Expand All @@ -146,8 +161,6 @@ void requestResponseShouldFailMemberThreeAddresses() {
final List<Address> addresses =
Arrays.asList(Address.from("test:0"), Address.from("test:1"), Address.from("test:2"));
final Member member = new Member("test", null, addresses, "namespace");
final Transport transport = mock(Transport.class);
final TransportWrapper transportWrapper = new TransportWrapper(transport);

when(transport.requestResponse(addresses.get(0), request))
.thenReturn(Mono.error(new RuntimeException("Error - 0")));
Expand All @@ -169,20 +182,31 @@ class SendTests {
void sendShouldWork() {
final List<Address> addresses = Collections.singletonList(Address.from("test:0"));
final Member member = new Member("test", null, addresses, "namespace");
final Transport transport = mock(Transport.class);
final TransportWrapper transportWrapper = new TransportWrapper(transport);

when(transport.send(addresses.get(0), request)).thenReturn(Mono.empty());

StepVerifier.create(transportWrapper.send(member, request).retry(2)).verifyComplete();
}

@Test
void sendShouldWorkThenFail() {
final List<Address> addresses = Collections.singletonList(Address.from("test:0"));
final Member member = new Member("test", null, addresses, "namespace");

when(transport.send(addresses.get(0), request))
.thenReturn(Mono.empty())
.thenReturn(Mono.error(new RuntimeException("Error")));

StepVerifier.create(transportWrapper.send(member, request)).verifyComplete();
StepVerifier.create(transportWrapper.send(member, request))
.verifyErrorSatisfies(
throwable -> Assertions.assertEquals("Error", throwable.getMessage()));
}

@Test
void sendShouldWorkMemberSingleAddress() {
final List<Address> addresses = Collections.singletonList(Address.from("test:0"));
final Member member = new Member("test", null, addresses, "namespace");
final Transport transport = mock(Transport.class);
final TransportWrapper transportWrapper = new TransportWrapper(transport);

when(transport.send(addresses.get(0), request)).thenReturn(Mono.empty());

Expand All @@ -193,8 +217,6 @@ void sendShouldWorkMemberSingleAddress() {
void sendShouldWorkMemberTwoAddresses() {
final List<Address> addresses = Arrays.asList(Address.from("test:0"), Address.from("test:1"));
final Member member = new Member("test", null, addresses, "namespace");
final Transport transport = mock(Transport.class);
final TransportWrapper transportWrapper = new TransportWrapper(transport);

when(transport.send(addresses.get(0), request))
.thenReturn(Mono.error(new RuntimeException("Error")));
Expand All @@ -208,8 +230,6 @@ void sendShouldWorkMemberThreeAddresses() {
final List<Address> addresses =
Arrays.asList(Address.from("test:0"), Address.from("test:1"), Address.from("test:2"));
final Member member = new Member("test", null, addresses, "namespace");
final Transport transport = mock(Transport.class);
final TransportWrapper transportWrapper = new TransportWrapper(transport);

when(transport.send(addresses.get(0), request))
.thenReturn(Mono.error(new RuntimeException("Error")));
Expand All @@ -224,8 +244,6 @@ void sendShouldWorkMemberThreeAddresses() {
void sendShouldFailMemberSingleAddress() {
final List<Address> addresses = Collections.singletonList(Address.from("test:0"));
final Member member = new Member("test", null, addresses, "namespace");
final Transport transport = mock(Transport.class);
final TransportWrapper transportWrapper = new TransportWrapper(transport);

when(transport.send(addresses.get(0), request))
.thenReturn(Mono.error(new RuntimeException("Error")));
Expand All @@ -239,8 +257,6 @@ void sendShouldFailMemberSingleAddress() {
void sendShouldFailMemberTwoAddresses() {
final List<Address> addresses = Arrays.asList(Address.from("test:0"), Address.from("test:1"));
final Member member = new Member("test", null, addresses, "namespace");
final Transport transport = mock(Transport.class);
final TransportWrapper transportWrapper = new TransportWrapper(transport);

when(transport.send(addresses.get(0), request))
.thenReturn(Mono.error(new RuntimeException("Error - 0")));
Expand All @@ -257,8 +273,6 @@ void sendShouldFailMemberThreeAddresses() {
final List<Address> addresses =
Arrays.asList(Address.from("test:0"), Address.from("test:1"), Address.from("test:2"));
final Member member = new Member("test", null, addresses, "namespace");
final Transport transport = mock(Transport.class);
final TransportWrapper transportWrapper = new TransportWrapper(transport);

when(transport.send(addresses.get(0), request))
.thenReturn(Mono.error(new RuntimeException("Error - 0")));
Expand Down

0 comments on commit 837d09e

Please sign in to comment.