-
Notifications
You must be signed in to change notification settings - Fork 13
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
Various Java cleanups #114
Changes from all commits
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 |
---|---|---|
|
@@ -37,5 +37,5 @@ public enum AuthenticationType { | |
/** | ||
* GSSAPI (Kerberos) authentication. | ||
*/ | ||
GSSAPI; | ||
GSSAPI | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import java.net.ServerSocket; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.time.Duration; | ||
import java.util.Optional; | ||
import java.util.function.BooleanSupplier; | ||
|
||
|
@@ -27,19 +28,19 @@ class Utils { | |
private static final Logger LOGGER = LoggerFactory.getLogger(Utils.class); | ||
|
||
/** | ||
* Poll the given {@code ready} function every {@code pollIntervalMs} milliseconds until it returns true, | ||
* or throw a WaitException if it doesn't returns true within {@code timeoutMs} milliseconds. | ||
* Poll the given {@code ready} function every {@code pollInterval} until it returns true, | ||
* or throw a WaitException if it doesn't returns true within {@code timeout}. | ||
* @return The remaining time left until timeout occurs | ||
* (helpful if you have several calls which need to share a common timeout), | ||
* | ||
* @param description waiting for `description` | ||
* @param pollIntervalMs poll interval in milliseconds | ||
* @param timeoutMs timeout in milliseconds | ||
* @param pollInterval poll interval | ||
* @param timeout timeout | ||
* @param ready lambda predicate | ||
*/ | ||
static long waitFor(String description, long pollIntervalMs, long timeoutMs, BooleanSupplier ready) { | ||
static long waitFor(String description, Duration pollInterval, Duration timeout, BooleanSupplier ready) { | ||
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. The class is not |
||
LOGGER.debug("Waiting for {}", description); | ||
long deadline = System.currentTimeMillis() + timeoutMs; | ||
long deadline = System.currentTimeMillis() + timeout.toMillis(); | ||
String exceptionMessage = null; | ||
int exceptionCount = 0; | ||
StringWriter stackTraceError = new StringWriter(); | ||
|
@@ -71,11 +72,11 @@ static long waitFor(String description, long pollIntervalMs, long timeoutMs, Boo | |
LOGGER.error(stackTraceError.toString()); | ||
} | ||
} | ||
WaitException waitException = new WaitException("Timeout after " + timeoutMs + " ms waiting for " + description); | ||
WaitException waitException = new WaitException("Timeout after " + timeout.toMillis() + " ms waiting for " + description); | ||
waitException.addSuppressed(waitException); | ||
throw waitException; | ||
} | ||
long sleepTime = Math.min(pollIntervalMs, timeLeft); | ||
long sleepTime = Math.min(pollInterval.toMillis(), timeLeft); | ||
if (LOGGER.isTraceEnabled()) { | ||
LOGGER.trace("{} not satisfied, will try again in {} ms ({}ms till timeout)", description, sleepTime, timeLeft); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,7 +72,7 @@ void testStartContainerWithEmptyConfiguration(final String imageName) { | |
systemUnderTest.start(); | ||
|
||
assertThat(systemUnderTest.getBootstrapServers(), is("PLAINTEXT://" | ||
+ systemUnderTest.getContainerIpAddress() + ":" + systemUnderTest.getMappedPort(9092))); | ||
+ systemUnderTest.getHost() + ":" + systemUnderTest.getMappedPort(9092))); | ||
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.
|
||
} | ||
} | ||
|
||
|
@@ -123,7 +123,7 @@ void testStartContainerWithSSLBootstrapServers(final String imageName) { | |
systemUnderTest.start(); | ||
|
||
assertThat(systemUnderTest.getBootstrapServers(), is("SSL://" | ||
+ systemUnderTest.getContainerIpAddress() + ":" + systemUnderTest.getMappedPort(9092))); | ||
+ systemUnderTest.getHost() + ":" + systemUnderTest.getMappedPort(9092))); | ||
} | ||
|
||
@ParameterizedTest(name = "testStartContainerWithServerProperties-{0}") | ||
|
@@ -140,7 +140,7 @@ void testStartContainerWithServerProperties(final String imageName) { | |
assertThat(logsFromKafka, containsString("auto.create.topics.enable = false")); | ||
|
||
assertThat(systemUnderTest.getBootstrapServers(), is("PLAINTEXT://" | ||
+ systemUnderTest.getContainerIpAddress() + ":" + systemUnderTest.getMappedPort(9092))); | ||
+ systemUnderTest.getHost() + ":" + systemUnderTest.getMappedPort(9092))); | ||
} | ||
|
||
@Test | ||
|
@@ -155,7 +155,7 @@ void testStartContainerWithStrimziKafkaImage() { | |
systemUnderTest.start(); | ||
|
||
assertThat(systemUnderTest.getBootstrapServers(), is("PLAINTEXT://" | ||
+ systemUnderTest.getContainerIpAddress() + ":" + systemUnderTest.getMappedPort(9092))); | ||
+ systemUnderTest.getHost() + ":" + systemUnderTest.getMappedPort(9092))); | ||
|
||
assertThat(systemUnderTest.getDockerImageName(), is(imageName)); | ||
|
||
|
@@ -172,7 +172,7 @@ void testStartContainerWithCustomImage() { | |
systemUnderTest.start(); | ||
|
||
assertThat(systemUnderTest.getBootstrapServers(), is("PLAINTEXT://" | ||
+ systemUnderTest.getContainerIpAddress() + ":" + systemUnderTest.getMappedPort(9092))); | ||
+ systemUnderTest.getHost() + ":" + systemUnderTest.getMappedPort(9092))); | ||
|
||
assertThat(systemUnderTest.getDockerImageName(), is(imageName)); | ||
} | ||
|
@@ -188,7 +188,7 @@ void testStartContainerWithCustomNetwork() { | |
systemUnderTest.start(); | ||
|
||
assertThat(systemUnderTest.getBootstrapServers(), is("PLAINTEXT://" | ||
+ systemUnderTest.getContainerIpAddress() + ":" + systemUnderTest.getMappedPort(9092))); | ||
+ systemUnderTest.getHost() + ":" + systemUnderTest.getMappedPort(9092))); | ||
|
||
assertThat(systemUnderTest.getNetwork().getId(), is(network.getId())); | ||
} | ||
|
@@ -349,7 +349,7 @@ void testKafkaContainerFunctionality() { | |
|
||
producer.send(new ProducerRecord<>(topicName, recordKey, recordValue)).get(); | ||
|
||
Utils.waitFor("Consumer records are present", Duration.ofSeconds(10).toMillis(), Duration.ofMinutes(2).toMillis(), | ||
Utils.waitFor("Consumer records are present", Duration.ofSeconds(10), Duration.ofMinutes(2), | ||
() -> { | ||
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100)); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,8 @@ | |
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.assertTrue; | ||
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 the junit 4 dependency brought via testcontainers. We should instead use |
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class StrimziKafkaContainerMockTest { | ||
|
||
|
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.
The field is
final
and initialized when declared so it should never benull
.