You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2020/12/30 11:38:29 UTC
[shardingsphere] branch master updated: Add ITWatcher to simplify
error log (#8831)
This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 8f396ea Add ITWatcher to simplify error log (#8831)
8f396ea is described below
commit 8f396ea0aa905c81c779cc3391b90a2faa318015
Author: Liang Zhang <te...@163.com>
AuthorDate: Wed Dec 30 19:38:04 2020 +0800
Add ITWatcher to simplify error log (#8831)
* Add IntegrationTestWatcher
* Remove useless error log
* Rename to ITWatcher
---
.../test/integration/engine/BatchIT.java | 11 ++----
.../test/integration/engine/ITWatcher.java | 35 +++++++++++++++++++
.../test/integration/engine/SingleIT.java | 10 +++---
.../test/integration/engine/dcl/GeneralDCLIT.java | 6 ----
.../integration/engine/ddl/JDBCGeneralDDLIT.java | 8 +----
.../integration/engine/ddl/ProxyGeneralDDLIT.java | 6 ----
.../test/integration/engine/dml/BaseDMLIT.java | 39 +++++++++-------------
.../test/integration/engine/dml/GeneralDMLIT.java | 15 ++-------
.../test/integration/engine/dql/BaseDQLIT.java | 11 ++----
.../test/integration/engine/dql/GeneralDQLIT.java | 6 ----
10 files changed, 63 insertions(+), 84 deletions(-)
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchIT.java
index b87187d..f5e98b0 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BatchIT.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.test.integration.engine;
import lombok.AccessLevel;
import lombok.Getter;
-import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineExpressionParser;
@@ -58,7 +57,6 @@ import java.util.Set;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-@Slf4j
@Getter(AccessLevel.PROTECTED)
public abstract class BatchIT extends BaseIT {
@@ -109,13 +107,8 @@ public abstract class BatchIT extends BaseIT {
assertThat(actualUpdateCounts.length, is(dataSets.size()));
int count = 0;
for (DataSet each : dataSets) {
- try {
- assertThat(actualUpdateCounts[count], is(each.getUpdateCount()));
- expectedList.add(each);
- } catch (final AssertionError ex) {
- log.error("[ERROR] SQL::{}, Expect::{}", sql, each);
- throw ex;
- }
+ assertThat(actualUpdateCounts[count], is(each.getUpdateCount()));
+ expectedList.add(each);
count++;
}
DataSet expected = merge(expectedList);
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ITWatcher.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ITWatcher.java
new file mode 100644
index 0000000..eb70de4
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ITWatcher.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.test.integration.engine;
+
+import lombok.extern.slf4j.Slf4j;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+
+/**
+ * Integration test watcher.
+ */
+@Slf4j
+public final class ITWatcher extends TestWatcher {
+
+ @Override
+ protected void failed(final Throwable ex, final Description description) {
+ log.error("Error case: {}", description.getMethodName());
+ super.failed(ex, description);
+ }
+}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/SingleIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/SingleIT.java
index 7a48276..d7d4f79 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/SingleIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/SingleIT.java
@@ -19,13 +19,13 @@ package org.apache.shardingsphere.test.integration.engine;
import lombok.AccessLevel;
import lombok.Getter;
-import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.test.integration.cases.assertion.root.IntegrateTestCaseAssertion;
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLCaseType;
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLValue;
import org.apache.shardingsphere.test.integration.cases.dataset.DataSet;
import org.apache.shardingsphere.test.integration.cases.dataset.DataSetLoader;
+import org.junit.Rule;
import javax.xml.bind.JAXBException;
import java.io.IOException;
@@ -35,10 +35,12 @@ import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
-@Slf4j
@Getter(AccessLevel.PROTECTED)
public abstract class SingleIT extends BaseIT {
+ @Rule
+ public ITWatcher watcher = new ITWatcher();
+
private final String caseIdentifier;
private final IntegrateTestCaseAssertion assertion;
@@ -63,8 +65,4 @@ public abstract class SingleIT extends BaseIT {
List<Object> parameters = null == assertion ? Collections.emptyList() : assertion.getSQLValues().stream().map(SQLValue::toString).collect(Collectors.toList());
return parameters.isEmpty() ? sql : String.format(sql.replace("%", "$").replace("?", "%s"), parameters.toArray()).replace("$", "%").replace("%%", "%").replace("'%'", "'%%'");
}
-
- protected final void logException(final Exception ex) {
- log.error("ruleType={}, databaseType={}, sql={}", getRuleType(), getDatabaseType().getName(), sql, ex);
- }
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java
index 8439854..eda077d 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dcl/GeneralDCLIT.java
@@ -52,9 +52,6 @@ public final class GeneralDCLIT extends BaseDCLIT {
} else {
connection.prepareStatement(getSql()).executeUpdate();
}
- } catch (final SQLException ex) {
- logException(ex);
- throw ex;
}
}
@@ -66,9 +63,6 @@ public final class GeneralDCLIT extends BaseDCLIT {
} else {
connection.prepareStatement(getSql()).execute();
}
- } catch (final SQLException ex) {
- logException(ex);
- throw ex;
}
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/JDBCGeneralDDLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/JDBCGeneralDDLIT.java
index b915b76..3554ba8 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/JDBCGeneralDDLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/JDBCGeneralDDLIT.java
@@ -21,13 +21,13 @@ import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConne
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
+import org.apache.shardingsphere.test.integration.IntegrateTestParameters;
import org.apache.shardingsphere.test.integration.cases.IntegrateTestCaseType;
import org.apache.shardingsphere.test.integration.cases.assertion.ddl.DDLIntegrateTestCaseAssertion;
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLCaseType;
import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSetColumn;
import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSetIndex;
import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSetMetadata;
-import org.apache.shardingsphere.test.integration.IntegrateTestParameters;
import org.apache.shardingsphere.test.integration.env.IntegrateTestEnvironment;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
@@ -69,9 +69,6 @@ public final class JDBCGeneralDDLIT extends BaseDDLIT {
connection.prepareStatement(getSql()).executeUpdate();
}
assertTableMetaData(((ShardingSphereConnection) connection).getMetaDataContexts().getDefaultMetaData().getSchema());
- } catch (final SQLException ex) {
- logException(ex);
- throw ex;
}
}
@@ -85,9 +82,6 @@ public final class JDBCGeneralDDLIT extends BaseDDLIT {
connection.prepareStatement(getSql()).execute();
}
assertTableMetaData(((ShardingSphereConnection) connection).getMetaDataContexts().getDefaultMetaData().getSchema());
- } catch (final SQLException ex) {
- logException(ex);
- throw ex;
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/ProxyGeneralDDLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/ProxyGeneralDDLIT.java
index 01a2342..1085c26 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/ProxyGeneralDDLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/ProxyGeneralDDLIT.java
@@ -68,9 +68,6 @@ public final class ProxyGeneralDDLIT extends BaseDDLIT {
connection.prepareStatement(getSql()).executeUpdate();
}
assertTableMetaData(connection);
- } catch (final SQLException ex) {
- logException(ex);
- throw ex;
}
}
@@ -84,9 +81,6 @@ public final class ProxyGeneralDDLIT extends BaseDDLIT {
connection.prepareStatement(getSql()).execute();
}
assertTableMetaData(connection);
- } catch (final SQLException ex) {
- logException(ex);
- throw ex;
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java
index 36e94d8..6a7aa48 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/BaseDMLIT.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.test.integration.engine.dml;
-import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
import org.apache.shardingsphere.infra.datanode.DataNode;
@@ -53,7 +52,6 @@ import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-@Slf4j
public abstract class BaseDMLIT extends SingleIT {
private final DataSetEnvironmentManager dataSetEnvironmentManager;
@@ -87,29 +85,24 @@ public abstract class BaseDMLIT extends SingleIT {
}
protected final void assertDataSet(final int actualUpdateCount) throws SQLException {
- try {
- assertThat("Only support single table for DML.", getDataSet().getMetadataList().size(), is(1));
- assertThat(actualUpdateCount, is(getDataSet().getUpdateCount()));
- DataSetMetadata expectedDataSetMetadata = getDataSet().getMetadataList().get(0);
- for (String each : new InlineExpressionParser(expectedDataSetMetadata.getDataNodes()).splitAndEvaluate()) {
- DataNode dataNode = new DataNode(each);
- String sql;
- if (getDatabaseType() instanceof PostgreSQLDatabaseType) {
- try (Connection connection = getActualDataSources().get(dataNode.getDataSourceName()).getConnection()) {
- String primaryKeyColumnName = getPostgreSQLTablePrimaryKeyColumnName(connection, dataNode.getTableName());
- sql = String.format("SELECT * FROM %s ORDER BY %s ASC", dataNode.getTableName(), primaryKeyColumnName);
- }
- } else {
- sql = String.format("SELECT * FROM %s", dataNode.getTableName());
- }
- try (Connection connection = getActualDataSources().get(dataNode.getDataSourceName()).getConnection();
- PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
- assertDataSet(preparedStatement, getDataSet().findRows(dataNode), expectedDataSetMetadata);
+ assertThat("Only support single table for DML.", getDataSet().getMetadataList().size(), is(1));
+ assertThat(actualUpdateCount, is(getDataSet().getUpdateCount()));
+ DataSetMetadata expectedDataSetMetadata = getDataSet().getMetadataList().get(0);
+ for (String each : new InlineExpressionParser(expectedDataSetMetadata.getDataNodes()).splitAndEvaluate()) {
+ DataNode dataNode = new DataNode(each);
+ String sql;
+ if (getDatabaseType() instanceof PostgreSQLDatabaseType) {
+ try (Connection connection = getActualDataSources().get(dataNode.getDataSourceName()).getConnection()) {
+ String primaryKeyColumnName = getPostgreSQLTablePrimaryKeyColumnName(connection, dataNode.getTableName());
+ sql = String.format("SELECT * FROM %s ORDER BY %s ASC", dataNode.getTableName(), primaryKeyColumnName);
}
+ } else {
+ sql = String.format("SELECT * FROM %s", dataNode.getTableName());
+ }
+ try (Connection connection = getActualDataSources().get(dataNode.getDataSourceName()).getConnection();
+ PreparedStatement preparedStatement = connection.prepareStatement(sql)) {
+ assertDataSet(preparedStatement, getDataSet().findRows(dataNode), expectedDataSetMetadata);
}
- } catch (final AssertionError ex) {
- log.error("[ERROR] SQL::{}, Parameter::{}, Expect::{}", getCaseIdentifier(), getAssertion().getParameters(), getAssertion().getExpectedDataFile());
- throw ex;
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java
index 755ae15..9bbcbb1 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dml/GeneralDMLIT.java
@@ -17,15 +17,13 @@
package org.apache.shardingsphere.test.integration.engine.dml;
+import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
+import org.apache.shardingsphere.test.integration.IntegrateTestParameters;
+import org.apache.shardingsphere.test.integration.cases.IntegrateTestCaseType;
import org.apache.shardingsphere.test.integration.cases.assertion.dml.DMLIntegrateTestCaseAssertion;
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLCaseType;
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLValue;
-import org.apache.shardingsphere.test.integration.cases.IntegrateTestCaseType;
-import org.apache.shardingsphere.test.integration.IntegrateTestParameters;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import javax.xml.bind.JAXBException;
@@ -40,7 +38,6 @@ import java.util.Collection;
import static org.junit.Assert.assertFalse;
-@RunWith(Parameterized.class)
public final class GeneralDMLIT extends BaseDMLIT {
private final DMLIntegrateTestCaseAssertion assertion;
@@ -72,9 +69,6 @@ public final class GeneralDMLIT extends BaseDMLIT {
int actualUpdateCount;
try (Connection connection = getTargetDataSource().getConnection()) {
actualUpdateCount = SQLCaseType.Literal == getCaseType() ? executeUpdateForStatement(connection) : executeUpdateForPreparedStatement(connection);
- } catch (final SQLException ex) {
- logException(ex);
- throw ex;
}
assertDataSet(actualUpdateCount);
}
@@ -107,9 +101,6 @@ public final class GeneralDMLIT extends BaseDMLIT {
int actualUpdateCount;
try (Connection connection = getTargetDataSource().getConnection()) {
actualUpdateCount = SQLCaseType.Literal == getCaseType() ? executeForStatement(connection) : executeForPreparedStatement(connection);
- } catch (final SQLException ex) {
- logException(ex);
- throw ex;
}
assertDataSet(actualUpdateCount);
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java
index 1119b12..9e26017 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.test.integration.engine.dql;
-import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.test.integration.cases.assertion.dql.DQLIntegrateTestCaseAssertion;
import org.apache.shardingsphere.test.integration.cases.assertion.root.SQLCaseType;
@@ -48,7 +47,6 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-@Slf4j
public abstract class BaseDQLIT extends SingleIT {
protected BaseDQLIT(final String parentPath, final DQLIntegrateTestCaseAssertion assertion, final String ruleType,
@@ -82,13 +80,8 @@ public abstract class BaseDQLIT extends SingleIT {
for (DataSetMetadata each : getDataSet().getMetadataList()) {
expectedColumns.addAll(each.getColumns());
}
- try {
- assertMetaData(resultSet.getMetaData(), expectedColumns);
- assertRows(resultSet, getDataSet().getRows());
- } catch (final AssertionError ex) {
- log.error("[ERROR] SQL::{}, Parameter::[{}], Expect::{}", getCaseIdentifier(), getAssertion().getParameters(), getAssertion().getExpectedDataFile());
- throw ex;
- }
+ assertMetaData(resultSet.getMetaData(), expectedColumns);
+ assertRows(resultSet, getDataSet().getRows());
}
private void assertMetaData(final ResultSetMetaData actualMetaData, final List<DataSetColumn> expectedColumns) throws SQLException {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java
index 80b73e9..67cc7ce 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/GeneralDQLIT.java
@@ -61,9 +61,6 @@ public final class GeneralDQLIT extends BaseDQLIT {
} else {
assertExecuteQueryForPreparedStatement(connection);
}
- } catch (final SQLException ex) {
- logException(ex);
- throw ex;
}
}
@@ -94,9 +91,6 @@ public final class GeneralDQLIT extends BaseDQLIT {
} else {
assertExecuteForPreparedStatement(connection);
}
- } catch (final SQLException ex) {
- logException(ex);
- throw ex;
}
}