Skip to content

Commit 84b1ad4

Browse files
authored
Apply spotless and checkstyle to examples (#6061)
Currently, spotless and checkstyle has been applied to the core modules. Now, both will execute to core modules and examples.
1 parent e97b58b commit 84b1ad4

File tree

37 files changed

+268
-224
lines changed

37 files changed

+268
-224
lines changed

build.gradle

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ subprojects {
3232
apply plugin: 'idea'
3333
apply plugin: 'io.franzbecker.gradle-lombok'
3434
apply from: "$rootDir/gradle/shading.gradle"
35-
apply plugin: 'com.diffplug.spotless'
35+
apply from: "$rootDir/gradle/spotless.gradle"
3636
apply plugin: 'checkstyle'
3737
apply plugin: 'org.gradle.test-retry'
3838

@@ -128,28 +128,6 @@ subprojects {
128128
testImplementation 'ch.qos.logback:logback-classic:1.3.3'
129129
}
130130

131-
spotless {
132-
java {
133-
toggleOffOn()
134-
removeUnusedImports()
135-
trimTrailingWhitespace()
136-
endWithNewline()
137-
138-
prettier(['prettier': '2.5.1', 'prettier-plugin-java': '1.6.1'])
139-
.config([
140-
'parser' : 'java',
141-
'tabWidth' : 4,
142-
'printWidth': 120
143-
])
144-
145-
importOrder('', 'java', 'javax', '\\#')
146-
}
147-
groovyGradle {
148-
target '**/*.groovy'
149-
greclipse('4.19.0')
150-
}
151-
}
152-
153131
checkstyle {
154132
toolVersion = "9.3"
155133
configFile = rootProject.file('config/checkstyle/checkstyle.xml')

examples/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
// empty build.gradle for dependabot
2+
plugins {
3+
id 'com.diffplug.spotless' version '6.8.0' apply false
4+
}
5+
26
apply from: "$rootDir/../gradle/ci-support.gradle"
37

48
subprojects {
59
apply plugin:"java"
10+
apply from: "$rootDir/../gradle/spotless.gradle"
11+
apply plugin: 'checkstyle'
612

713
repositories {
814
mavenCentral()
915
}
16+
17+
checkstyle {
18+
toolVersion = "9.3"
19+
configFile = rootProject.file('../config/checkstyle/checkstyle.xml')
20+
}
1021
}

examples/cucumber/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ dependencies {
1313
testImplementation 'io.cucumber:cucumber-java:7.8.0'
1414
testImplementation 'io.cucumber:cucumber-junit:7.8.0'
1515
testImplementation 'org.testcontainers:selenium'
16+
testImplementation 'org.assertj:assertj-core:3.23.1'
1617
}

examples/cucumber/src/test/java/org/testcontainers/examples/CucumberTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,5 @@
55
import org.junit.runner.RunWith;
66

77
@RunWith(Cucumber.class)
8-
@CucumberOptions(plugin = {"pretty"})
9-
public class CucumberTest {
10-
11-
12-
}
8+
@CucumberOptions(plugin = { "pretty" })
9+
public class CucumberTest {}

examples/cucumber/src/test/java/org/testcontainers/examples/Stepdefs.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,23 @@
1010
import org.openqa.selenium.chrome.ChromeOptions;
1111
import org.openqa.selenium.remote.RemoteWebDriver;
1212
import org.testcontainers.containers.BrowserWebDriverContainer;
13+
import org.testcontainers.containers.BrowserWebDriverContainer.VncRecordingMode;
1314
import org.testcontainers.lifecycle.TestDescription;
1415

1516
import java.io.File;
1617
import java.util.List;
1718
import java.util.Optional;
1819

19-
import static junit.framework.TestCase.assertEquals;
20-
import static org.testcontainers.containers.BrowserWebDriverContainer.VncRecordingMode.RECORD_ALL;
20+
import static org.assertj.core.api.Assertions.assertThat;
2121

2222
public class Stepdefs {
2323

2424
private BrowserWebDriverContainer container = new BrowserWebDriverContainer()
25-
.withCapabilities(new ChromeOptions())
26-
.withRecordingMode(RECORD_ALL, new File("build"));
25+
.withCapabilities(new ChromeOptions())
26+
.withRecordingMode(VncRecordingMode.RECORD_ALL, new File("build"));
2727

2828
private String location;
29+
2930
private String answer;
3031

3132
@Before
@@ -35,17 +36,20 @@ public void beforeScenario() {
3536

3637
@After
3738
public void afterScenario(Scenario scenario) {
38-
container.afterTest(new TestDescription() {
39-
@Override
40-
public String getTestId() {
41-
return scenario.getId();
42-
}
39+
container.afterTest(
40+
new TestDescription() {
41+
@Override
42+
public String getTestId() {
43+
return scenario.getId();
44+
}
4345

44-
@Override
45-
public String getFilesystemFriendlyName() {
46-
return scenario.getName();
47-
}
48-
}, Optional.of(scenario).filter(Scenario::isFailed).map(__ -> new RuntimeException()));
46+
@Override
47+
public String getFilesystemFriendlyName() {
48+
return scenario.getName();
49+
}
50+
},
51+
Optional.of(scenario).filter(Scenario::isFailed).map(__ -> new RuntimeException())
52+
);
4953
}
5054

5155
@Given("^location is \"([^\"]*)\"$")
@@ -63,8 +67,6 @@ public void iAskIsItPossibleToSearchHere() throws Exception {
6367

6468
@Then("^I should be told \"([^\"]*)\"$")
6569
public void iShouldBeTold(String expected) throws Exception {
66-
assertEquals(expected, answer);
70+
assertThat(answer).isEqualTo(expected);
6771
}
68-
69-
7072
}

examples/immudb/src/test/java/ImmuDbTest.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.junit.Test;
99
import org.testcontainers.containers.GenericContainer;
1010
import org.testcontainers.containers.wait.strategy.Wait;
11+
1112
import static org.assertj.core.api.Assertions.assertThat;
1213

1314
/**
@@ -17,28 +18,33 @@ public class ImmuDbTest {
1718

1819
// Default port for the ImmuDb server
1920
private static final int IMMUDB_PORT = 3322;
21+
2022
// Default username for the ImmuDb server
2123
private final String IMMUDB_USER = "immudb";
24+
2225
// Default password for the ImmuDb server
2326
private final String IMMUDB_PASSWORD = "immudb";
27+
2428
// Default database name for the ImmuDb server
2529
private final String IMMUDB_DATABASE = "defaultdb";
2630

2731
// Test container for the ImmuDb database, with the latest version of the image and exposed port
2832
@ClassRule
2933
public static final GenericContainer<?> immuDbContainer = new GenericContainer<>("codenotary/immudb:1.3")
30-
.withExposedPorts(IMMUDB_PORT).waitingFor(
31-
Wait.forLogMessage(".*Web API server enabled.*", 1)
32-
);
34+
.withExposedPorts(IMMUDB_PORT)
35+
.waitingFor(Wait.forLogMessage(".*Web API server enabled.*", 1));
36+
3337
// ImmuClient used to interact with the DB
3438
private ImmuClient immuClient;
3539

3640
@Before
3741
public void setUp() {
38-
this.immuClient = ImmuClient.newBuilder()
39-
.withServerUrl(immuDbContainer.getHost())
40-
.withServerPort(immuDbContainer.getMappedPort(IMMUDB_PORT))
41-
.build();
42+
this.immuClient =
43+
ImmuClient
44+
.newBuilder()
45+
.withServerUrl(immuDbContainer.getHost())
46+
.withServerPort(immuDbContainer.getMappedPort(IMMUDB_PORT))
47+
.build();
4248
this.immuClient.login(IMMUDB_USER, IMMUDB_PASSWORD);
4349
this.immuClient.useDatabase(IMMUDB_DATABASE);
4450
}

examples/kafka-cluster/src/test/java/com/example/kafkacluster/KafkaContainerCluster.java

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
import org.rnorth.ducttape.unreliables.Unreliables;
55
import org.testcontainers.containers.Container;
66
import org.testcontainers.containers.GenericContainer;
7+
import org.testcontainers.containers.KafkaContainer;
78
import org.testcontainers.containers.Network;
89
import org.testcontainers.lifecycle.Startable;
9-
import org.testcontainers.lifecycle.Startables;
10-
import org.testcontainers.containers.KafkaContainer;
1110
import org.testcontainers.utility.DockerImageName;
1211

1312
import java.time.Duration;
@@ -17,67 +16,69 @@
1716
import java.util.stream.IntStream;
1817
import java.util.stream.Stream;
1918

20-
import static java.util.concurrent.TimeUnit.SECONDS;
21-
2219
/**
2320
* Provides an easy way to launch a Kafka cluster with multiple brokers.
2421
*/
2522
public class KafkaContainerCluster implements Startable {
2623

2724
private final int brokersNum;
25+
2826
private final Network network;
27+
2928
private final GenericContainer<?> zookeeper;
29+
3030
private final Collection<KafkaContainer> brokers;
3131

3232
public KafkaContainerCluster(String confluentPlatformVersion, int brokersNum, int internalTopicsRf) {
3333
if (brokersNum < 0) {
3434
throw new IllegalArgumentException("brokersNum '" + brokersNum + "' must be greater than 0");
3535
}
3636
if (internalTopicsRf < 0 || internalTopicsRf > brokersNum) {
37-
throw new IllegalArgumentException("internalTopicsRf '" + internalTopicsRf + "' must be less than brokersNum and greater than 0");
37+
throw new IllegalArgumentException(
38+
"internalTopicsRf '" + internalTopicsRf + "' must be less than brokersNum and greater than 0"
39+
);
3840
}
3941

4042
this.brokersNum = brokersNum;
4143
this.network = Network.newNetwork();
4244

43-
this.zookeeper = new GenericContainer<>(DockerImageName.parse("confluentinc/cp-zookeeper").withTag(confluentPlatformVersion))
44-
.withNetwork(network)
45-
.withNetworkAliases("zookeeper")
46-
.withEnv("ZOOKEEPER_CLIENT_PORT", String.valueOf(KafkaContainer.ZOOKEEPER_PORT));
47-
48-
this.brokers = IntStream
49-
.range(0, this.brokersNum)
50-
.mapToObj(brokerNum -> {
51-
return new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka").withTag(confluentPlatformVersion))
52-
.withNetwork(this.network)
53-
.withNetworkAliases("broker-" + brokerNum)
54-
.dependsOn(this.zookeeper)
55-
.withExternalZookeeper("zookeeper:" + KafkaContainer.ZOOKEEPER_PORT)
56-
.withEnv("KAFKA_BROKER_ID", brokerNum + "")
57-
.withEnv("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", internalTopicsRf + "")
58-
.withEnv("KAFKA_OFFSETS_TOPIC_NUM_PARTITIONS", internalTopicsRf + "")
59-
.withEnv("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR", internalTopicsRf + "")
60-
.withEnv("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR", internalTopicsRf + "")
61-
.withStartupTimeout(Duration.ofMinutes(1));
62-
})
63-
.collect(Collectors.toList());
45+
this.zookeeper =
46+
new GenericContainer<>(DockerImageName.parse("confluentinc/cp-zookeeper").withTag(confluentPlatformVersion))
47+
.withNetwork(network)
48+
.withNetworkAliases("zookeeper")
49+
.withEnv("ZOOKEEPER_CLIENT_PORT", String.valueOf(KafkaContainer.ZOOKEEPER_PORT));
50+
51+
this.brokers =
52+
IntStream
53+
.range(0, this.brokersNum)
54+
.mapToObj(brokerNum -> {
55+
return new KafkaContainer(
56+
DockerImageName.parse("confluentinc/cp-kafka").withTag(confluentPlatformVersion)
57+
)
58+
.withNetwork(this.network)
59+
.withNetworkAliases("broker-" + brokerNum)
60+
.dependsOn(this.zookeeper)
61+
.withExternalZookeeper("zookeeper:" + KafkaContainer.ZOOKEEPER_PORT)
62+
.withEnv("KAFKA_BROKER_ID", brokerNum + "")
63+
.withEnv("KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", internalTopicsRf + "")
64+
.withEnv("KAFKA_OFFSETS_TOPIC_NUM_PARTITIONS", internalTopicsRf + "")
65+
.withEnv("KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR", internalTopicsRf + "")
66+
.withEnv("KAFKA_TRANSACTION_STATE_LOG_MIN_ISR", internalTopicsRf + "")
67+
.withStartupTimeout(Duration.ofMinutes(1));
68+
})
69+
.collect(Collectors.toList());
6470
}
6571

6672
public Collection<KafkaContainer> getBrokers() {
6773
return this.brokers;
6874
}
6975

7076
public String getBootstrapServers() {
71-
return brokers.stream()
72-
.map(KafkaContainer::getBootstrapServers)
73-
.collect(Collectors.joining(","));
77+
return brokers.stream().map(KafkaContainer::getBootstrapServers).collect(Collectors.joining(","));
7478
}
7579

7680
private Stream<GenericContainer<?>> allContainers() {
77-
return Stream.concat(
78-
this.brokers.stream(),
79-
Stream.of(this.zookeeper)
80-
);
81+
return Stream.concat(this.brokers.stream(), Stream.of(this.zookeeper));
8182
}
8283

8384
@Override
@@ -86,15 +87,23 @@ public void start() {
8687
// sequential start to avoid resource contention on CI systems with weaker hardware
8788
brokers.forEach(GenericContainer::start);
8889

89-
Unreliables.retryUntilTrue(30, TimeUnit.SECONDS, () -> {
90-
Container.ExecResult result = this.zookeeper.execInContainer(
91-
"sh", "-c",
92-
"zookeeper-shell zookeeper:" + KafkaContainer.ZOOKEEPER_PORT + " ls /brokers/ids | tail -n 1"
93-
);
94-
String brokers = result.getStdout();
95-
96-
return brokers != null && brokers.split(",").length == this.brokersNum;
97-
});
90+
Unreliables.retryUntilTrue(
91+
30,
92+
TimeUnit.SECONDS,
93+
() -> {
94+
Container.ExecResult result =
95+
this.zookeeper.execInContainer(
96+
"sh",
97+
"-c",
98+
"zookeeper-shell zookeeper:" +
99+
KafkaContainer.ZOOKEEPER_PORT +
100+
" ls /brokers/ids | tail -n 1"
101+
);
102+
String brokers = result.getStdout();
103+
104+
return brokers != null && brokers.split(",").length == this.brokersNum;
105+
}
106+
);
98107
}
99108

100109
@Override

0 commit comments

Comments
 (0)