Skip to content

Commit 52b2bf7

Browse files
authored
Fixes code inspections on agent module (#38760)
1 parent 984df9a commit 52b2bf7

9 files changed

Lines changed: 14 additions & 22 deletions

File tree

agent/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ ShardingSphere-Agent module provides an observable framework for ShardingSphere,
77
### Logging
88

99
The logging plugin uses to record logs of ShardingSphere.
10-
Supports for File.
10+
Support for File.
1111

1212
### Metrics
1313

1414
The metrics plugin uses to collect and expose monitoring metrics.
15-
Supports for prometheus.
15+
Support for prometheus.
1616

1717
### Tracing
1818

1919
The tracing plugin uses to obtain the link trace information of SQL parsing and SQL execution.
20-
Supports for OpenTelemetry.
20+
Support for OpenTelemetry.
2121

2222
## How To Build
2323

agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/executor/type/ConstructorAdviceExecutorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void assertAdviceCatchException() {
5959
assertDoesNotThrow(() -> executor.advice(new SimpleTargetAdviceObject(), new Object[]{new LinkedList<>()}));
6060
}
6161

62-
@SuppressWarnings("unchecked")
62+
@SuppressWarnings({"unchecked", "rawtypes"})
6363
@Test
6464
void assertIntercept() {
6565
Builder<?> builder = mock(Builder.class);

agent/core/src/test/java/org/apache/shardingsphere/agent/core/advisor/executor/type/InstanceMethodAdviceExecutorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void assertAdviceWhenAfterThrows() throws ReflectiveOperationException {
142142
assertThat(queue, is(Arrays.asList("first before foo", "second before bar", "origin call")));
143143
}
144144

145-
@SuppressWarnings("unchecked")
145+
@SuppressWarnings({"unchecked", "rawtypes"})
146146
@Test
147147
void assertIntercept() {
148148
Builder<?> builder = mock(Builder.class);

agent/core/src/test/java/org/apache/shardingsphere/agent/core/builder/AgentBuilderFactoryTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class AgentBuilderFactoryTest {
5151
@BeforeAll
5252
static void setup() {
5353
ByteBuddyAgent.install();
54-
AdvisorConfiguration advisorConfig = createAdvisorConfiguration(TARGET_CLASS_NAME);
54+
AdvisorConfiguration advisorConfig = createAdvisorConfiguration();
5555
Map<String, AdvisorConfiguration> advisorConfigs = Collections.singletonMap(advisorConfig.getTargetClassName(), advisorConfig);
5656
AgentBuilder agentBuilder = AgentBuilderFactory.create(Collections.emptyMap(), Collections.emptyList(), advisorConfigs, true);
5757
agent = agentBuilder.installOnByteBuddyAgent();
@@ -62,8 +62,8 @@ static void setup() {
6262
.getLoaded();
6363
}
6464

65-
private static AdvisorConfiguration createAdvisorConfiguration(final String targetClassName) {
66-
AdvisorConfiguration result = new AdvisorConfiguration(targetClassName);
65+
private static AdvisorConfiguration createAdvisorConfiguration() {
66+
AdvisorConfiguration result = new AdvisorConfiguration(TARGET_CLASS_NAME);
6767
result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.isConstructor().and(ElementMatchers.takesArguments(1)), FooAdvice.class.getName(), "FIXTURE"));
6868
result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.isConstructor().and(ElementMatchers.takesArguments(1)), BarAdvice.class.getName(), "FIXTURE"));
6969
result.getAdvisors().add(new MethodAdvisorConfiguration(ElementMatchers.named("call"), FooAdvice.class.getName(), "FIXTURE"));

agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/loader/YamlPluginConfigurationLoaderTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ class YamlPluginConfigurationLoaderTest {
3838
@Test
3939
void assertLoad(@TempDir final Path tempDir) throws IOException {
4040
Path yamlFile = tempDir.resolve("agent.yaml");
41-
String yamlContent = ""
42-
+ "plugins:\n"
41+
String yamlContent = "plugins:\n"
4342
+ " logging:\n"
4443
+ " FILE:\n"
4544
+ " host: localhost\n"

agent/core/src/test/java/org/apache/shardingsphere/agent/core/plugin/config/yaml/swapper/YamlPluginsConfigurationSwapperTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@
3030
import java.io.UnsupportedEncodingException;
3131
import java.net.URLDecoder;
3232
import java.nio.file.Files;
33-
import java.util.LinkedHashMap;
3433
import java.util.Collections;
3534
import java.util.Map;
3635
import java.util.Objects;
3736
import java.util.Properties;
3837

39-
import static org.hamcrest.Matchers.is;
4038
import static org.hamcrest.MatcherAssert.assertThat;
39+
import static org.hamcrest.Matchers.is;
4140
import static org.junit.jupiter.api.Assertions.assertNull;
4241
import static org.junit.jupiter.api.Assertions.assertTrue;
4342

@@ -102,9 +101,7 @@ void assertSwapWithNullLoggingPlugins() {
102101
@Test
103102
void assertSwapWithNullPluginConfigurationValue() {
104103
YamlPluginCategoryConfiguration yamlPluginCategoryConfig = new YamlPluginCategoryConfiguration();
105-
Map<String, YamlPluginConfiguration> logging = new LinkedHashMap<>();
106-
logging.put("log_fixture", null);
107-
yamlPluginCategoryConfig.setLogging(logging);
104+
yamlPluginCategoryConfig.setLogging(Collections.singletonMap("log_fixture", null));
108105
YamlAgentConfiguration yamlAgentConfig = new YamlAgentConfiguration();
109106
yamlAgentConfig.setPlugins(yamlPluginCategoryConfig);
110107
Map<String, PluginConfiguration> actual = YamlPluginsConfigurationSwapper.swap(yamlAgentConfig);

agent/plugins/core/src/test/java/org/apache/shardingsphere/agent/plugin/core/config/validator/PluginConfigurationValidatorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
import org.apache.shardingsphere.agent.api.PluginConfiguration;
2121
import org.junit.jupiter.api.Test;
2222

23+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2324
import static org.junit.jupiter.api.Assertions.assertThrows;
2425

2526
class PluginConfigurationValidatorTest {
2627

2728
@Test
2829
void assertValidateHostAndPortSuccess() {
29-
PluginConfigurationValidator.validateHostAndPort("foo_type", new PluginConfiguration("localhost", 8080, "pwd", null));
30+
assertDoesNotThrow(() -> PluginConfigurationValidator.validateHostAndPort("foo_type", new PluginConfiguration("localhost", 8080, "pwd", null)));
3031
}
3132

3233
@Test

agent/plugins/metrics/type/prometheus/src/test/java/org/apache/shardingsphere/agent/plugin/metrics/prometheus/collector/type/PrometheusMetricsHistogramCollectorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void assertObserveWithoutBuckets() throws ReflectiveOperationException {
4242
MetricCollectorType.HISTOGRAM, "foo_help", Collections.emptyList(), Collections.emptyMap()));
4343
collector.observe(1D);
4444
Histogram histogram = (Histogram) Plugins.getMemberAccessor().get(PrometheusMetricsHistogramCollector.class.getDeclaredField("histogram"), collector);
45-
assertThat(histogram.collect().get(0).samples.stream().filter(sample -> sample.name.endsWith("_count")).findFirst().get().value, is(1D));
45+
assertThat(histogram.collect().get(0).samples.stream().filter(sample -> sample.name.endsWith("_count")).findFirst().map(optional -> optional.value).orElse(0D), is(1D));
4646
}
4747

4848
@Test

src/resources/idea/inspections.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@
145145
<inspection_tool class="DoubleLiteralMayBeFloatLiteral" enabled="true" level="WARNING" enabled_by_default="true" />
146146
<inspection_tool class="DuplicateExpressions" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
147147
<inspection_tool class="DuplicatedBeanNamesInspection" enabled="false" level="WARNING" enabled_by_default="false" />
148-
<inspection_tool class="DynamicRegexReplaceableByCompiledPattern" enabled="true" level="WARNING" enabled_by_default="true" />
149148
<inspection_tool class="EmptyClass" enabled="true" level="WARNING" enabled_by_default="true">
150149
<option name="ignorableAnnotations">
151150
<value />
@@ -215,7 +214,6 @@
215214
<inspection_tool class="GroovyUnsynchronizedMethodOverridesSynchronizedMethod" enabled="false" level="WARNING" enabled_by_default="false" />
216215
<inspection_tool class="GroovyUnusedAssignment" enabled="false" level="WARNING" enabled_by_default="false" />
217216
<inspection_tool class="GroovyUnusedIncOrDec" enabled="false" level="WARNING" enabled_by_default="false" />
218-
<inspection_tool class="HardcodedLineSeparators" enabled="true" level="WARNING" enabled_by_default="true" />
219217
<inspection_tool class="HasPlatformType" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
220218
<inspection_tool class="HashCodeUsesNonFinalVariable" enabled="true" level="WARNING" enabled_by_default="true" />
221219
<inspection_tool class="HtmlExtraClosingTag" enabled="false" level="WARNING" enabled_by_default="false" />
@@ -242,9 +240,6 @@
242240
<inspection_tool class="InjectionValueTypeInspection" enabled="false" level="ERROR" enabled_by_default="false" />
243241
<inspection_tool class="InnerClassReferencedViaSubclass" enabled="true" level="WARNING" enabled_by_default="true" />
244242
<inspection_tool class="InstanceofCatchParameter" enabled="true" level="WARNING" enabled_by_default="true" />
245-
<inspection_tool class="InstanceofChain" enabled="true" level="WARNING" enabled_by_default="true">
246-
<option name="ignoreInstanceofOnLibraryClasses" value="false" />
247-
</inspection_tool>
248243
<inspection_tool class="InstanceofThis" enabled="true" level="WARNING" enabled_by_default="true" />
249244
<inspection_tool class="IntLiteralMayBeLongLiteral" enabled="true" level="WARNING" enabled_by_default="true" />
250245
<inspection_tool class="IntroduceWhenSubject" enabled="false" level="WEAK WARNING" enabled_by_default="false" />

0 commit comments

Comments
 (0)