Skip to content

Commit

Permalink
Refactored integration tests (#1025)
Browse files Browse the repository at this point in the history
* Refactored integration tests

Signed-off-by: dhoard <[email protected]>
  • Loading branch information
dhoard authored Oct 30, 2024
1 parent e1b1115 commit e192cbb
Show file tree
Hide file tree
Showing 71 changed files with 5,113 additions and 2,006 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
name: Build

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -19,5 +17,6 @@ jobs:
cache: 'maven'
- name: Run the Maven verify phase
run: |
./integration_test_suite/pull-smoke-test-docker-images.sh
./mvnw --batch-mode clean install
./mvnw --batch-mode javadoc:jar
1 change: 1 addition & 0 deletions .github/workflows/manual-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ jobs:
cache: 'maven'
- name: Run the Maven verify phase
run: |
./integration_test_suite/pull-smoke-test-docker-images.sh
./mvnw --batch-mode clean install
./mvnw --batch-mode javadoc:jar
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ output.log
stress-test.log
test.sh
test.log
verify-full.sh
verify-full.log
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public void add(ObjectName objectName, String attributeName) {
}
}

/**
* Method to only keep "alive" mBeans, remove old mBeans to prevent memory growth
*
* @param aliveMBeans aliveMBeans
*/
public void onlyKeepMBeans(Set<ObjectName> aliveMBeans) {
if (autoExcludeObjectNameAttributes) {
for (ObjectName prevName : dynamicExcludeObjectNameAttributesMap.keySet()) {
Expand Down
14 changes: 5 additions & 9 deletions integration_test_suite/integration_tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<prometheus.metrics.version>1.3.2</prometheus.metrics.version>
<verifyica.version>0.6.1</verifyica.version>
</properties>

Expand Down Expand Up @@ -131,12 +132,12 @@
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>prometheus-metrics-model</artifactId>
<version>1.3.2</version>
<version>${prometheus.metrics.version}</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>prometheus-metrics-exposition-formats</artifactId>
<version>1.3.2</version>
<version>${prometheus.metrics.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -146,17 +147,12 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.11</version>
<version>1.5.12</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.20.2</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>5.0.0-alpha.14</version>
<version>1.20.3</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package io.prometheus.jmx.test.support;

import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;

import io.prometheus.jmx.test.support.http.HttpResponse;
import io.prometheus.jmx.test.support.http.HttpResponseBody;

/** Class to implement Assertions */
public class Assertions {

/** Constructor */
private Assertions() {
// INTENTIONALLY BLANK
}

/**
* Assert a health response
*
* @param httpResponse httpResponse
*/
public static void assertHealthyResponse(HttpResponse httpResponse) {
assertThat(httpResponse).isNotNull();
assertThat(httpResponse.statusCode()).isEqualTo(200);
assertThat(httpResponse.body()).isNotNull();
assertThat(httpResponse.body().string()).isNotBlank();
assertThat(httpResponse.body().string()).contains("Exporter is healthy.");
}

/**
* Assert common metrics response
*
* @param httpResponse httpResponse
*/
public static void assertCommonMetricsResponse(HttpResponse httpResponse) {
assertThat(httpResponse).isNotNull();

int statusCode = httpResponse.statusCode();
if (statusCode != 200) {
HttpResponseBody body = httpResponse.body();
if (body != null) {
throw new AssertionError(
format(
"Expected statusCode [%d] but was [%d] body [%s]",
200, statusCode, body.string()));
} else {
throw new AssertionError(
format("Expected statusCode [%d] but was [%d] no body", 200, statusCode));
}
}

assertThat(httpResponse.headers()).isNotNull();
assertThat(httpResponse.headers().get("CONTENT-TYPE")).hasSize(1);
assertThat(httpResponse.body()).isNotNull();
assertThat(httpResponse.body().bytes()).isNotNull();
assertThat(httpResponse.body().bytes().length).isGreaterThan(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

/** Enum of the two operational modes */
public enum JmxExporterMode {
/** JavaAgent */
JavaAgent,
/** Standalone */
Standalone
}

This file was deleted.

Loading

0 comments on commit e192cbb

Please sign in to comment.