Skip to content

Commit

Permalink
Merge pull request #1778 from allegro/integration_tests_framework
Browse files Browse the repository at this point in the history
new framework for integration tests
  • Loading branch information
szczygiel-m authored Jan 24, 2024
2 parents 187b31a + 982411c commit 11808ea
Show file tree
Hide file tree
Showing 237 changed files with 11,699 additions and 12,260 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checkstyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: gradle/gradle-build-action@v2
- name: Run check style
# ignore lengthy console setup tasks
run: ./gradlew --continue clean checkstyleMain checkstyleTest checkstyleIntegration checkstyleJmh -PmaxCheckstyleWarnings=0 -x attachHermesConsole -x prepareIndexTemplate
run: ./gradlew --continue clean checkstyleMain checkstyleTest checkstyleIntegrationTest checkstyleSlowIntegrationTest checkstyleJmh -PmaxCheckstyleWarnings=0 -x attachHermesConsole -x prepareIndexTemplate
- name: Run reviewdog
if: ${{ success() || failure() }}
env:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
tasks: [
{alias: "unitTests", name: "check"},
{alias: "integrationTests", name: "integrationTest"},
{alias: "slowIntegrationTests", name: "slowIntegrationTest"},
{alias: "benchmark", name: "jmh -Pjmh.iterations=1 -Pjmh.timeOnIteration=5s -Pjmh.warmupIterations=0"}
]
fail-fast: false
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ You can also use other *magic words* from [GitHub handbook](https://help.github.

* use `spock` when writing new unit tests in all modules
* when changing old tests use your best judgement as to when rewrite them to `spock`
* use `TestNG` with defined environment in `integration` module
* use `JUnit5` with defined environment in `integration-tests` module
* prepend configuration options with module name, i.e. `frontend.` or `consumer.` when it applies to single module
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ allprojects {
undertow : '2.0.29.Final',
spring_web : '6.1.2',
failsafe : '2.3.1',
junit_jupiter : '5.8.2',
junit_jupiter : '5.9.1',
testcontainers : '1.18.1',
spring : '3.2.1',
assertj : '3.22.0'
assertj : '3.24.2'
]

repositories {
Expand Down Expand Up @@ -113,7 +113,7 @@ allprojects {
}


configure(subprojects - project(':integration')) {
configure(subprojects - project(':integration-tests')) {
apply plugin: 'jacoco'
apply plugin: 'maven-publish'
apply plugin: 'signing'
Expand Down
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
-->
<module name="LineLength">
<property name="fileExtensions" value="java"/>
<property name="max" value="140"/>
<property name="max" value="400"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>

Expand Down
1 change: 0 additions & 1 deletion hermes-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ dependencies {
testImplementation group: 'com.squareup.okhttp3', name: 'okhttp', version: versions.okhttp
testImplementation group: 'io.projectreactor.netty', name: 'reactor-netty', version: '1.0.25'
testImplementation group: 'io.projectreactor', name: 'reactor-test', version: '3.4.25'

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ public void start() {
public void stop() {
server.stop(0);
}

public int getPort() {
return server.getAddress().getPort();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import pl.allegro.tech.hermes.frontend.publishing.preview.MessagePreviewPersister;
import pl.allegro.tech.hermes.frontend.services.HealthCheckService;

import java.net.InetSocketAddress;

import static io.undertow.UndertowOptions.ALWAYS_SET_KEEP_ALIVE;
import static io.undertow.UndertowOptions.ENABLE_HTTP2;
import static io.undertow.UndertowOptions.MAX_COOKIES;
Expand Down Expand Up @@ -151,4 +153,22 @@ private HttpHandler handlers() {
private boolean isFrontendRequestDumperEnabled() {
return hermesServerParameters.isRequestDumperEnabled();
}

public int getPort() {
InetSocketAddress socketAddress = (InetSocketAddress) undertow.getListenerInfo().stream()
.findFirst()
.orElseThrow(() -> new IllegalStateException("No port available yet."))
.getAddress();
return socketAddress.getPort();
}

public int getSSLPort() {
InetSocketAddress socketAddress = (InetSocketAddress) undertow.getListenerInfo().stream()
.filter(listener -> listener.getSslContext() != null)
.findFirst()
.orElseThrow(() -> new IllegalStateException("No SSL port available yet."))
.getAddress();
return socketAddress.getPort();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public void updateTopic(TopicName topicName, PatchData patch, RequestUser modifi

if (!retrieved.equals(modified)) {
Instant beforeMigrationInstant = clock.instant();
// TODO: this does not work as intended, uses == instead of equals
if (retrieved.getRetentionTime() != modified.getRetentionTime()) {
multiDCAwareService.manageTopic(brokerTopicManagement ->
brokerTopicManagement.updateTopic(modified)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public MonitoringSubscriptionMetrics subscriptionMetrics(SubscriptionName subscr
The query is based on MetricsQL, available only in VictoriaMetrics
https://docs.victoriametrics.com/MetricsQL.html. Basic PromQL does not support `keep_metric_names` param.
*/
String queryFormat = "sum by (__name__,group,topic,subscription,status_code)"
+ "(irate({__name__=~'%s',group='%s',topic='%s',subscription='%s', %s}[1m]) keep_metric_names)";
String queryFormat = "sum by (__name__, group, topic, subscription, status_code)"
+ " (irate({__name__=~'%s', group='%s', topic='%s', subscription='%s', %s}[1m]) keep_metric_names)";
String query = String.format(queryFormat, subscriptionMetricsToQuery, subscriptionName.getTopicName().getGroupName(),
subscriptionName.getTopicName().getName(), subscriptionName.getName(), additionalFilters);
MonitoringMetricsContainer prometheusMetricsContainer = prometheusClient.readMetrics(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ class HybridPrometheusBasedSubscriptionMetricsRepositoryTest extends Specificati
private HybridSubscriptionMetricsRepository repository = new HybridSubscriptionMetricsRepository(prometheusMetricsProvider,
summedSharedCounter, zookeeperPaths, lagSource)

private static final String query = "sum by (__name__,group,topic,subscription,status_code)" +
private static final String query = "sum by (__name__, group, topic, subscription, status_code) " +
"(irate({__name__=~'hermes_consumers_subscription_delivered_total" +
"|hermes_consumers_subscription_timeouts_total" +
"|hermes_consumers_subscription_throughput_bytes_total" +
"|hermes_consumers_subscription_other_errors_total" +
"|hermes_consumers_subscription_batches_total" +
"|hermes_consumers_subscription_http_status_codes_total'," +
"group='group',topic='topic',subscription='subscription', service=~'hermes'}[1m]) keep_metric_names)"
"|hermes_consumers_subscription_http_status_codes_total', " +
"group='group', topic='topic', subscription='subscription', service=~'hermes'}[1m]) keep_metric_names)"

def "should read subscription metrics from multiple places"() {
given:
Expand Down
11 changes: 3 additions & 8 deletions hermes-test-helper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@ dependencies {
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
implementation group: 'com.jayway.jsonpath', name: 'json-path', version: '2.5.0'
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: versions.jackson
implementation group: 'org.springframework', name: 'spring-test', version: versions.spring_web
implementation group: 'org.springframework', name: 'spring-webflux', version: versions.spring_web
implementation group: 'org.awaitility', name: 'awaitility', version: '4.2.0'

//TODO: remove after migrating from apache oltu
implementation group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.1.1'

implementation group: 'org.apache.oltu.oauth2', name: 'org.apache.oltu.oauth2.authzserver', version: '1.0.2'
implementation group: 'org.apache.oltu.oauth2', name: 'org.apache.oltu.oauth2.resourceserver', version: '1.0.2'
implementation group: 'io.undertow', name: 'undertow-servlet', version: versions.undertow

testImplementation group: 'org.apache.oltu.oauth2', name: 'org.apache.oltu.oauth2.client', version: '1.0.2'
testImplementation group: 'org.spockframework', name: 'spock-core', version: versions.spock
testImplementation group: 'org.spockframework', name: 'spock-junit4', version: versions.spock

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public String getName() {
}

public int getAge() {
return Integer.valueOf(record.get(AGE_FIELD).toString());
return Integer.parseInt(record.get(AGE_FIELD).toString());
}

public String getFavoriteColor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ static byte[] recordToBytes(GenericRecord record, Schema schema) throws IOExcept
static GenericRecord bytesToRecord(byte [] data, Schema schema) throws IOException {
GenericDatumReader<GenericRecord> reader = new GenericDatumReader<>(schema);
BinaryDecoder binaryDecoder = DecoderFactory.get().binaryDecoder(data, null);
GenericRecord record = reader.read(null, binaryDecoder);
return record;
return reader.read(null, binaryDecoder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import pl.allegro.tech.hermes.api.Group;

import java.util.concurrent.atomic.AtomicLong;

public class GroupBuilder {

private static final AtomicLong sequence = new AtomicLong();

private final String groupName;

private GroupBuilder(String name) {
Expand All @@ -17,4 +21,8 @@ public static GroupBuilder group(String name) {
public Group build() {
return new Group(groupName);
}

public static GroupBuilder groupWithRandomName() {
return group(GroupBuilder.class.getSimpleName() + "Group" + sequence.incrementAndGet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class OAuthProviderBuilder {

private String name;
private final String name;

private String tokenEndpoint = "http://example.com/token";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;

public class SubscriptionBuilder {

private static final AtomicLong sequence = new AtomicLong();

private final TopicName topicName;

private final String name;
Expand Down Expand Up @@ -52,11 +56,11 @@ public class SubscriptionBuilder {

private DeliveryType deliveryType = DeliveryType.SERIAL;

private List<MessageFilterSpecification> filters = new ArrayList<>();
private final List<MessageFilterSpecification> filters = new ArrayList<>();

private SubscriptionMode mode = SubscriptionMode.ANYCAST;

private List<Header> headers = new ArrayList<>();
private final List<Header> headers = new ArrayList<>();

private EndpointAddressResolverMetadata metadata = EndpointAddressResolverMetadata.empty();
private SubscriptionOAuthPolicy oAuthPolicy;
Expand All @@ -76,6 +80,14 @@ private SubscriptionBuilder(TopicName topicName, String subscriptionName) {
this.name = subscriptionName;
}

public static SubscriptionBuilder subscriptionWithRandomName(TopicName topicName, String endpoint) {
return new SubscriptionBuilder(topicName, "subscription" + sequence.incrementAndGet(), EndpointAddress.of(endpoint));
}

public static SubscriptionBuilder subscriptionWithRandomName(TopicName topicName) {
return new SubscriptionBuilder(topicName, UUID.randomUUID().toString());
}

public static SubscriptionBuilder subscription(SubscriptionName subscriptionName) {
return new SubscriptionBuilder(subscriptionName.getTopicName(), subscriptionName.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

public class TopicBuilder {

private static final AtomicLong sequence = new AtomicLong();

private final TopicName name;

private String description = "description";
Expand All @@ -41,7 +44,7 @@ public class TopicBuilder {

private int maxMessageSize = 1024 * 1024;

private List<String> publishers = new ArrayList<>();
private final List<String> publishers = new ArrayList<>();

private boolean authEnabled = false;

Expand All @@ -57,6 +60,13 @@ private TopicBuilder(TopicName topicName) {
this.name = topicName;
}

public static TopicBuilder topicWithRandomName() {
return topic(
TopicBuilder.class.getSimpleName() + "Group" + sequence.incrementAndGet(),
TopicBuilder.class.getSimpleName() + "Topic" + sequence.incrementAndGet()
);
}

public static TopicBuilder randomTopic(String group, String topicNamePrefix) {
return topic(group, topicNamePrefix + "-" + UUID.randomUUID());
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class Hermes {
private ClientConfig managementConfig = getDefaultManagementConfig();
private ClientConfig publisherConfig = getDefaultPublisherConfig();

private Collection<ClientRequestFilter> filters = new ArrayList<>();
private final Collection<ClientRequestFilter> filters = new ArrayList<>();

public Hermes(String url, String consumerUrl) {
this.url = url;
Expand All @@ -60,7 +60,7 @@ private static ClientConfig getDefaultManagementConfig() {
return clientConfig;
}

private static ClientConfig getDefaultPublisherConfig() {
public static ClientConfig getDefaultPublisherConfig() {
ClientConfig clientConfig = new ClientConfig();
clientConfig.property(ClientProperties.ASYNC_THREADPOOL_SIZE, DEFAULT_THREAD_POOL_SIZE);
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT);
Expand All @@ -69,7 +69,7 @@ private static ClientConfig getDefaultPublisherConfig() {
return clientConfig;
}

private static ClientBuilder getClientBuilder(ClientConfig clientConfig) {
public static ClientBuilder getClientBuilder(ClientConfig clientConfig) {
return ClientBuilder.newBuilder().withConfig(clientConfig).register(
new JacksonXmlBindJsonProvider(
new ObjectMapper().registerModule(new JavaTimeModule()),
Expand Down

This file was deleted.

Loading

0 comments on commit 11808ea

Please sign in to comment.