You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by to...@apache.org on 2022/05/11 16:30:35 UTC
[shardingsphere] branch master updated: Use assertThat and instanceOf to instead of assertTrue and instanceof (#17599)
This is an automated email from the ASF dual-hosted git repository.
totalo 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 2c617c330af Use assertThat and instanceOf to instead of assertTrue and instanceof (#17599)
2c617c330af is described below
commit 2c617c330afd9e17ef14756904cb7cb12e7b06b4
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu May 12 00:30:27 2022 +0800
Use assertThat and instanceOf to instead of assertTrue and instanceof (#17599)
---
.../interceptor/ConstructorInterceptorTest.java | 8 +-
.../command/OpenGaussCommandPacketFactoryTest.java | 12 +-
.../impl/EncryptAlterTableTokenGeneratorTest.java | 135 ++++++++++-----------
.../impl/EncryptCreateTableTokenGeneratorTest.java | 6 +-
.../engine/ShardingConditionEngineFactoryTest.java | 8 +-
.../strategy/ShardingStrategyFactoryTest.java | 56 ++++-----
...AlterShardingTableRuleStatementUpdaterTest.java | 42 ++-----
...reateShardingTableRuleStatementUpdaterTest.java | 49 +++-----
.../namespace/ShardingSpringNamespaceTest.java | 3 +-
.../RowNumberPaginationContextEngineTest.java | 5 +-
.../RuleConfigurationCheckerFactoryTest.java | 4 +-
.../DialectSchemaMetaDataLoaderFactoryTest.java | 4 +-
.../connection/CircuitBreakerConnectionTest.java | 22 ++--
.../datasource/CircuitBreakerDataSourceTest.java | 6 +-
.../scaling/core/spi/ScalingEntryFactoryTest.java | 5 +-
.../mysql/ingest/MySQLIncrementalDumperTest.java | 12 +-
.../value/MySQLDataTypeHandlerFactoryTest.java | 12 +-
.../ingest/wal/decode/MppdbDecodingPluginTest.java | 15 +--
.../ingest/wal/WalEventConverterTest.java | 12 +-
.../ingest/wal/decode/TestDecodingPluginTest.java | 6 +-
.../transaction/core/ResourceDataSourceTest.java | 3 +-
.../lock/DistributeLockContextTest.java | 28 ++---
.../CuratorZookeeperExceptionHandlerTest.java | 5 +-
.../query/QueryHeaderBuilderFactoryTest.java | 7 +-
.../OpenGaussAdminExecutorFactoryTest.java | 7 +-
.../PostgreSQLAdminExecutorFactoryTest.java | 2 +-
.../database/CreateDatabaseBackendHandlerTest.java | 13 +-
.../ImportDatabaseConfigurationHandlerTest.java | 90 ++++++--------
.../resource/AddResourceBackendHandlerTest.java | 5 +-
.../resource/AlterResourceBackendHandlerTest.java | 8 +-
.../resource/DropResourceBackendHandlerTest.java | 71 ++++-------
.../command/MySQLCommandExecutorFactoryTest.java | 6 +-
.../admin/MySQLComSetOptionExecutorTest.java | 4 +-
.../query/MySQLComQueryPacketExecutorTest.java | 9 +-
.../query/MySQLMultiStatementsHandlerTest.java | 4 +-
.../OpenGaussCommandExecutorFactoryTest.java | 33 ++---
.../bind/OpenGaussComBatchBindExecutorTest.java | 4 +-
.../PostgreSQLCommandExecutorFactoryTest.java | 29 +++--
.../command/query/extended/JDBCPortalTest.java | 22 ++--
...egatedBatchedStatementsCommandExecutorTest.java | 4 +-
.../PostgreSQLAggregatedCommandExecutorTest.java | 13 +-
.../parse/PostgreSQLComParseExecutorTest.java | 6 +-
...eDatabaseProtocolFrontendEngineFactoryTest.java | 5 +-
.../spi/type/required/RequiredSPIRegistryTest.java | 7 +-
.../core/job/progress/JobProgressTest.java | 32 +++--
.../pipeline/core/task/IncrementalTaskTest.java | 4 +-
.../data/pipeline/core/task/InventoryTaskTest.java | 39 +++---
47 files changed, 382 insertions(+), 500 deletions(-)
diff --git a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/ConstructorInterceptorTest.java b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/ConstructorInterceptorTest.java
index 83a59f816b4..19debb1bc29 100644
--- a/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/ConstructorInterceptorTest.java
+++ b/shardingsphere-agent/shardingsphere-agent-core/src/test/java/org/apache/shardingsphere/agent/core/plugin/interceptor/ConstructorInterceptorTest.java
@@ -29,8 +29,8 @@ import net.bytebuddy.jar.asm.Opcodes;
import net.bytebuddy.matcher.ElementMatchers;
import org.apache.shardingsphere.agent.api.advice.AdviceTargetObject;
import org.apache.shardingsphere.agent.core.bytebuddy.listener.LoggingListener;
-import org.apache.shardingsphere.agent.core.mock.material.ConstructorMaterial;
import org.apache.shardingsphere.agent.core.mock.advice.MockConstructorAdvice;
+import org.apache.shardingsphere.agent.core.mock.material.ConstructorMaterial;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -39,8 +39,9 @@ import org.junit.Test;
import java.util.LinkedList;
import java.util.List;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
public final class ConstructorInterceptorTest {
@@ -75,10 +76,9 @@ public final class ConstructorInterceptorTest {
.installOnByteBuddyAgent();
}
- @SuppressWarnings("ConstantConditions")
@Test
public void assertNoArgConstructor() {
- assertTrue(new ConstructorMaterial() instanceof AdviceTargetObject);
+ assertThat(new ConstructorMaterial(), instanceOf(AdviceTargetObject.class));
}
@Test
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-opengauss/src/test/java/org/apache/shardingsphere/db/protocol/opengauss/packet/command/OpenGaussCommandPacketFactoryTest.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-opengauss/src/test/java/org/apache/shardingsphere/db/protocol/opengauss/packet/command/OpenGaussCommandPacketFactoryTest.java
index 65ef0d73d73..cd12bc7429c 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-opengauss/src/test/java/org/apache/shardingsphere/db/protocol/opengauss/packet/command/OpenGaussCommandPacketFactoryTest.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-opengauss/src/test/java/org/apache/shardingsphere/db/protocol/opengauss/packet/command/OpenGaussCommandPacketFactoryTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.db.protocol.opengauss.packet.command;
import io.netty.buffer.ByteBuf;
-import org.apache.shardingsphere.db.protocol.packet.CommandPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.PostgreSQLAggregatedCommandPacket;
@@ -29,8 +28,8 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -43,14 +42,11 @@ public final class OpenGaussCommandPacketFactoryTest {
@Test
public void assertNewOpenGaussComBatchBindPacket() {
when(payload.getByteBuf()).thenReturn(mock(ByteBuf.class));
- CommandPacket actual = OpenGaussCommandPacketFactory.newInstance(OpenGaussCommandPacketType.BATCH_BIND_COMMAND, payload);
- assertTrue(actual instanceof PostgreSQLAggregatedCommandPacket);
+ assertThat(OpenGaussCommandPacketFactory.newInstance(OpenGaussCommandPacketType.BATCH_BIND_COMMAND, payload), instanceOf(PostgreSQLAggregatedCommandPacket.class));
}
@Test
public void assertNewPostgreSQLPacket() {
- CommandPacket actual = OpenGaussCommandPacketFactory.newInstance(mock(PostgreSQLCommandPacketType.class), payload);
- assertTrue(actual instanceof PostgreSQLCommandPacket);
- assertFalse(actual instanceof OpenGaussCommandPacket);
+ assertThat(OpenGaussCommandPacketFactory.newInstance(mock(PostgreSQLCommandPacketType.class), payload), instanceOf(PostgreSQLCommandPacket.class));
}
}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptAlterTableTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptAlterTableTokenGeneratorTest.java
index fda0ee90b0a..730c1f664db 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptAlterTableTokenGeneratorTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptAlterTableTokenGeneratorTest.java
@@ -46,9 +46,9 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -60,7 +60,48 @@ public final class EncryptAlterTableTokenGeneratorTest {
@Before
public void setup() {
generator = new EncryptAlterTableTokenGenerator();
- generator.setEncryptRule(buildEncryptRule());
+ generator.setEncryptRule(mockEncryptRule());
+ }
+
+ private EncryptRule mockEncryptRule() {
+ EncryptRule result = mock(EncryptRule.class);
+ when(result.getCipherColumn("t_encrypt", "certificate_number")).thenReturn("cipher_certificate_number");
+ when(result.findAssistedQueryColumn("t_encrypt", "certificate_number")).thenReturn(Optional.of("assisted_certificate_number"));
+ when(result.findPlainColumn("t_encrypt", "certificate_number")).thenReturn(Optional.of("certificate_number_plain"));
+ EncryptTable encryptTable = mock(EncryptTable.class);
+ when(encryptTable.getLogicColumns()).thenReturn(Collections.singleton("t_encrypt"));
+ EncryptAlgorithm<?, ?> encryptAlgorithm = mock(EncryptAlgorithm.class);
+ when(result.findEncryptor("t_encrypt", "certificate_number")).thenReturn(Optional.of(encryptAlgorithm));
+ when(result.findEncryptor("t_encrypt", "certificate_number_new")).thenReturn(Optional.of(encryptAlgorithm));
+ when(result.findEncryptTable("t_encrypt")).thenReturn(Optional.of(encryptTable));
+ when(result.containsConfigDataType("t_encrypt", "certificate_number")).thenReturn(true);
+ when(result.containsConfigDataType("t_encrypt", "certificate_number_new")).thenReturn(true);
+ when(result.findEncryptColumn("t_encrypt", "certificate_number")).thenReturn(Optional.of(mockEncryptColumn()));
+ when(result.findEncryptColumn("t_encrypt", "certificate_number_new")).thenReturn(Optional.of(mockNewEncryptColumn()));
+ return result;
+ }
+
+ private EncryptColumn mockEncryptColumn() {
+ Map<String, Integer> dataTypes = new HashMap<>(2, 1);
+ dataTypes.put("int", Types.INTEGER);
+ dataTypes.put("varchar", Types.VARCHAR);
+ EncryptColumnDataType logicDataType = new EncryptColumnDataType("int(20) unsigned not null default 0", dataTypes);
+ EncryptColumnDataType cipherDataType = new EncryptColumnDataType("varchar(200) not null default ''", dataTypes);
+ EncryptColumnDataType assistedQueryDataType = new EncryptColumnDataType("varchar(200) not null", dataTypes);
+ EncryptColumnDataType plainDataType = new EncryptColumnDataType("int(20) unsigned not null default 0", dataTypes);
+ return new EncryptColumn(logicDataType, "cipher_certificate_number", cipherDataType, "assisted_certificate_number", assistedQueryDataType, "certificate_number_plain", plainDataType, "test");
+ }
+
+ private EncryptColumn mockNewEncryptColumn() {
+ Map<String, Integer> dataTypes = new HashMap<>(2, 1);
+ dataTypes.put("int", Types.INTEGER);
+ dataTypes.put("varchar", Types.VARCHAR);
+ EncryptColumnDataType logicDataType = new EncryptColumnDataType("int(20) unsigned not null default 0", dataTypes);
+ EncryptColumnDataType cipherDataType = new EncryptColumnDataType("varchar(500) not null", dataTypes);
+ EncryptColumnDataType assistedQueryDataType = new EncryptColumnDataType("varchar(200) not null", dataTypes);
+ EncryptColumnDataType plainDataType = new EncryptColumnDataType("int(20) unsigned not null default 0", dataTypes);
+ return new EncryptColumn(logicDataType, "cipher_certificate_number_new", cipherDataType,
+ "assisted_certificate_number_new", assistedQueryDataType, "certificate_number_new_plain", plainDataType, "test");
}
@Test
@@ -68,7 +109,7 @@ public final class EncryptAlterTableTokenGeneratorTest {
Collection<SQLToken> sqlTokens = generator.generateSQLTokens(buildAddColumnStatementContext());
assertThat(sqlTokens.size(), is(4));
Iterator<SQLToken> iterator = sqlTokens.iterator();
- assertTrue(iterator.next() instanceof RemoveToken);
+ assertThat(iterator.next(), instanceOf(RemoveToken.class));
EncryptConfigDataTypeToken cipherToken = (EncryptConfigDataTypeToken) iterator.next();
assertThat(cipherToken.toString(), is("cipher_certificate_number varchar(200) not null default ''"));
assertThat(cipherToken.getStartIndex(), is(68));
@@ -83,12 +124,21 @@ public final class EncryptAlterTableTokenGeneratorTest {
assertThat(plainToken.getStopIndex(), is(67));
}
+ private AlterTableStatementContext buildAddColumnStatementContext() {
+ AlterTableStatementContext result = mock(AlterTableStatementContext.class, RETURNS_DEEP_STUBS);
+ when(result.getSqlStatement().getTable().getTableName().getIdentifier().getValue()).thenReturn("t_encrypt");
+ ColumnDefinitionSegment segment = new ColumnDefinitionSegment(33, 67, new ColumnSegment(33, 50, new IdentifierValue("certificate_number")), new DataTypeSegment(), false);
+ AddColumnDefinitionSegment addColumnDefinitionSegment = new AddColumnDefinitionSegment(22, 67, Collections.singletonList(segment));
+ when(result.getSqlStatement().getAddColumnDefinitions()).thenReturn(Collections.singletonList(addColumnDefinitionSegment));
+ return result;
+ }
+
@Test
public void assertModifyColumnGenerateSQLTokens() {
Collection<SQLToken> sqlTokens = generator.generateSQLTokens(buildModifyColumnStatementContext());
assertThat(sqlTokens.size(), is(4));
Iterator<SQLToken> iterator = sqlTokens.iterator();
- assertTrue(iterator.next() instanceof RemoveToken);
+ assertThat(iterator.next(), instanceOf(RemoveToken.class));
EncryptConfigDataTypeToken cipherToken = (EncryptConfigDataTypeToken) iterator.next();
assertThat(cipherToken.toString(), is("cipher_certificate_number varchar(200) not null default ''"));
assertThat(cipherToken.getStartIndex(), is(71));
@@ -103,15 +153,24 @@ public final class EncryptAlterTableTokenGeneratorTest {
assertThat(plainToken.getStopIndex(), is(70));
}
+ private AlterTableStatementContext buildModifyColumnStatementContext() {
+ AlterTableStatementContext result = mock(AlterTableStatementContext.class, RETURNS_DEEP_STUBS);
+ when(result.getSqlStatement().getTable().getTableName().getIdentifier().getValue()).thenReturn("t_encrypt");
+ ColumnDefinitionSegment segment = new ColumnDefinitionSegment(36, 70, new ColumnSegment(36, 53, new IdentifierValue("certificate_number")), new DataTypeSegment(), false);
+ ModifyColumnDefinitionSegment modifyColumnDefinitionSegment = new ModifyColumnDefinitionSegment(22, 70, segment);
+ when(result.getSqlStatement().getModifyColumnDefinitions()).thenReturn(Collections.singletonList(modifyColumnDefinitionSegment));
+ return result;
+ }
+
@Test
public void assertChangeColumnGenerateSQLTokens() {
Collection<SQLToken> sqlTokens = generator.generateSQLTokens(buildChangeColumnStatementContext());
assertThat(sqlTokens.size(), is(6));
Iterator<SQLToken> iterator = sqlTokens.iterator();
- assertTrue(iterator.next() instanceof RemoveToken);
+ assertThat(iterator.next(), instanceOf(RemoveToken.class));
EncryptAlterTableToken previous = (EncryptAlterTableToken) iterator.next();
assertThat(previous.toString(), is("cipher_certificate_number"));
- assertTrue(iterator.next() instanceof RemoveToken);
+ assertThat(iterator.next(), instanceOf(RemoveToken.class));
EncryptConfigDataTypeToken cipherToken = (EncryptConfigDataTypeToken) iterator.next();
assertThat(cipherToken.toString(), is("cipher_certificate_number_new varchar(500) not null"));
assertThat(cipherToken.getStartIndex(), is(94));
@@ -126,26 +185,6 @@ public final class EncryptAlterTableTokenGeneratorTest {
assertThat(plainToken.getStopIndex(), is(93));
}
- private AlterTableStatementContext buildAddColumnStatementContext() {
- AlterTableStatementContext result = mock(AlterTableStatementContext.class, RETURNS_DEEP_STUBS);
- when(result.getSqlStatement().getTable().getTableName().getIdentifier().getValue()).thenReturn("t_encrypt");
- ColumnDefinitionSegment segment = new ColumnDefinitionSegment(33, 67,
- new ColumnSegment(33, 50, new IdentifierValue("certificate_number")), new DataTypeSegment(), false);
- AddColumnDefinitionSegment addColumnDefinitionSegment = new AddColumnDefinitionSegment(22, 67, Collections.singletonList(segment));
- when(result.getSqlStatement().getAddColumnDefinitions()).thenReturn(Collections.singletonList(addColumnDefinitionSegment));
- return result;
- }
-
- private AlterTableStatementContext buildModifyColumnStatementContext() {
- AlterTableStatementContext result = mock(AlterTableStatementContext.class, RETURNS_DEEP_STUBS);
- when(result.getSqlStatement().getTable().getTableName().getIdentifier().getValue()).thenReturn("t_encrypt");
- ColumnDefinitionSegment segment = new ColumnDefinitionSegment(36, 70,
- new ColumnSegment(36, 53, new IdentifierValue("certificate_number")), new DataTypeSegment(), false);
- ModifyColumnDefinitionSegment modifyColumnDefinitionSegment = new ModifyColumnDefinitionSegment(22, 70, segment);
- when(result.getSqlStatement().getModifyColumnDefinitions()).thenReturn(Collections.singletonList(modifyColumnDefinitionSegment));
- return result;
- }
-
private AlterTableStatementContext buildChangeColumnStatementContext() {
AlterTableStatementContext result = mock(AlterTableStatementContext.class, RETURNS_DEEP_STUBS);
when(result.getSqlStatement().getTable().getTableName().getIdentifier().getValue()).thenReturn("t_encrypt");
@@ -156,48 +195,4 @@ public final class EncryptAlterTableTokenGeneratorTest {
when(result.getSqlStatement().getChangeColumnDefinitions()).thenReturn(Collections.singletonList(changeColumnDefinitionSegment));
return result;
}
-
- private EncryptRule buildEncryptRule() {
- EncryptRule result = mock(EncryptRule.class);
- EncryptTable encryptTable = mock(EncryptTable.class);
- when(result.getCipherColumn("t_encrypt", "certificate_number")).thenReturn("cipher_certificate_number");
- when(result.findAssistedQueryColumn("t_encrypt", "certificate_number")).thenReturn(Optional.of("assisted_certificate_number"));
- when(result.findPlainColumn("t_encrypt", "certificate_number")).thenReturn(Optional.of("certificate_number_plain"));
- when(encryptTable.getLogicColumns()).thenReturn(Collections.singletonList("t_encrypt"));
- EncryptAlgorithm<?, ?> encryptAlgorithm = mock(EncryptAlgorithm.class);
- when(result.findEncryptor("t_encrypt", "certificate_number")).thenReturn(Optional.of(encryptAlgorithm));
- when(result.findEncryptor("t_encrypt", "certificate_number_new")).thenReturn(Optional.of(encryptAlgorithm));
- when(result.findEncryptTable("t_encrypt")).thenReturn(Optional.of(encryptTable));
- when(result.containsConfigDataType("t_encrypt", "certificate_number")).thenReturn(true);
- when(result.containsConfigDataType("t_encrypt", "certificate_number_new")).thenReturn(true);
- EncryptColumn column = mockEncryptColumn();
- when(result.findEncryptColumn("t_encrypt", "certificate_number")).thenReturn(Optional.of(column));
- EncryptColumn newColumn = mockNewEncryptColumn();
- when(result.findEncryptColumn("t_encrypt", "certificate_number_new")).thenReturn(Optional.of(newColumn));
- return result;
- }
-
- private EncryptColumn mockEncryptColumn() {
- Map<String, Integer> dataTypes = new HashMap<>();
- dataTypes.put("int", Types.INTEGER);
- dataTypes.put("varchar", Types.VARCHAR);
- EncryptColumnDataType logicDataType = new EncryptColumnDataType("int(20) unsigned not null default 0", dataTypes);
- EncryptColumnDataType cipherDataType = new EncryptColumnDataType("varchar(200) not null default ''", dataTypes);
- EncryptColumnDataType assistedQueryDataType = new EncryptColumnDataType("varchar(200) not null", dataTypes);
- EncryptColumnDataType plainDataType = new EncryptColumnDataType("int(20) unsigned not null default 0", dataTypes);
- return new EncryptColumn(logicDataType, "cipher_certificate_number", cipherDataType,
- "assisted_certificate_number", assistedQueryDataType, "certificate_number_plain", plainDataType, "test");
- }
-
- private EncryptColumn mockNewEncryptColumn() {
- Map<String, Integer> dataTypes = new HashMap<>();
- dataTypes.put("int", Types.INTEGER);
- dataTypes.put("varchar", Types.VARCHAR);
- EncryptColumnDataType logicDataType = new EncryptColumnDataType("int(20) unsigned not null default 0", dataTypes);
- EncryptColumnDataType cipherDataType = new EncryptColumnDataType("varchar(500) not null", dataTypes);
- EncryptColumnDataType assistedQueryDataType = new EncryptColumnDataType("varchar(200) not null", dataTypes);
- EncryptColumnDataType plainDataType = new EncryptColumnDataType("int(20) unsigned not null default 0", dataTypes);
- return new EncryptColumn(logicDataType, "cipher_certificate_number_new", cipherDataType,
- "assisted_certificate_number_new", assistedQueryDataType, "certificate_number_new_plain", plainDataType, "test");
- }
}
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptCreateTableTokenGeneratorTest.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptCreateTableTokenGeneratorTest.java
index 86522c88807..dc7d5a05c6d 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptCreateTableTokenGeneratorTest.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptCreateTableTokenGeneratorTest.java
@@ -17,13 +17,13 @@
package org.apache.shardingsphere.encrypt.rewrite.impl;
-import org.apache.shardingsphere.encrypt.spi.context.EncryptColumnDataType;
import org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptCreateTableTokenGenerator;
import org.apache.shardingsphere.encrypt.rewrite.token.pojo.EncryptConfigDataTypeToken;
import org.apache.shardingsphere.encrypt.rule.EncryptColumn;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.EncryptTable;
import org.apache.shardingsphere.encrypt.spi.EncryptAlgorithm;
+import org.apache.shardingsphere.encrypt.spi.context.EncryptColumnDataType;
import org.apache.shardingsphere.infra.binder.statement.ddl.CreateTableStatementContext;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.RemoveToken;
@@ -42,9 +42,9 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -64,7 +64,7 @@ public final class EncryptCreateTableTokenGeneratorTest {
Collection<SQLToken> sqlTokens = generator.generateSQLTokens(buildCreateTableStatementContext());
assertThat(sqlTokens.size(), is(4));
Iterator<SQLToken> iterator = sqlTokens.iterator();
- assertTrue(iterator.next() instanceof RemoveToken);
+ assertThat(iterator.next(), instanceOf(RemoveToken.class));
EncryptConfigDataTypeToken cipherToken = (EncryptConfigDataTypeToken) iterator.next();
assertThat(cipherToken.toString(), is("cipher_certificate_number varchar(200) not null default ''"));
assertThat(cipherToken.getStartIndex(), is(79));
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactoryTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactoryTest.java
index 95cf74853b2..18705fae1b3 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactoryTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/condition/engine/ShardingConditionEngineFactoryTest.java
@@ -33,7 +33,8 @@ import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -54,17 +55,18 @@ public final class ShardingConditionEngineFactoryTest {
when(metaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(mock(ShardingSphereSchema.class));
}
+ @SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void assertCreateInsertClauseShardingConditionEngine() {
SQLStatementContext insertStatementContext = mock(InsertStatementContext.class);
when(logicSQL.getSqlStatementContext()).thenReturn(insertStatementContext);
ShardingConditionEngine<?> actual = ShardingConditionEngineFactory.createShardingConditionEngine(logicSQL, metaData, shardingRule);
- assertTrue(actual instanceof InsertClauseShardingConditionEngine);
+ assertThat(actual, instanceOf(InsertClauseShardingConditionEngine.class));
}
@Test
public void assertCreateWhereClauseShardingConditionEngine() {
ShardingConditionEngine<?> actual = ShardingConditionEngineFactory.createShardingConditionEngine(logicSQL, metaData, shardingRule);
- assertTrue(actual instanceof WhereClauseShardingConditionEngine);
+ assertThat(actual, instanceOf(WhereClauseShardingConditionEngine.class));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/strategy/ShardingStrategyFactoryTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/strategy/ShardingStrategyFactoryTest.java
index 4217f7cb018..26c50178963 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/strategy/ShardingStrategyFactoryTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/strategy/ShardingStrategyFactoryTest.java
@@ -28,48 +28,42 @@ import org.apache.shardingsphere.sharding.route.strategy.type.hint.HintShardingS
import org.apache.shardingsphere.sharding.route.strategy.type.none.NoneShardingStrategy;
import org.apache.shardingsphere.sharding.route.strategy.type.standard.StandardShardingStrategy;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
public final class ShardingStrategyFactoryTest {
- @Mock
- private StandardShardingStrategyConfiguration standardShardingStrategyConfig;
-
- @Mock
- private CoreStandardShardingAlgorithmFixture standardShardingAlgorithmFixture;
-
- @Mock
- private ComplexShardingStrategyConfiguration complexShardingStrategyConfig;
+ @Test
+ public void assertNewInstanceForStandardShardingStrategy() {
+ StandardShardingStrategyConfiguration standardShardingStrategyConfig = mock(StandardShardingStrategyConfiguration.class);
+ when(standardShardingStrategyConfig.getShardingColumn()).thenReturn("standard_sharding_column");
+ assertThat(ShardingStrategyFactory.newInstance(standardShardingStrategyConfig, mock(CoreStandardShardingAlgorithmFixture.class), null), instanceOf(StandardShardingStrategy.class));
+ }
- @Mock
- private CoreComplexKeysShardingAlgorithmFixture complexKeysShardingAlgorithmFixture;
+ @Test
+ public void assertNewInstanceForStandardShardingStrategyWithDefaultColumnStrategy() {
+ ShardingStrategy actual = ShardingStrategyFactory.newInstance(mock(StandardShardingStrategyConfiguration.class), mock(CoreStandardShardingAlgorithmFixture.class), "order_id");
+ assertTrue(actual.getShardingColumns().contains("order_id"));
+ }
- @Mock
- private HintShardingStrategyConfiguration hintShardingStrategyConfig;
+ @Test
+ public void assertNewInstanceForComplexShardingStrategy() {
+ ComplexShardingStrategyConfiguration complexShardingStrategyConfig = mock(ComplexShardingStrategyConfiguration.class);
+ when(complexShardingStrategyConfig.getShardingColumns()).thenReturn("complex_sharding_column");
+ assertThat(ShardingStrategyFactory.newInstance(complexShardingStrategyConfig, mock(CoreComplexKeysShardingAlgorithmFixture.class), null), instanceOf(ComplexShardingStrategy.class));
+ }
- @Mock
- private CoreHintShardingAlgorithmFixture hintShardingAlgorithmFixture;
+ @Test
+ public void assertNewInstanceForHintShardingStrategy() {
+ assertThat(ShardingStrategyFactory.newInstance(mock(HintShardingStrategyConfiguration.class), mock(CoreHintShardingAlgorithmFixture.class), null), instanceOf(HintShardingStrategy.class));
+ }
@Test
- public void assertNewInstance() {
- when(standardShardingStrategyConfig.getShardingColumn()).thenReturn("standard_sharding_column");
- ShardingStrategy actualStandardShardingStrategy = ShardingStrategyFactory.newInstance(standardShardingStrategyConfig, standardShardingAlgorithmFixture, null);
- assertTrue(actualStandardShardingStrategy instanceof StandardShardingStrategy);
- when(complexShardingStrategyConfig.getShardingColumns()).thenReturn("complex_sharding_column");
- ShardingStrategy actualComplexShardingStrategy = ShardingStrategyFactory.newInstance(complexShardingStrategyConfig, complexKeysShardingAlgorithmFixture, null);
- assertTrue(actualComplexShardingStrategy instanceof ComplexShardingStrategy);
- ShardingStrategy actualHintShardingStrategy = ShardingStrategyFactory.newInstance(hintShardingStrategyConfig, hintShardingAlgorithmFixture, null);
- assertTrue(actualHintShardingStrategy instanceof HintShardingStrategy);
- ShardingStrategy actualNoneShardingStrategy = ShardingStrategyFactory.newInstance(null, null, null);
- assertTrue(actualNoneShardingStrategy instanceof NoneShardingStrategy);
- ShardingStrategy actualStandardWithDefaultColumnStrategy = ShardingStrategyFactory.newInstance(mock(StandardShardingStrategyConfiguration.class), standardShardingAlgorithmFixture, "order_id");
- assertTrue(actualStandardWithDefaultColumnStrategy.getShardingColumns().contains("order_id"));
+ public void assertNewInstanceForNoneShardingStrategy() {
+ assertThat(ShardingStrategyFactory.newInstance(null, null, null), instanceOf(NoneShardingStrategy.class));
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java
index cb8848ed14f..0c6e60cccaa 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/AlterShardingTableRuleStatementUpdaterTest.java
@@ -23,14 +23,12 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.update.AlterShardingTableRuleStatementUpdater;
-import org.apache.shardingsphere.sharding.distsql.parser.segment.AbstractTableRuleSegment;
import org.apache.shardingsphere.sharding.distsql.parser.segment.AutoTableRuleSegment;
import org.apache.shardingsphere.sharding.distsql.parser.segment.KeyGenerateStrategySegment;
import org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingStrategySegment;
@@ -44,16 +42,14 @@ import org.mockito.junit.MockitoJUnitRunner;
import javax.sql.DataSource;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -77,15 +73,12 @@ public final class AlterShardingTableRuleStatementUpdaterTest {
when(shardingSphereMetaData.getDatabaseName()).thenReturn("schema");
when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(shardingSphereRuleMetaData);
- when(shardingSphereRuleMetaData.getRules()).thenReturn(createShardingSphereRule());
+ when(shardingSphereRuleMetaData.getRules()).thenReturn(Collections.emptyList());
}
@Test
public void assertUpdate() throws DistSQLException {
- Collection<AbstractTableRuleSegment> rules = new LinkedList<>();
- rules.add(createCompleteAutoTableRule("t_order_item"));
- rules.add(createCompleteTableRule("t_order"));
- AlterShardingTableRuleStatement statement = new AlterShardingTableRuleStatement(rules);
+ AlterShardingTableRuleStatement statement = new AlterShardingTableRuleStatement(Arrays.asList(createCompleteAutoTableRule("t_order_item"), createCompleteTableRule("t_order")));
updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig);
ShardingRuleConfiguration toBeAlteredRuleConfig = updater.buildToBeAlteredRuleConfiguration(statement);
updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeAlteredRuleConfig);
@@ -93,10 +86,10 @@ public final class AlterShardingTableRuleStatementUpdaterTest {
ShardingTableRuleConfiguration tableRule = currentRuleConfig.getTables().iterator().next();
assertThat(tableRule.getLogicTable(), is("t_order"));
assertThat(tableRule.getActualDataNodes(), is("ds_${0..1}.t_order${0..1}"));
- assertTrue(tableRule.getTableShardingStrategy() instanceof StandardShardingStrategyConfiguration);
+ assertThat(tableRule.getTableShardingStrategy(), instanceOf(StandardShardingStrategyConfiguration.class));
assertThat(((StandardShardingStrategyConfiguration) tableRule.getTableShardingStrategy()).getShardingColumn(), is("product_id"));
assertThat(tableRule.getTableShardingStrategy().getShardingAlgorithmName(), is("t_order_algorithm"));
- assertTrue(tableRule.getDatabaseShardingStrategy() instanceof StandardShardingStrategyConfiguration);
+ assertThat(tableRule.getDatabaseShardingStrategy(), instanceOf(StandardShardingStrategyConfiguration.class));
assertThat(tableRule.getDatabaseShardingStrategy().getShardingAlgorithmName(), is("t_order_database_inline"));
assertThat(currentRuleConfig.getTables().size(), is(1));
ShardingAutoTableRuleConfiguration autoTableRule = currentRuleConfig.getAutoTables().iterator().next();
@@ -110,10 +103,7 @@ public final class AlterShardingTableRuleStatementUpdaterTest {
@Test
public void assertUpdateTableType() throws DistSQLException {
- Collection<AbstractTableRuleSegment> rules = new LinkedList<>();
- rules.add(createCompleteAutoTableRule("t_order"));
- rules.add(createCompleteTableRule("t_order_item"));
- AlterShardingTableRuleStatement statement = new AlterShardingTableRuleStatement(rules);
+ AlterShardingTableRuleStatement statement = new AlterShardingTableRuleStatement(Arrays.asList(createCompleteAutoTableRule("t_order"), createCompleteTableRule("t_order_item")));
updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig);
ShardingRuleConfiguration toBeAlteredRuleConfig = updater.buildToBeAlteredRuleConfiguration(statement);
updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeAlteredRuleConfig);
@@ -121,10 +111,10 @@ public final class AlterShardingTableRuleStatementUpdaterTest {
ShardingTableRuleConfiguration tableRule = currentRuleConfig.getTables().iterator().next();
assertThat(tableRule.getLogicTable(), is("t_order_item"));
assertThat(tableRule.getActualDataNodes(), is("ds_${0..1}.t_order${0..1}"));
- assertTrue(tableRule.getTableShardingStrategy() instanceof StandardShardingStrategyConfiguration);
+ assertThat(tableRule.getTableShardingStrategy(), instanceOf(StandardShardingStrategyConfiguration.class));
assertThat(((StandardShardingStrategyConfiguration) tableRule.getTableShardingStrategy()).getShardingColumn(), is("product_id"));
assertThat(tableRule.getTableShardingStrategy().getShardingAlgorithmName(), is("t_order_algorithm"));
- assertTrue(tableRule.getDatabaseShardingStrategy() instanceof StandardShardingStrategyConfiguration);
+ assertThat(tableRule.getDatabaseShardingStrategy(), instanceOf(StandardShardingStrategyConfiguration.class));
assertThat(tableRule.getDatabaseShardingStrategy().getShardingAlgorithmName(), is("t_order_item_database_inline"));
assertThat(currentRuleConfig.getTables().size(), is(1));
ShardingAutoTableRuleConfiguration autoTableRule = currentRuleConfig.getAutoTables().iterator().next();
@@ -140,28 +130,24 @@ public final class AlterShardingTableRuleStatementUpdaterTest {
AutoTableRuleSegment result = new AutoTableRuleSegment(logicTableName, Arrays.asList("ds_0", "ds_1"));
result.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("product_id", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties())));
result.setShardingColumn("order_id");
- result.setShardingAlgorithmSegment(new AlgorithmSegment("FOO.DISTSQL.FIXTURE", newProperties("", "")));
+ result.setShardingAlgorithmSegment(new AlgorithmSegment("FOO.DISTSQL.FIXTURE", createProperties("", "")));
return result;
}
private TableRuleSegment createCompleteTableRule(final String logicTableName) {
TableRuleSegment result = new TableRuleSegment(logicTableName, Collections.singletonList("ds_${0..1}.t_order${0..1}"));
result.setTableStrategySegment(new ShardingStrategySegment("standard", "product_id", "t_order_algorithm", null));
- AlgorithmSegment databaseAlgorithmSegment = getAutoCreativeAlgorithmSegment("inline", newProperties("algorithm-expression", "ds_${user_id% 2}"));
+ AlgorithmSegment databaseAlgorithmSegment = new AlgorithmSegment("inline", createProperties("algorithm-expression", "ds_${user_id% 2}"));
result.setDatabaseStrategySegment(new ShardingStrategySegment("standard", "product_id", null, databaseAlgorithmSegment));
result.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("product_id", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties())));
return result;
}
- private AlgorithmSegment getAutoCreativeAlgorithmSegment(final String name, final Properties props) {
- return new AlgorithmSegment(name, props);
- }
-
private ShardingRuleConfiguration createCurrentShardingRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getTables().add(createTableRuleConfiguration());
result.getAutoTables().add(createAutoTableRuleConfiguration());
- result.getShardingAlgorithms().put("t_order_algorithm", new ShardingSphereAlgorithmConfiguration("hash_mod", newProperties("sharding-count", "4")));
+ result.getShardingAlgorithms().put("t_order_algorithm", new ShardingSphereAlgorithmConfiguration("hash_mod", createProperties("sharding-count", "4")));
result.getKeyGenerators().put("t_order_item_snowflake", new ShardingSphereAlgorithmConfiguration("snowflake", new Properties()));
return result;
}
@@ -179,11 +165,7 @@ public final class AlterShardingTableRuleStatementUpdaterTest {
return result;
}
- private static Collection<ShardingSphereRule> createShardingSphereRule() {
- return Collections.emptyList();
- }
-
- private static Properties newProperties(final String key, final String value) {
+ private static Properties createProperties(final String key, final String value) {
Properties result = new Properties();
result.put(key, value);
return result;
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
index a0302adf025..42ce71df42e 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-handler/src/test/java/org/apache/shardingsphere/sharding/distsql/update/CreateShardingTableRuleStatementUpdaterTest.java
@@ -23,7 +23,6 @@ import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.infra.rule.identifier.type.DataSourceContainedRule;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
@@ -31,7 +30,6 @@ import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfi
import org.apache.shardingsphere.sharding.api.config.strategy.keygen.KeyGenerateStrategyConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.update.CreateShardingTableRuleStatementUpdater;
-import org.apache.shardingsphere.sharding.distsql.parser.segment.AbstractTableRuleSegment;
import org.apache.shardingsphere.sharding.distsql.parser.segment.AutoTableRuleSegment;
import org.apache.shardingsphere.sharding.distsql.parser.segment.KeyGenerateStrategySegment;
import org.apache.shardingsphere.sharding.distsql.parser.segment.ShardingStrategySegment;
@@ -44,17 +42,17 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import javax.sql.DataSource;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -78,33 +76,30 @@ public final class CreateShardingTableRuleStatementUpdaterTest {
when(shardingSphereMetaData.getDatabaseName()).thenReturn("schema");
when(shardingSphereMetaData.getResource()).thenReturn(shardingSphereResource);
when(shardingSphereMetaData.getRuleMetaData()).thenReturn(shardingSphereRuleMetaData);
- when(shardingSphereRuleMetaData.getRules()).thenReturn(createShardingSphereRule());
+ when(shardingSphereRuleMetaData.getRules()).thenReturn(Collections.singleton(new MockDataSourceContainedRule()));
}
@Test
public void assertUpdate() throws DistSQLException {
- Collection<AbstractTableRuleSegment> rules = new LinkedList<>();
- rules.add(createCompleteAutoTableRule());
- rules.add(createCompleteTableRule());
- CreateShardingTableRuleStatement statement = new CreateShardingTableRuleStatement(rules);
+ CreateShardingTableRuleStatement statement = new CreateShardingTableRuleStatement(Arrays.asList(createCompleteAutoTableRule(), createCompleteTableRule()));
updater.checkSQLStatement(shardingSphereMetaData, statement, currentRuleConfig);
ShardingRuleConfiguration toBeAlteredRuleConfig = updater.buildToBeCreatedRuleConfiguration(statement);
updater.updateCurrentRuleConfiguration(currentRuleConfig, toBeAlteredRuleConfig);
assertThat(currentRuleConfig.getTables().size(), is(2));
Iterator<ShardingTableRuleConfiguration> tableRuleIterator = currentRuleConfig.getTables().iterator();
ShardingTableRuleConfiguration tableRule = tableRuleIterator.next();
- assertTrue(tableRule.getTableShardingStrategy() instanceof StandardShardingStrategyConfiguration);
+ assertThat(tableRule.getTableShardingStrategy(), instanceOf(StandardShardingStrategyConfiguration.class));
assertThat(tableRule.getLogicTable(), is("t_order"));
assertThat(tableRule.getActualDataNodes(), is("ds_${0..1}.t_order_${0..1}"));
assertThat(((StandardShardingStrategyConfiguration) tableRule.getTableShardingStrategy()).getShardingColumn(), is("order_id"));
assertThat(tableRule.getTableShardingStrategy().getShardingAlgorithmName(), is("t_order_algorithm"));
tableRule = tableRuleIterator.next();
- assertTrue(tableRule.getTableShardingStrategy() instanceof StandardShardingStrategyConfiguration);
+ assertThat(tableRule.getTableShardingStrategy(), instanceOf(StandardShardingStrategyConfiguration.class));
assertThat(tableRule.getLogicTable(), is("t_order_input"));
assertThat(tableRule.getActualDataNodes(), is("ds_${0..1}.t_order_${0..1}"));
assertThat(((StandardShardingStrategyConfiguration) tableRule.getTableShardingStrategy()).getShardingColumn(), is("product_id"));
assertThat(tableRule.getTableShardingStrategy().getShardingAlgorithmName(), is("t_order_algorithm"));
- assertTrue(tableRule.getDatabaseShardingStrategy() instanceof StandardShardingStrategyConfiguration);
+ assertThat(tableRule.getDatabaseShardingStrategy(), instanceOf(StandardShardingStrategyConfiguration.class));
assertThat(tableRule.getDatabaseShardingStrategy().getShardingAlgorithmName(), is("t_order_input_database_inline"));
assertThat(currentRuleConfig.getTables().size(), is(2));
Iterator<ShardingAutoTableRuleConfiguration> autoTableIterator = currentRuleConfig.getAutoTables().iterator();
@@ -128,28 +123,24 @@ public final class CreateShardingTableRuleStatementUpdaterTest {
AutoTableRuleSegment result = new AutoTableRuleSegment("t_order_item_input", Collections.singletonList("logic_ds"));
result.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("product_id", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties())));
result.setShardingColumn("order_id");
- result.setShardingAlgorithmSegment(new AlgorithmSegment("FOO.DISTSQL.FIXTURE", newProperties("", "")));
+ result.setShardingAlgorithmSegment(new AlgorithmSegment("FOO.DISTSQL.FIXTURE", createProperties("", "")));
return result;
}
private TableRuleSegment createCompleteTableRule() {
TableRuleSegment result = new TableRuleSegment("t_order_input", Collections.singletonList("ds_${0..1}.t_order_${0..1}"));
result.setTableStrategySegment(new ShardingStrategySegment("standard", "product_id", "t_order_algorithm", null));
- AlgorithmSegment databaseAlgorithmSegment = getAutoCreativeAlgorithmSegment("inline", newProperties("algorithm-expression", "ds_${user_id% 2}"));
+ AlgorithmSegment databaseAlgorithmSegment = new AlgorithmSegment("inline", createProperties("algorithm-expression", "ds_${user_id% 2}"));
result.setDatabaseStrategySegment(new ShardingStrategySegment("standard", "product_id", null, databaseAlgorithmSegment));
result.setKeyGenerateStrategySegment(new KeyGenerateStrategySegment("product_id", new AlgorithmSegment("DISTSQL.FIXTURE", new Properties())));
return result;
}
- private AlgorithmSegment getAutoCreativeAlgorithmSegment(final String name, final Properties props) {
- return new AlgorithmSegment(name, props);
- }
-
private ShardingRuleConfiguration createCurrentShardingRuleConfiguration() {
ShardingRuleConfiguration result = new ShardingRuleConfiguration();
result.getTables().add(createTableRuleConfiguration());
result.getAutoTables().add(createAutoTableRuleConfiguration());
- result.getShardingAlgorithms().put("t_order_algorithm", new ShardingSphereAlgorithmConfiguration("hash_mod", newProperties("sharding-count", "4")));
+ result.getShardingAlgorithms().put("t_order_algorithm", new ShardingSphereAlgorithmConfiguration("hash_mod", createProperties("sharding-count", "4")));
result.getKeyGenerators().put("t_order_item_snowflake", new ShardingSphereAlgorithmConfiguration("snowflake", new Properties()));
return result;
}
@@ -167,19 +158,13 @@ public final class CreateShardingTableRuleStatementUpdaterTest {
return result;
}
- private static Collection<ShardingSphereRule> createShardingSphereRule() {
- Collection<ShardingSphereRule> result = new LinkedList<>();
- result.add(new MockDataSourceContainedRule());
- return result;
- }
-
- private static Properties newProperties(final String key, final String value) {
+ private Properties createProperties(final String key, final String value) {
Properties result = new Properties();
result.put(key, value);
return result;
}
- private static Map<String, DataSource> createDataSource() {
+ private Map<String, DataSource> createDataSource() {
Map<String, DataSource> result = new HashMap<>(2, 1);
result.put("ds_0", mock(DataSource.class));
result.put("ds_1", mock(DataSource.class));
@@ -189,15 +174,13 @@ public final class CreateShardingTableRuleStatementUpdaterTest {
private static class MockDataSourceContainedRule implements DataSourceContainedRule {
@Override
- public String getType() {
- return "mock";
+ public Map<String, Collection<String>> getDataSourceMapper() {
+ return Collections.singletonMap("logic_ds", null);
}
@Override
- public Map<String, Collection<String>> getDataSourceMapper() {
- Map<String, Collection<String>> result = new HashMap<>(1, 1);
- result.put("logic_ds", null);
- return result;
+ public String getType() {
+ return "mock";
}
}
}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/test/java/org/apache/shardingsphere/sharding/spring/namespace/ShardingSpringNamespaceTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/test/java/org/apache/shardingsphere/sharding/spring/namespace/ShardingSpringNamespaceTest.java
index 3e4c7551a81..6776f8d1412 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/test/java/org/apache/shardingsphere/sharding/spring/namespace/ShardingSpringNamespaceTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-spring/shardingsphere-sharding-spring-namespace/src/test/java/org/apache/shardingsphere/sharding/spring/namespace/ShardingSpringNamespaceTest.java
@@ -39,6 +39,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -250,7 +251,7 @@ public final class ShardingSpringNamespaceTest extends AbstractJUnit4SpringConte
@Test
public void assertShardingRule() {
assertThat(shardingRule.getDefaultShardingColumn(), is("order_id"));
- assertTrue(shardingRule.getDefaultDatabaseShardingStrategy() instanceof StandardShardingStrategyConfiguration);
+ assertThat(shardingRule.getDefaultDatabaseShardingStrategy(), instanceOf(StandardShardingStrategyConfiguration.class));
assertNull(((StandardShardingStrategyConfiguration) shardingRule.getDefaultDatabaseShardingStrategy()).getShardingColumn());
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/engine/RowNumberPaginationContextEngineTest.java b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/engine/RowNumberPaginationContextEngineTest.java
index 687092e924a..154e029893a 100644
--- a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/engine/RowNumberPaginationContextEngineTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/segment/select/pagination/engine/RowNumberPaginationContextEngineTest.java
@@ -123,7 +123,7 @@ public final class RowNumberPaginationContextEngineTest {
Optional<PaginationValueSegment> paginationValueSegmentOptional = paginationContext.getRowCountSegment();
assertTrue(paginationValueSegmentOptional.isPresent());
PaginationValueSegment paginationValueSegment = paginationValueSegmentOptional.get();
- assertTrue(paginationValueSegment instanceof NumberLiteralRowNumberValueSegment);
+ assertThat(paginationValueSegment, instanceOf(NumberLiteralRowNumberValueSegment.class));
NumberLiteralRowNumberValueSegment numberLiteralRowNumberValueSegment = (NumberLiteralRowNumberValueSegment) paginationValueSegment;
assertThat(numberLiteralRowNumberValueSegment.getStartIndex(), is(0));
assertThat(numberLiteralRowNumberValueSegment.getStopIndex(), is(10));
@@ -145,7 +145,6 @@ public final class RowNumberPaginationContextEngineTest {
assertThat(actualPaginationValueSegment.getStartIndex(), is(0));
assertThat(actualPaginationValueSegment.getStopIndex(), is(10));
assertThat(((NumberLiteralRowNumberValueSegment) actualPaginationValueSegment).getValue(), is(100L));
- Optional<PaginationValueSegment> rowCountSegment = rowNumberPaginationContextEngine.getRowCountSegment();
- assertFalse(rowCountSegment.isPresent());
+ assertFalse(rowNumberPaginationContextEngine.getRowCountSegment().isPresent());
}
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/checker/RuleConfigurationCheckerFactoryTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/checker/RuleConfigurationCheckerFactoryTest.java
index b5294764b0c..43089cceaba 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/checker/RuleConfigurationCheckerFactoryTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/config/checker/RuleConfigurationCheckerFactoryTest.java
@@ -23,7 +23,9 @@ import org.junit.Test;
import java.util.Optional;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public final class RuleConfigurationCheckerFactoryTest {
@@ -33,7 +35,7 @@ public final class RuleConfigurationCheckerFactoryTest {
public void assertFindInstance() {
Optional<RuleConfigurationChecker> checker = RuleConfigurationCheckerFactory.findInstance(new TestRuleConfiguration());
assertTrue(checker.isPresent());
- assertTrue(checker.get() instanceof RuleConfigurationCheckerFixture);
+ assertThat(checker.get(), instanceOf(RuleConfigurationCheckerFixture.class));
}
@SuppressWarnings("rawtypes")
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/loader/spi/DialectSchemaMetaDataLoaderFactoryTest.java b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/loader/spi/DialectSchemaMetaDataLoaderFactoryTest.java
index 7564134a6ec..4b05d97fee0 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/loader/spi/DialectSchemaMetaDataLoaderFactoryTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/metadata/schema/loader/spi/DialectSchemaMetaDataLoaderFactoryTest.java
@@ -23,6 +23,8 @@ import org.junit.Test;
import java.util.Optional;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public final class DialectSchemaMetaDataLoaderFactoryTest {
@@ -31,6 +33,6 @@ public final class DialectSchemaMetaDataLoaderFactoryTest {
public void assertFindInstance() {
Optional<DialectSchemaMetaDataLoader> actual = DialectSchemaMetaDataLoaderFactory.findInstance(new H2DatabaseType());
assertTrue(actual.isPresent());
- assertTrue(actual.get() instanceof H2SchemaMetaDataLoader);
+ assertThat(actual.get(), instanceOf(H2SchemaMetaDataLoader.class));
}
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/state/circuit/connection/CircuitBreakerConnectionTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/state/circuit/connection/CircuitBreakerConnectionTest.java
index f35c77dbea5..7dd8e43c8df 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/state/circuit/connection/CircuitBreakerConnectionTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/state/circuit/connection/CircuitBreakerConnectionTest.java
@@ -26,11 +26,11 @@ import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
public final class CircuitBreakerConnectionTest {
@@ -38,7 +38,7 @@ public final class CircuitBreakerConnectionTest {
@Test
public void assertGetMetaData() {
- assertTrue(connection.getMetaData() instanceof CircuitBreakerDatabaseMetaData);
+ assertThat(connection.getMetaData(), instanceOf(CircuitBreakerDatabaseMetaData.class));
}
@Test
@@ -108,19 +108,19 @@ public final class CircuitBreakerConnectionTest {
@Test
public void assertPrepareStatement() {
String sql = "SELECT 1";
- assertTrue(connection.prepareStatement(sql) instanceof CircuitBreakerPreparedStatement);
- assertTrue(connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) instanceof CircuitBreakerPreparedStatement);
- assertTrue(connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT) instanceof CircuitBreakerPreparedStatement);
- assertTrue(connection.prepareStatement(sql, Statement.NO_GENERATED_KEYS) instanceof CircuitBreakerPreparedStatement);
- assertTrue(connection.prepareStatement(sql, new int[]{0}) instanceof CircuitBreakerPreparedStatement);
- assertTrue(connection.prepareStatement(sql, new String[]{""}) instanceof CircuitBreakerPreparedStatement);
+ assertThat(connection.prepareStatement(sql), instanceOf(CircuitBreakerPreparedStatement.class));
+ assertThat(connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY), instanceOf(CircuitBreakerPreparedStatement.class));
+ assertThat(connection.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT), instanceOf(CircuitBreakerPreparedStatement.class));
+ assertThat(connection.prepareStatement(sql, Statement.NO_GENERATED_KEYS), instanceOf(CircuitBreakerPreparedStatement.class));
+ assertThat(connection.prepareStatement(sql, new int[]{0}), instanceOf(CircuitBreakerPreparedStatement.class));
+ assertThat(connection.prepareStatement(sql, new String[]{""}), instanceOf(CircuitBreakerPreparedStatement.class));
}
@Test
public void assertCreateStatement() {
- assertTrue(connection.createStatement() instanceof CircuitBreakerStatement);
- assertTrue(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) instanceof CircuitBreakerStatement);
- assertTrue(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT) instanceof CircuitBreakerStatement);
+ assertThat(connection.createStatement(), instanceOf(CircuitBreakerStatement.class));
+ assertThat(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY), instanceOf(CircuitBreakerStatement.class));
+ assertThat(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT), instanceOf(CircuitBreakerStatement.class));
}
@Test
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/state/circuit/datasource/CircuitBreakerDataSourceTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/state/circuit/datasource/CircuitBreakerDataSourceTest.java
index 98127cb0f0d..487c7c73dd4 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/state/circuit/datasource/CircuitBreakerDataSourceTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/state/circuit/datasource/CircuitBreakerDataSourceTest.java
@@ -20,9 +20,9 @@ package org.apache.shardingsphere.driver.state.circuit.datasource;
import org.apache.shardingsphere.driver.state.circuit.connection.CircuitBreakerConnection;
import org.junit.Test;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
public final class CircuitBreakerDataSourceTest {
@@ -35,8 +35,8 @@ public final class CircuitBreakerDataSourceTest {
@Test
public void assertGetConnection() {
- assertTrue(dataSource.getConnection() instanceof CircuitBreakerConnection);
- assertTrue(dataSource.getConnection("", "") instanceof CircuitBreakerConnection);
+ assertThat(dataSource.getConnection(), instanceOf(CircuitBreakerConnection.class));
+ assertThat(dataSource.getConnection("", ""), instanceOf(CircuitBreakerConnection.class));
}
@Test
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/scaling/core/spi/ScalingEntryFactoryTest.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/scaling/core/spi/ScalingEntryFactoryTest.java
index 2aceedfe2c2..0c3fcb5e8ae 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/scaling/core/spi/ScalingEntryFactoryTest.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/test/java/org/apache/shardingsphere/scaling/core/spi/ScalingEntryFactoryTest.java
@@ -20,12 +20,13 @@ package org.apache.shardingsphere.scaling.core.spi;
import org.apache.shardingsphere.scaling.core.spi.fixture.ScalingEntryFixture;
import org.junit.Test;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
public final class ScalingEntryFactoryTest {
@Test
public void assertGetInstance() {
- assertTrue(ScalingEntryFactory.getInstance("FIXTURE") instanceof ScalingEntryFixture);
+ assertThat(ScalingEntryFactory.getInstance("FIXTURE"), instanceOf(ScalingEntryFixture.class));
}
}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumperTest.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumperTest.java
index acf6cdd1406..0706d8281f0 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumperTest.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumperTest.java
@@ -50,9 +50,9 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
public final class MySQLIncrementalDumperTest {
@@ -107,7 +107,7 @@ public final class MySQLIncrementalDumperTest {
invokeHandleEvent(rowsEvent);
List<Record> records = channel.fetchRecords(1, 0);
assertThat(records.size(), is(1));
- assertTrue(records.get(0) instanceof DataRecord);
+ assertThat(records.get(0), instanceOf(DataRecord.class));
assertThat(((DataRecord) records.get(0)).getType(), is(IngestDataChangeType.INSERT));
}
@@ -125,7 +125,7 @@ public final class MySQLIncrementalDumperTest {
invokeHandleEvent(rowsEvent);
List<Record> records = channel.fetchRecords(1, 0);
assertThat(records.size(), is(1));
- assertTrue(records.get(0) instanceof DataRecord);
+ assertThat(records.get(0), instanceOf(DataRecord.class));
assertThat(((DataRecord) records.get(0)).getType(), is(IngestDataChangeType.UPDATE));
}
@@ -140,7 +140,7 @@ public final class MySQLIncrementalDumperTest {
invokeHandleEvent(rowsEvent);
List<Record> records = channel.fetchRecords(1, 0);
assertThat(records.size(), is(1));
- assertTrue(records.get(0) instanceof DataRecord);
+ assertThat(records.get(0), instanceOf(DataRecord.class));
assertThat(((DataRecord) records.get(0)).getType(), is(IngestDataChangeType.DELETE));
}
@@ -149,7 +149,7 @@ public final class MySQLIncrementalDumperTest {
invokeHandleEvent(new PlaceholderEvent());
List<Record> records = channel.fetchRecords(1, 0);
assertThat(records.size(), is(1));
- assertTrue(records.get(0) instanceof PlaceholderRecord);
+ assertThat(records.get(0), instanceOf(PlaceholderRecord.class));
}
@Test
@@ -159,7 +159,7 @@ public final class MySQLIncrementalDumperTest {
invokeHandleEvent(rowsEvent);
List<Record> records = channel.fetchRecords(1, 0);
assertThat(records.size(), is(1));
- assertTrue(records.get(0) instanceof PlaceholderRecord);
+ assertThat(records.get(0), instanceOf(PlaceholderRecord.class));
}
@SneakyThrows({NoSuchMethodException.class, ReflectiveOperationException.class})
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/column/value/MySQLDataTypeHandlerFactoryTest.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/column/value/MySQLDataTypeHandlerFactoryTest.java
index 5964f2f5620..43f8d5230db 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/column/value/MySQLDataTypeHandlerFactoryTest.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/column/value/MySQLDataTypeHandlerFactoryTest.java
@@ -27,6 +27,8 @@ import org.junit.Test;
import java.util.Optional;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public final class MySQLDataTypeHandlerFactoryTest {
@@ -35,34 +37,34 @@ public final class MySQLDataTypeHandlerFactoryTest {
public void assertFindInstanceWithMySQLUnsignedTinyintHandler() {
Optional<MySQLDataTypeHandler> actual = MySQLDataTypeHandlerFactory.findInstance("TINYINT UNSIGNED");
assertTrue(actual.isPresent());
- assertTrue(actual.get() instanceof MySQLUnsignedTinyintHandler);
+ assertThat(actual.get(), instanceOf(MySQLUnsignedTinyintHandler.class));
}
@Test
public void assertFindInstanceWithMySQLUnsignedSmallintHandler() {
Optional<MySQLDataTypeHandler> actual = MySQLDataTypeHandlerFactory.findInstance("SMALLINT UNSIGNED");
assertTrue(actual.isPresent());
- assertTrue(actual.get() instanceof MySQLUnsignedSmallintHandler);
+ assertThat(actual.get(), instanceOf(MySQLUnsignedSmallintHandler.class));
}
@Test
public void assertFindInstanceWithMySQLUnsignedMediumintHandler() {
Optional<MySQLDataTypeHandler> actual = MySQLDataTypeHandlerFactory.findInstance("MEDIUMINT UNSIGNED");
assertTrue(actual.isPresent());
- assertTrue(actual.get() instanceof MySQLUnsignedMediumintHandler);
+ assertThat(actual.get(), instanceOf(MySQLUnsignedMediumintHandler.class));
}
@Test
public void assertFindInstanceWithMySQLUnsignedIntHandler() {
Optional<MySQLDataTypeHandler> actual = MySQLDataTypeHandlerFactory.findInstance("INT UNSIGNED");
assertTrue(actual.isPresent());
- assertTrue(actual.get() instanceof MySQLUnsignedIntHandler);
+ assertThat(actual.get(), instanceOf(MySQLUnsignedIntHandler.class));
}
@Test
public void assertFindInstanceWithMySQLUnsignedBigintHandler() {
Optional<MySQLDataTypeHandler> actual = MySQLDataTypeHandlerFactory.findInstance("BIGINT UNSIGNED");
assertTrue(actual.isPresent());
- assertTrue(actual.get() instanceof MySQLUnsignedBigintHandler);
+ assertThat(actual.get(), instanceOf(MySQLUnsignedBigintHandler.class));
}
}
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-opengauss/src/test/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/wal/decode/MppdbDecodingPluginTest.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-opengauss/src/test/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/wal/decode/MppdbDecodingPluginTest.java
index 5b426c24829..9c9ff6eb686 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-opengauss/src/test/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/wal/decode/MppdbDecodingPluginTest.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-opengauss/src/test/java/org/apache/shardingsphere/data/pipeline/opengauss/ingest/wal/decode/MppdbDecodingPluginTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.data.pipeline.opengauss.ingest.wal.decode;
import com.google.gson.Gson;
-import lombok.SneakyThrows;
import org.apache.shardingsphere.data.pipeline.core.ingest.exception.IngestException;
import org.apache.shardingsphere.data.pipeline.postgresql.ingest.wal.decode.DecodingException;
import org.apache.shardingsphere.data.pipeline.postgresql.ingest.wal.event.DeleteRowEvent;
@@ -36,9 +35,9 @@ import java.sql.Time;
import java.sql.Timestamp;
import java.util.stream.IntStream;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -129,8 +128,7 @@ public final class MppdbDecodingPluginTest {
}
@Test
- @SneakyThrows(SQLException.class)
- public void assertDecodeWriteRowEventWithDateAndTime() {
+ public void assertDecodeWriteRowEventWithDateAndTime() throws SQLException {
MppTableData tableData = new MppTableData();
tableData.setTableName("public.test");
tableData.setOpType("INSERT");
@@ -168,7 +166,7 @@ public final class MppdbDecodingPluginTest {
assertThat(actual.getLogSequenceNumber(), is(logSequenceNumber));
assertThat(actual.getTableName(), is("test"));
Object byteaObj = actual.getAfterRow().get(0);
- assertTrue(byteaObj instanceof PGobject);
+ assertThat(byteaObj, instanceOf(PGobject.class));
assertThat(byteaObj.toString(), is(new String(new byte[]{(byte) 0xff, (byte) 0, (byte) 0xab})));
}
@@ -185,14 +183,14 @@ public final class MppdbDecodingPluginTest {
assertThat(actual.getLogSequenceNumber(), is(logSequenceNumber));
assertThat(actual.getTableName(), is("test"));
Object byteaObj = actual.getAfterRow().get(0);
- assertTrue(byteaObj instanceof PGobject);
+ assertThat(byteaObj, instanceOf(PGobject.class));
assertThat(byteaObj.toString(), is("7D"));
}
@Test
public void assertDecodeUnknownTableType() {
ByteBuffer data = ByteBuffer.wrap("unknown".getBytes());
- assertTrue(new MppdbDecodingPlugin(null).decode(data, logSequenceNumber) instanceof PlaceholderEvent);
+ assertThat(new MppdbDecodingPlugin(null).decode(data, logSequenceNumber), instanceOf(PlaceholderEvent.class));
}
@Test(expected = IngestException.class)
@@ -208,8 +206,7 @@ public final class MppdbDecodingPluginTest {
}
@Test(expected = DecodingException.class)
- @SneakyThrows(SQLException.class)
- public void assertDecodeTime() {
+ public void assertDecodeTime() throws SQLException {
MppTableData tableData = new MppTableData();
tableData.setTableName("public.test");
tableData.setOpType("INSERT");
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/WalEventConverterTest.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/WalEventConverterTest.java
index 4d1eb4d44dc..d0f7b954a82 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/WalEventConverterTest.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/WalEventConverterTest.java
@@ -45,9 +45,9 @@ import java.sql.Statement;
import java.util.Arrays;
import java.util.Collections;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
public final class WalEventConverterTest {
@@ -90,34 +90,34 @@ public final class WalEventConverterTest {
@Test
public void assertConvertWriteRowEvent() {
Record record = walEventConverter.convert(mockWriteRowEvent());
- assertTrue(record instanceof DataRecord);
+ assertThat(record, instanceOf(DataRecord.class));
assertThat(((DataRecord) record).getType(), is(IngestDataChangeType.INSERT));
}
@Test
public void assertConvertUpdateRowEvent() {
Record record = walEventConverter.convert(mockUpdateRowEvent());
- assertTrue(record instanceof DataRecord);
+ assertThat(record, instanceOf(DataRecord.class));
assertThat(((DataRecord) record).getType(), is(IngestDataChangeType.UPDATE));
}
@Test
public void assertConvertDeleteRowEvent() {
Record record = walEventConverter.convert(mockDeleteRowEvent());
- assertTrue(record instanceof DataRecord);
+ assertThat(record, instanceOf(DataRecord.class));
assertThat(((DataRecord) record).getType(), is(IngestDataChangeType.DELETE));
}
@Test
public void assertConvertPlaceholderEvent() {
Record record = walEventConverter.convert(new PlaceholderEvent());
- assertTrue(record instanceof PlaceholderRecord);
+ assertThat(record, instanceOf(PlaceholderRecord.class));
}
@Test
public void assertUnknownTable() {
Record record = walEventConverter.convert(mockUnknownTableEvent());
- assertTrue(record instanceof PlaceholderRecord);
+ assertThat(record, instanceOf(PlaceholderRecord.class));
}
@Test(expected = UnsupportedOperationException.class)
diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPluginTest.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPluginTest.java
index fc7cf8a925b..47c352be308 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPluginTest.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-dialect/shardingsphere-data-pipeline-postgresql/src/test/java/org/apache/shardingsphere/data/pipeline/postgresql/ingest/wal/decode/TestDecodingPluginTest.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.data.pipeline.postgresql.ingest.wal.decode;
import lombok.SneakyThrows;
import org.apache.shardingsphere.data.pipeline.core.ingest.exception.IngestException;
-import org.apache.shardingsphere.data.pipeline.postgresql.ingest.wal.event.AbstractWalEvent;
import org.apache.shardingsphere.data.pipeline.postgresql.ingest.wal.event.DeleteRowEvent;
import org.apache.shardingsphere.data.pipeline.postgresql.ingest.wal.event.PlaceholderEvent;
import org.apache.shardingsphere.data.pipeline.postgresql.ingest.wal.event.UpdateRowEvent;
@@ -31,9 +30,9 @@ import org.postgresql.replication.LogSequenceNumber;
import java.nio.ByteBuffer;
import java.sql.SQLException;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -82,8 +81,7 @@ public final class TestDecodingPluginTest {
@Test
public void assertDecodeUnknownTableType() {
ByteBuffer data = ByteBuffer.wrap("unknown".getBytes());
- AbstractWalEvent actual = new TestDecodingPlugin(null).decode(data, logSequenceNumber);
- assertTrue(actual instanceof PlaceholderEvent);
+ assertThat(new TestDecodingPlugin(null).decode(data, logSequenceNumber), instanceOf(PlaceholderEvent.class));
}
@Test(expected = IngestException.class)
diff --git a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java
index f2375c6135e..eb88846db62 100644
--- a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java
+++ b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.transaction.core;
import org.apache.shardingsphere.test.mock.MockedDataSource;
import org.junit.Test;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -30,7 +31,7 @@ public final class ResourceDataSourceTest {
public void assertNewInstance() {
ResourceDataSource actual = new ResourceDataSource("fooDataSource", new MockedDataSource());
assertThat(actual.getOriginalName(), is("fooDataSource"));
- assertTrue(actual.getDataSource() instanceof MockedDataSource);
+ assertThat(actual.getDataSource(), instanceOf(MockedDataSource.class));
assertTrue(actual.getUniqueResourceName().startsWith("resource"));
assertTrue(actual.getUniqueResourceName().endsWith("fooDataSource"));
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContextTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContextTest.java
index 10386e6e30c..041e16a0e52 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContextTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/lock/DistributeLockContextTest.java
@@ -23,13 +23,13 @@ import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.instance.definition.InstanceDefinition;
import org.apache.shardingsphere.infra.instance.definition.InstanceType;
import org.apache.shardingsphere.infra.instance.workerid.WorkerIdGenerator;
-import org.apache.shardingsphere.infra.lock.ShardingSphereLock;
import org.apache.shardingsphere.mode.manager.cluster.coordinator.lock.global.general.ShardingSphereGeneralLock;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import org.junit.Test;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
public final class DistributeLockContextTest {
@@ -38,18 +38,15 @@ public final class DistributeLockContextTest {
public void assertTryLockWriteDatabase() {
ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
DistributeLockContext distributeLockContext = new DistributeLockContext(mock(ClusterPersistRepository.class), currentInstance);
- InstanceContext instanceContext = new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributeLockContext);
- instanceContext.initLockContext();
- ShardingSphereLock databaseLock = distributeLockContext.getGlobalLock("database");
- assertNotNull(databaseLock);
+ new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributeLockContext).initLockContext();
+ assertNotNull(distributeLockContext.getGlobalLock("database"));
}
@Test
public void assertReleaseLockWriteDatabase() {
ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
DistributeLockContext distributeLockContext = new DistributeLockContext(mock(ClusterPersistRepository.class), currentInstance);
- InstanceContext instanceContext = new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributeLockContext);
- instanceContext.initLockContext();
+ new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributeLockContext).initLockContext();
distributeLockContext.releaseLockWriteDatabase("database");
}
@@ -57,8 +54,7 @@ public final class DistributeLockContextTest {
public void assertIsLockedDatabase() {
ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
DistributeLockContext distributeLockContext = new DistributeLockContext(mock(ClusterPersistRepository.class), currentInstance);
- InstanceContext instanceContext = new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributeLockContext);
- instanceContext.initLockContext();
+ new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributeLockContext).initLockContext();
distributeLockContext.isLockedDatabase("database");
}
@@ -66,20 +62,16 @@ public final class DistributeLockContextTest {
public void assertGetOrCreateGlobalLock() {
DistributeLockContext distributeLockContext = new DistributeLockContext(mock(ClusterPersistRepository.class), mock(ComputeNodeInstance.class));
ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
- InstanceContext instanceContext = new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributeLockContext);
- instanceContext.initLockContext();
- ShardingSphereLock databaseLock = distributeLockContext.getGlobalLock("database");
- assertNotNull(databaseLock);
+ new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributeLockContext).initLockContext();
+ assertNotNull(distributeLockContext.getGlobalLock("database"));
}
@Test
public void assertGetGlobalLock() {
DistributeLockContext distributeLockContext = new DistributeLockContext(mock(ClusterPersistRepository.class), mock(ComputeNodeInstance.class));
ComputeNodeInstance currentInstance = new ComputeNodeInstance(new InstanceDefinition(InstanceType.PROXY, "127.0.0.1@3307"));
- InstanceContext instanceContext = new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributeLockContext);
- instanceContext.initLockContext();
+ new InstanceContext(currentInstance, mock(WorkerIdGenerator.class), mock(ModeConfiguration.class), distributeLockContext).initLockContext();
distributeLockContext.getGlobalLock("database");
- ShardingSphereLock databaseLock = distributeLockContext.getGlobalLock("database");
- assertTrue(databaseLock instanceof ShardingSphereGeneralLock);
+ assertThat(distributeLockContext.getGlobalLock("database"), instanceOf(ShardingSphereGeneralLock.class));
}
}
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/handler/CuratorZookeeperExceptionHandlerTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mo [...]
index 5308b994ddf..18be18a5d86 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/handler/CuratorZookeeperExceptionHandlerTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-repository/shardingsphere-cluster-mode-repository-provider/shardingsphere-cluster-mode-repository-zookeeper-curator/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/handler/CuratorZookeeperExceptionHandlerTest.java
@@ -21,7 +21,8 @@ import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositor
import org.apache.zookeeper.KeeperException.NoNodeException;
import org.junit.Test;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
public final class CuratorZookeeperExceptionHandlerTest {
@@ -37,7 +38,7 @@ public final class CuratorZookeeperExceptionHandlerTest {
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
- assertTrue(ex instanceof ClusterPersistRepositoryException);
+ assertThat(ex, instanceOf(ClusterPersistRepositoryException.class));
}
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderFactoryTest.java
index 0b0128f735d..a9d89b761ba 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/response/header/query/QueryHeaderBuilderFactoryTest.java
@@ -23,17 +23,18 @@ import org.apache.shardingsphere.proxy.backend.response.header.query.impl.MySQLQ
import org.apache.shardingsphere.proxy.backend.response.header.query.impl.PostgreSQLQueryHeaderBuilder;
import org.junit.Test;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
public final class QueryHeaderBuilderFactoryTest {
@Test
public void assertGetInstance() {
- assertTrue(QueryHeaderBuilderFactory.getInstance(new PostgreSQLDatabaseType()) instanceof PostgreSQLQueryHeaderBuilder);
+ assertThat(QueryHeaderBuilderFactory.getInstance(new PostgreSQLDatabaseType()), instanceOf(PostgreSQLQueryHeaderBuilder.class));
}
@Test
public void assertGetInstanceWithUnsupportedDatabaseType() {
- assertTrue(QueryHeaderBuilderFactory.getInstance(new OracleDatabaseType()) instanceof MySQLQueryHeaderBuilder);
+ assertThat(QueryHeaderBuilderFactory.getInstance(new OracleDatabaseType()), instanceOf(MySQLQueryHeaderBuilder.class));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/opengauss/OpenGaussAdminExecutorFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/opengauss/OpenGaussAdminExecutorFactoryTest.java
index 0fa90f7e2d6..ff3aa62f08a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/opengauss/OpenGaussAdminExecutorFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/opengauss/OpenGaussAdminExecutorFactoryTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.proxy.backend.text.admin.opengauss;
-import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.proxy.backend.text.admin.executor.DatabaseAdminExecutor;
import org.apache.shardingsphere.proxy.backend.text.admin.postgresql.PostgreSQLAdminExecutorCreator;
@@ -31,6 +30,7 @@ import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Optional;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -47,8 +47,7 @@ public final class OpenGaussAdminExecutorFactoryTest {
private OpenGaussAdminExecutorCreator openGaussAdminExecutorFactory;
@Before
- @SneakyThrows
- public void setup() {
+ public void setup() throws IllegalAccessException, NoSuchFieldException {
Field field = OpenGaussAdminExecutorCreator.class.getDeclaredField("delegated");
field.setAccessible(true);
openGaussAdminExecutorFactory = new OpenGaussAdminExecutorCreator();
@@ -71,7 +70,7 @@ public final class OpenGaussAdminExecutorFactoryTest {
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singletonList("pg_database"));
Optional<DatabaseAdminExecutor> actual = openGaussAdminExecutorFactory.create(sqlStatementContext, "select datcompatibility from pg_database where datname = 'sharding_db'", "");
assertTrue(actual.isPresent());
- assertTrue(actual.get() instanceof OpenGaussSelectDatabaseExecutor);
+ assertThat(actual.get(), instanceOf(OpenGaussSelectDatabaseExecutor.class));
}
@Test
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorFactoryTest.java
index c273e619af6..d14d61fb09a 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorFactoryTest.java
@@ -78,7 +78,7 @@ public final class PostgreSQLAdminExecutorFactoryTest {
CommonSQLStatementContext<SetStatement> statementContext = new CommonSQLStatementContext<>(setStatement);
Optional<DatabaseAdminExecutor> actual = postgreSQLAdminExecutorFactory.create(statementContext, null, null);
assertTrue(actual.isPresent());
- assertTrue(actual.get() instanceof PostgreSQLSetCharsetExecutor);
+ assertThat(actual.get(), instanceOf(PostgreSQLSetCharsetExecutor.class));
}
@Test
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandlerTest.java
index 4e6d2a1abb8..a69a62b9274 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandlerTest.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.exception.DBCreateExistsException;
-import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateDatabaseStatement;
import org.junit.Before;
@@ -33,7 +32,8 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.Collections;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -60,16 +60,14 @@ public final class CreateDatabaseBackendHandlerTest {
@Test
public void assertExecuteCreateNewDatabase() {
when(statement.getDatabaseName()).thenReturn("other_db");
- ResponseHeader responseHeader = handler.execute();
- assertTrue(responseHeader instanceof UpdateResponseHeader);
+ assertThat(handler.execute(), instanceOf(UpdateResponseHeader.class));
}
@SneakyThrows
@Test(expected = DBCreateExistsException.class)
public void assertExecuteCreateExistDatabase() {
when(statement.getDatabaseName()).thenReturn("test_db");
- ResponseHeader responseHeader = handler.execute();
- assertTrue(responseHeader instanceof UpdateResponseHeader);
+ assertThat(handler.execute(), instanceOf(UpdateResponseHeader.class));
}
@SneakyThrows
@@ -77,7 +75,6 @@ public final class CreateDatabaseBackendHandlerTest {
public void assertExecuteCreateExistDatabaseWithIfNotExists() {
when(statement.getDatabaseName()).thenReturn("test_db");
when(statement.isContainsNotExistClause()).thenReturn(true);
- ResponseHeader responseHeader = handler.execute();
- assertTrue(responseHeader instanceof UpdateResponseHeader);
+ assertThat(handler.execute(), instanceOf(UpdateResponseHeader.class));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportDatabaseConfigurationHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportDatabaseConfigurationHandlerTest.java
index 7d29eee5837..ee4d3b188f3 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportDatabaseConfigurationHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/updatable/ImportDatabaseConfigurationHandlerTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.updatable;
import org.apache.shardingsphere.distsql.parser.statement.ral.common.updatable.ImportDatabaseConfigurationStatement;
-import org.apache.shardingsphere.infra.config.RuleConfiguration;
import org.apache.shardingsphere.infra.database.DefaultDatabase;
import org.apache.shardingsphere.infra.datasource.props.DataSourcePropertiesValidator;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -28,7 +27,6 @@ import org.apache.shardingsphere.infra.metadata.schema.model.IndexMetaData;
import org.apache.shardingsphere.infra.metadata.schema.model.TableMetaData;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.distsql.ral.RALBackendHandler;
@@ -51,8 +49,9 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -86,7 +85,7 @@ public final class ImportDatabaseConfigurationHandlerTest {
private ImportDatabaseConfigurationHandler importDatabaseConfigurationHandler;
- private final Map<String, String> featureMap = new HashMap<>();
+ private final Map<String, String> featureMap = new HashMap<>(3, 1);
@Before
public void setup() {
@@ -95,32 +94,15 @@ public final class ImportDatabaseConfigurationHandlerTest {
featureMap.put(databaseDiscovery, dbDiscoveryFilePath);
}
- private void init(final String feature) throws Exception {
- importDatabaseConfigurationHandler = new ImportDatabaseConfigurationHandler().init(getParameter(createSqlStatement(featureMap.get(feature)), mockConnectionSession()));
- Field validatorField = importDatabaseConfigurationHandler.getClass().getDeclaredField("validator");
- validatorField.setAccessible(true);
- validatorField.set(importDatabaseConfigurationHandler, validator);
- ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(contextManager.getMetaDataContexts().getAllDatabaseNames()).thenReturn(Collections.singletonList(feature));
- ShardingSphereMetaData shardingSphereMetaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
- when(shardingSphereMetaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(new ShardingSphereSchema(createTableMap()));
- when(shardingSphereMetaData.getResource().getDataSources()).thenReturn(createDataSourceMap());
- when(contextManager.getMetaDataContexts().getMetaData(feature)).thenReturn(shardingSphereMetaData);
- ProxyContext.getInstance().init(contextManager);
- }
-
@Test
public void assertImportDatabaseExecutorForSharding() throws Exception {
init(sharding);
Field shardingRuleConfigurationImportCheckerField = importDatabaseConfigurationHandler.getClass().getDeclaredField("shardingRuleConfigurationImportChecker");
shardingRuleConfigurationImportCheckerField.setAccessible(true);
shardingRuleConfigurationImportCheckerField.set(importDatabaseConfigurationHandler, shardingRuleConfigurationImportChecker);
- Map<String, DataSource> dataSourceMap = ProxyContext.getInstance().getContextManager().getDataSourceMap(sharding);
- assertNotNull(dataSourceMap);
- Collection<RuleConfiguration> ruleConfigurations = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(sharding).getRuleMetaData().getConfigurations();
- assertNotNull(ruleConfigurations);
- ResponseHeader responseHeader = importDatabaseConfigurationHandler.execute();
- assertTrue(responseHeader instanceof UpdateResponseHeader);
+ assertNotNull(ProxyContext.getInstance().getContextManager().getDataSourceMap(sharding));
+ assertNotNull(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(sharding).getRuleMetaData().getConfigurations());
+ assertThat(importDatabaseConfigurationHandler.execute(), instanceOf(UpdateResponseHeader.class));
}
@Test
@@ -129,12 +111,9 @@ public final class ImportDatabaseConfigurationHandlerTest {
Field readwriteSplittingRuleConfigurationImportCheckerField = importDatabaseConfigurationHandler.getClass().getDeclaredField("readwriteSplittingRuleConfigurationImportChecker");
readwriteSplittingRuleConfigurationImportCheckerField.setAccessible(true);
readwriteSplittingRuleConfigurationImportCheckerField.set(importDatabaseConfigurationHandler, readwriteSplittingRuleConfigurationImportChecker);
- Map<String, DataSource> dataSourceMap = ProxyContext.getInstance().getContextManager().getDataSourceMap(readwriteSplitting);
- assertNotNull(dataSourceMap);
- Collection<RuleConfiguration> ruleConfigurations = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(readwriteSplitting).getRuleMetaData().getConfigurations();
- assertNotNull(ruleConfigurations);
- ResponseHeader responseHeader = importDatabaseConfigurationHandler.execute();
- assertTrue(responseHeader instanceof UpdateResponseHeader);
+ assertNotNull(ProxyContext.getInstance().getContextManager().getDataSourceMap(readwriteSplitting));
+ assertNotNull(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(readwriteSplitting).getRuleMetaData().getConfigurations());
+ assertThat(importDatabaseConfigurationHandler.execute(), instanceOf(UpdateResponseHeader.class));
}
@Test
@@ -143,42 +122,41 @@ public final class ImportDatabaseConfigurationHandlerTest {
Field databaseDiscoveryRuleConfigurationImportCheckerField = importDatabaseConfigurationHandler.getClass().getDeclaredField("databaseDiscoveryRuleConfigurationImportChecker");
databaseDiscoveryRuleConfigurationImportCheckerField.setAccessible(true);
databaseDiscoveryRuleConfigurationImportCheckerField.set(importDatabaseConfigurationHandler, databaseDiscoveryRuleConfigurationImportChecker);
- Map<String, DataSource> dataSourceMap = ProxyContext.getInstance().getContextManager().getDataSourceMap(databaseDiscovery);
- assertNotNull(dataSourceMap);
- Collection<RuleConfiguration> ruleConfigurations = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseDiscovery).getRuleMetaData().getConfigurations();
- assertNotNull(ruleConfigurations);
- ResponseHeader responseHeader = importDatabaseConfigurationHandler.execute();
- assertTrue(responseHeader instanceof UpdateResponseHeader);
+ assertNotNull(ProxyContext.getInstance().getContextManager().getDataSourceMap(databaseDiscovery));
+ assertNotNull(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(databaseDiscovery).getRuleMetaData().getConfigurations());
+ assertThat(importDatabaseConfigurationHandler.execute(), instanceOf(UpdateResponseHeader.class));
+ }
+
+ private void init(final String feature) throws Exception {
+ importDatabaseConfigurationHandler = new ImportDatabaseConfigurationHandler().init(getParameter(featureMap.get(feature), mock(ConnectionSession.class)));
+ Field validatorField = importDatabaseConfigurationHandler.getClass().getDeclaredField("validator");
+ validatorField.setAccessible(true);
+ validatorField.set(importDatabaseConfigurationHandler, validator);
+ ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
+ when(contextManager.getMetaDataContexts().getAllDatabaseNames()).thenReturn(Collections.singletonList(feature));
+ ShardingSphereMetaData shardingSphereMetaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
+ when(shardingSphereMetaData.getSchemaByName(DefaultDatabase.LOGIC_NAME)).thenReturn(new ShardingSphereSchema(createTableMap()));
+ when(shardingSphereMetaData.getResource().getDataSources()).thenReturn(createDataSourceMap());
+ when(contextManager.getMetaDataContexts().getMetaData(feature)).thenReturn(shardingSphereMetaData);
+ ProxyContext.getInstance().init(contextManager);
}
private Map<String, DataSource> createDataSourceMap() {
Map<String, DataSource> result = new LinkedHashMap<>(2, 1);
- result.put("ds_0", createDataSource());
- result.put("ds_1", createDataSource());
+ result.put("ds_0", new MockedDataSource());
+ result.put("ds_1", new MockedDataSource());
return result;
}
- private DataSource createDataSource() {
- return new MockedDataSource();
- }
-
private Map<String, TableMetaData> createTableMap() {
- Collection<ColumnMetaData> columns = Collections.singletonList(new ColumnMetaData("order_id", 0, false, false, false));
- Collection<IndexMetaData> indexes = Collections.singletonList(new IndexMetaData("primary"));
- Map<String, TableMetaData> result = new HashMap<>(1, 1);
- result.put("t_order", new TableMetaData("t_order", columns, indexes, Collections.emptyList()));
- return result;
- }
-
- private ImportDatabaseConfigurationStatement createSqlStatement(final String importFilePath) {
- return new ImportDatabaseConfigurationStatement(Objects.requireNonNull(ImportDatabaseConfigurationHandlerTest.class.getResource(importFilePath)).getPath());
- }
-
- private ConnectionSession mockConnectionSession() {
- return mock(ConnectionSession.class);
+ Collection<ColumnMetaData> columns = Collections.singleton(new ColumnMetaData("order_id", 0, false, false, false));
+ Collection<IndexMetaData> indexes = Collections.singleton(new IndexMetaData("primary"));
+ return Collections.singletonMap("t_order", new TableMetaData("t_order", columns, indexes, Collections.emptyList()));
}
- private RALBackendHandler.HandlerParameter<ImportDatabaseConfigurationStatement> getParameter(final ImportDatabaseConfigurationStatement statement, final ConnectionSession connectionSession) {
+ private RALBackendHandler.HandlerParameter<ImportDatabaseConfigurationStatement> getParameter(final String importFilePath, final ConnectionSession connectionSession) {
+ ImportDatabaseConfigurationStatement statement = new ImportDatabaseConfigurationStatement(
+ Objects.requireNonNull(ImportDatabaseConfigurationHandlerTest.class.getResource(importFilePath)).getPath());
return new RALBackendHandler.HandlerParameter<ImportDatabaseConfigurationStatement>().setStatement(statement).setConnectionSession(connectionSession);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java
index d379ac3a0ed..3e66875a946 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AddResourceBackendHandlerTest.java
@@ -44,7 +44,8 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.Properties;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -91,7 +92,7 @@ public final class AddResourceBackendHandlerTest {
when(metaData.getResource()).thenReturn(resource);
when(resource.getDataSources()).thenReturn(Collections.emptyMap());
ResponseHeader responseHeader = addResourceBackendHandler.execute("test_db", createAddResourceStatement());
- assertTrue(responseHeader instanceof UpdateResponseHeader);
+ assertThat(responseHeader, instanceOf(UpdateResponseHeader.class));
}
@Test(expected = DuplicateResourceException.class)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java
index bfc8d52e725..d74f62a79ba 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/AlterResourceBackendHandlerTest.java
@@ -48,7 +48,8 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.Properties;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -97,8 +98,7 @@ public final class AlterResourceBackendHandlerTest {
when(metaDataContexts.getMetaData("test_db")).thenReturn(metaData);
when(metaData.getResource()).thenReturn(resource);
when(resource.getDataSources()).thenReturn(Collections.singletonMap("ds_0", mockHikariDataSource("ds_0")));
- ResponseHeader responseHeader = alterResourceBackendHandler.execute("test_db", createAlterResourceStatement("ds_0"));
- assertTrue(responseHeader instanceof UpdateResponseHeader);
+ assertThat(alterResourceBackendHandler.execute("test_db", createAlterResourceStatement("ds_0")), instanceOf(UpdateResponseHeader.class));
}
@Test(expected = DuplicateResourceException.class)
@@ -128,7 +128,7 @@ public final class AlterResourceBackendHandlerTest {
when(metaData.getResource()).thenReturn(resource);
when(resource.getDataSources()).thenReturn(Collections.singletonMap("ds_0", mockHikariDataSource("ds_1")));
ResponseHeader responseHeader = alterResourceBackendHandler.execute("test_db", createAlterResourceStatement("ds_0"));
- assertTrue(responseHeader instanceof UpdateResponseHeader);
+ assertThat(responseHeader, instanceOf(UpdateResponseHeader.class));
}
private AlterResourceStatement createAlterResourceStatement(final String resourceName) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java
index 9c7eac831a2..c597e1c75c5 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/resource/DropResourceBackendHandlerTest.java
@@ -26,7 +26,6 @@ import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
@@ -40,13 +39,10 @@ import org.mockito.junit.MockitoJUnitRunner;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -99,21 +95,18 @@ public final class DropResourceBackendHandlerTest {
@Test
public void assertExecute() throws DistSQLException {
when(ruleMetaData.getRules()).thenReturn(Collections.emptyList());
- Map<String, DataSource> dataSources = new HashMap<>(1, 1);
- dataSources.put("test0", dataSource);
- when(resource.getDataSources()).thenReturn(dataSources);
- DropResourceStatement dropResourceStatement = createDropResourceStatement();
- ResponseHeader responseHeader = dropResourceBackendHandler.execute("test", dropResourceStatement);
- assertTrue(responseHeader instanceof UpdateResponseHeader);
+ when(resource.getDataSources()).thenReturn(Collections.singletonMap("foo_ds", dataSource));
+ DropResourceStatement dropResourceStatement = new DropResourceStatement(Collections.singleton("foo_ds"), false);
+ assertThat(dropResourceBackendHandler.execute("test", dropResourceStatement), instanceOf(UpdateResponseHeader.class));
verify(contextManager).dropResource("test", dropResourceStatement.getNames());
}
@Test
public void assertResourceNameNotExistedExecute() {
try {
- dropResourceBackendHandler.execute("test", createDropResourceStatement());
+ dropResourceBackendHandler.execute("test", new DropResourceStatement(Collections.singleton("foo_ds"), false));
} catch (final SQLException ex) {
- assertThat(ex.getMessage(), is("Resources [test0] do not exist in database test."));
+ assertThat(ex.getMessage(), is("Resources [foo_ds] do not exist in database test."));
}
}
@@ -121,12 +114,12 @@ public final class DropResourceBackendHandlerTest {
public void assertResourceNameInUseExecute() {
when(ruleMetaData.getRules()).thenReturn(Collections.singleton(shadowRule));
when(shadowRule.getType()).thenReturn("ShadowRule");
- when(shadowRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("", Collections.singleton("test0")));
- when(resource.getDataSources()).thenReturn(Collections.singletonMap("test0", dataSource));
+ when(shadowRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("", Collections.singleton("foo_ds")));
+ when(resource.getDataSources()).thenReturn(Collections.singletonMap("foo_ds", dataSource));
try {
- dropResourceBackendHandler.execute("test", createDropResourceStatement());
+ dropResourceBackendHandler.execute("test", new DropResourceStatement(Collections.singleton("foo_ds"), false));
} catch (final SQLException ex) {
- assertThat(ex.getMessage(), is("Resource [test0] is still used by [ShadowRule]."));
+ assertThat(ex.getMessage(), is("Resource [foo_ds] is still used by [ShadowRule]."));
}
}
@@ -135,13 +128,13 @@ public final class DropResourceBackendHandlerTest {
when(ruleMetaData.getRules()).thenReturn(Collections.singleton(singleTableRule));
when(singleTableRule.getType()).thenReturn("SingleTableRule");
DataNode dataNode = mock(DataNode.class);
- when(dataNode.getDataSourceName()).thenReturn("test0");
+ when(dataNode.getDataSourceName()).thenReturn("foo_ds");
when(singleTableRule.getAllDataNodes()).thenReturn(Collections.singletonMap("", Collections.singleton(dataNode)));
- when(resource.getDataSources()).thenReturn(Collections.singletonMap("test0", dataSource));
+ when(resource.getDataSources()).thenReturn(Collections.singletonMap("foo_ds", dataSource));
try {
- dropResourceBackendHandler.execute("test", createDropResourceStatement());
+ dropResourceBackendHandler.execute("test", new DropResourceStatement(Collections.singleton("foo_ds"), false));
} catch (final SQLException ex) {
- assertThat(ex.getMessage(), is("Resource [test0] is still used by [SingleTableRule]."));
+ assertThat(ex.getMessage(), is("Resource [foo_ds] is still used by [SingleTableRule]."));
}
}
@@ -150,20 +143,18 @@ public final class DropResourceBackendHandlerTest {
when(ruleMetaData.getRules()).thenReturn(Collections.singleton(singleTableRule));
when(singleTableRule.getType()).thenReturn("SingleTableRule");
DataNode dataNode = mock(DataNode.class);
- when(dataNode.getDataSourceName()).thenReturn("test0");
+ when(dataNode.getDataSourceName()).thenReturn("foo_ds");
when(singleTableRule.getAllDataNodes()).thenReturn(Collections.singletonMap("", Collections.singleton(dataNode)));
- when(resource.getDataSources()).thenReturn(getDataSourceMapForSupportRemove());
- DropResourceStatement dropResourceStatement = createDropResourceStatementIgnoreSingleTables();
- ResponseHeader responseHeader = dropResourceBackendHandler.execute("test", dropResourceStatement);
- assertTrue(responseHeader instanceof UpdateResponseHeader);
+ when(resource.getDataSources()).thenReturn(Collections.singletonMap("foo_ds", dataSource));
+ DropResourceStatement dropResourceStatement = new DropResourceStatement(Collections.singleton("foo_ds"), true);
+ assertThat(dropResourceBackendHandler.execute("test", dropResourceStatement), instanceOf(UpdateResponseHeader.class));
verify(contextManager).dropResource("test", dropResourceStatement.getNames());
}
@Test
public void assertExecuteWithIfExists() throws DistSQLException {
- DropResourceStatement dropResourceStatement = createDropResourceStatementWithIfExists();
- ResponseHeader responseHeader = dropResourceBackendHandler.execute("test", dropResourceStatement);
- assertTrue(responseHeader instanceof UpdateResponseHeader);
+ DropResourceStatement dropResourceStatement = new DropResourceStatement(true, Collections.singleton("foo_ds"), true);
+ assertThat(dropResourceBackendHandler.execute("test", dropResourceStatement), instanceOf(UpdateResponseHeader.class));
verify(contextManager).dropResource("test", dropResourceStatement.getNames());
}
@@ -171,26 +162,8 @@ public final class DropResourceBackendHandlerTest {
public void assertResourceNameInUseWithIfExists() throws DistSQLException {
when(ruleMetaData.getRules()).thenReturn(Collections.singleton(shadowRule));
when(shadowRule.getType()).thenReturn("ShadowRule");
- when(shadowRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("", Collections.singleton("test0")));
- DropResourceStatement dropResourceStatement = createDropResourceStatementWithIfExists();
+ when(shadowRule.getDataSourceMapper()).thenReturn(Collections.singletonMap("", Collections.singleton("foo_ds")));
+ DropResourceStatement dropResourceStatement = new DropResourceStatement(true, Collections.singleton("foo_ds"), true);
dropResourceBackendHandler.execute("test", dropResourceStatement);
}
-
- private Map<String, DataSource> getDataSourceMapForSupportRemove() {
- Map<String, DataSource> result = new LinkedHashMap<>();
- result.put("test0", dataSource);
- return result;
- }
-
- private DropResourceStatement createDropResourceStatement() {
- return new DropResourceStatement(Collections.singleton("test0"), false);
- }
-
- private DropResourceStatement createDropResourceStatementIgnoreSingleTables() {
- return new DropResourceStatement(Collections.singleton("test0"), true);
- }
-
- private DropResourceStatement createDropResourceStatementWithIfExists() {
- return new DropResourceStatement(true, Collections.singleton("test0"), true);
- }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java
index 780dbb6364f..b4e9c830f4d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java
@@ -70,7 +70,6 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -168,12 +167,11 @@ public final class MySQLCommandExecutorFactoryTest {
@Test
public void assertNewInstanceWithComSetOption() throws SQLException {
- assertTrue(MySQLCommandExecutorFactory.newInstance(MySQLCommandPacketType.COM_SET_OPTION, mock(MySQLComSetOptionPacket.class), connectionSession) instanceof MySQLComSetOptionExecutor);
+ assertThat(MySQLCommandExecutorFactory.newInstance(MySQLCommandPacketType.COM_SET_OPTION, mock(MySQLComSetOptionPacket.class), connectionSession), instanceOf(MySQLComSetOptionExecutor.class));
}
@Test
public void assertNewInstanceWithUnsupportedCommand() throws SQLException {
- assertThat(MySQLCommandExecutorFactory.newInstance(MySQLCommandPacketType.COM_REFRESH,
- mock(CommandPacket.class), connectionSession), instanceOf(MySQLUnsupportedCommandExecutor.class));
+ assertThat(MySQLCommandExecutorFactory.newInstance(MySQLCommandPacketType.COM_REFRESH, mock(CommandPacket.class), connectionSession), instanceOf(MySQLUnsupportedCommandExecutor.class));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/MySQLComSetOptionExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/MySQLComSetOptionExecutorTest.java
index 03ccdcc0395..6df2a4cea57 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/MySQLComSetOptionExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/MySQLComSetOptionExecutorTest.java
@@ -33,9 +33,9 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.sql.SQLException;
import java.util.Collection;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -60,7 +60,7 @@ public final class MySQLComSetOptionExecutorTest {
when(connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_OPTION_MULTI_STATEMENTS)).thenReturn(attribute);
Collection<DatabasePacket<?>> actual = executor.execute();
assertThat(actual.size(), is(1));
- assertTrue(actual.iterator().next() instanceof MySQLOKPacket);
+ assertThat(actual.iterator().next(), instanceOf(MySQLOKPacket.class));
verify(attribute).set(MySQLComSetOptionPacket.MYSQL_OPTION_MULTI_STATEMENTS_ON);
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
index 7008b70b8f0..aad2d279987 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLCharacterSet;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConstants;
-import org.apache.shardingsphere.db.protocol.mysql.packet.MySQLPacket;
import org.apache.shardingsphere.db.protocol.mysql.packet.command.query.text.MySQLTextResultSetRowPacket;
import org.apache.shardingsphere.db.protocol.mysql.packet.command.query.text.query.MySQLComQueryPacket;
import org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLOKPacket;
@@ -29,8 +28,8 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader;
+import org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
import org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
@@ -50,6 +49,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
@@ -115,7 +115,7 @@ public final class MySQLComQueryPacketExecutorTest {
when(textProtocolBackendHandler.execute()).thenReturn(new UpdateResponseHeader(mock(SQLStatement.class)));
Collection<DatabasePacket<?>> actualPackets = actual.execute();
assertThat(actualPackets.size(), is(1));
- assertTrue(actualPackets.iterator().next() instanceof MySQLOKPacket);
+ assertThat(actualPackets.iterator().next(), instanceOf(MySQLOKPacket.class));
}
}
@@ -130,8 +130,7 @@ public final class MySQLComQueryPacketExecutorTest {
@Test
public void assertGetQueryRowPacket() throws SQLException {
- MySQLPacket actual = new MySQLComQueryPacketExecutor(packet, connectionSession).getQueryRowPacket();
- assertTrue(actual instanceof MySQLTextResultSetRowPacket);
+ assertThat(new MySQLComQueryPacketExecutor(packet, connectionSession).getQueryRowPacket(), instanceOf(MySQLTextResultSetRowPacket.class));
}
@Test
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java
index baa12937632..8dabd215722 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java
@@ -43,9 +43,9 @@ import java.sql.Statement;
import java.util.Collections;
import java.util.Optional;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
@@ -93,7 +93,7 @@ public final class MySQLMultiStatementsHandlerTest {
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().<Boolean>getValue(ConfigurationPropertyKey.SQL_SHOW)).thenReturn(false);
when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getProps().<Integer>getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY)).thenReturn(1);
ResponseHeader actual = new MySQLMultiStatementsHandler(connectionSession, expectedStatement, sql).execute();
- assertTrue(actual instanceof UpdateResponseHeader);
+ assertThat(actual, instanceOf(UpdateResponseHeader.class));
UpdateResponseHeader actualHeader = (UpdateResponseHeader) actual;
assertThat(actualHeader.getUpdateCount(), is(3L));
assertThat(actualHeader.getLastInsertId(), is(0L));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecutorFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecutorFactoryTest.java
index b109fe5bd92..5f59916263b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecutorFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/OpenGaussCommandExecutorFactoryTest.java
@@ -56,8 +56,9 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -74,7 +75,7 @@ public final class OpenGaussCommandExecutorFactoryTest {
public void assertNewOpenGaussBatchBindExecutor() throws SQLException {
OpenGaussComBatchBindPacket batchBindPacket = mock(OpenGaussComBatchBindPacket.class);
CommandExecutor actual = OpenGaussCommandExecutorFactory.newInstance(OpenGaussCommandPacketType.BATCH_BIND_COMMAND, batchBindPacket, connectionSession, connectionContext);
- assertTrue(actual instanceof OpenGaussComBatchBindExecutor);
+ assertThat(actual, instanceOf(OpenGaussComBatchBindExecutor.class));
}
@Test
@@ -82,13 +83,13 @@ public final class OpenGaussCommandExecutorFactoryTest {
PostgreSQLComQueryPacket queryPacket = mock(PostgreSQLComQueryPacket.class);
when(queryPacket.getSql()).thenReturn("");
CommandExecutor actual = OpenGaussCommandExecutorFactory.newInstance(PostgreSQLCommandPacketType.SIMPLE_QUERY, queryPacket, connectionSession, connectionContext);
- assertTrue(actual instanceof OpenGaussComQueryExecutor);
+ assertThat(actual, instanceOf(OpenGaussComQueryExecutor.class));
}
@Test
public void assertNewUnsupportedExecutor() throws SQLException {
CommandExecutor actual = OpenGaussCommandExecutorFactory.newInstance(PostgreSQLCommandPacketType.FLUSH_COMMAND, null, connectionSession, connectionContext);
- assertTrue(actual instanceof PostgreSQLUnsupportedCommandExecutor);
+ assertThat(actual, instanceOf(PostgreSQLUnsupportedCommandExecutor.class));
}
@Test
@@ -107,13 +108,13 @@ public final class OpenGaussCommandExecutorFactoryTest {
when(packet.isContainsBatchedStatements()).thenReturn(false);
when(packet.getPackets()).thenReturn(Arrays.asList(parsePacket, bindPacket, describePacket, executePacket, syncPacket));
CommandExecutor actual = OpenGaussCommandExecutorFactory.newInstance(null, packet, connectionSession, connectionContext);
- assertTrue(actual instanceof PostgreSQLAggregatedCommandExecutor);
+ assertThat(actual, instanceOf(PostgreSQLAggregatedCommandExecutor.class));
Iterator<CommandExecutor> actualPacketsIterator = getExecutorsFromAggregatedCommandExecutor((PostgreSQLAggregatedCommandExecutor) actual).iterator();
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComParseExecutor);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComBindExecutor);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComDescribeExecutor);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComExecuteExecutor);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComSyncExecutor);
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComParseExecutor.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComBindExecutor.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComDescribeExecutor.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComExecuteExecutor.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComSyncExecutor.class));
assertFalse(actualPacketsIterator.hasNext());
}
@@ -137,13 +138,13 @@ public final class OpenGaussCommandExecutorFactoryTest {
when(packet.getFirstBindIndex()).thenReturn(1);
when(packet.getLastExecuteIndex()).thenReturn(6);
CommandExecutor actual = OpenGaussCommandExecutorFactory.newInstance(null, packet, connectionSession, connectionContext);
- assertTrue(actual instanceof PostgreSQLAggregatedCommandExecutor);
+ assertThat(actual, instanceOf(PostgreSQLAggregatedCommandExecutor.class));
Iterator<CommandExecutor> actualPacketsIterator = getExecutorsFromAggregatedCommandExecutor((PostgreSQLAggregatedCommandExecutor) actual).iterator();
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComParseExecutor);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLAggregatedBatchedStatementsCommandExecutor);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComCloseExecutor);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComSyncExecutor);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComTerminationExecutor);
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComParseExecutor.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLAggregatedBatchedStatementsCommandExecutor.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComCloseExecutor.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComSyncExecutor.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComTerminationExecutor.class));
assertFalse(actualPacketsIterator.hasNext());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java
index 5c014ebda2e..07233ebc830 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java
@@ -45,10 +45,10 @@ import java.sql.SQLException;
import java.util.Collections;
import java.util.Iterator;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyList;
@@ -98,7 +98,7 @@ public final class OpenGaussComBatchBindExecutorTest {
OpenGaussComBatchBindExecutor executor = new OpenGaussComBatchBindExecutor(packet, connectionSession);
Iterator<DatabasePacket<?>> actualPacketsIterator = executor.execute().iterator();
assertThat(actualPacketsIterator.next(), is(PostgreSQLBindCompletePacket.getInstance()));
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLCommandCompletePacket);
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLCommandCompletePacket.class));
assertFalse(actualPacketsIterator.hasNext());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactoryTest.java
index c34c9710da2..abf0798ecc7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecutorFactoryTest.java
@@ -59,7 +59,6 @@ import java.util.List;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -84,14 +83,14 @@ public final class PostgreSQLCommandExecutorFactoryTest {
new InputOutput(PostgreSQLCommandPacketType.CLOSE_COMMAND, PostgreSQLComClosePacket.class, PostgreSQLComCloseExecutor.class),
new InputOutput(PostgreSQLCommandPacketType.TERMINATE, PostgreSQLComTerminationPacket.class, PostgreSQLComTerminationExecutor.class),
new InputOutput(PostgreSQLCommandPacketType.FLUSH_COMMAND, null, PostgreSQLUnsupportedCommandExecutor.class));
- for (InputOutput inputOutput : inputOutputs) {
- Class<? extends PostgreSQLCommandPacket> commandPacketClass = inputOutput.getCommandPacketClass();
+ for (InputOutput each : inputOutputs) {
+ Class<? extends PostgreSQLCommandPacket> commandPacketClass = each.getCommandPacketClass();
if (null == commandPacketClass) {
commandPacketClass = PostgreSQLCommandPacket.class;
}
PostgreSQLCommandPacket packet = preparePacket(commandPacketClass);
- CommandExecutor actual = PostgreSQLCommandExecutorFactory.newInstance(inputOutput.getCommandPacketType(), packet, connectionSession, connectionContext);
- assertThat(actual, instanceOf(inputOutput.getResultClass()));
+ CommandExecutor actual = PostgreSQLCommandExecutorFactory.newInstance(each.getCommandPacketType(), packet, connectionSession, connectionContext);
+ assertThat(actual, instanceOf(each.getResultClass()));
}
}
@@ -119,13 +118,13 @@ public final class PostgreSQLCommandExecutorFactoryTest {
when(packet.isContainsBatchedStatements()).thenReturn(false);
when(packet.getPackets()).thenReturn(Arrays.asList(parsePacket, bindPacket, describePacket, executePacket, syncPacket));
CommandExecutor actual = PostgreSQLCommandExecutorFactory.newInstance(null, packet, connectionSession, connectionContext);
- assertTrue(actual instanceof PostgreSQLAggregatedCommandExecutor);
+ assertThat(actual, instanceOf(PostgreSQLAggregatedCommandExecutor.class));
Iterator<CommandExecutor> actualPacketsIterator = getExecutorsFromAggregatedCommandExecutor((PostgreSQLAggregatedCommandExecutor) actual).iterator();
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComParseExecutor);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComBindExecutor);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComDescribeExecutor);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComExecuteExecutor);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComSyncExecutor);
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComParseExecutor.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComBindExecutor.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComDescribeExecutor.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComExecuteExecutor.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComSyncExecutor.class));
assertFalse(actualPacketsIterator.hasNext());
}
@@ -144,11 +143,11 @@ public final class PostgreSQLCommandExecutorFactoryTest {
when(packet.getFirstBindIndex()).thenReturn(1);
when(packet.getLastExecuteIndex()).thenReturn(6);
CommandExecutor actual = PostgreSQLCommandExecutorFactory.newInstance(null, packet, connectionSession, connectionContext);
- assertTrue(actual instanceof PostgreSQLAggregatedCommandExecutor);
+ assertThat(actual, instanceOf(PostgreSQLAggregatedCommandExecutor.class));
Iterator<CommandExecutor> actualPacketsIterator = getExecutorsFromAggregatedCommandExecutor((PostgreSQLAggregatedCommandExecutor) actual).iterator();
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComParseExecutor);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLAggregatedBatchedStatementsCommandExecutor);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLComSyncExecutor);
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComParseExecutor.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLAggregatedBatchedStatementsCommandExecutor.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLComSyncExecutor.class));
assertFalse(actualPacketsIterator.hasNext());
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/JDBCPortalTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/JDBCPortalTest.java
index 2f952f1ff81..1ce50853c6c 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/JDBCPortalTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/JDBCPortalTest.java
@@ -60,9 +60,9 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -123,14 +123,14 @@ public final class JDBCPortalTest {
when(databaseCommunicationEngine.getQueryResponseRow())
.thenReturn(new QueryResponseRow(Collections.singletonList(new TextQueryResponseCell(0))), new QueryResponseRow(Collections.singletonList(new TextQueryResponseCell(1))));
portal.bind();
- assertTrue(portal.describe() instanceof PostgreSQLRowDescriptionPacket);
+ assertThat(portal.describe(), instanceOf(PostgreSQLRowDescriptionPacket.class));
setField(portal, "sqlStatement", mock(SelectStatement.class));
List<PostgreSQLPacket> actualPackets = portal.execute(0);
assertThat(actualPackets.size(), is(3));
Iterator<PostgreSQLPacket> actualPacketsIterator = actualPackets.iterator();
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLDataRowPacket);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLDataRowPacket);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLCommandCompletePacket);
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLDataRowPacket.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLDataRowPacket.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLCommandCompletePacket.class));
}
@Test
@@ -147,14 +147,14 @@ public final class JDBCPortalTest {
new QueryResponseRow(Collections.singletonList(new BinaryQueryResponseCell(Types.INTEGER, 1))));
setField(portal, "resultFormats", Collections.singletonList(PostgreSQLValueFormat.BINARY));
portal.bind();
- assertTrue(portal.describe() instanceof PostgreSQLRowDescriptionPacket);
+ assertThat(portal.describe(), instanceOf(PostgreSQLRowDescriptionPacket.class));
setField(portal, "sqlStatement", mock(SelectStatement.class));
List<PostgreSQLPacket> actualPackets = portal.execute(2);
assertThat(actualPackets.size(), is(3));
Iterator<PostgreSQLPacket> actualPacketsIterator = actualPackets.iterator();
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLDataRowPacket);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLDataRowPacket);
- assertTrue(actualPacketsIterator.next() instanceof PostgreSQLPortalSuspendedPacket);
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLDataRowPacket.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLDataRowPacket.class));
+ assertThat(actualPacketsIterator.next(), instanceOf(PostgreSQLPortalSuspendedPacket.class));
}
@Test
@@ -167,7 +167,7 @@ public final class JDBCPortalTest {
assertThat(portal.describe(), is(PostgreSQLNoDataPacket.getInstance()));
setField(portal, "sqlStatement", mock(InsertStatement.class));
List<PostgreSQLPacket> actualPackets = portal.execute(0);
- assertTrue(actualPackets.iterator().next() instanceof PostgreSQLCommandCompletePacket);
+ assertThat(actualPackets.iterator().next(), instanceOf(PostgreSQLCommandCompletePacket.class));
}
@Test
@@ -179,7 +179,7 @@ public final class JDBCPortalTest {
portal.bind();
assertThat(portal.describe(), is(PostgreSQLNoDataPacket.getInstance()));
List<PostgreSQLPacket> actualPackets = portal.execute(0);
- assertTrue(actualPackets.iterator().next() instanceof PostgreSQLEmptyQueryResponsePacket);
+ assertThat(actualPackets.iterator().next(), instanceOf(PostgreSQLEmptyQueryResponsePacket.class));
}
@Test(expected = IllegalStateException.class)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java
index 6ab115cea57..b8feb0b8a7f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java
@@ -50,9 +50,9 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.nullable;
@@ -107,7 +107,7 @@ public final class PostgreSQLAggregatedBatchedStatementsCommandExecutorTest {
for (int i = 0; i < BATCH_SIZE; i++) {
assertThat(actualPackets.get(i * 3), is(PostgreSQLBindCompletePacket.getInstance()));
assertThat(actualPackets.get(i * 3 + 1), is(PostgreSQLNoDataPacket.getInstance()));
- assertTrue(actualPackets.get(i * 3 + 2) instanceof PostgreSQLCommandCompletePacket);
+ assertThat(actualPackets.get(i * 3 + 2), instanceOf(PostgreSQLCommandCompletePacket.class));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedCommandExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedCommandExecutorTest.java
index f0db296cf50..d68eb93c26e 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedCommandExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedCommandExecutorTest.java
@@ -24,12 +24,13 @@ import org.junit.Test;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -39,17 +40,15 @@ public final class PostgreSQLAggregatedCommandExecutorTest {
public void assertExecute() throws SQLException {
int commandCount = 16;
List<CommandExecutor> executors = new ArrayList<>(commandCount);
- List<DatabasePacket<?>> expectedPackets = new ArrayList<>(commandCount);
for (int i = 0; i < commandCount; i++) {
CommandExecutor executor = mock(CommandExecutor.class);
- DatabasePacket expectedPacket = mock(DatabasePacket.class);
- expectedPackets.add(expectedPacket);
- when(executor.execute()).thenReturn(Collections.singletonList(expectedPacket));
+ DatabasePacket<?> expectedPacket = mock(DatabasePacket.class);
+ when(executor.execute()).thenReturn(Collections.singleton(expectedPacket));
executors.add(executor);
}
PostgreSQLAggregatedCommandExecutor actualExecutor = new PostgreSQLAggregatedCommandExecutor(executors);
- List<DatabasePacket<?>> actualPackets = new ArrayList<>(actualExecutor.execute());
+ Collection<DatabasePacket<?>> actualPackets = actualExecutor.execute();
assertThat(actualPackets.size(), is(1));
- assertTrue(actualPackets.iterator().next() instanceof PostgreSQLAggregatedResponsesPacket);
+ assertThat(actualPackets.iterator().next(), instanceOf(PostgreSQLAggregatedResponsesPacket.class));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java
index 7cbb841cc9f..0069ad5af50 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/parse/PostgreSQLComParseExecutorTest.java
@@ -45,9 +45,9 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@@ -89,7 +89,7 @@ public final class PostgreSQLComParseExecutorTest {
assertThat(actualPackets.size(), is(1));
assertThat(actualPackets.iterator().next(), is(PostgreSQLParseCompletePacket.getInstance()));
PostgreSQLPreparedStatement actualPreparedStatement = PostgreSQLPreparedStatementRegistry.getInstance().get(CONNECTION_ID, statementId);
- assertTrue(actualPreparedStatement.getSqlStatement() instanceof EmptyStatement);
+ assertThat(actualPreparedStatement.getSqlStatement(), instanceOf(EmptyStatement.class));
assertThat(actualPreparedStatement.getSql(), is(expectedSQL));
assertThat(actualPreparedStatement.getParameterTypes(), is(Collections.emptyList()));
}
@@ -109,7 +109,7 @@ public final class PostgreSQLComParseExecutorTest {
assertThat(actualPackets.size(), is(1));
assertThat(actualPackets.iterator().next(), is(PostgreSQLParseCompletePacket.getInstance()));
PostgreSQLPreparedStatement actualPreparedStatement = PostgreSQLPreparedStatementRegistry.getInstance().get(CONNECTION_ID, statementId);
- assertTrue(actualPreparedStatement.getSqlStatement() instanceof PostgreSQLInsertStatement);
+ assertThat(actualPreparedStatement.getSqlStatement(), instanceOf(PostgreSQLInsertStatement.class));
assertThat(actualPreparedStatement.getSql(), is(expectedSQL));
assertThat(actualPreparedStatement.getParameterTypes(), is(Arrays.asList(PostgreSQLColumnType.POSTGRESQL_TYPE_INT4, PostgreSQLColumnType.POSTGRESQL_TYPE_UNSPECIFIED)));
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/ReactiveDatabaseProtocolFrontendEngineFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/ReactiveDatabaseProtocolFrontendEngineFactoryTest.java
index 10da3d6b4fb..722b0b47221 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/ReactiveDatabaseProtocolFrontendEngineFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-reactive-core/src/test/java/org/apache/shardingsphere/proxy/frontend/reactive/protocol/ReactiveDatabaseProtocolFrontendEngineFactoryTest.java
@@ -19,15 +19,16 @@ package org.apache.shardingsphere.proxy.frontend.reactive.protocol;
import org.apache.shardingsphere.proxy.frontend.reactive.protocol.fixture.DummyReactiveDatabaseProtocolFrontendEngine;
import org.apache.shardingsphere.spi.exception.ServiceProviderNotFoundException;
+import org.junit.Assert;
import org.junit.Test;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.instanceOf;
public final class ReactiveDatabaseProtocolFrontendEngineFactoryTest {
@Test
public void assertNewInstance() {
- assertTrue(ReactiveDatabaseProtocolFrontendEngineFactory.newInstance("Dummy") instanceof DummyReactiveDatabaseProtocolFrontendEngine);
+ Assert.assertThat(ReactiveDatabaseProtocolFrontendEngineFactory.newInstance("Dummy"), instanceOf(DummyReactiveDatabaseProtocolFrontendEngine.class));
}
@Test(expected = ServiceProviderNotFoundException.class)
diff --git a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/required/RequiredSPIRegistryTest.java b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/required/RequiredSPIRegistryTest.java
index c33b34d9795..ab1e1424ae1 100644
--- a/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/required/RequiredSPIRegistryTest.java
+++ b/shardingsphere-spi/src/test/java/org/apache/shardingsphere/spi/type/required/RequiredSPIRegistryTest.java
@@ -26,7 +26,8 @@ import org.apache.shardingsphere.spi.type.required.fixture.single.SingleRequired
import org.apache.shardingsphere.spi.type.required.fixture.single.SingleRequiredSPIFixtureImpl;
import org.junit.Test;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
public final class RequiredSPIRegistryTest {
@@ -43,11 +44,11 @@ public final class RequiredSPIRegistryTest {
@Test
public void assertRegisteredServiceWithOneImplementation() {
- assertTrue(RequiredSPIRegistry.getRegisteredService(SingleRequiredSPIFixture.class) instanceof SingleRequiredSPIFixtureImpl);
+ assertThat(RequiredSPIRegistry.getRegisteredService(SingleRequiredSPIFixture.class), instanceOf(SingleRequiredSPIFixtureImpl.class));
}
@Test
public void assertRegisteredServiceWithMoreImplementations() {
- assertTrue(RequiredSPIRegistry.getRegisteredService(MultipleRequiredSPIFixture.class) instanceof DefaultMultipleRequiredSPIFixtureImpl);
+ assertThat(RequiredSPIRegistry.getRegisteredService(MultipleRequiredSPIFixture.class), instanceOf(DefaultMultipleRequiredSPIFixtureImpl.class));
}
}
diff --git a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/progress/JobProgressTest.java b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/progress/JobProgressTest.java
index 2c037589b42..f49b80c8f2e 100644
--- a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/progress/JobProgressTest.java
+++ b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/progress/JobProgressTest.java
@@ -31,6 +31,7 @@ import org.junit.Test;
import java.util.Optional;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -39,10 +40,6 @@ public final class JobProgressTest {
private static final JobProgressYamlSwapper JOB_PROGRESS_YAML_SWAPPER = new JobProgressYamlSwapper();
- private JobProgress getJobProgress(final String data) {
- return JOB_PROGRESS_YAML_SWAPPER.swapToObject(YamlEngine.unmarshal(data, YamlJobProgress.class));
- }
-
@Test
public void assertInit() {
JobProgress jobProgress = getJobProgress(ConfigurationFileUtil.readFile("job-progress.yaml"));
@@ -57,16 +54,16 @@ public final class JobProgressTest {
JobProgress jobProgress = getJobProgress(ConfigurationFileUtil.readFile("job-progress.yaml"));
Optional<IngestPosition<?>> positionOptional = jobProgress.getIncrementalPosition("ds0");
assertTrue(positionOptional.isPresent());
- assertTrue(positionOptional.get() instanceof PlaceholderPosition);
+ assertThat(positionOptional.get(), instanceOf(PlaceholderPosition.class));
}
@Test
public void assertGetInventoryPosition() {
JobProgress jobProgress = getJobProgress(ConfigurationFileUtil.readFile("job-progress.yaml"));
assertThat(jobProgress.getInventoryPosition("ds0").size(), is(2));
- assertTrue(jobProgress.getInventoryPosition("ds0").get("ds0.t_1") instanceof FinishedPosition);
- assertTrue(jobProgress.getInventoryPosition("ds1").get("ds1.t_1") instanceof PlaceholderPosition);
- assertTrue(jobProgress.getInventoryPosition("ds1").get("ds1.t_2") instanceof IntegerPrimaryKeyPosition);
+ assertThat(jobProgress.getInventoryPosition("ds0").get("ds0.t_1"), instanceOf(FinishedPosition.class));
+ assertThat(jobProgress.getInventoryPosition("ds1").get("ds1.t_1"), instanceOf(PlaceholderPosition.class));
+ assertThat(jobProgress.getInventoryPosition("ds1").get("ds1.t_2"), instanceOf(IntegerPrimaryKeyPosition.class));
}
@Test
@@ -77,31 +74,30 @@ public final class JobProgressTest {
@Test
public void assertGetNoFinishedInventoryFinishedPercentage() {
- JobProgress jobProgress = getJobProgress(ConfigurationFileUtil.readFile("job-progress-no-finished.yaml"));
- assertThat(jobProgress.getInventoryFinishedPercentage(), is(0));
+ assertThat(getJobProgress(ConfigurationFileUtil.readFile("job-progress-no-finished.yaml")).getInventoryFinishedPercentage(), is(0));
}
@Test
public void assertGetAllFinishedInventoryFinishedPercentage() {
- JobProgress jobProgress = getJobProgress(ConfigurationFileUtil.readFile("job-progress-all-finished.yaml"));
- assertThat(jobProgress.getInventoryFinishedPercentage(), is(100));
+ assertThat(getJobProgress(ConfigurationFileUtil.readFile("job-progress-all-finished.yaml")).getInventoryFinishedPercentage(), is(100));
}
@Test
public void assertGetIncrementalLatestActiveTimeMillis() {
- JobProgress jobProgress = getJobProgress(ConfigurationFileUtil.readFile("job-progress.yaml"));
- assertThat(jobProgress.getIncrementalLatestActiveTimeMillis(), is(0L));
+ assertThat(getJobProgress(ConfigurationFileUtil.readFile("job-progress.yaml")).getIncrementalLatestActiveTimeMillis(), is(0L));
}
@Test
public void assertGetIncrementalDataLatestActiveTimeMillis() {
- JobProgress jobProgress = getJobProgress(ConfigurationFileUtil.readFile("job-progress-all-finished.yaml"));
- assertThat(jobProgress.getIncrementalLatestActiveTimeMillis(), is(50L));
+ assertThat(getJobProgress(ConfigurationFileUtil.readFile("job-progress-all-finished.yaml")).getIncrementalLatestActiveTimeMillis(), is(50L));
}
@Test
public void assertGetNoIncrementalDataLatestActiveTimeMillis() {
- JobProgress jobProgress = getJobProgress(ConfigurationFileUtil.readFile("job-progress-no-finished.yaml"));
- assertThat(jobProgress.getIncrementalLatestActiveTimeMillis(), is(0L));
+ assertThat(getJobProgress(ConfigurationFileUtil.readFile("job-progress-no-finished.yaml")).getIncrementalLatestActiveTimeMillis(), is(0L));
+ }
+
+ private JobProgress getJobProgress(final String data) {
+ return JOB_PROGRESS_YAML_SWAPPER.swapToObject(YamlEngine.unmarshal(data, YamlJobProgress.class));
}
}
diff --git a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/task/IncrementalTaskTest.java b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/task/IncrementalTaskTest.java
index f57466bfe7d..fd758bb0f73 100644
--- a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/task/IncrementalTaskTest.java
+++ b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/task/IncrementalTaskTest.java
@@ -30,9 +30,9 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
public final class IncrementalTaskTest {
@@ -58,7 +58,7 @@ public final class IncrementalTaskTest {
public void assertStart() {
incrementalTask.start();
assertThat(incrementalTask.getTaskId(), is("ds_0"));
- assertTrue(incrementalTask.getProgress().getPosition() instanceof PlaceholderPosition);
+ assertThat(incrementalTask.getProgress().getPosition(), instanceOf(PlaceholderPosition.class));
}
@After
diff --git a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/task/InventoryTaskTest.java b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/task/InventoryTaskTest.java
index 45740aa2a16..6d2379d1c15 100644
--- a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/task/InventoryTaskTest.java
+++ b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/task/InventoryTaskTest.java
@@ -21,8 +21,6 @@ import org.apache.shardingsphere.data.pipeline.api.config.ingest.DumperConfigura
import org.apache.shardingsphere.data.pipeline.api.config.ingest.InventoryDumperConfiguration;
import org.apache.shardingsphere.data.pipeline.api.config.rulealtered.TaskConfiguration;
import org.apache.shardingsphere.data.pipeline.api.datasource.PipelineDataSourceWrapper;
-import org.apache.shardingsphere.data.pipeline.api.ingest.position.FinishedPosition;
-import org.apache.shardingsphere.data.pipeline.api.ingest.position.IngestPosition;
import org.apache.shardingsphere.data.pipeline.api.ingest.position.IntegerPrimaryKeyPosition;
import org.apache.shardingsphere.data.pipeline.core.datasource.PipelineDataSourceManager;
import org.apache.shardingsphere.data.pipeline.core.ingest.exception.IngestException;
@@ -40,7 +38,8 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
-import static org.junit.Assert.assertFalse;
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertThat;
public final class InventoryTaskTest {
@@ -65,16 +64,7 @@ public final class InventoryTaskTest {
@Test(expected = IngestException.class)
public void assertStartWithGetEstimatedRowsFailure() {
- InventoryDumperConfiguration inventoryDumperConfig = new InventoryDumperConfiguration(taskConfig.getDumperConfig());
- inventoryDumperConfig.setActualTableName("t_non_exist");
- inventoryDumperConfig.setLogicTableName("t_non_exist");
- IngestPosition<?> position = taskConfig.getDumperConfig().getPosition();
- if (null == position) {
- position = new IntegerPrimaryKeyPosition(0, 1000);
- }
- inventoryDumperConfig.setPosition(position);
- inventoryDumperConfig.setPrimaryKey("order_id");
- inventoryDumperConfig.setUniqueKeyDataType(Types.INTEGER);
+ InventoryDumperConfiguration inventoryDumperConfig = createInventoryDumperConfiguration("t_non_exist", "t_non_exist");
PipelineDataSourceWrapper dataSource = DATA_SOURCE_MANAGER.getDataSource(inventoryDumperConfig.getDataSourceConfig());
PipelineTableMetaDataLoader metaDataLoader = new PipelineTableMetaDataLoader(dataSource);
try (
@@ -88,17 +78,8 @@ public final class InventoryTaskTest {
@Test
public void assertGetProgress() throws SQLException {
initTableData(taskConfig.getDumperConfig());
- InventoryDumperConfiguration inventoryDumperConfig = new InventoryDumperConfiguration(taskConfig.getDumperConfig());
// TODO use t_order_0, and also others
- inventoryDumperConfig.setActualTableName("t_order");
- inventoryDumperConfig.setLogicTableName("t_order");
- inventoryDumperConfig.setPrimaryKey("order_id");
- inventoryDumperConfig.setUniqueKeyDataType(Types.INTEGER);
- IngestPosition<?> position = taskConfig.getDumperConfig().getPosition();
- if (null == position) {
- position = new IntegerPrimaryKeyPosition(0, 1000);
- }
- inventoryDumperConfig.setPosition(position);
+ InventoryDumperConfiguration inventoryDumperConfig = createInventoryDumperConfiguration("t_order", "t_order");
PipelineDataSourceWrapper dataSource = DATA_SOURCE_MANAGER.getDataSource(inventoryDumperConfig.getDataSourceConfig());
PipelineTableMetaDataLoader metaDataLoader = new PipelineTableMetaDataLoader(dataSource);
try (
@@ -106,7 +87,7 @@ public final class InventoryTaskTest {
PipelineContextUtil.getPipelineChannelCreator(),
new PipelineDataSourceManager(), dataSource, metaDataLoader, PipelineContextUtil.getExecuteEngine())) {
inventoryTask.start();
- assertFalse(inventoryTask.getProgress().getPosition() instanceof FinishedPosition);
+ assertThat(inventoryTask.getProgress().getPosition(), instanceOf(IntegerPrimaryKeyPosition.class));
}
}
@@ -121,4 +102,14 @@ public final class InventoryTaskTest {
statement.execute("INSERT INTO t_order (order_id, user_id) VALUES (1, 'xxx'), (999, 'yyy')");
}
}
+
+ private InventoryDumperConfiguration createInventoryDumperConfiguration(final String logicTableName, final String actualTableName) {
+ InventoryDumperConfiguration result = new InventoryDumperConfiguration(taskConfig.getDumperConfig());
+ result.setLogicTableName(logicTableName);
+ result.setActualTableName(actualTableName);
+ result.setPrimaryKey("order_id");
+ result.setUniqueKeyDataType(Types.INTEGER);
+ result.setPosition(null == taskConfig.getDumperConfig().getPosition() ? new IntegerPrimaryKeyPosition(0, 1000) : taskConfig.getDumperConfig().getPosition());
+ return result;
+ }
}