Skip to content

Commit

Permalink
Updated Verifyica version (#1005)
Browse files Browse the repository at this point in the history
* Updated Verifyica version

---------

Signed-off-by: dhoard <[email protected]>
  • Loading branch information
dhoard authored Oct 9, 2024
1 parent 50d2a9a commit 194faa5
Show file tree
Hide file tree
Showing 44 changed files with 1,159 additions and 158 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
- name: Run the Maven verify phase
run: |
./mvnw --batch-mode clean install
./mvnw javadoc:jar
./mvnw --batch-mode javadoc:jar
14 changes: 7 additions & 7 deletions integration_test_suite/integration_tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +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>
<verifyica.version>0.0.7</verifyica.version>
<verifyica.version>0.3.0</verifyica.version>
</properties>

<build>
Expand Down Expand Up @@ -75,8 +75,8 @@
</configuration>
</plugin>
<plugin>
<groupId>org.antublue.verifyica</groupId>
<artifactId>maven-plugin</artifactId>
<groupId>org.verifyica</groupId>
<artifactId>verifyica-maven-plugin</artifactId>
<version>${verifyica.version}</version>
<executions>
<execution>
Expand Down Expand Up @@ -114,13 +114,13 @@

<dependencies>
<dependency>
<groupId>org.antublue.verifyica</groupId>
<artifactId>api</artifactId>
<groupId>org.verifyica</groupId>
<artifactId>verifyica-api</artifactId>
<version>${verifyica.version}</version>
</dependency>
<dependency>
<groupId>org.antublue.verifyica</groupId>
<artifactId>engine</artifactId>
<groupId>org.verifyica</groupId>
<artifactId>verifyica-engine</artifactId>
<version>${verifyica.version}</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,138 +16,137 @@

package io.prometheus.jmx.test.support;

import static java.lang.String.format;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.function.Predicate;

/** Class to implement JavaDockerImages */
public final class JavaDockerImages {

private static final String DOCKER_IMAGES_CONFIGURATION = "java.docker.images";
private static final String ALL = "ALL";

private static final String DOCKER_IMAGES_RESOURCE = "/java-docker-images.txt";
private static final String DOCKER_IMAGES_CONFIGURATION = "java.docker.images";

private static final String SMOKE_TEST_DOCKER_IMAGES_RESOURCE =
"/smoke-test-java-docker-images.txt";

private static String[] ALL_DOCKER_IMAGE_NAMES;
private static final List<String> SMOKE_TEST_DOCKER_IMAGES =
Collections.unmodifiableList(load(SMOKE_TEST_DOCKER_IMAGES_RESOURCE));

private static String[] SMOKE_TEST_DOCKER_IMAGES;
private static final String ALL_DOCKER_IMAGES_RESOURCE = "/java-docker-images.txt";

/** Predicate to accept all Docker image names */
public static final Predicate<String> ACCEPT_ALL = name -> true;
private static final List<String> ALL_DOCKER_IMAGE_NAMES =
Collections.unmodifiableList(load(ALL_DOCKER_IMAGES_RESOURCE));

/** Constructor */
private JavaDockerImages() {
// DO NOTHING
}

/**
* Method to get Collection of all Docker image names
*
* @return the Collection of Docker image names
*/
public static Collection<String> names() {
return names(ACCEPT_ALL);
}

/**
* Method to get List of Docker image names filtered by a Predicate
*
* @param predicate predicate
* @return the List of Docker image names
*/
public static Collection<String> names(Predicate<String> predicate) {
Objects.requireNonNull(predicate);

synchronized (JavaDockerImages.class) {
if (ALL_DOCKER_IMAGE_NAMES == null) {
ALL_DOCKER_IMAGE_NAMES = load(DOCKER_IMAGES_RESOURCE);
}
if (SMOKE_TEST_DOCKER_IMAGES == null) {
SMOKE_TEST_DOCKER_IMAGES = load(SMOKE_TEST_DOCKER_IMAGES_RESOURCE);
}
}

String[] dockerImageNames;

String dockerImageNameValue =
public static Collection<String> names() {
String configurationValues =
System.getenv(
DOCKER_IMAGES_CONFIGURATION.toUpperCase(Locale.ENGLISH).replace('.', '_'));

if (dockerImageNameValue != null) {
dockerImageNameValue = dockerImageNameValue.trim();
if (dockerImageNameValue.isBlank()) {
dockerImageNameValue = null;
}
}

if (dockerImageNameValue == null) {
dockerImageNameValue = System.getProperty(DOCKER_IMAGES_CONFIGURATION);
if (dockerImageNameValue != null) {
if (dockerImageNameValue.isBlank()) {
dockerImageNameValue = null;
}
}
if (configurationValues == null || configurationValues.trim().isEmpty()) {
configurationValues = System.getProperty(DOCKER_IMAGES_CONFIGURATION);
}

if (dockerImageNameValue == null) {
dockerImageNames = SMOKE_TEST_DOCKER_IMAGES;
} else if (dockerImageNameValue.equalsIgnoreCase("ALL")) {
dockerImageNames = ALL_DOCKER_IMAGE_NAMES;
} else {
dockerImageNames = dockerImageNameValue.split("\\s+");
if (configurationValues == null || configurationValues.trim().isEmpty()) {
return SMOKE_TEST_DOCKER_IMAGES;
}

Collection<String> dockerImageNamesCollection = new ArrayList<>();
for (String dockerImageName : dockerImageNames) {
if (predicate.test(dockerImageName)) {
dockerImageNamesCollection.add(dockerImageName);
}
if (configurationValues.trim().equalsIgnoreCase(ALL)) {
return ALL_DOCKER_IMAGE_NAMES;
}

return Collections.unmodifiableCollection(dockerImageNamesCollection);
return Collections.unmodifiableList(toList(configurationValues));
}

/**
* Method to load the list of Docker image names from a resource
*
* @param resource resource
* @return the String array of lines
* @return the List of lines
*/
private static String[] load(String resource) {
Collection<String> dockerImageNames = new ArrayList<>();
BufferedReader bufferedReader;
private static List<String> load(String resource) {
List<String> lines = new ArrayList<>();

InputStream inputStream = null;
BufferedReader bufferedReader = null;

try {
inputStream = JavaDockerImages.class.getResourceAsStream(resource);

if (inputStream == null) {
throw new IOException("Resource not found");
}

bufferedReader =
new BufferedReader(
new InputStreamReader(
JavaDockerImages.class.getResourceAsStream(resource),
StandardCharsets.UTF_8));
new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));

while (true) {
String line = bufferedReader.readLine();

if (line == null) {
break;
}

if (!line.trim().isEmpty() && !line.trim().startsWith("#")) {
dockerImageNames.add(line.trim());
lines.add(line.trim());
}
}

return dockerImageNames.toArray(new String[0]);
} catch (IOException e) {
throw new RuntimeException("Exception reading resource " + DOCKER_IMAGES_RESOURCE, e);
return lines;
} catch (Throwable t) {
throw new RuntimeException(format("Exception reading resource [%s]", resource), t);
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (Throwable t) {
// DO NOTHING
}
}

if (inputStream != null) {
try {
inputStream.close();
} catch (Throwable t) {
// DO NOTHING
}
}
}
}

/**
* Method to split a String on whitespace and return a List of Strings
*
* @param string string
* @return a List of Strings
*/
private static List<String> toList(String string) {
List<String> list = new ArrayList<>();

String[] strings = string.split("\\s+");
for (String s : strings) {
if (!s.trim().isEmpty()) {
list.add(s.trim());
}
}

return list;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.prometheus.jmx.test.support.http;

import static java.lang.String.format;
import static org.antublue.verifyica.api.Fail.fail;
import static org.assertj.core.api.Assertions.assertThat;

public class HttpResponseAssertions {
Expand Down Expand Up @@ -44,16 +43,18 @@ public static void assertHttpMetricsResponse(HttpResponse httpResponse) {
HttpResponseBody httpResponseBody = httpResponse.body();
if (httpResponseBody != null) {
String content = httpResponseBody.string();
fail(
throw new AssertionError(
format(
"Exporter error, HTTP status code [%d] content [%n%s]",
statusCode, content));
"Expected statusCode [%d] but was [%d] content [%s]",
200, statusCode, content));
} else {
fail(format("Exporter error, HTTP status code [%d] no content", statusCode));
throw new AssertionError(
format(
"Expected statusCode [%d] but was [%d] no content",
200, statusCode));
}
}

assertThat(httpResponse.statusCode()).isEqualTo(200);
assertHttpResponseHasHeaders(httpResponse);
assertHttpResponseHasHeader(httpResponse, HttpHeader.CONTENT_TYPE);
assertHttpResponseHasBody(httpResponse);
Expand Down
Loading

0 comments on commit 194faa5

Please sign in to comment.