You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2022/12/22 12:23:21 UTC
[shardingsphere] branch master updated: Refactor BatchPreparedStatementExecutorTest (#23039)
This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 14d9038756a Refactor BatchPreparedStatementExecutorTest (#23039)
14d9038756a is described below
commit 14d9038756a22e8c88cb5e38bfb8d93a0cb8566d
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Dec 22 20:23:06 2022 +0800
Refactor BatchPreparedStatementExecutorTest (#23039)
---
.../batch/BatchPreparedStatementExecutorTest.java | 30 +++++++++-------------
1 file changed, 12 insertions(+), 18 deletions(-)
diff --git a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java
index 4e4911b8fdf..32801c266c6 100644
--- a/jdbc/core/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java
+++ b/jdbc/core/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java
@@ -18,22 +18,22 @@
package org.apache.shardingsphere.driver.executor.batch;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.infra.database.DefaultDatabase;
-import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
-import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupContext;
-import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor;
import org.apache.shardingsphere.driver.executor.AbstractBaseExecutorTest;
import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
-import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
+import org.apache.shardingsphere.infra.database.DefaultDatabase;
+import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup;
+import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupContext;
import org.apache.shardingsphere.infra.executor.sql.context.ExecutionUnit;
import org.apache.shardingsphere.infra.executor.sql.context.SQLUnit;
-import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup;
+import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
+import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit;
+import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor;
+import org.apache.shardingsphere.infra.util.eventbus.EventBusContext;
import org.junit.Test;
import org.mockito.Mock;
+import org.mockito.internal.util.reflection.InstanceField;
-import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
@@ -145,16 +145,10 @@ public final class BatchPreparedStatementExecutorTest extends AbstractBaseExecut
setFields(executionGroups, batchExecutionUnits);
}
- @SneakyThrows(ReflectiveOperationException.class)
+ @SneakyThrows(NoSuchFieldException.class)
private void setFields(final Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups, final Collection<BatchExecutionUnit> batchExecutionUnits) {
- Field field = BatchPreparedStatementExecutor.class.getDeclaredField("executionGroupContext");
- field.setAccessible(true);
- field.set(actual, new ExecutionGroupContext<>(executionGroups));
- field = BatchPreparedStatementExecutor.class.getDeclaredField("batchExecutionUnits");
- field.setAccessible(true);
- field.set(actual, batchExecutionUnits);
- field = BatchPreparedStatementExecutor.class.getDeclaredField("batchCount");
- field.setAccessible(true);
- field.set(actual, 2);
+ new InstanceField(BatchPreparedStatementExecutor.class.getDeclaredField("executionGroupContext"), actual).set(new ExecutionGroupContext<>(executionGroups));
+ new InstanceField(BatchPreparedStatementExecutor.class.getDeclaredField("batchExecutionUnits"), actual).set(batchExecutionUnits);
+ new InstanceField(BatchPreparedStatementExecutor.class.getDeclaredField("batchCount"), actual).set(2);
}
}