Skip to content

Commit 4df26e7

Browse files
committed
Add spotless
1 parent 8ac93c9 commit 4df26e7

File tree

9 files changed

+65
-467
lines changed

9 files changed

+65
-467
lines changed

.checkstyle/checkstyle.xml

Lines changed: 0 additions & 377 deletions
This file was deleted.

.github/workflows/pull_request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222
distribution: 'temurin'
2323
cache: maven
2424

25-
- name: Check style
26-
run: mvn checkstyle:check
25+
- name: Lint
26+
run: mvn spotless:check
2727

2828
- name: Build
2929
run: mvn -B package

.github/workflows/push_main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222
distribution: 'temurin'
2323
cache: maven
2424

25-
- name: Check style
26-
run: mvn checkstyle:check
25+
- name: Lint
26+
run: mvn spotless:check
2727

2828
- name: Build
2929
run: mvn -B package
File renamed without changes.

pom.xml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
<version>1.0.0</version>
1010

1111
<properties>
12-
<checkstyle.version>10.21.4</checkstyle.version>
1312
<jib-maven-plugin.version>3.4.4</jib-maven-plugin.version>
1413
<junit-jupiter.version>5.12.0</junit-jupiter.version>
1514
<kafka-streams.version>3.9.0</kafka-streams.version>
1615
<logback.version>1.5.17</logback.version>
17-
<maven.checkstyle.plugin>3.6.0</maven.checkstyle.plugin>
1816
<maven.compiler.source>21</maven.compiler.source>
1917
<maven.compiler.target>21</maven.compiler.target>
18+
<palantir.version>2.39.0</palantir.version>
2019
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2120
<slf4j-api.version>2.0.17</slf4j-api.version>
21+
<spotless-maven-plugin.version>2.44.3</spotless-maven-plugin.version>
2222
</properties>
2323

2424
<dependencies>
@@ -81,32 +81,32 @@
8181
</plugin>
8282

8383
<plugin>
84-
<groupId>org.apache.maven.plugins</groupId>
85-
<artifactId>maven-checkstyle-plugin</artifactId>
86-
<version>${maven.checkstyle.plugin}</version>
87-
<dependencies>
88-
<dependency>
89-
<groupId>com.puppycrawl.tools</groupId>
90-
<artifactId>checkstyle</artifactId>
91-
<version>${checkstyle.version}</version>
92-
</dependency>
93-
</dependencies>
84+
<groupId>com.diffplug.spotless</groupId>
85+
<artifactId>spotless-maven-plugin</artifactId>
86+
<version>${spotless-maven-plugin.version}</version>
9487
<configuration>
95-
<configLocation>.checkstyle/checkstyle.xml</configLocation>
96-
<violationSeverity>info</violationSeverity>
97-
<consoleOutput>true</consoleOutput>
98-
<includeTestSourceDirectory>true</includeTestSourceDirectory>
99-
<sourceDirectories>
100-
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
101-
</sourceDirectories>
102-
<testSourceDirectories>
103-
<testSourceDirectory>${project.build.testSourceDirectory}</testSourceDirectory>
104-
</testSourceDirectories>
88+
<java>
89+
<includes>
90+
<include>src/main/java/**/*.java</include>
91+
<include>src/test/java/**/*.java</include>
92+
</includes>
93+
<palantirJavaFormat>
94+
<version>${palantir.version}</version>
95+
<style>PALANTIR</style>
96+
<formatJavadoc>true</formatJavadoc>
97+
</palantirJavaFormat>
98+
<removeUnusedImports />
99+
<formatAnnotations />
100+
<importOrder />
101+
<trimTrailingWhitespace />
102+
<endWithNewline />
103+
<licenseHeader>
104+
<file>.spotless/HEADER</file>
105+
</licenseHeader>
106+
</java>
105107
</configuration>
106108
<executions>
107109
<execution>
108-
<id>check-style</id>
109-
<phase>verify</phase>
110110
<goals>
111111
<goal>check</goal>
112112
</goals>

src/main/java/com/michelin/kafka/processing/error/handling/CustomProcessingExceptionHandler.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
2019
package com.michelin.kafka.processing.error.handling;
2120

2221
import java.util.Map;
@@ -26,24 +25,21 @@
2625
import org.slf4j.Logger;
2726
import org.slf4j.LoggerFactory;
2827

29-
/**
30-
* Custom processing exception handler that logs the exception and decides whether to continue processing or fail.
31-
*/
28+
/** Custom processing exception handler that logs the exception and decides whether to continue processing or fail. */
3229
public class CustomProcessingExceptionHandler implements ProcessingExceptionHandler {
3330
private static final Logger log = LoggerFactory.getLogger(CustomProcessingExceptionHandler.class);
3431

3532
@Override
3633
public ProcessingHandlerResponse handle(ErrorHandlerContext context, Record<?, ?> record, Exception exception) {
3734
log.warn(
38-
"Exception caught for processorNodeId = {}, topic = {}, partition = {}, offset = {}, key = {}, value = {}",
39-
context.processorNodeId(),
40-
context.topic(),
41-
context.partition(),
42-
context.offset(),
43-
record != null ? record.key() : null,
44-
record != null ? record.value() : null,
45-
exception
46-
);
35+
"Exception caught for processorNodeId = {}, topic = {}, partition = {}, offset = {}, key = {}, value = {}",
36+
context.processorNodeId(),
37+
context.topic(),
38+
context.partition(),
39+
context.offset(),
40+
record != null ? record.key() : null,
41+
record != null ? record.value() : null,
42+
exception);
4743

4844
return isContinuableException(exception) ? ProcessingHandlerResponse.CONTINUE : ProcessingHandlerResponse.FAIL;
4945
}
@@ -55,8 +51,8 @@ public void configure(Map<String, ?> map) {
5551

5652
private boolean isContinuableException(Exception exception) {
5753
return exception instanceof NumberFormatException
58-
|| exception instanceof NullPointerException
59-
|| exception instanceof IndexOutOfBoundsException
60-
|| exception instanceof KaboomException;
54+
|| exception instanceof NullPointerException
55+
|| exception instanceof IndexOutOfBoundsException
56+
|| exception instanceof KaboomException;
6157
}
6258
}

src/main/java/com/michelin/kafka/processing/error/handling/KaboomException.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
2019
package com.michelin.kafka.processing.error.handling;
2120

22-
/**
23-
* Custom exception.
24-
*/
21+
/** Custom exception. */
2522
public class KaboomException extends RuntimeException {
2623

2724
/**

src/main/java/com/michelin/kafka/processing/error/handling/KafkaStreamsApp.java

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
2019
package com.michelin.kafka.processing.error.handling;
2120

2221
import static org.apache.kafka.streams.StreamsConfig.APPLICATION_ID_CONFIG;
@@ -31,16 +30,13 @@
3130
import org.apache.kafka.streams.KafkaStreams;
3231
import org.apache.kafka.streams.StreamsBuilder;
3332
import org.apache.kafka.streams.kstream.Consumed;
34-
import org.apache.kafka.streams.kstream.KStream;
3533
import org.apache.kafka.streams.kstream.Produced;
3634
import org.apache.kafka.streams.processor.PunctuationType;
3735
import org.apache.kafka.streams.processor.api.ContextualProcessor;
3836
import org.apache.kafka.streams.processor.api.ProcessorContext;
3937
import org.apache.kafka.streams.processor.api.Record;
4038

41-
/**
42-
* Kafka Streams application.
43-
*/
39+
/** Kafka Streams application. */
4440
public class KafkaStreamsApp {
4541

4642
/**
@@ -52,9 +48,8 @@ public static void main(String[] args) {
5248
Properties properties = new Properties();
5349
properties.put(APPLICATION_ID_CONFIG, "error-handling-app");
5450
properties.put(
55-
BOOTSTRAP_SERVERS_CONFIG,
56-
Optional.ofNullable(System.getenv("BOOTSTRAP_SERVERS")).orElse("localhost:9092")
57-
);
51+
BOOTSTRAP_SERVERS_CONFIG,
52+
Optional.ofNullable(System.getenv("BOOTSTRAP_SERVERS")).orElse("localhost:9092"));
5853
properties.put(PROCESSING_EXCEPTION_HANDLER_CLASS_CONFIG, CustomProcessingExceptionHandler.class.getName());
5954

6055
StreamsBuilder streamsBuilder = new StreamsBuilder();
@@ -73,39 +68,29 @@ public static void main(String[] args) {
7368
* @param streamsBuilder The streams builder
7469
*/
7570
public static void buildTopology(StreamsBuilder streamsBuilder) {
76-
KStream<String, String> stream = streamsBuilder.stream(
77-
"INPUT_TOPIC", Consumed.with(Serdes.String(), Serdes.String())
78-
);
79-
80-
stream
81-
// NullPointerException or NumberFormatException
82-
.filter((key, value) -> Integer.parseInt(value.split(",")[0].trim()) >= 2)
83-
.mapValues(value -> value.split(",", 2)[1]) // IndexOutOfBoundsException
84-
.process(CustomProcessor::new) // KaboomException or NullPointerException
85-
.to("OUTPUT_TOPIC", Produced.with(Serdes.String(), Serdes.String()));
71+
streamsBuilder.stream("INPUT_TOPIC", Consumed.with(Serdes.String(), Serdes.String()))
72+
// NullPointerException or NumberFormatException
73+
.filter((key, value) -> Integer.parseInt(value.split(",")[0].trim()) >= 2)
74+
.mapValues(value -> value.split(",", 2)[1]) // IndexOutOfBoundsException
75+
.process(CustomProcessor::new) // KaboomException or NullPointerException
76+
.to("OUTPUT_TOPIC", Produced.with(Serdes.String(), Serdes.String()));
8677
}
8778

88-
/**
89-
* Custom processor.
90-
*/
79+
/** Custom processor. */
9180
public static class CustomProcessor extends ContextualProcessor<String, String, String, String> {
9281
@Override
9382
public void init(ProcessorContext<String, String> context) {
9483
super.init(context);
95-
context.schedule(
96-
Duration.ofMinutes(1),
97-
PunctuationType.WALL_CLOCK_TIME,
98-
timestamp -> {
99-
// Simulate an intentional exception
100-
throw new KaboomException("Simulated exception in punctuation");
101-
}
102-
);
84+
context.schedule(Duration.ofMinutes(1), PunctuationType.WALL_CLOCK_TIME, timestamp -> {
85+
// Simulate an intentional exception
86+
throw new KaboomException("Simulated exception in punctuation");
87+
});
10388
}
10489

10590
@Override
10691
public void process(Record<String, String> record) {
107-
Arrays.stream(record.value().split(","))
108-
.forEach(item -> context().forward(record.withKey(record.key().toUpperCase()).withValue(item.trim())));
92+
Arrays.stream(record.value().split(",")).forEach(item -> context()
93+
.forward(record.withKey(record.key().toUpperCase()).withValue(item.trim())));
10994
}
11095
}
11196
}

src/test/java/com/michelin/kafka/processing/error/handling/KafkaStreamsAppTest.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
2019
package com.michelin.kafka.processing.error.handling;
2120

2221
import static org.apache.kafka.common.utils.Utils.mkEntry;
@@ -52,9 +51,7 @@ public void setUp() {
5251
properties.setProperty(APPLICATION_ID_CONFIG, "error-handling-app-test");
5352
properties.setProperty(BOOTSTRAP_SERVERS_CONFIG, "dummy:1234");
5453
properties.setProperty(
55-
PROCESSING_EXCEPTION_HANDLER_CLASS_CONFIG,
56-
CustomProcessingExceptionHandler.class.getName()
57-
);
54+
PROCESSING_EXCEPTION_HANDLER_CLASS_CONFIG, CustomProcessingExceptionHandler.class.getName());
5855

5956
StreamsBuilder streamsBuilder = new StreamsBuilder();
6057
KafkaStreamsApp.buildTopology(streamsBuilder);
@@ -92,7 +89,9 @@ void shouldHandleExceptionsAndContinueProcessing() {
9289
assertEquals(KeyValue.pair("ORD1006", "Bluetooth Speaker"), results.get(6));
9390

9491
assertEquals(5.0, testDriver.metrics().get(droppedRecordsTotalMetric()).metricValue());
95-
assertEquals(0.03333333333333333, testDriver.metrics().get(droppedRecordsRateMetric()).metricValue());
92+
assertEquals(
93+
0.03333333333333333,
94+
testDriver.metrics().get(droppedRecordsRateMetric()).metricValue());
9695
}
9796

9897
private MetricName droppedRecordsTotalMetric() {
@@ -105,11 +104,9 @@ private MetricName droppedRecordsRateMetric() {
105104

106105
private MetricName createMetric(String name, String description) {
107106
return new MetricName(
108-
name, "stream-task-metrics", description,
109-
mkMap(
110-
mkEntry("thread-id", Thread.currentThread().getName()),
111-
mkEntry("task-id", "0_0")
112-
)
113-
);
107+
name,
108+
"stream-task-metrics",
109+
description,
110+
mkMap(mkEntry("thread-id", Thread.currentThread().getName()), mkEntry("task-id", "0_0")));
114111
}
115112
}

0 commit comments

Comments
 (0)