-
Notifications
You must be signed in to change notification settings - Fork 202
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
Run tests on the current JVM / Gradle 8.8 #4730
Changes from all commits
ddd0503
2ded41a
05e6604
7337a21
b1cf22a
5b7880c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ public abstract class AbstractSink<T extends Record<?>> implements Sink<T> { | |
private Thread retryThread; | ||
private int maxRetries; | ||
private int waitTimeMs; | ||
private SinkThread sinkThread; | ||
|
||
public AbstractSink(final PluginSetting pluginSetting, int numRetries, int waitTimeMs) { | ||
this.pluginMetrics = PluginMetrics.fromPluginSetting(pluginSetting); | ||
|
@@ -51,7 +52,8 @@ public void initialize() { | |
// the exceptions which are not retryable. | ||
doInitialize(); | ||
if (!isReady() && retryThread == null) { | ||
retryThread = new Thread(new SinkThread(this, maxRetries, waitTimeMs)); | ||
sinkThread = new SinkThread(this, maxRetries, waitTimeMs); | ||
retryThread = new Thread(sinkThread); | ||
retryThread.start(); | ||
} | ||
} | ||
|
@@ -76,7 +78,7 @@ public void output(Collection<T> records) { | |
@Override | ||
public void shutdown() { | ||
if (retryThread != null) { | ||
retryThread.stop(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Java 21, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have other locations in plugins where threads are stopped like this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ran IntelliJ's "Find Usages" feature on |
||
sinkThread.stop(); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,6 @@ dependencies { | |
exclude group: 'commons-logging', module: 'commons-logging' | ||
} | ||
implementation 'software.amazon.cloudwatchlogs:aws-embedded-metrics:2.0.0-beta-1' | ||
testImplementation 'org.apache.logging.log4j:log4j-jpl:2.23.0' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason, in Java 17 and 21, this results in all the logs going to stdout in the Gradle task. This makes understanding the build very difficult as there is far too much noise. |
||
testImplementation testLibs.spring.test | ||
implementation libs.armeria.core | ||
implementation libs.armeria.grpc | ||
|
@@ -89,8 +88,6 @@ task integrationTest(type: Test) { | |
|
||
classpath = sourceSets.integrationTest.runtimeClasspath | ||
|
||
systemProperty 'log4j.configurationFile', 'src/test/resources/log4j2.properties' | ||
|
||
filter { | ||
includeTestsMatching '*IT' | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Random; | ||
import java.util.Timer; | ||
import java.util.UUID; | ||
import java.util.stream.Stream; | ||
|
||
|
@@ -218,7 +218,7 @@ static class SomeUnknownTypesArgumentsProvider implements ArgumentsProvider { | |
@Override | ||
public Stream<? extends Arguments> provideArguments(ExtensionContext context) { | ||
return Stream.of( | ||
arguments(Random.class), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Java 21 (and maybe 17?), |
||
arguments(Timer.class), | ||
arguments(InputStream.class), | ||
arguments(File.class) | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,7 +328,7 @@ public Stream<? extends Arguments> provideArguments(final ExtensionContext conte | |
return Stream.of( | ||
Arguments.of(0, randomInt + 1, 0.0), | ||
Arguments.of(1, 100, 1.0), | ||
Arguments.of(randomInt, randomInt, 100.0), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can sometimes be zero, and this will cause the test to fail. So, ensure it is not |
||
Arguments.of(randomInt + 1, randomInt + 1, 100.0), | ||
Arguments.of(randomInt, randomInt + 250, ((double) randomInt / (randomInt + 250)) * 100), | ||
Arguments.of(6, 9, 66.66666666666666), | ||
Arguments.of(531, 1000, 53.1), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,12 @@ | |
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is mostly running the IntelliJ formatter. The only other changes are the |
||
import static org.mockito.Mockito.when; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import org.mockito.Mock; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.not; | ||
|
@@ -28,6 +31,7 @@ | |
import java.io.ByteArrayInputStream; | ||
|
||
import java.time.Instant; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.List; | ||
import java.util.LinkedList; | ||
import java.util.Map; | ||
|
@@ -56,7 +60,7 @@ public EventJsonInputCodec createInputCodec() { | |
@ParameterizedTest | ||
@ValueSource(strings = {"", "{}"}) | ||
public void emptyTest(String input) throws Exception { | ||
input = "{\""+EventJsonDefines.VERSION+"\":\""+DataPrepperVersion.getCurrentVersion().toString()+"\", \""+EventJsonDefines.EVENTS+"\":["+input+"]}"; | ||
input = "{\"" + EventJsonDefines.VERSION + "\":\"" + DataPrepperVersion.getCurrentVersion().toString() + "\", \"" + EventJsonDefines.EVENTS + "\":[" + input + "]}"; | ||
ByteArrayInputStream inputStream = new ByteArrayInputStream(input.getBytes()); | ||
inputCodec = createInputCodec(); | ||
Consumer<Record<Event>> consumer = mock(Consumer.class); | ||
|
@@ -70,15 +74,15 @@ public void inCompatibleVersionTest() throws Exception { | |
final String key = UUID.randomUUID().toString(); | ||
final String value = UUID.randomUUID().toString(); | ||
Map<String, Object> data = Map.of(key, value); | ||
Instant startTime = Instant.now(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In later versions of Java on Linux, there is an issue where the nanosecond resolution results in test failures. |
||
Instant startTime = Instant.now().truncatedTo(ChronoUnit.MICROS); | ||
Event event = createEvent(data, startTime); | ||
|
||
Map<String, Object> dataMap = event.toMap(); | ||
Map<String, Object> metadataMap = objectMapper.convertValue(event.getMetadata(), Map.class); | ||
String input = "{\""+EventJsonDefines.VERSION+"\":\"3.0\", \""+EventJsonDefines.EVENTS+"\":["; | ||
String input = "{\"" + EventJsonDefines.VERSION + "\":\"3.0\", \"" + EventJsonDefines.EVENTS + "\":["; | ||
String comma = ""; | ||
for (int i = 0; i < 2; i++) { | ||
input += comma+"{\"data\":"+objectMapper.writeValueAsString(dataMap)+","+"\"metadata\":"+objectMapper.writeValueAsString(metadataMap)+"}"; | ||
input += comma + "{\"data\":" + objectMapper.writeValueAsString(dataMap) + "," + "\"metadata\":" + objectMapper.writeValueAsString(metadataMap) + "}"; | ||
comma = ","; | ||
} | ||
input += "]}"; | ||
|
@@ -95,24 +99,24 @@ public void basicTest() throws Exception { | |
final String key = UUID.randomUUID().toString(); | ||
final String value = UUID.randomUUID().toString(); | ||
Map<String, Object> data = Map.of(key, value); | ||
Instant startTime = Instant.now(); | ||
Instant startTime = Instant.now().truncatedTo(ChronoUnit.MICROS); | ||
Event event = createEvent(data, startTime); | ||
|
||
Map<String, Object> dataMap = event.toMap(); | ||
Map<String, Object> metadataMap = objectMapper.convertValue(event.getMetadata(), Map.class); | ||
String input = "{\""+EventJsonDefines.VERSION+"\":\""+DataPrepperVersion.getCurrentVersion().toString()+"\", \""+EventJsonDefines.EVENTS+"\":["; | ||
String input = "{\"" + EventJsonDefines.VERSION + "\":\"" + DataPrepperVersion.getCurrentVersion().toString() + "\", \"" + EventJsonDefines.EVENTS + "\":["; | ||
String comma = ""; | ||
for (int i = 0; i < 2; i++) { | ||
input += comma+"{\"data\":"+objectMapper.writeValueAsString(dataMap)+","+"\"metadata\":"+objectMapper.writeValueAsString(metadataMap)+"}"; | ||
input += comma + "{\"data\":" + objectMapper.writeValueAsString(dataMap) + "," + "\"metadata\":" + objectMapper.writeValueAsString(metadataMap) + "}"; | ||
comma = ","; | ||
} | ||
input += "]}"; | ||
inputStream = new ByteArrayInputStream(input.getBytes()); | ||
List<Record<Event>> records = new LinkedList<>(); | ||
inputCodec.parse(inputStream, records::add); | ||
assertThat(records.size(), equalTo(2)); | ||
for(Record record : records) { | ||
Event e = (Event)record.getData(); | ||
for (Record record : records) { | ||
Event e = (Event) record.getData(); | ||
assertThat(e.get(key, String.class), equalTo(value)); | ||
assertThat(e.getMetadata().getTimeReceived(), equalTo(startTime)); | ||
assertThat(e.getMetadata().getTags().size(), equalTo(0)); | ||
|
@@ -126,24 +130,24 @@ public void test_with_timeReceivedOverridden() throws Exception { | |
final String key = UUID.randomUUID().toString(); | ||
final String value = UUID.randomUUID().toString(); | ||
Map<String, Object> data = Map.of(key, value); | ||
Instant startTime = Instant.now().minusSeconds(5); | ||
Instant startTime = Instant.now().truncatedTo(ChronoUnit.MICROS).minusSeconds(5); | ||
Event event = createEvent(data, startTime); | ||
|
||
Map<String, Object> dataMap = event.toMap(); | ||
Map<String, Object> metadataMap = objectMapper.convertValue(event.getMetadata(), Map.class); | ||
String input = "{\""+EventJsonDefines.VERSION+"\":\""+DataPrepperVersion.getCurrentVersion().toString()+"\", \""+EventJsonDefines.EVENTS+"\":["; | ||
String input = "{\"" + EventJsonDefines.VERSION + "\":\"" + DataPrepperVersion.getCurrentVersion().toString() + "\", \"" + EventJsonDefines.EVENTS + "\":["; | ||
String comma = ""; | ||
for (int i = 0; i < 2; i++) { | ||
input += comma+"{\"data\":"+objectMapper.writeValueAsString(dataMap)+","+"\"metadata\":"+objectMapper.writeValueAsString(metadataMap)+"}"; | ||
input += comma + "{\"data\":" + objectMapper.writeValueAsString(dataMap) + "," + "\"metadata\":" + objectMapper.writeValueAsString(metadataMap) + "}"; | ||
comma = ","; | ||
} | ||
input += "]}"; | ||
inputStream = new ByteArrayInputStream(input.getBytes()); | ||
List<Record<Event>> records = new LinkedList<>(); | ||
inputCodec.parse(inputStream, records::add); | ||
assertThat(records.size(), equalTo(2)); | ||
for(Record record : records) { | ||
Event e = (Event)record.getData(); | ||
for (Record record : records) { | ||
Event e = (Event) record.getData(); | ||
assertThat(e.get(key, String.class), equalTo(value)); | ||
assertThat(e.getMetadata().getTimeReceived(), not(equalTo(startTime))); | ||
assertThat(e.getMetadata().getTags().size(), equalTo(0)); | ||
|
@@ -159,7 +163,7 @@ private Event createEvent(final Map<String, Object> json, final Instant timeRece | |
if (timeReceived != null) { | ||
logBuilder.withTimeReceived(timeReceived); | ||
} | ||
final JacksonEvent event = (JacksonEvent)logBuilder.build(); | ||
final JacksonEvent event = (JacksonEvent) logBuilder.build(); | ||
|
||
return event; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tells Gradle to use the current JVM version for running the tests. This is what now allows our tests to run on Java 17 or 21.