Skip to content

Commit

Permalink
Fix code inspection for agent module (#31200)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored May 10, 2024
1 parent 8b19d81 commit 3901caf
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public final class PluginLifecycleServiceManager {
*/
public static void init(final Map<String, PluginConfiguration> pluginConfigs, final Collection<JarFile> pluginJars, final ClassLoader pluginClassLoader, final boolean isEnhancedForProxy) {
if (STARTED_FLAG.compareAndSet(false, true)) {
PluginLifecycleServiceManager.start(pluginConfigs, pluginClassLoader, isEnhancedForProxy);
Runtime.getRuntime().addShutdownHook(new Thread(() -> PluginLifecycleServiceManager.close(pluginJars)));
start(pluginConfigs, pluginClassLoader, isEnhancedForProxy);
Runtime.getRuntime().addShutdownHook(new Thread(() -> close(pluginJars)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public final class AgentServiceLoader<T> {

private AgentServiceLoader(final Class<T> service) {
AgentPreconditions.checkArgument(service.isInterface(), String.format("SPI class `%s` is not interface.", service));
this.services = load(service);
services = load(service);
}

private Collection<T> load(final Class<T> service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,9 @@
import org.apache.shardingsphere.agent.api.advice.type.InstanceMethodAdvice;
import org.apache.shardingsphere.agent.api.advice.type.StaticMethodAdvice;

import java.lang.reflect.Method;

public final class YamlAdviceFixture implements ConstructorAdvice, InstanceMethodAdvice, StaticMethodAdvice {

@Override
public void onConstructor(final TargetAdviceObject target, final Object[] args, final String pluginType) {
}

@Override
public void beforeMethod(final TargetAdviceObject target, final Method method, final Object[] args, final String pluginType) {
}

@Override
public void beforeMethod(final Class<?> clazz, final Method method, final Object[] args, final String pluginType) {
}

@Override
public void afterMethod(final TargetAdviceObject target, final Method method, final Object[] args, final Object result, final String pluginType) {
}

@Override
public void afterMethod(final Class<?> clazz, final Method method, final Object[] args, final Object result, final String pluginType) {
}

@Override
public void onThrowing(final TargetAdviceObject target, final Method method, final Object[] args, final Throwable throwable, final String pluginType) {
}

@Override
public void onThrowing(final Class<?> clazz, final Method method, final Object[] args, final Throwable throwable, final String pluginType) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ private void assertLoggingPluginConfiguration(final PluginConfiguration actual)
assertNull(actual.getPassword());
assertThat(actual.getPort(), is(8080));
assertThat(actual.getProps().size(), is(1));
assertThat(actual.getProps().get("key"), is("value"));
assertThat(actual.getProps().getProperty("key"), is("value"));
}

private void assertMetricsPluginConfiguration(final PluginConfiguration actual) {
assertThat(actual.getHost(), is("localhost"));
assertThat(actual.getPassword(), is("random"));
assertThat(actual.getPort(), is(8081));
assertThat(actual.getProps().size(), is(1));
assertThat(actual.getProps().get("key"), is("value"));
assertThat(actual.getProps().getProperty("key"), is("value"));
}

private void assertTracingPluginConfiguration(final PluginConfiguration actual) {
assertThat(actual.getHost(), is("localhost"));
assertThat(actual.getPassword(), is("random"));
assertThat(actual.getPort(), is(8082));
assertThat(actual.getProps().size(), is(1));
assertThat(actual.getProps().get("key"), is("value"));
assertThat(actual.getProps().getProperty("key"), is("value"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,23 @@ private void assertLogFixturePluginConfiguration(final PluginConfiguration actua
assertNull(actual.getPassword());
assertThat(actual.getPort(), is(8080));
assertThat(actual.getProps().size(), is(1));
assertThat(actual.getProps().get("key"), is("value"));
assertThat(actual.getProps().getProperty("key"), is("value"));
}

private void assertMetricsPluginConfiguration(final PluginConfiguration actual) {
assertThat(actual.getHost(), is("localhost"));
assertThat(actual.getPassword(), is("random"));
assertThat(actual.getPort(), is(8081));
assertThat(actual.getProps().size(), is(1));
assertThat(actual.getProps().get("key"), is("value"));
assertThat(actual.getProps().getProperty("key"), is("value"));
}

private void assertTracingPluginConfiguration(final PluginConfiguration actual) {
assertThat(actual.getHost(), is("localhost"));
assertThat(actual.getPassword(), is("random"));
assertThat(actual.getPort(), is(8082));
assertThat(actual.getProps().size(), is(1));
assertThat(actual.getProps().get("key"), is("value"));
assertThat(actual.getProps().getProperty("key"), is("value"));
}

private Properties createProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void call(final List<String> queue) {
* @throws UnsupportedOperationException unsupported operation exception
*/
public void callWhenExceptionThrown(final List<String> queue) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException("");
}

/**
Expand All @@ -60,6 +60,6 @@ public static void staticCall(final List<String> queue) {
* @throws UnsupportedOperationException unsupported operation exception
*/
public static void staticCallWhenExceptionThrown(final List<String> queue) {
throw new UnsupportedOperationException();
throw new UnsupportedOperationException("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,23 @@ private void assertLogFixturePluginConfiguration(final PluginConfiguration actua
assertNull(actual.getPassword());
assertThat(actual.getPort(), is(8080));
assertThat(actual.getProps().size(), is(1));
assertThat(actual.getProps().get("key"), is("value"));
assertThat(actual.getProps().getProperty("key"), is("value"));
}

private void assertMetricsPluginConfiguration(final PluginConfiguration actual) {
assertThat(actual.getHost(), is("localhost"));
assertThat(actual.getPassword(), is("random"));
assertThat(actual.getPort(), is(8081));
assertThat(actual.getProps().size(), is(1));
assertThat(actual.getProps().get("key"), is("value"));
assertThat(actual.getProps().getProperty("key"), is("value"));
}

private void assertTracingPluginConfiguration(final PluginConfiguration actual) {
assertThat(actual.getHost(), is("localhost"));
assertThat(actual.getPassword(), is("random"));
assertThat(actual.getPort(), is(8082));
assertThat(actual.getProps().size(), is(1));
assertThat(actual.getProps().get("key"), is("value"));
assertThat(actual.getProps().getProperty("key"), is("value"));
}

private void assertYamlAdvisorConfiguration(final YamlAdvisorConfiguration actual) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public final class PluginServiceLoader<T> {

private PluginServiceLoader(final Class<T> service) {
PluginPreconditions.checkArgument(service.isInterface(), String.format("SPI class `%s` is not interface.", service));
this.services = load(service);
services = load(service);
}

private Collection<T> load(final Class<T> service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ private InetSocketAddress getSocketAddress(final PluginConfiguration pluginConfi
return isNullOrEmpty(pluginConfig.getHost()) ? new InetSocketAddress(pluginConfig.getPort()) : new InetSocketAddress(pluginConfig.getHost(), pluginConfig.getPort());
}

private boolean isNullOrEmpty(final String string) {
return null == string || string.isEmpty();
private boolean isNullOrEmpty(final String value) {
return null == value || value.isEmpty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void assertMethod() {
void assertExceptionHandle() {
OpenTelemetryJDBCExecutorCallbackAdvice advice = new OpenTelemetryJDBCExecutorCallbackAdvice();
advice.beforeMethod(targetObject, null, new Object[]{executionUnit, false}, "OpenTelemetry");
advice.onThrowing(targetObject, null, new Object[]{executionUnit, false}, new IOException(), "OpenTelemetry");
advice.onThrowing(targetObject, null, new Object[]{executionUnit, false}, new IOException(""), "OpenTelemetry");
List<SpanData> spanItems = testExporter.getFinishedSpanItems();
assertCommonData(spanItems);
assertThat(spanItems.iterator().next().getStatus().getStatusCode(), is(StatusCode.ERROR));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void assertMethod() {
void assertExceptionHandle() {
OpenTelemetryRootSpanAdvice advice = new OpenTelemetryRootSpanAdvice();
advice.beforeMethod(new TargetAdviceObjectFixture(), null, new Object[]{}, "OpenTelemetry");
advice.onThrowing(new TargetAdviceObjectFixture(), null, new Object[]{}, new IOException(), "OpenTelemetry");
advice.onThrowing(new TargetAdviceObjectFixture(), null, new Object[]{}, new IOException(""), "OpenTelemetry");
List<SpanData> spanItems = testExporter.getFinishedSpanItems();
assertCommonData(spanItems);
assertThat(spanItems.iterator().next().getStatus().getStatusCode(), is(StatusCode.ERROR));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void assertExceptionHandle() {
TargetAdviceObjectFixture adviceObjectFixture = new TargetAdviceObjectFixture();
OpenTelemetrySQLParserEngineAdvice advice = new OpenTelemetrySQLParserEngineAdvice();
advice.beforeMethod(adviceObjectFixture, null, new Object[]{SQL, true}, "OpenTelemetry");
advice.onThrowing(adviceObjectFixture, null, new Object[]{SQL, true}, new IOException(), "OpenTelemetry");
advice.onThrowing(adviceObjectFixture, null, new Object[]{SQL, true}, new IOException(""), "OpenTelemetry");
List<SpanData> spanItems = testExporter.getFinishedSpanItems();
assertCommonData(spanItems);
assertThat(spanItems.iterator().next().getStatus().getStatusCode(), is(StatusCode.ERROR));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private List<List<Object>> getParameterSets(final JDBCExecutionUnit executionUni
return each.getParameterSets();
}
}
throw new IllegalStateException();
throw new IllegalStateException("Can not get value from parameter sets.");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ShardingSphereSavepoint() {
}

public ShardingSphereSavepoint(final String name) throws SQLException {
ShardingSpherePreconditions.checkState(null != name && 0 != name.length(), () -> new SQLFeatureNotSupportedException("Savepoint name can not be NULL or empty"));
ShardingSpherePreconditions.checkNotEmpty(name, () -> new SQLFeatureNotSupportedException("Savepoint name can not be NULL or empty"));
savepointName = name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private Map<String, StorageUnit> mockStorageUnits() throws SQLException {
Map<String, StorageUnit> result = new HashMap<>(2, 1F);
result.put("ds", mockStorageUnit(new MockedDataSource()));
DataSource invalidDataSource = mock(DataSource.class);
when(invalidDataSource.getConnection()).thenThrow(new SQLException());
when(invalidDataSource.getConnection()).thenThrow(new SQLException(""));
result.put("invalid_ds", mockStorageUnit(invalidDataSource));
return result;
}
Expand Down

This file was deleted.

0 comments on commit 3901caf

Please sign in to comment.