Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust batch delivery tests to new framework #1791

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package pl.allegro.tech.hermes.consumers;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import pl.allegro.tech.hermes.consumers.consumer.sender.resolver.EndpointAddressResolver;
import pl.allegro.tech.hermes.test.helper.endpoint.MultiUrlEndpointAddressResolver;

@Configuration
public class EndpointAddressResolverConfiguration {

@Bean
@Primary
@Profile("integration")
public EndpointAddressResolver testMultiUrlEndpointAddressResolver() {
return new MultiUrlEndpointAddressResolver();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public void waitUntilAnyMessageReceived() {
await().atMost(adjust(new Duration(DEFAULT_WAIT_TIME_IN_SEC, SECONDS))).until(() ->
assertThat(receivedRequests.size()).isPositive());
}
public void waitUntilReceived(Duration duration, int numberOfExpectedMessages) {
await().atMost(adjust(duration)).until(() ->
assertThat(receivedRequests.size()).isEqualTo(numberOfExpectedMessages));
}

public void waitUntilRequestReceived(Consumer<LoggedRequest> requestConsumer) {
waitUntilAnyMessageReceived();
Expand All @@ -64,6 +68,16 @@ public void waitUntilRequestReceived(Consumer<LoggedRequest> requestConsumer) {
}
}

public void waitUntilRequestsReceived(Consumer<List<LoggedRequest>> requestsConsumer) {
await().atMost(adjust(new Duration(DEFAULT_WAIT_TIME_IN_SEC, SECONDS))).until(
() -> {
synchronized (receivedRequests) {
requestsConsumer.accept(receivedRequests);
}
}
);
}

public void noMessagesReceived() {
assertThat(receivedRequests).isEmpty();
}
Expand Down Expand Up @@ -97,7 +111,7 @@ private LoggedRequest getFirstReceivedRequest() {
}
}

private LoggedRequest getLastReceivedRequest() {
public LoggedRequest getLastReceivedRequest() {
synchronized (receivedRequests) {
return Streams.findLast(receivedRequests.stream()).orElseThrow(NoSuchElementException::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,25 @@ public TestSubscribersExtension() {
}

public TestSubscriber createSubscriber(String endpointPathSuffix) {
return createSubscriber(OK.getStatusCode(), endpointPathSuffix);
}

public TestSubscriber createSubscriber() {
return createSubscriber("");
}

public TestSubscriber createSubscriber(int statusCode) {
return createSubscriber(statusCode, "");
}

public TestSubscriber createSubscriber(int statusCode, String endpointPathSuffix) {
String path = createPath(endpointPathSuffix);
service.addStubMapping(post(urlPathEqualTo(path)).willReturn(aResponse().withStatus(OK.getStatusCode())).build());
service.addStubMapping(post(urlPathEqualTo(path)).willReturn(aResponse().withStatus(statusCode)).build());
TestSubscriber subscriber = new TestSubscriber(createSubscriberURI(path));
subscribersPerPath.put(path, subscriber);
return subscriber;
}

public TestSubscriber createSubscriber() {
return createSubscriber("");
}

public TestSubscriber createSubscriberWithRetry(String message, int delay) {
String path = createPath("");
Expand Down Expand Up @@ -84,7 +93,18 @@ public TestSubscriber createSubscriberWithRetry(String message, int delay) {

private String createPath(String pathSuffix) {
return "/subscriber-" + subscriberIndex.incrementAndGet() + pathSuffix;
}

public interface SubscriberScenario {
void apply(WireMockServer subscriber, String endpoint);
}

public TestSubscriber createSubscriber(SubscriberScenario scenario) {
String path = createPath("");
scenario.apply(service, path);
TestSubscriber subscriber = new TestSubscriber(createSubscriberURI(path));
subscribersPerPath.put(path, subscriber);
return subscriber;
}

private URI createSubscriberURI(String path) {
Expand Down
Loading
Loading