This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 ace8013c743 Fix sonar issues (#33891)
ace8013c743 is described below
commit ace8013c7432bf2846b11b27aefd78b667cd5836
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Dec 3 15:35:51 2024 +0800
Fix sonar issues (#33891)
---
.../value/time/MySQLTimestamp2BinlogProtocolValueTest.java | 6 +++---
.../value/time/MySQLTimestampBinlogProtocolValueTest.java | 2 +-
.../db/protocol/mysql/payload/MySQLPacketPayloadTest.java | 12 ++++++------
.../at/SeataATShardingSphereTransactionManagerTest.java | 8 ++++----
.../proxy/backend/config/ProxyConfigurationLoaderTest.java | 12 ++++++------
.../yaml/swapper/YamlProxyConfigurationSwapperTest.java | 2 +-
.../test/e2e/env/container/atomic/DockerITContainer.java | 2 +-
.../impl/ShardingSphereMultiProxyClusterContainer.java | 2 +-
.../it/rewrite/engine/scenario/EncryptSQLRewriterIT.java | 2 +-
.../it/rewrite/engine/scenario/ShardingSQLRewriterIT.java | 2 +-
.../test/natived/jdbc/databases/MySQLTest.java | 2 +-
.../test/natived/proxy/databases/MySQLTest.java | 4 ++--
12 files changed, 28 insertions(+), 28 deletions(-)
diff --git
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLTimestamp2BinlogProtocolValueTest.java
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLTimestamp2BinlogProtocolValueTest.java
index 219849627de..58f8457415a 100644
---
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLTimestamp2BinlogProtocolValueTest.java
+++
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLTimestamp2BinlogProtocolValueTest.java
@@ -52,7 +52,7 @@ class MySQLTimestamp2BinlogProtocolValueTest {
@Test
void assertReadWithoutFraction() {
- int currentSeconds = Long.valueOf(System.currentTimeMillis() /
1000L).intValue();
+ int currentSeconds = (int) (System.currentTimeMillis() / 1000L);
when(byteBuf.readInt()).thenReturn(currentSeconds);
assertThat(new MySQLTimestamp2BinlogProtocolValue().read(columnDef,
payload), is(new Timestamp(currentSeconds * 1000L)));
}
@@ -61,8 +61,8 @@ class MySQLTimestamp2BinlogProtocolValueTest {
void assertReadWithFraction() {
columnDef.setColumnMeta(1);
long currentTimeMillis = 1678795614082L;
- int currentSeconds = Long.valueOf(currentTimeMillis /
1000L).intValue();
- int currentMilliseconds = Long.valueOf(currentTimeMillis %
100L).intValue();
+ int currentSeconds = (int) (System.currentTimeMillis() / 1000L);
+ int currentMilliseconds = (int) (currentTimeMillis % 100L);
when(payload.readInt1()).thenReturn(currentMilliseconds);
when(byteBuf.readInt()).thenReturn(currentSeconds);
assertThat("currentTimeMillis:" + currentTimeMillis, new
MySQLTimestamp2BinlogProtocolValue().read(columnDef, payload), is(new
Timestamp(currentSeconds * 1000L + currentMilliseconds * 10L)));
diff --git
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLTimestampBinlogProtocolValueTest.java
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLTimestampBinlogProtocolValueTest.java
index 6f128c8d291..37b6737e271 100644
---
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLTimestampBinlogProtocolValueTest.java
+++
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/column/value/time/MySQLTimestampBinlogProtocolValueTest.java
@@ -42,7 +42,7 @@ class MySQLTimestampBinlogProtocolValueTest {
@Test
void assertRead() {
- int currentSeconds = Long.valueOf(System.currentTimeMillis() /
1000L).intValue();
+ int currentSeconds = (int) (System.currentTimeMillis() / 1000L);
when(payload.readInt4()).thenReturn(currentSeconds);
assertThat(new MySQLTimestampBinlogProtocolValue().read(columnDef,
payload),
is(DateTimeFormatterFactory.getStandardFormatter().format(new
Timestamp(currentSeconds * 1000L).toLocalDateTime())));
diff --git
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/payload/MySQLPacketPayloadTest.java
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/payload/MySQLPacketPayloadTest.java
index 753f0a531a4..346c67767b7 100644
---
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/payload/MySQLPacketPayloadTest.java
+++
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/payload/MySQLPacketPayloadTest.java
@@ -151,23 +151,23 @@ class MySQLPacketPayloadTest {
@Test
void assertWriteIntLenencWithTwoBytes() {
- new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeIntLenenc(Double.valueOf(Math.pow(2D,
16D)).longValue() - 1L);
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeIntLenenc((long) (Math.pow(2D, 16D)) - 1L);
verify(byteBuf).writeByte(0xfc);
- verify(byteBuf).writeShortLE(Double.valueOf(Math.pow(2D,
16D)).intValue() - 1);
+ verify(byteBuf).writeShortLE((int) (Math.pow(2D, 16D)) - 1);
}
@Test
void assertWriteIntLenencWithThreeBytes() {
- new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeIntLenenc(Double.valueOf(Math.pow(2D,
24D)).longValue() - 1L);
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeIntLenenc((long) (Math.pow(2D, 24D)) - 1L);
verify(byteBuf).writeByte(0xfd);
- verify(byteBuf).writeMediumLE(Double.valueOf(Math.pow(2D,
24D)).intValue() - 1);
+ verify(byteBuf).writeMediumLE((int) (Math.pow(2D, 24D)) - 1);
}
@Test
void assertWriteIntLenencWithFourBytes() {
- new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeIntLenenc(Double.valueOf(Math.pow(2D,
25D)).longValue() - 1L);
+ new MySQLPacketPayload(byteBuf,
StandardCharsets.UTF_8).writeIntLenenc((long) (Math.pow(2D, 25D)) - 1L);
verify(byteBuf).writeByte(0xfe);
- verify(byteBuf).writeLongLE(Double.valueOf(Math.pow(2D,
25D)).intValue() - 1L);
+ verify(byteBuf).writeLongLE((int) (Math.pow(2D, 25D)) - 1L);
}
@Test
diff --git
a/kernel/transaction/type/base/seata-at/src/test/java/org/apache/shardingsphere/transaction/base/seata/at/SeataATShardingSphereTransactionManagerTest.java
b/kernel/transaction/type/base/seata-at/src/test/java/org/apache/shardingsphere/transaction/base/seata/at/SeataATShardingSphereTransactionManagerTest.java
index 0d3f9a921ff..ae9f3507905 100644
---
a/kernel/transaction/type/base/seata-at/src/test/java/org/apache/shardingsphere/transaction/base/seata/at/SeataATShardingSphereTransactionManagerTest.java
+++
b/kernel/transaction/type/base/seata-at/src/test/java/org/apache/shardingsphere/transaction/base/seata/at/SeataATShardingSphereTransactionManagerTest.java
@@ -163,11 +163,11 @@ class SeataATShardingSphereTransactionManagerTest {
}
private void assertResult(final Class<?> requestClass, final Class<?>
responseClass) {
- assertTrue(requestQueue.stream().anyMatch(each -> each instanceof
RegisterTMRequest));
- assertTrue(requestQueue.stream().anyMatch(each -> each instanceof
RegisterRMRequest));
+
assertTrue(requestQueue.stream().anyMatch(RegisterTMRequest.class::isInstance));
+
assertTrue(requestQueue.stream().anyMatch(RegisterRMRequest.class::isInstance));
assertTrue(requestQueue.stream().anyMatch(each ->
requestClass.equals(each.getClass())));
- assertTrue(responseQueue.stream().anyMatch(each -> each instanceof
RegisterTMResponse));
- assertTrue(responseQueue.stream().anyMatch(each -> each instanceof
RegisterRMResponse));
+
assertTrue(responseQueue.stream().anyMatch(RegisterTMResponse.class::isInstance));
+
assertTrue(responseQueue.stream().anyMatch(RegisterRMResponse.class::isInstance));
assertTrue(responseQueue.stream().anyMatch(each ->
responseClass.equals(each.getClass())));
while (!requestQueue.isEmpty()) {
Object requestPackage = requestQueue.poll();
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java
index 3f912b1fa88..300b9fdca2d 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/ProxyConfigurationLoaderTest.java
@@ -73,11 +73,11 @@ class ProxyConfigurationLoaderTest {
assertDataSourceConfiguration(actual.getDataSources().get("ds_0"),
"jdbc:mysql://127.0.0.1:3306/ds_0");
assertDataSourceConfiguration(actual.getDataSources().get("ds_1"),
"jdbc:mysql://127.0.0.1:3306/ds_1");
Optional<YamlShardingRuleConfiguration> shardingRuleConfig =
actual.getRules().stream()
- .filter(each -> each instanceof
YamlShardingRuleConfiguration).findFirst().map(each ->
(YamlShardingRuleConfiguration) each);
+
.filter(YamlShardingRuleConfiguration.class::isInstance).findFirst().map(YamlShardingRuleConfiguration.class::cast);
assertTrue(shardingRuleConfig.isPresent());
assertShardingRuleConfiguration(shardingRuleConfig.get());
assertFalse(
- actual.getRules().stream().filter(each -> each instanceof
YamlEncryptRuleConfiguration).findFirst().map(each ->
(YamlEncryptRuleConfiguration) each).isPresent());
+
actual.getRules().stream().filter(YamlEncryptRuleConfiguration.class::isInstance).findFirst().map(YamlEncryptRuleConfiguration.class::cast).isPresent());
}
private void assertShardingRuleConfiguration(final
YamlShardingRuleConfiguration actual) {
@@ -96,11 +96,11 @@ class ProxyConfigurationLoaderTest {
assertDataSourceConfiguration(actual.getDataSources().get("write_ds"),
"jdbc:mysql://127.0.0.1:3306/write_ds");
assertDataSourceConfiguration(actual.getDataSources().get("read_ds_0"),
"jdbc:mysql://127.0.0.1:3306/read_ds_0");
assertDataSourceConfiguration(actual.getDataSources().get("read_ds_1"),
"jdbc:mysql://127.0.0.1:3306/read_ds_1");
- assertFalse(actual.getRules().stream().filter(each -> each instanceof
YamlShardingRuleConfiguration).findFirst().map(each ->
(YamlShardingRuleConfiguration) each).isPresent());
+
assertFalse(actual.getRules().stream().filter(YamlShardingRuleConfiguration.class::isInstance).findFirst().map(YamlShardingRuleConfiguration.class::cast).isPresent());
assertFalse(
actual.getRules().stream().filter(each -> each instanceof
YamlEncryptRuleConfiguration).findFirst().map(each ->
(YamlEncryptRuleConfiguration) each).isPresent());
Optional<YamlReadwriteSplittingRuleConfiguration> ruleConfig =
actual.getRules().stream()
- .filter(each -> each instanceof
YamlReadwriteSplittingRuleConfiguration).findFirst().map(each ->
(YamlReadwriteSplittingRuleConfiguration) each);
+
.filter(YamlReadwriteSplittingRuleConfiguration.class::isInstance).findFirst().map(YamlReadwriteSplittingRuleConfiguration.class::cast);
assertTrue(ruleConfig.isPresent());
for (YamlReadwriteSplittingDataSourceGroupRuleConfiguration each :
ruleConfig.get().getDataSourceGroups().values()) {
assertReadwriteSplittingRuleConfiguration(each);
@@ -117,9 +117,9 @@ class ProxyConfigurationLoaderTest {
assertThat(actual.getDataSources().size(), is(1));
assertDataSourceConfiguration(actual.getDataSources().get("ds_0"),
"jdbc:mysql://127.0.0.1:3306/encrypt_ds");
assertFalse(actual.getRules().stream()
- .filter(each -> each instanceof
YamlShardingRuleConfiguration).findFirst().map(each ->
(YamlShardingRuleConfiguration) each).isPresent());
+
.filter(YamlShardingRuleConfiguration.class::isInstance).findFirst().map(YamlShardingRuleConfiguration.class::cast).isPresent());
Optional<YamlEncryptRuleConfiguration> encryptRuleConfig =
actual.getRules().stream()
- .filter(each -> each instanceof
YamlEncryptRuleConfiguration).findFirst().map(each ->
(YamlEncryptRuleConfiguration) each);
+
.filter(YamlEncryptRuleConfiguration.class::isInstance).findFirst().map(YamlEncryptRuleConfiguration.class::cast);
assertTrue(encryptRuleConfig.isPresent());
assertEncryptRuleConfiguration(encryptRuleConfig.get());
}
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
index 678790a3eab..d5f323838d8 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/config/yaml/swapper/YamlProxyConfigurationSwapperTest.java
@@ -97,7 +97,7 @@ class YamlProxyConfigurationSwapperTest {
}
private Optional<AuthorityRuleConfiguration>
findAuthorityRuleConfiguration(final Collection<RuleConfiguration>
globalRuleConfigs) {
- return globalRuleConfigs.stream().filter(each -> each instanceof
AuthorityRuleConfiguration).findFirst().map(each ->
(AuthorityRuleConfiguration) each);
+ return
globalRuleConfigs.stream().filter(AuthorityRuleConfiguration.class::isInstance).findFirst().map(AuthorityRuleConfiguration.class::cast);
}
private void assertProxyConfigurationProps(final ProxyConfiguration
proxyConfig) {
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/DockerITContainer.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/DockerITContainer.java
index caf74c366ae..8f99a402943 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/DockerITContainer.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/DockerITContainer.java
@@ -53,7 +53,7 @@ public abstract class DockerITContainer extends
GenericContainer<DockerITContain
}
private void startDependencies() {
- Collection<DockerITContainer> dependencies =
getDependencies().stream().filter(each -> each instanceof
DockerITContainer).map(each -> (DockerITContainer)
each).collect(Collectors.toList());
+ Collection<DockerITContainer> dependencies =
getDependencies().stream().filter(DockerITContainer.class::isInstance).map(DockerITContainer.class::cast).collect(Collectors.toList());
dependencies.stream().filter(each ->
!each.isCreated()).forEach(GenericContainer::start);
dependencies.stream()
.filter(each -> {
diff --git
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereMultiProxyClusterContainer.java
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereMultiProxyClusterContainer.java
index 3bd4be35ebe..bb41ba9e757 100644
---
a/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereMultiProxyClusterContainer.java
+++
b/test/e2e/env/src/test/java/org/apache/shardingsphere/test/e2e/env/container/atomic/adapter/impl/ShardingSphereMultiProxyClusterContainer.java
@@ -79,7 +79,7 @@ public final class ShardingSphereMultiProxyClusterContainer
implements AdapterCo
@Override
public Collection<ITContainer> getContainers() {
- return proxyClusterContainers.stream().map(each -> (ITContainer)
each).collect(Collectors.toList());
+ return
proxyClusterContainers.stream().map(ITContainer.class::cast).collect(Collectors.toList());
}
private static class RandomDataSourceAdapter implements DataSource {
diff --git
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java
index b2d127dce06..1e314b7a83a 100644
---
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java
+++
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/EncryptSQLRewriterIT.java
@@ -100,7 +100,7 @@ class EncryptSQLRewriterIT extends SQLRewriterIT {
@Override
protected void mockRules(final Collection<ShardingSphereRule> rules, final
String schemaName, final SQLStatement sqlStatement) {
- Optional<SingleRule> singleRule = rules.stream().filter(each -> each
instanceof SingleRule).map(each -> (SingleRule) each).findFirst();
+ Optional<SingleRule> singleRule =
rules.stream().filter(SingleRule.class::isInstance).map(SingleRule.class::cast).findFirst();
if (singleRule.isPresent() && !(sqlStatement instanceof
CreateTableStatement)) {
singleRule.get().getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).put("encrypt_ds",
schemaName, "t_account");
singleRule.get().getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).put("encrypt_ds",
schemaName, "t_account_bak");
diff --git
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java
index 95d2ba30b54..0c939beff96 100644
---
a/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java
+++
b/test/it/rewriter/src/test/java/org/apache/shardingsphere/test/it/rewrite/engine/scenario/ShardingSQLRewriterIT.java
@@ -56,7 +56,7 @@ class ShardingSQLRewriterIT extends SQLRewriterIT {
@Override
protected void mockRules(final Collection<ShardingSphereRule> rules, final
String schemaName, final SQLStatement sqlStatement) {
- Optional<SingleRule> singleRule = rules.stream().filter(each -> each
instanceof SingleRule).map(each -> (SingleRule) each).findFirst();
+ Optional<SingleRule> singleRule =
rules.stream().filter(SingleRule.class::isInstance).map(SingleRule.class::cast).findFirst();
if (singleRule.isPresent() && !(sqlStatement instanceof
CreateTableStatement)) {
singleRule.get().getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).put("db",
schemaName, "t_single");
singleRule.get().getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).put("db",
schemaName, "t_single_extend");
diff --git
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java
index 33c9912e817..876c2659d2f 100644
---
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java
+++
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/MySQLTest.java
@@ -111,7 +111,7 @@ class MySQLTest {
@SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"})
private DataSource createDataSource() throws SQLException {
-
Awaitility.await().atMost(Duration.ofMinutes(1L)).ignoreExceptionsMatching(e ->
e instanceof CommunicationsException).until(() -> {
+
Awaitility.await().atMost(Duration.ofMinutes(1L)).ignoreExceptionsMatching(CommunicationsException.class::isInstance).until(()
-> {
openConnection().close();
return true;
});
diff --git
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/MySQLTest.java
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/MySQLTest.java
index f5a767f76db..ee9c6942972 100644
---
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/MySQLTest.java
+++
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/proxy/databases/MySQLTest.java
@@ -56,7 +56,7 @@ class MySQLTest {
@BeforeAll
static void beforeAll() throws SQLException {
-
Awaitility.await().atMost(Duration.ofSeconds(30L)).ignoreExceptionsMatching(e
-> e instanceof CommunicationsException).until(() -> {
+
Awaitility.await().atMost(Duration.ofSeconds(30L)).ignoreExceptionsMatching(CommunicationsException.class::isInstance).until(()
-> {
openConnection("root", "yourStrongPassword123!",
"jdbc:mysql://127.0.0.1:" + MYSQL_CONTAINER.getMappedPort(3306))
.close();
return true;
@@ -70,7 +70,7 @@ class MySQLTest {
}
String absolutePath =
Paths.get("src/test/resources/test-native/yaml/proxy/databases/mysql").toAbsolutePath().toString();
proxyTestingServer = new ProxyTestingServer(absolutePath);
-
Awaitility.await().atMost(Duration.ofSeconds(30L)).ignoreExceptionsMatching(e
-> e instanceof CommunicationsException).until(() -> {
+
Awaitility.await().atMost(Duration.ofSeconds(30L)).ignoreExceptionsMatching(CommunicationsException.class::isInstance).until(()
-> {
openConnection("root", "root", "jdbc:mysql://127.0.0.1:" +
proxyTestingServer.getProxyPort()).close();
return true;
});