This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new b8e5e27 Fix test cases (#12100)
b8e5e27 is described below
commit b8e5e2769539a3a1cfd5714a4a5ece3da7f868fb
Author: Dachuan J <[email protected]>
AuthorDate: Mon Aug 30 16:04:42 2021 +0800
Fix test cases (#12100)
---
.../api/advice/ChannelHandlerAdviceTest.java | 11 ++--
.../api/advice/CommandExecutorTaskAdviceTest.java | 13 ++--
.../api/advice/SQLRouteEngineAdviceTest.java | 76 ++++++++++++----------
.../metrics/api/advice/TransactionAdviceTest.java | 11 ++--
4 files changed, 57 insertions(+), 54 deletions(-)
diff --git
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/ChannelHandlerAdviceTest.java
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/ChannelHandlerAdviceTest.java
index 09ae8e0..8c551a9 100644
---
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/ChannelHandlerAdviceTest.java
+++
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/ChannelHandlerAdviceTest.java
@@ -29,8 +29,8 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.lang.reflect.Method;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -48,7 +48,6 @@ public final class ChannelHandlerAdviceTest extends
MetricsAdviceBaseTest {
private Method channelInactive;
@Test
- @SuppressWarnings("OptionalGetWithoutIsPresent")
public void assertMethod() {
when(channelRead.getName()).thenReturn(ChannelHandlerAdvice.CHANNEL_READ);
when(channelActive.getName()).thenReturn(ChannelHandlerAdvice.CHANNEL_ACTIVE);
@@ -59,10 +58,10 @@ public final class ChannelHandlerAdviceTest extends
MetricsAdviceBaseTest {
channelHandlerAdvice.beforeMethod(targetObject, channelActive, new
Object[]{}, new MethodInvocationResult());
channelHandlerAdvice.beforeMethod(targetObject, channelInactive, new
Object[]{}, new MethodInvocationResult());
FixtureWrapper requestWrapper = (FixtureWrapper)
MetricsPool.get(MetricIds.PROXY_REQUEST).get();
- assertNotNull(requestWrapper);
- assertThat(requestWrapper.getFixtureValue(), is(1d));
+ assertTrue(MetricsPool.get(MetricIds.PROXY_REQUEST).isPresent());
+ assertThat(requestWrapper.getFixtureValue(), is(1.0));
FixtureWrapper connectionWrapper = (FixtureWrapper)
MetricsPool.get(MetricIds.PROXY_COLLECTION).get();
- assertNotNull(connectionWrapper);
- assertThat(connectionWrapper.getFixtureValue(), is(1d));
+ assertTrue(MetricsPool.get(MetricIds.PROXY_COLLECTION).isPresent());
+ assertThat(connectionWrapper.getFixtureValue(), is(1.0));
}
}
diff --git
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/CommandExecutorTaskAdviceTest.java
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/CommandExecutorTaskAdviceTest.java
index f0f6fcf..1c236ec 100644
---
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/CommandExecutorTaskAdviceTest.java
+++
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/CommandExecutorTaskAdviceTest.java
@@ -21,6 +21,7 @@ import
org.apache.shardingsphere.agent.api.result.MethodInvocationResult;
import org.apache.shardingsphere.agent.metrics.api.MetricsPool;
import org.apache.shardingsphere.agent.metrics.api.constant.MetricIds;
import org.apache.shardingsphere.agent.metrics.api.fixture.FixtureWrapper;
+import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -28,8 +29,8 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.lang.reflect.Method;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -44,7 +45,6 @@ public final class CommandExecutorTaskAdviceTest extends
MetricsAdviceBaseTest {
private Method processException;
@Test
- @SuppressWarnings("OptionalGetWithoutIsPresent")
public void assertExecuteLatency() {
when(run.getName()).thenReturn(CommandExecutorTaskAdvice.COMMAND_EXECUTOR_RUN);
MockAdviceTargetObject targetObject = new MockAdviceTargetObject();
@@ -56,18 +56,17 @@ public final class CommandExecutorTaskAdviceTest extends
MetricsAdviceBaseTest {
}
commandExecutorTaskAdvice.afterMethod(targetObject, run, new
Object[]{}, new MethodInvocationResult());
FixtureWrapper requestWrapper = (FixtureWrapper)
MetricsPool.get(MetricIds.PROXY_EXECUTE_LATENCY_MILLIS).get();
- assertNotNull(requestWrapper);
- assertThat(requestWrapper.getFixtureValue(),
org.hamcrest.Matchers.greaterThan(0d));
+
assertTrue(MetricsPool.get(MetricIds.PROXY_EXECUTE_LATENCY_MILLIS).isPresent());
+ assertThat(requestWrapper.getFixtureValue(),
Matchers.greaterThan(0.0));
}
@Test
- @SuppressWarnings("OptionalGetWithoutIsPresent")
public void assertExecutorErrorTotal() {
when(processException.getName()).thenReturn(CommandExecutorTaskAdvice.COMMAND_EXECUTOR_EXCEPTION);
MockAdviceTargetObject targetObject = new MockAdviceTargetObject();
commandExecutorTaskAdvice.afterMethod(targetObject, processException,
new Object[]{}, new MethodInvocationResult());
FixtureWrapper requestWrapper = (FixtureWrapper)
MetricsPool.get(MetricIds.PROXY_EXECUTE_ERROR).get();
- assertNotNull(requestWrapper);
- assertThat(requestWrapper.getFixtureValue(),
org.hamcrest.Matchers.greaterThan(0d));
+ assertTrue(MetricsPool.get(MetricIds.PROXY_EXECUTE_ERROR).isPresent());
+ assertThat(requestWrapper.getFixtureValue(),
Matchers.greaterThan(0.0));
}
}
diff --git
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/SQLRouteEngineAdviceTest.java
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/SQLRouteEngineAdviceTest.java
index 5f1d87b..59f67d4 100644
---
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/SQLRouteEngineAdviceTest.java
+++
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/SQLRouteEngineAdviceTest.java
@@ -31,48 +31,54 @@ import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQ
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLSelectStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dml.MySQLUpdateStatement;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
import java.lang.reflect.Method;
import java.util.Collections;
-import static org.junit.Assert.assertNotNull;
+import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
-@RunWith(MockitoJUnitRunner.class)
public final class SQLRouteEngineAdviceTest extends MetricsAdviceBaseTest {
private final SQLRouteEngineAdvice sqlRouteEngineAdvice = new
SQLRouteEngineAdvice();
- @Mock
- private Method route;
+ @Test
+ public void assertInsertRoute() {
+ LogicSQL logicSQL = new LogicSQL(new CommonSQLStatementContext<>(new
MySQLInsertStatement()), "", Collections.emptyList());
+ assertRoute(MetricIds.ROUTE_SQL_INSERT, logicSQL);
+ }
@Test
- @SuppressWarnings({"unchecked", "OptionalGetWithoutIsPresent", "rawtypes"})
- public void assertRoute() {
+ public void assertSelectRoute() {
+ LogicSQL logicSQL = new LogicSQL(new CommonSQLStatementContext<>(new
MySQLSelectStatement()), "", Collections.emptyList());
+ assertRoute(MetricIds.ROUTE_SQL_SELECT, logicSQL);
+ }
+
+ @Test
+ public void assertDeleteRoute() {
+ LogicSQL logicSQL = new LogicSQL(new CommonSQLStatementContext<>(new
MySQLDeleteStatement()), "", Collections.emptyList());
+ assertRoute(MetricIds.ROUTE_SQL_DELETE, logicSQL);
+ }
+
+ @Test
+ public void assertUpdateRoute() {
+ LogicSQL logicSQL = new LogicSQL(new CommonSQLStatementContext<>(new
MySQLUpdateStatement()), "", Collections.emptyList());
+ assertRoute(MetricIds.ROUTE_SQL_UPDATE, logicSQL);
+ }
+
+ public void assertRoute(final String metricIds, final LogicSQL logicSQL) {
+ MockAdviceTargetObject targetObject = new MockAdviceTargetObject();
+ sqlRouteEngineAdvice.beforeMethod(targetObject, mock(Method.class),
new Object[]{logicSQL}, new MethodInvocationResult());
+ FixtureWrapper wrapper = (FixtureWrapper)
MetricsPool.get(metricIds).get();
+ assertTrue(MetricsPool.get(metricIds).isPresent());
+ assertThat(((FixtureWrapper)
MetricsPool.get(metricIds).get()).getFixtureValue(), is(1.0));
+ }
+
+ @Test
+ public void assertRouteDataSourceAndTable() {
MockAdviceTargetObject targetObject = new MockAdviceTargetObject();
- LogicSQL logicSQL = new LogicSQL(new CommonSQLStatementContext(new
MySQLInsertStatement()), "", Collections.emptyList());
- sqlRouteEngineAdvice.beforeMethod(targetObject, route, new
Object[]{logicSQL}, new MethodInvocationResult());
- FixtureWrapper wrapper = (FixtureWrapper)
MetricsPool.get(MetricIds.ROUTE_SQL_INSERT).get();
- assertNotNull(wrapper);
- assertThat(wrapper.getFixtureValue(), org.hamcrest.Matchers.is(1.0));
- logicSQL = new LogicSQL(new CommonSQLStatementContext(new
MySQLSelectStatement()), "", Collections.emptyList());
- sqlRouteEngineAdvice.beforeMethod(targetObject, route, new
Object[]{logicSQL}, new MethodInvocationResult());
- wrapper = (FixtureWrapper)
MetricsPool.get(MetricIds.ROUTE_SQL_SELECT).get();
- assertNotNull(wrapper);
- assertThat(wrapper.getFixtureValue(), org.hamcrest.Matchers.is(1.0));
- logicSQL = new LogicSQL(new CommonSQLStatementContext(new
MySQLUpdateStatement()), "", Collections.emptyList());
- sqlRouteEngineAdvice.beforeMethod(targetObject, route, new
Object[]{logicSQL}, new MethodInvocationResult());
- wrapper = (FixtureWrapper)
MetricsPool.get(MetricIds.ROUTE_SQL_UPDATE).get();
- assertNotNull(wrapper);
- assertThat(wrapper.getFixtureValue(), org.hamcrest.Matchers.is(1.0));
- logicSQL = new LogicSQL(new CommonSQLStatementContext(new
MySQLDeleteStatement()), "", Collections.emptyList());
- sqlRouteEngineAdvice.beforeMethod(targetObject, route, new
Object[]{logicSQL}, new MethodInvocationResult());
- wrapper = (FixtureWrapper)
MetricsPool.get(MetricIds.ROUTE_SQL_DELETE).get();
- assertNotNull(wrapper);
- assertThat(wrapper.getFixtureValue(), org.hamcrest.Matchers.is(1.0));
RouteContext routeContext = new RouteContext();
RouteMapper dsMapper = new RouteMapper("logic_db", "ds_0");
RouteMapper tbMapper = new RouteMapper("t_order", "t_order_0");
@@ -80,12 +86,12 @@ public final class SQLRouteEngineAdviceTest extends
MetricsAdviceBaseTest {
routeContext.getRouteUnits().add(routeUnit);
MethodInvocationResult result = new MethodInvocationResult();
result.rebase(routeContext);
- sqlRouteEngineAdvice.afterMethod(targetObject, route, new Object[]{},
result);
- wrapper = (FixtureWrapper)
MetricsPool.get(MetricIds.ROUTE_DATASOURCE).get();
- assertNotNull(wrapper);
- assertThat(wrapper.getFixtureValue(), org.hamcrest.Matchers.is(1.0));
+ sqlRouteEngineAdvice.afterMethod(targetObject, mock(Method.class), new
Object[]{}, result);
+ FixtureWrapper wrapper = (FixtureWrapper)
MetricsPool.get(MetricIds.ROUTE_DATASOURCE).get();
+ assertTrue(MetricsPool.get(MetricIds.ROUTE_DATASOURCE).isPresent());
+ assertThat(wrapper.getFixtureValue(), is(1.0));
wrapper = (FixtureWrapper)
MetricsPool.get(MetricIds.ROUTE_TABLE).get();
- assertNotNull(wrapper);
- assertThat(wrapper.getFixtureValue(), org.hamcrest.Matchers.is(1.0));
+ assertTrue(MetricsPool.get(MetricIds.ROUTE_TABLE).isPresent());
+ assertThat(wrapper.getFixtureValue(), is(1.0));
}
}
diff --git
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/TransactionAdviceTest.java
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/TransactionAdviceTest.java
index 480d5ab..bbcaf2a 100644
---
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/TransactionAdviceTest.java
+++
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-api/src/test/java/org/apache/shardingsphere/agent/metrics/api/advice/TransactionAdviceTest.java
@@ -29,8 +29,8 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.lang.reflect.Method;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -45,7 +45,6 @@ public final class TransactionAdviceTest extends
MetricsAdviceBaseTest {
private Method rollback;
@Test
- @SuppressWarnings("OptionalGetWithoutIsPresent")
public void assertMethod() {
when(commit.getName()).thenReturn(TransactionAdvice.COMMIT);
when(rollback.getName()).thenReturn(TransactionAdvice.ROLLBACK);
@@ -53,10 +52,10 @@ public final class TransactionAdviceTest extends
MetricsAdviceBaseTest {
transactionAdvice.beforeMethod(targetObject, commit, new Object[]{},
new MethodInvocationResult());
transactionAdvice.beforeMethod(targetObject, rollback, new Object[]{},
new MethodInvocationResult());
FixtureWrapper commitWrapper = (FixtureWrapper)
MetricsPool.get(MetricIds.TRANSACTION_COMMIT).get();
- assertNotNull(commitWrapper);
- assertThat(commitWrapper.getFixtureValue(), Matchers.is(1d));
+ assertTrue(MetricsPool.get(MetricIds.TRANSACTION_COMMIT).isPresent());
+ assertThat(commitWrapper.getFixtureValue(), Matchers.is(1.0));
FixtureWrapper rollbackWrapper = (FixtureWrapper)
MetricsPool.get(MetricIds.TRANSACTION_ROLLBACK).get();
- assertNotNull(rollbackWrapper);
- assertThat(rollbackWrapper.getFixtureValue(), Matchers.is(1d));
+
assertTrue(MetricsPool.get(MetricIds.TRANSACTION_ROLLBACK).isPresent());
+ assertThat(rollbackWrapper.getFixtureValue(), Matchers.is(1.0));
}
}