Skip to content

Commit e0c0120

Browse files
committed
reproducer for issue #1679
1 parent 3d528f0 commit e0c0120

File tree

3 files changed

+266
-0
lines changed

3 files changed

+266
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright 2021-2022 Creek Contributors (https://github.com/creek-service)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.github.creek.service.basic.kafka.streams.demo.services;
18+
19+
// formatting:off
20+
// begin-snippet: includes-1
21+
import static io.github.creek.service.basic.kafka.streams.demo.internal.TopicConfigBuilder.withPartitions;
22+
import static io.github.creek.service.basic.kafka.streams.demo.internal.TopicDescriptors.inputTopic;
23+
import static io.github.creek.service.basic.kafka.streams.demo.internal.TopicDescriptors.outputTopic;
24+
// end-snippet
25+
import java.time.Duration;
26+
import java.util.ArrayList;
27+
import java.util.Collection;
28+
import java.util.List;
29+
// begin-snippet: includes-2
30+
import org.creekservice.api.kafka.metadata.OwnedKafkaTopicInput;
31+
import org.creekservice.api.kafka.metadata.OwnedKafkaTopicOutput;
32+
// end-snippet
33+
import org.creekservice.api.platform.metadata.ComponentInput;
34+
import org.creekservice.api.platform.metadata.ComponentInternal;
35+
import org.creekservice.api.platform.metadata.ComponentOutput;
36+
import org.creekservice.api.platform.metadata.ServiceDescriptor;
37+
// formatting:on
38+
39+
// begin-snippet: class-name
40+
public final class HandleOccurrenceServiceDescriptor implements ServiceDescriptor {
41+
// end-snippet
42+
private static final List<ComponentInput> INPUTS = new ArrayList<>();
43+
private static final List<ComponentInternal> INTERNALS = new ArrayList<>();
44+
private static final List<ComponentOutput> OUTPUTS = new ArrayList<>();
45+
46+
// formatting:off
47+
// begin-snippet: topic-resources
48+
// Define the tweet-text input topic, conceptually owned by this service:
49+
public static final OwnedKafkaTopicInput<Long, String> TweetTextStream =
50+
register(
51+
inputTopic(
52+
"twitter.tweet.text", // Topic name
53+
Long.class, // Topic key: Tweet id
54+
String.class, // Topic value: Tweet text
55+
withPartitions(5))); // Topic config
56+
57+
// Define the output topic, again conceptually owned by this service:
58+
public static final OwnedKafkaTopicOutput<String, Integer> TweetHandleUsageStream =
59+
register(outputTopic(
60+
"twitter.handle.usage",
61+
String.class, // Twitter handle
62+
Integer.class, // Usage count
63+
withPartitions(6)
64+
.withRetentionTime(Duration.ofHours(12))
65+
));
66+
// end-snippet
67+
// formatting:on
68+
69+
public HandleOccurrenceServiceDescriptor() {}
70+
71+
@Override
72+
public String dockerImage() {
73+
return "ghcr.io/creek-service/basic-kafka-streams-demo-handle-occurrence-service";
74+
}
75+
76+
@Override
77+
public Collection<ComponentInput> inputs() {
78+
return List.copyOf(INPUTS);
79+
}
80+
81+
@Override
82+
public Collection<ComponentInternal> internals() {
83+
return List.copyOf(INTERNALS);
84+
}
85+
86+
@Override
87+
public Collection<ComponentOutput> outputs() {
88+
return List.copyOf(OUTPUTS);
89+
}
90+
91+
private static <T extends ComponentInput> T register(final T input) {
92+
INPUTS.add(input);
93+
return input;
94+
}
95+
96+
// Uncomment if needed:
97+
// private static <T extends ComponentInternal> T register(final T internal) {
98+
// INTERNALS.add(internal);
99+
// return internal;
100+
// }
101+
102+
private static <T extends ComponentOutput> T register(final T output) {
103+
OUTPUTS.add(output);
104+
return output;
105+
}
106+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright 2021-2022 Creek Contributors (https://github.com/creek-service)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.github.creek.service.basic.kafka.streams.demo.services;
18+
19+
// formatting:off
20+
// begin-snippet: includes-1
21+
import static io.github.creek.service.basic.kafka.streams.demo.internal.TopicConfigBuilder.withPartitions;
22+
import static io.github.creek.service.basic.kafka.streams.demo.internal.TopicDescriptors.inputTopic;
23+
import static io.github.creek.service.basic.kafka.streams.demo.internal.TopicDescriptors.outputTopic;
24+
// end-snippet
25+
import java.time.Duration;
26+
import java.util.ArrayList;
27+
import java.util.Collection;
28+
import java.util.List;
29+
// begin-snippet: includes-2
30+
import org.creekservice.api.kafka.metadata.OwnedKafkaTopicInput;
31+
import org.creekservice.api.kafka.metadata.OwnedKafkaTopicOutput;
32+
// end-snippet
33+
import org.creekservice.api.platform.metadata.ComponentInput;
34+
import org.creekservice.api.platform.metadata.ComponentInternal;
35+
import org.creekservice.api.platform.metadata.ComponentOutput;
36+
import org.creekservice.api.platform.metadata.ServiceDescriptor;
37+
// formatting:on
38+
39+
// begin-snippet: class-name
40+
public final class HandleOccurrenceServiceDescriptor implements ServiceDescriptor {
41+
// end-snippet
42+
private static final List<ComponentInput> INPUTS = new ArrayList<>();
43+
private static final List<ComponentInternal> INTERNALS = new ArrayList<>();
44+
private static final List<ComponentOutput> OUTPUTS = new ArrayList<>();
45+
46+
// formatting:off
47+
// begin-snippet: topic-resources
48+
// Define the tweet-text input topic, conceptually owned by this service:
49+
public static final OwnedKafkaTopicInput<Long, String> TweetTextStream =
50+
register(
51+
inputTopic(
52+
"twitter.tweet.text", // Topic name
53+
Long.class, // Topic key: Tweet id
54+
String.class, // Topic value: Tweet text
55+
withPartitions(5))); // Topic config
56+
57+
// Define the output topic, again conceptually owned by this service:
58+
public static final OwnedKafkaTopicOutput<String, Integer> TweetHandleUsageStream =
59+
register(outputTopic(
60+
"twitter.handle.usage",
61+
String.class, // Twitter handle
62+
Integer.class, // Usage count
63+
withPartitions(6)
64+
.withRetentionTime(Duration.ofHours(12))
65+
));
66+
// end-snippet
67+
// formatting:on
68+
69+
public HandleOccurrenceServiceDescriptor() {}
70+
71+
@Override
72+
public String dockerImage() {
73+
return "ghcr.io/creek-service/basic-kafka-streams-demo-handle-occurrence-service";
74+
}
75+
76+
@Override
77+
public Collection<ComponentInput> inputs() { return List.copyOf(INPUTS); }
78+
79+
@Override
80+
public Collection<ComponentInternal> internals() {
81+
return List.copyOf(INTERNALS);
82+
}
83+
84+
@Override
85+
public Collection<ComponentOutput> outputs() {
86+
return List.copyOf(OUTPUTS);
87+
}
88+
89+
private static <T extends ComponentInput> T register(final T input) {
90+
INPUTS.add(input);
91+
return input;
92+
}
93+
94+
// Uncomment if needed:
95+
// private static <T extends ComponentInternal> T register(final T internal) {
96+
// INTERNALS.add(internal);
97+
// return internal;
98+
// }
99+
100+
private static <T extends ComponentOutput> T register(final T output) {
101+
OUTPUTS.add(output);
102+
return output;
103+
}
104+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2023 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.spotless.combined;
17+
18+
import static com.diffplug.spotless.TestProvisioner.mavenCentral;
19+
20+
import org.junit.jupiter.api.Test;
21+
22+
import com.diffplug.spotless.FormatterStep;
23+
import com.diffplug.spotless.ResourceHarness;
24+
import com.diffplug.spotless.StepHarness;
25+
import com.diffplug.spotless.generic.EndWithNewlineStep;
26+
import com.diffplug.spotless.generic.IndentStep;
27+
import com.diffplug.spotless.generic.PipeStepPair;
28+
import com.diffplug.spotless.generic.TrimTrailingWhitespaceStep;
29+
import com.diffplug.spotless.java.GoogleJavaFormatStep;
30+
import com.diffplug.spotless.java.ImportOrderStep;
31+
import com.diffplug.spotless.java.RemoveUnusedImportsStep;
32+
33+
public class CombinedJavaFormatStepTest extends ResourceHarness {
34+
35+
@Test
36+
void checkIssue1679() {
37+
FormatterStep gjf = GoogleJavaFormatStep.create("1.15.0", "AOSP", mavenCentral());
38+
FormatterStep indentWithSpaces = IndentStep.Type.SPACE.create();
39+
FormatterStep importOrder = ImportOrderStep.forJava().createFrom();
40+
FormatterStep removeUnused = RemoveUnusedImportsStep.create(mavenCentral());
41+
FormatterStep trimTrailing = TrimTrailingWhitespaceStep.create();
42+
FormatterStep endWithNewLine = EndWithNewlineStep.create();
43+
PipeStepPair toggleOffOnPair = PipeStepPair.named(PipeStepPair.defaultToggleName()).openClose("formatting:off", "formatting:on").buildPair();
44+
try (StepHarness formatter = StepHarness.forSteps(
45+
toggleOffOnPair.in(),
46+
gjf,
47+
indentWithSpaces,
48+
importOrder,
49+
removeUnused,
50+
trimTrailing,
51+
endWithNewLine,
52+
toggleOffOnPair.out())) {
53+
formatter.testResource("combined/issue1679.dirty", "combined/issue1679.clean");
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)