diff --git a/ecosystem/error-handler/type/dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/fixture/DingtalkInternalController.java b/ecosystem/error-handler/type/dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/fixture/DingtalkInternalController.java
index 1dd005ba9a..08572cacf2 100644
--- a/ecosystem/error-handler/type/dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/fixture/DingtalkInternalController.java
+++ b/ecosystem/error-handler/type/dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/fixture/DingtalkInternalController.java
@@ -31,7 +31,6 @@
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
-import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
@@ -53,7 +52,7 @@ public final class DingtalkInternalController implements RestfulController {
* @param timestamp timestamp
* @param sign sign
* @param body body
- * @return send Result
+ * @return send result
*/
@SneakyThrows
@Mapping(method = Http.POST, path = "/send")
@@ -64,7 +63,7 @@ public String send(@Param(name = "access_token", source = ParamSource.QUERY) fin
if (!ACCESS_TOKEN.equals(accessToken)) {
return GsonFactory.getGson().toJson(ImmutableMap.of("errcode", 300001, "errmsg", "token is not exist"));
}
- String content = Map.class.cast(body.get("text")).get("content").toString();
+ String content = ((Map) body.get("text")).get("content").toString();
if (!content.startsWith(KEYWORD)) {
return GsonFactory.getGson().toJson(ImmutableMap.of("errcode", 310000, "errmsg", "keywords not in content, more: [https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq]"));
}
@@ -78,11 +77,11 @@ public String send(@Param(name = "access_token", source = ParamSource.QUERY) fin
return GsonFactory.getGson().toJson(ImmutableMap.of("errcode", 0, "errmsg", "ok"));
}
- private String sign(final Long timestamp) throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException {
+ private String sign(final Long timestamp) throws NoSuchAlgorithmException, InvalidKeyException {
String stringToSign = timestamp + "\n" + SECRET;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(SECRET.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
byte[] signData = mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
- return new String(Base64.getEncoder().encode(signData), StandardCharsets.UTF_8.name());
+ return new String(Base64.getEncoder().encode(signData), StandardCharsets.UTF_8);
}
}
diff --git a/ecosystem/error-handler/type/email/pom.xml b/ecosystem/error-handler/type/email/pom.xml
index 82932ddd94..78853f3cae 100644
--- a/ecosystem/error-handler/type/email/pom.xml
+++ b/ecosystem/error-handler/type/email/pom.xml
@@ -32,6 +32,13 @@
${project.parent.version}
+
+ org.apache.shardingsphere.elasticjob
+ elasticjob-test-util
+ ${project.parent.version}
+ test
+
+
com.sun.mail
javax.mail
diff --git a/ecosystem/error-handler/type/email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java b/ecosystem/error-handler/type/email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java
index 78a1cf3597..3c216f262d 100644
--- a/ecosystem/error-handler/type/email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java
+++ b/ecosystem/error-handler/type/email/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/email/EmailJobErrorHandlerTest.java
@@ -20,8 +20,8 @@
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.read.ListAppender;
-import lombok.SneakyThrows;
import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandler;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
@@ -33,9 +33,9 @@
import javax.mail.Address;
import javax.mail.Message;
+import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
-import java.lang.reflect.Field;
import java.util.List;
import java.util.Properties;
@@ -81,11 +81,10 @@ void assertHandleExceptionWithMessagingException() {
}
@Test
- @SneakyThrows
- void assertHandleExceptionSucceedInSendingEmail() {
+ void assertHandleExceptionSucceedInSendingEmail() throws MessagingException {
EmailJobErrorHandler emailJobErrorHandler = getEmailJobErrorHandler(createConfigurationProperties());
setUpMockSession(session);
- setFieldValue(emailJobErrorHandler, "session", session);
+ ReflectionUtils.setFieldValue(emailJobErrorHandler, "session", session);
Throwable cause = new RuntimeException("test");
String jobName = "test_job";
when(session.getTransport()).thenReturn(transport);
@@ -102,17 +101,10 @@ private EmailJobErrorHandler getEmailJobErrorHandler(final Properties props) {
private void setUpMockSession(final Session session) {
Properties props = new Properties();
- setFieldValue(session, "props", props);
+ ReflectionUtils.setFieldValue(session, "props", props);
when(session.getProperties()).thenReturn(props);
}
- @SneakyThrows
- private void setFieldValue(final Object target, final String fieldName, final Object fieldValue) {
- Field field = target.getClass().getDeclaredField(fieldName);
- field.setAccessible(true);
- field.set(target, fieldValue);
- }
-
private Properties createConfigurationProperties() {
Properties result = new Properties();
result.setProperty(EmailPropertiesConstants.HOST, "localhost");
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/api/listener/DistributeOnceElasticJobListenerTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/api/listener/DistributeOnceElasticJobListenerTest.java
index eebcfcf16f..8b4b57f30b 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/api/listener/DistributeOnceElasticJobListenerTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/api/listener/DistributeOnceElasticJobListenerTest.java
@@ -24,7 +24,7 @@
import org.apache.shardingsphere.elasticjob.kernel.api.listener.fixture.ElasticJobListenerCaller;
import org.apache.shardingsphere.elasticjob.kernel.api.listener.fixture.TestDistributeOnceElasticJobListener;
import org.apache.shardingsphere.elasticjob.kernel.internal.guarantee.GuaranteeService;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/integrate/BaseIntegrateTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/integrate/BaseIntegrateTest.java
index 55b803da28..3a8b340c6c 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/integrate/BaseIntegrateTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/integrate/BaseIntegrateTest.java
@@ -26,7 +26,7 @@
import org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl.ScheduleJobBootstrap;
import org.apache.shardingsphere.elasticjob.kernel.internal.election.LeaderService;
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/annotation/integrate/BaseAnnotationTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/annotation/integrate/BaseAnnotationTest.java
index 3b729764cb..483bf963c6 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/annotation/integrate/BaseAnnotationTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/annotation/integrate/BaseAnnotationTest.java
@@ -27,7 +27,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.annotation.JobAnnotationBuilder;
import org.apache.shardingsphere.elasticjob.kernel.internal.election.LeaderService;
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/config/ConfigurationServiceTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/config/ConfigurationServiceTest.java
index 3b445d3ee6..62d8c8e150 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/config/ConfigurationServiceTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/config/ConfigurationServiceTest.java
@@ -24,7 +24,7 @@
import org.apache.shardingsphere.elasticjob.infra.yaml.YamlEngine;
import org.apache.shardingsphere.elasticjob.kernel.fixture.YamlConstants;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/config/RescheduleListenerManagerTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/config/RescheduleListenerManagerTest.java
index dd2006808d..a59224e5fe 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/config/RescheduleListenerManagerTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/config/RescheduleListenerManagerTest.java
@@ -22,7 +22,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobScheduleController;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent;
import org.junit.jupiter.api.BeforeEach;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/election/ElectionListenerManagerTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/election/ElectionListenerManagerTest.java
index eca460720a..448ec37ce3 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/election/ElectionListenerManagerTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/election/ElectionListenerManagerTest.java
@@ -23,7 +23,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.server.ServerService;
import org.apache.shardingsphere.elasticjob.kernel.internal.server.ServerStatus;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent.Type;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/election/LeaderServiceTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/election/LeaderServiceTest.java
index d5729780cc..4b37afff8e 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/election/LeaderServiceTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/election/LeaderServiceTest.java
@@ -23,7 +23,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobScheduleController;
import org.apache.shardingsphere.elasticjob.kernel.internal.server.ServerService;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/executor/JobFacadeTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/executor/JobFacadeTest.java
index 2ab96dba5a..b84c0191d2 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/executor/JobFacadeTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/executor/JobFacadeTest.java
@@ -28,7 +28,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.sharding.ExecutionContextService;
import org.apache.shardingsphere.elasticjob.kernel.internal.sharding.ExecutionService;
import org.apache.shardingsphere.elasticjob.kernel.internal.sharding.ShardingService;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.tracing.JobTracingEventBus;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/executor/error/handler/JobErrorHandlerReloaderTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/executor/error/handler/JobErrorHandlerReloaderTest.java
index 741b22113f..cbf0899268 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/executor/error/handler/JobErrorHandlerReloaderTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/executor/error/handler/JobErrorHandlerReloaderTest.java
@@ -17,17 +17,16 @@
package org.apache.shardingsphere.elasticjob.kernel.internal.executor.error.handler;
-import lombok.SneakyThrows;
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.error.handler.JobErrorHandler;
import org.apache.shardingsphere.elasticjob.kernel.internal.executor.error.handler.general.IgnoreJobErrorHandler;
import org.apache.shardingsphere.elasticjob.kernel.internal.executor.error.handler.general.LogJobErrorHandler;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import java.lang.reflect.Field;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
@@ -59,8 +58,8 @@ void assertReload() {
JobConfiguration jobConfig = JobConfiguration.newBuilder("job", 1).jobErrorHandlerType("IGNORE").build();
try (JobErrorHandlerReloader jobErrorHandlerReloader = new JobErrorHandlerReloader(jobConfig)) {
when(jobErrorHandler.getType()).thenReturn("mock");
- setField(jobErrorHandlerReloader, "jobErrorHandler", jobErrorHandler);
- setField(jobErrorHandlerReloader, "props", new Properties());
+ ReflectionUtils.setFieldValue(jobErrorHandlerReloader, "jobErrorHandler", jobErrorHandler);
+ ReflectionUtils.setFieldValue(jobErrorHandlerReloader, "props", new Properties());
String newJobErrorHandlerType = "LOG";
JobConfiguration newJobConfig = JobConfiguration.newBuilder("job", 1).jobErrorHandlerType(newJobErrorHandlerType).build();
jobErrorHandlerReloader.reloadIfNecessary(newJobConfig);
@@ -86,20 +85,9 @@ void assertUnnecessaryToReload() {
void assertShutdown() {
JobConfiguration jobConfig = JobConfiguration.newBuilder("job", 1).jobErrorHandlerType("IGNORE").build();
try (JobErrorHandlerReloader jobErrorHandlerReloader = new JobErrorHandlerReloader(jobConfig)) {
- setField(jobErrorHandlerReloader, "jobErrorHandler", jobErrorHandler);
+ ReflectionUtils.setFieldValue(jobErrorHandlerReloader, "jobErrorHandler", jobErrorHandler);
jobErrorHandlerReloader.close();
verify(jobErrorHandler).close();
}
}
-
- @SneakyThrows
- private void setField(final Object target, final String fieldName, final Object value) {
- Field field = target.getClass().getDeclaredField(fieldName);
- boolean originAccessible = field.isAccessible();
- if (!originAccessible) {
- field.setAccessible(true);
- }
- field.set(target, value);
- field.setAccessible(originAccessible);
- }
}
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/executor/threadpool/ExecutorServiceReloaderTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/executor/threadpool/ExecutorServiceReloaderTest.java
index e2bc5e5cd7..dff7117bf4 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/executor/threadpool/ExecutorServiceReloaderTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/executor/threadpool/ExecutorServiceReloaderTest.java
@@ -17,14 +17,13 @@
package org.apache.shardingsphere.elasticjob.kernel.internal.executor.threadpool;
-import lombok.SneakyThrows;
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import java.lang.reflect.Field;
import java.util.concurrent.ExecutorService;
import static org.hamcrest.CoreMatchers.is;
@@ -54,8 +53,8 @@ void assertInitialize() {
@Test
void assertReload() {
ExecutorServiceReloader executorServiceReloader = new ExecutorServiceReloader(JobConfiguration.newBuilder("job", 1).jobExecutorThreadPoolSizeProviderType("SINGLE_THREAD").build());
- setField(executorServiceReloader, "jobExecutorThreadPoolSizeProviderType", "mock");
- setField(executorServiceReloader, "executorService", mockExecutorService);
+ ReflectionUtils.setFieldValue(executorServiceReloader, "jobExecutorThreadPoolSizeProviderType", "mock");
+ ReflectionUtils.setFieldValue(executorServiceReloader, "executorService", mockExecutorService);
JobConfiguration jobConfig = JobConfiguration.newBuilder("job", 1).build();
executorServiceReloader.reloadIfNecessary(jobConfig);
verify(mockExecutorService).shutdown();
@@ -80,19 +79,8 @@ void assertUnnecessaryToReload() {
@Test
void assertShutdown() {
ExecutorServiceReloader executorServiceReloader = new ExecutorServiceReloader(JobConfiguration.newBuilder("job", 1).jobExecutorThreadPoolSizeProviderType("SINGLE_THREAD").build());
- setField(executorServiceReloader, "executorService", mockExecutorService);
+ ReflectionUtils.setFieldValue(executorServiceReloader, "executorService", mockExecutorService);
executorServiceReloader.close();
verify(mockExecutorService).shutdown();
}
-
- @SneakyThrows
- private void setField(final Object target, final String fieldName, final Object value) {
- Field field = target.getClass().getDeclaredField(fieldName);
- boolean originAccessible = field.isAccessible();
- if (!originAccessible) {
- field.setAccessible(true);
- }
- field.set(target, value);
- field.setAccessible(originAccessible);
- }
}
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/failover/FailoverListenerManagerTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/failover/FailoverListenerManagerTest.java
index ed83b72c79..a5dfafa4c5 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/failover/FailoverListenerManagerTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/failover/FailoverListenerManagerTest.java
@@ -28,7 +28,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.sharding.ExecutionService;
import org.apache.shardingsphere.elasticjob.kernel.internal.sharding.ShardingService;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent.Type;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEventListener;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/failover/FailoverServiceTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/failover/FailoverServiceTest.java
index 700d42121d..5d2c1a0a07 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/failover/FailoverServiceTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/failover/FailoverServiceTest.java
@@ -24,7 +24,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobScheduleController;
import org.apache.shardingsphere.elasticjob.kernel.internal.sharding.ShardingService;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/guarantee/GuaranteeListenerManagerTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/guarantee/GuaranteeListenerManagerTest.java
index b51f851ea4..8de42c1832 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/guarantee/GuaranteeListenerManagerTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/guarantee/GuaranteeListenerManagerTest.java
@@ -20,7 +20,7 @@
import org.apache.shardingsphere.elasticjob.infra.listener.ElasticJobListener;
import org.apache.shardingsphere.elasticjob.kernel.api.listener.AbstractDistributeOnceElasticJobListener;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent.Type;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEventListener;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/guarantee/GuaranteeServiceTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/guarantee/GuaranteeServiceTest.java
index b57d475955..0db9a27296 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/guarantee/GuaranteeServiceTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/guarantee/GuaranteeServiceTest.java
@@ -22,7 +22,7 @@
import org.apache.shardingsphere.elasticjob.kernel.api.listener.AbstractDistributeOnceElasticJobListener;
import org.apache.shardingsphere.elasticjob.kernel.internal.config.ConfigurationService;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/instance/InstanceServiceTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/instance/InstanceServiceTest.java
index 7fbb551c63..ae01059cda 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/instance/InstanceServiceTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/instance/InstanceServiceTest.java
@@ -21,7 +21,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
import org.apache.shardingsphere.elasticjob.kernel.internal.server.ServerService;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/instance/ShutdownListenerManagerTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/instance/ShutdownListenerManagerTest.java
index d6bcf4146f..da8c0f7624 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/instance/ShutdownListenerManagerTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/instance/ShutdownListenerManagerTest.java
@@ -22,7 +22,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobScheduleController;
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.SchedulerFacade;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent.Type;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/listener/ListenerManagerTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/listener/ListenerManagerTest.java
index 3b24e005f8..e952653c42 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/listener/ListenerManagerTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/listener/ListenerManagerTest.java
@@ -26,7 +26,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.sharding.ShardingListenerManager;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
import org.apache.shardingsphere.elasticjob.kernel.internal.trigger.TriggerListenerManager;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/listener/RegistryCenterConnectionStateListenerTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/listener/RegistryCenterConnectionStateListenerTest.java
index 2eaacd6992..ce55241397 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/listener/RegistryCenterConnectionStateListenerTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/listener/RegistryCenterConnectionStateListenerTest.java
@@ -24,7 +24,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.server.ServerService;
import org.apache.shardingsphere.elasticjob.kernel.internal.sharding.ExecutionService;
import org.apache.shardingsphere.elasticjob.kernel.internal.sharding.ShardingService;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.listener.ConnectionStateChangedEventListener.State;
import org.junit.jupiter.api.BeforeEach;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/reconcile/ReconcileServiceTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/reconcile/ReconcileServiceTest.java
index c086172ac4..ea91034a79 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/reconcile/ReconcileServiceTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/reconcile/ReconcileServiceTest.java
@@ -23,7 +23,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.config.ConfigurationService;
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
import org.apache.shardingsphere.elasticjob.kernel.internal.sharding.ShardingService;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/schedule/JobRegistryTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/schedule/JobRegistryTest.java
index c9e8f46c83..04e7fe28b3 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/schedule/JobRegistryTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/schedule/JobRegistryTest.java
@@ -19,7 +19,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.sharding.JobInstance;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/schedule/JobScheduleControllerTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/schedule/JobScheduleControllerTest.java
index 7638f6eae9..b85551f921 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/schedule/JobScheduleControllerTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/schedule/JobScheduleControllerTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.elasticjob.kernel.internal.schedule;
import org.apache.shardingsphere.elasticjob.infra.exception.JobSystemException;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/schedule/SchedulerFacadeTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/schedule/SchedulerFacadeTest.java
index b97a253e8c..a63e34cae6 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/schedule/SchedulerFacadeTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/schedule/SchedulerFacadeTest.java
@@ -20,7 +20,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.sharding.JobInstance;
import org.apache.shardingsphere.elasticjob.kernel.internal.election.LeaderService;
import org.apache.shardingsphere.elasticjob.kernel.internal.sharding.ShardingService;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/server/ServerServiceTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/server/ServerServiceTest.java
index 5352f9f69f..d808119bb5 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/server/ServerServiceTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/server/ServerServiceTest.java
@@ -21,7 +21,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobScheduleController;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/setup/SetUpFacadeTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/setup/SetUpFacadeTest.java
index 0a9393b62e..c61434c7e8 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/setup/SetUpFacadeTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/setup/SetUpFacadeTest.java
@@ -24,7 +24,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.reconcile.ReconcileService;
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
import org.apache.shardingsphere.elasticjob.kernel.internal.server.ServerService;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ExecutionContextServiceTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ExecutionContextServiceTest.java
index 08d77ff142..04f2c930a2 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ExecutionContextServiceTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ExecutionContextServiceTest.java
@@ -23,7 +23,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.config.ConfigurationService;
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ExecutionServiceTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ExecutionServiceTest.java
index b67b695994..e66d54fdcc 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ExecutionServiceTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ExecutionServiceTest.java
@@ -22,7 +22,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.config.ConfigurationService;
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/MonitorExecutionListenerManagerTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/MonitorExecutionListenerManagerTest.java
index b492175833..48101f36c3 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/MonitorExecutionListenerManagerTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/MonitorExecutionListenerManagerTest.java
@@ -19,7 +19,7 @@
import org.apache.shardingsphere.elasticjob.kernel.fixture.YamlConstants;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent.Type;
import org.junit.jupiter.api.BeforeEach;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ShardingListenerManagerTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ShardingListenerManagerTest.java
index 2006512257..06f8f75f36 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ShardingListenerManagerTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ShardingListenerManagerTest.java
@@ -24,7 +24,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobScheduleController;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent.Type;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ShardingServiceTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ShardingServiceTest.java
index df8c4f550e..f0d9c9eaa0 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ShardingServiceTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/sharding/ShardingServiceTest.java
@@ -26,7 +26,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobScheduleController;
import org.apache.shardingsphere.elasticjob.kernel.internal.server.ServerService;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/BaseSnapshotServiceTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/BaseSnapshotServiceTest.java
index abf59a8761..023a62c148 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/BaseSnapshotServiceTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/BaseSnapshotServiceTest.java
@@ -23,7 +23,7 @@
import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.kernel.api.bootstrap.impl.ScheduleJobBootstrap;
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/SnapshotServiceDisableTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/SnapshotServiceDisableTest.java
index 62c5a02fbe..1024fa4bd4 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/SnapshotServiceDisableTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/snapshot/SnapshotServiceDisableTest.java
@@ -17,12 +17,11 @@
package org.apache.shardingsphere.elasticjob.kernel.internal.snapshot;
-import lombok.SneakyThrows;
import org.apache.shardingsphere.elasticjob.kernel.fixture.job.DetailedFooJob;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.junit.jupiter.api.Test;
import java.io.IOException;
-import java.lang.reflect.Field;
import java.net.ServerSocket;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -41,21 +40,15 @@ void assertMonitorWithDumpCommand() {
@Test
void assertPortInvalid() {
- assertThrows(IllegalArgumentException.class, () -> {
- SnapshotService snapshotService = new SnapshotService(getREG_CENTER(), -1);
- snapshotService.listen();
- });
+ assertThrows(IllegalArgumentException.class, () -> new SnapshotService(getREG_CENTER(), -1).listen());
}
@Test
- @SneakyThrows
- void assertListenException() {
+ void assertListenException() throws IOException {
ServerSocket serverSocket = new ServerSocket(9898);
SnapshotService snapshotService = new SnapshotService(getREG_CENTER(), 9898);
snapshotService.listen();
serverSocket.close();
- Field field = snapshotService.getClass().getDeclaredField("serverSocket");
- field.setAccessible(true);
- assertNull(field.get(snapshotService));
+ assertNull(ReflectionUtils.getFieldValue(snapshotService, "serverSocket"));
}
}
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/storage/JobNodeStorageTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/storage/JobNodeStorageTest.java
index 2d43bcb628..33e69ac903 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/storage/JobNodeStorageTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/storage/JobNodeStorageTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.elasticjob.kernel.internal.storage;
import org.apache.shardingsphere.elasticjob.kernel.internal.listener.ListenerNotifierManager;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.base.transaction.TransactionOperation;
import org.apache.shardingsphere.elasticjob.reg.exception.RegException;
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/trigger/TriggerListenerManagerTest.java b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/trigger/TriggerListenerManagerTest.java
index bb070e647a..811bbce8eb 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/trigger/TriggerListenerManagerTest.java
+++ b/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/internal/trigger/TriggerListenerManagerTest.java
@@ -21,7 +21,7 @@
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobRegistry;
import org.apache.shardingsphere.elasticjob.kernel.internal.schedule.JobScheduleController;
import org.apache.shardingsphere.elasticjob.kernel.internal.storage.JobNodeStorage;
-import org.apache.shardingsphere.elasticjob.kernel.util.ReflectionUtils;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent;
import org.junit.jupiter.api.BeforeEach;
diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java
index 131479fd03..50cecb141b 100644
--- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java
+++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java
@@ -25,6 +25,7 @@
import org.apache.curator.test.KillSession;
import org.apache.shardingsphere.elasticjob.reg.base.ElectionCandidate;
import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -32,7 +33,6 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import java.lang.reflect.Field;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
@@ -74,7 +74,7 @@ void assertContend() throws Exception {
KillSession.kill(client.getZookeeperClient().getZooKeeper());
service.stop();
blockUntilCondition(() -> hasLeadership(anotherService));
- ((CountDownLatch) getFieldValue(anotherService, "leaderLatch")).countDown();
+ ((CountDownLatch) ReflectionUtils.getFieldValue(anotherService, "leaderLatch")).countDown();
blockUntilCondition(() -> !hasLeadership(anotherService));
anotherService.stop();
verify(anotherElectionCandidate, atLeastOnce()).startLeadership();
@@ -87,13 +87,6 @@ private void blockUntilCondition(final Supplier condition) {
@SneakyThrows
private boolean hasLeadership(final ZookeeperElectionService zookeeperElectionService) {
- return ((LeaderSelector) getFieldValue(zookeeperElectionService, "leaderSelector")).hasLeadership();
- }
-
- @SneakyThrows
- private Object getFieldValue(final Object target, final String fieldName) {
- Field field = target.getClass().getDeclaredField(fieldName);
- field.setAccessible(true);
- return field.get(target);
+ return ((LeaderSelector) ReflectionUtils.getFieldValue(zookeeperElectionService, "leaderSelector")).hasLeadership();
}
}
diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterForAuthTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterForAuthTest.java
index 34fa53a612..95592c85c8 100644
--- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterForAuthTest.java
+++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterForAuthTest.java
@@ -20,7 +20,7 @@
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryOneTime;
-import org.apache.shardingsphere.elasticjob.reg.zookeeper.util.ZookeeperRegistryCenterTestUtil;
+import org.apache.shardingsphere.elasticjob.reg.zookeeper.env.RegistryCenterEnvironmentPreparer;
import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.apache.zookeeper.KeeperException.NoAuthException;
import org.junit.jupiter.api.AfterAll;
@@ -49,7 +49,7 @@ static void setUp() {
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(5000);
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
zkRegCenter.init();
- ZookeeperRegistryCenterTestUtil.persist(zkRegCenter);
+ RegistryCenterEnvironmentPreparer.persist(zkRegCenter);
}
@AfterAll
@@ -59,22 +59,25 @@ static void tearDown() {
@Test
void assertInitWithDigestSuccess() throws Exception {
- CuratorFramework client = CuratorFrameworkFactory.builder()
- .connectString(EMBED_TESTING_SERVER.getConnectionString())
- .retryPolicy(new RetryOneTime(2000))
- .authorization("digest", "digest:password".getBytes()).build();
- client.start();
- client.blockUntilConnected();
- assertThat(client.getData().forPath("/" + ZookeeperRegistryCenterForAuthTest.class.getName() + "/test/deep/nested"), is("deepNested".getBytes()));
+ try (
+ CuratorFramework client = CuratorFrameworkFactory.builder()
+ .connectString(EMBED_TESTING_SERVER.getConnectionString())
+ .retryPolicy(new RetryOneTime(2000))
+ .authorization("digest", "digest:password".getBytes()).build()) {
+ client.start();
+ client.blockUntilConnected();
+ assertThat(client.getData().forPath("/" + ZookeeperRegistryCenterForAuthTest.class.getName() + "/test/deep/nested"), is("deepNested".getBytes()));
+ }
}
@Test
void assertInitWithDigestFailure() {
assertThrows(NoAuthException.class, () -> {
- CuratorFramework client = CuratorFrameworkFactory.newClient(EMBED_TESTING_SERVER.getConnectionString(), new RetryOneTime(2000));
- client.start();
- client.blockUntilConnected();
- client.getData().forPath("/" + ZookeeperRegistryCenterForAuthTest.class.getName() + "/test/deep/nested");
+ try (CuratorFramework client = CuratorFrameworkFactory.newClient(EMBED_TESTING_SERVER.getConnectionString(), new RetryOneTime(2000))) {
+ client.start();
+ client.blockUntilConnected();
+ client.getData().forPath("/" + ZookeeperRegistryCenterForAuthTest.class.getName() + "/test/deep/nested");
+ }
});
}
}
diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterListenerTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterListenerTest.java
index 1b1657b417..205861e812 100644
--- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterListenerTest.java
+++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterListenerTest.java
@@ -22,7 +22,7 @@
import org.apache.curator.framework.recipes.cache.CuratorCache;
import org.apache.curator.framework.recipes.cache.CuratorCacheListener;
import org.apache.curator.framework.state.ConnectionStateListener;
-import org.apache.shardingsphere.elasticjob.reg.zookeeper.util.ZookeeperRegistryCenterTestUtil;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -66,8 +66,8 @@ class ZookeeperRegistryCenterListenerTest {
@BeforeEach
void setUp() {
regCenter = new ZookeeperRegistryCenter(null);
- ZookeeperRegistryCenterTestUtil.setFieldValue(regCenter, "caches", caches);
- ZookeeperRegistryCenterTestUtil.setFieldValue(regCenter, "client", client);
+ ReflectionUtils.setFieldValue(regCenter, "caches", caches);
+ ReflectionUtils.setFieldValue(regCenter, "client", client);
}
@Test
@@ -140,11 +140,11 @@ void testRemoveConnStateListenerEmptyListeners() {
@SuppressWarnings("unchecked")
private Map> getConnStateListeners() {
- return (Map>) ZookeeperRegistryCenterTestUtil.getFieldValue(regCenter, "connStateListeners");
+ return (Map>) ReflectionUtils.getFieldValue(regCenter, "connStateListeners");
}
@SuppressWarnings("unchecked")
private Map> getDataListeners() {
- return (Map>) ZookeeperRegistryCenterTestUtil.getFieldValue(regCenter, "dataListeners");
+ return (Map>) ReflectionUtils.getFieldValue(regCenter, "dataListeners");
}
}
diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterModifyTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterModifyTest.java
index 10eda57b7c..d4a1c9c5fc 100644
--- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterModifyTest.java
+++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterModifyTest.java
@@ -20,7 +20,7 @@
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryOneTime;
-import org.apache.shardingsphere.elasticjob.reg.zookeeper.util.ZookeeperRegistryCenterTestUtil;
+import org.apache.shardingsphere.elasticjob.reg.zookeeper.env.RegistryCenterEnvironmentPreparer;
import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
@@ -49,7 +49,7 @@ static void setUp() {
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
zkRegCenter.init();
- ZookeeperRegistryCenterTestUtil.persist(zkRegCenter);
+ RegistryCenterEnvironmentPreparer.persist(zkRegCenter);
}
@AfterAll
@@ -91,35 +91,37 @@ void assertPersistEphemeral() throws Exception {
void assertPersistSequential() throws Exception {
assertThat(zkRegCenter.persistSequential("/sequential/test_sequential", "test_value"), startsWith("/sequential/test_sequential"));
assertThat(zkRegCenter.persistSequential("/sequential/test_sequential", "test_value"), startsWith("/sequential/test_sequential"));
- CuratorFramework client = CuratorFrameworkFactory.newClient(EMBED_TESTING_SERVER.getConnectionString(), new RetryOneTime(2000));
- client.start();
- client.blockUntilConnected();
- List actual = client.getChildren().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
- assertThat(actual.size(), is(2));
- for (String each : actual) {
- assertThat(each, startsWith("test_sequential"));
- assertThat(zkRegCenter.get("/sequential/" + each), startsWith("test_value"));
+ try (CuratorFramework client = CuratorFrameworkFactory.newClient(EMBED_TESTING_SERVER.getConnectionString(), new RetryOneTime(2000))) {
+ client.start();
+ client.blockUntilConnected();
+ List actual = client.getChildren().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
+ assertThat(actual.size(), is(2));
+ for (String each : actual) {
+ assertThat(each, startsWith("test_sequential"));
+ assertThat(zkRegCenter.get("/sequential/" + each), startsWith("test_value"));
+ }
+ zkRegCenter.remove("/sequential");
+ assertFalse(zkRegCenter.isExisted("/sequential"));
}
- zkRegCenter.remove("/sequential");
- assertFalse(zkRegCenter.isExisted("/sequential"));
}
@Test
void assertPersistEphemeralSequential() throws Exception {
zkRegCenter.persistEphemeralSequential("/sequential/test_ephemeral_sequential");
zkRegCenter.persistEphemeralSequential("/sequential/test_ephemeral_sequential");
- CuratorFramework client = CuratorFrameworkFactory.newClient(EMBED_TESTING_SERVER.getConnectionString(), new RetryOneTime(2000));
- client.start();
- client.blockUntilConnected();
- List actual = client.getChildren().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
- assertThat(actual.size(), is(2));
- for (String each : actual) {
- assertThat(each, startsWith("test_ephemeral_sequential"));
+ try (CuratorFramework client = CuratorFrameworkFactory.newClient(EMBED_TESTING_SERVER.getConnectionString(), new RetryOneTime(2000))) {
+ client.start();
+ client.blockUntilConnected();
+ List actual = client.getChildren().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
+ assertThat(actual.size(), is(2));
+ for (String each : actual) {
+ assertThat(each, startsWith("test_ephemeral_sequential"));
+ }
+ zkRegCenter.close();
+ actual = client.getChildren().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
+ assertTrue(actual.isEmpty());
+ zkRegCenter.init();
}
- zkRegCenter.close();
- actual = client.getChildren().forPath("/" + ZookeeperRegistryCenterModifyTest.class.getName() + "/sequential");
- assertTrue(actual.isEmpty());
- zkRegCenter.init();
}
@Test
diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithCacheTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithCacheTest.java
index 5a27306906..59eb61cf83 100644
--- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithCacheTest.java
+++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithCacheTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.elasticjob.reg.zookeeper;
-import org.apache.shardingsphere.elasticjob.reg.zookeeper.util.ZookeeperRegistryCenterTestUtil;
+import org.apache.shardingsphere.elasticjob.reg.zookeeper.env.RegistryCenterEnvironmentPreparer;
import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
@@ -42,7 +42,7 @@ static void setUp() {
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
zkRegCenter.init();
- ZookeeperRegistryCenterTestUtil.persist(zkRegCenter);
+ RegistryCenterEnvironmentPreparer.persist(zkRegCenter);
zkRegCenter.addCacheData("/test");
}
diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithoutCacheTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithoutCacheTest.java
index 99fa81960c..c370073a85 100644
--- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithoutCacheTest.java
+++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterQueryWithoutCacheTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.elasticjob.reg.zookeeper;
-import org.apache.shardingsphere.elasticjob.reg.zookeeper.util.ZookeeperRegistryCenterTestUtil;
+import org.apache.shardingsphere.elasticjob.reg.zookeeper.env.RegistryCenterEnvironmentPreparer;
import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
@@ -47,7 +47,7 @@ static void setUp() {
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
zkRegCenter.init();
- ZookeeperRegistryCenterTestUtil.persist(zkRegCenter);
+ RegistryCenterEnvironmentPreparer.persist(zkRegCenter);
zkRegCenter.addCacheData("/other");
}
diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterTransactionTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterTransactionTest.java
index d520728109..b08795a04b 100644
--- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterTransactionTest.java
+++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterTransactionTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.elasticjob.reg.zookeeper;
import org.apache.shardingsphere.elasticjob.reg.base.transaction.TransactionOperation;
-import org.apache.shardingsphere.elasticjob.reg.zookeeper.util.ZookeeperRegistryCenterTestUtil;
+import org.apache.shardingsphere.elasticjob.reg.zookeeper.env.RegistryCenterEnvironmentPreparer;
import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.apache.zookeeper.KeeperException;
import org.junit.jupiter.api.BeforeAll;
@@ -51,7 +51,7 @@ static void setUp() {
@BeforeEach
void setup() {
- ZookeeperRegistryCenterTestUtil.persist(zkRegCenter);
+ RegistryCenterEnvironmentPreparer.persist(zkRegCenter);
}
@Test
diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterWatchTest.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterWatchTest.java
index 8318bc4f9d..1ead5e3f15 100644
--- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterWatchTest.java
+++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperRegistryCenterWatchTest.java
@@ -19,7 +19,7 @@
import org.apache.curator.utils.ThreadUtils;
import org.apache.shardingsphere.elasticjob.reg.listener.DataChangedEvent;
-import org.apache.shardingsphere.elasticjob.reg.zookeeper.util.ZookeeperRegistryCenterTestUtil;
+import org.apache.shardingsphere.elasticjob.reg.zookeeper.env.RegistryCenterEnvironmentPreparer;
import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
@@ -49,7 +49,7 @@ static void setUp() {
zkRegCenter = new ZookeeperRegistryCenter(ZOOKEEPER_CONFIGURATION);
ZOOKEEPER_CONFIGURATION.setConnectionTimeoutMilliseconds(30000);
zkRegCenter.init();
- ZookeeperRegistryCenterTestUtil.persist(zkRegCenter);
+ RegistryCenterEnvironmentPreparer.persist(zkRegCenter);
}
@AfterAll
diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/env/RegistryCenterEnvironmentPreparer.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/env/RegistryCenterEnvironmentPreparer.java
new file mode 100644
index 0000000000..1e86d4e932
--- /dev/null
+++ b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/env/RegistryCenterEnvironmentPreparer.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.elasticjob.reg.zookeeper.env;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
+
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class RegistryCenterEnvironmentPreparer {
+
+ /**
+ * Persist the data to registry center.
+ *
+ * @param registryCenter ZooKeeper registry center
+ */
+ public static void persist(final ZookeeperRegistryCenter registryCenter) {
+ registryCenter.persist("/test", "test");
+ registryCenter.persist("/test/deep/nested", "deepNested");
+ registryCenter.persist("/test/child", "child");
+ }
+}
diff --git a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/util/ZookeeperRegistryCenterTestUtil.java b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/util/ZookeeperRegistryCenterTestUtil.java
deleted file mode 100644
index dc16f0dd99..0000000000
--- a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/util/ZookeeperRegistryCenterTestUtil.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.elasticjob.reg.zookeeper.util;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import lombok.SneakyThrows;
-import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
-
-import java.lang.reflect.Field;
-
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ZookeeperRegistryCenterTestUtil {
-
- /**
- * Persist the data to registry center.
- *
- * @param zookeeperRegistryCenter registry center
- */
- public static void persist(final ZookeeperRegistryCenter zookeeperRegistryCenter) {
- zookeeperRegistryCenter.persist("/test", "test");
- zookeeperRegistryCenter.persist("/test/deep/nested", "deepNested");
- zookeeperRegistryCenter.persist("/test/child", "child");
- }
-
- /**
- * Set field value use reflection.
- *
- * @param target target object
- * @param fieldName field name
- * @param fieldValue field value
- */
- @SneakyThrows
- public static void setFieldValue(final Object target, final String fieldName, final Object fieldValue) {
- Field field = target.getClass().getDeclaredField(fieldName);
- field.setAccessible(true);
- field.set(target, fieldValue);
- }
-
- /**
- * Get field value use reflection.
- *
- * @param target target object
- * @param fieldName field name
- * @return field value
- */
- @SneakyThrows
- public static Object getFieldValue(final Object target, final String fieldName) {
- Field field = target.getClass().getDeclaredField(fieldName);
- field.setAccessible(true);
- return field.get(target);
- }
-}
diff --git a/restful/src/main/java/org/apache/shardingsphere/elasticjob/restful/NettyRestfulServiceConfiguration.java b/restful/src/main/java/org/apache/shardingsphere/elasticjob/restful/NettyRestfulServiceConfiguration.java
index 9a68787261..4b4414b1fc 100644
--- a/restful/src/main/java/org/apache/shardingsphere/elasticjob/restful/NettyRestfulServiceConfiguration.java
+++ b/restful/src/main/java/org/apache/shardingsphere/elasticjob/restful/NettyRestfulServiceConfiguration.java
@@ -32,27 +32,26 @@
/**
* Configuration for {@link NettyRestfulService}.
*/
-@Getter
@RequiredArgsConstructor
+@Getter
+@Setter
public final class NettyRestfulServiceConfiguration {
+ private final List filterInstances = new LinkedList<>();
+
+ private final List controllerInstances = new LinkedList<>();
+
+ private final Map, ExceptionHandler extends Throwable>> exceptionHandlers = new HashMap<>();
+
private final int port;
- @Setter
private String host;
/**
* If trailing slash sensitive, /foo/bar
is not equals to /foo/bar/
.
*/
- @Setter
private boolean trailingSlashSensitive;
- private final List filterInstances = new LinkedList<>();
-
- private final List controllerInstances = new LinkedList<>();
-
- private final Map, ExceptionHandler extends Throwable>> exceptionHandlers = new HashMap<>();
-
/**
* Add instances of {@link Filter}.
*
diff --git a/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobSpringBootTest.java b/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobSpringBootTest.java
index 2cd365349d..1937eacd02 100644
--- a/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobSpringBootTest.java
+++ b/spring/boot-starter/src/test/java/org/apache/shardingsphere/elasticjob/spring/boot/job/ElasticJobSpringBootTest.java
@@ -28,6 +28,7 @@
import org.apache.shardingsphere.elasticjob.spring.boot.reg.ZookeeperProperties;
import org.apache.shardingsphere.elasticjob.spring.boot.tracing.TracingProperties;
import org.apache.shardingsphere.elasticjob.test.util.EmbedTestingServer;
+import org.apache.shardingsphere.elasticjob.test.util.ReflectionUtils;
import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.BeforeAll;
@@ -39,7 +40,6 @@
import org.springframework.test.context.ActiveProfiles;
import javax.sql.DataSource;
-import java.lang.reflect.Field;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Collection;
@@ -147,36 +147,26 @@ void assertJobScheduleCreation() {
}
@Test
- void assertOneOffJobBootstrapBeanName() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
+ void assertOneOffJobBootstrapBeanName() {
assertNotNull(applicationContext);
- OneOffJobBootstrap customTestJobBootstrap =
- applicationContext.getBean("customTestJobBean", OneOffJobBootstrap.class);
+ OneOffJobBootstrap customTestJobBootstrap = applicationContext.getBean("customTestJobBean", OneOffJobBootstrap.class);
assertNotNull(customTestJobBootstrap);
- Field jobSchedulerField = customTestJobBootstrap.getClass().getDeclaredField("jobScheduler");
- jobSchedulerField.setAccessible(true);
- Collection extraConfigurations =
- ((JobScheduler) jobSchedulerField.get(customTestJobBootstrap)).getJobConfig().getExtraConfigurations();
- assertThat(extraConfigurations.size(), is(0));
- OneOffJobBootstrap printTestJobBootstrap =
- applicationContext.getBean("printTestJobBean", OneOffJobBootstrap.class);
- jobSchedulerField = printTestJobBootstrap.getClass().getDeclaredField("jobScheduler");
- jobSchedulerField.setAccessible(true);
- extraConfigurations =
- ((JobScheduler) jobSchedulerField.get(printTestJobBootstrap)).getJobConfig().getExtraConfigurations();
- assertThat(extraConfigurations.size(), is(1));
+ Collection extraConfigs = ((JobScheduler) ReflectionUtils.getFieldValue(customTestJobBootstrap, "jobScheduler")).getJobConfig().getExtraConfigurations();
+ assertThat(extraConfigs.size(), is(0));
+ OneOffJobBootstrap printTestJobBootstrap = applicationContext.getBean("printTestJobBean", OneOffJobBootstrap.class);
+ extraConfigs = ((JobScheduler) ReflectionUtils.getFieldValue(printTestJobBootstrap, "jobScheduler")).getJobConfig().getExtraConfigurations();
+ assertThat(extraConfigs.size(), is(1));
}
@Test
void assertDefaultBeanNameWithClassJob() {
assertNotNull(applicationContext);
- assertNotNull(applicationContext.getBean("defaultBeanNameClassJobScheduleJobBootstrap",
- ScheduleJobBootstrap.class));
+ assertNotNull(applicationContext.getBean("defaultBeanNameClassJobScheduleJobBootstrap", ScheduleJobBootstrap.class));
}
@Test
void assertDefaultBeanNameWithTypeJob() {
assertNotNull(applicationContext);
- assertNotNull(applicationContext.getBean("defaultBeanNameTypeJobScheduleJobBootstrap",
- ScheduleJobBootstrap.class));
+ assertNotNull(applicationContext.getBean("defaultBeanNameTypeJobScheduleJobBootstrap", ScheduleJobBootstrap.class));
}
}
diff --git a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/util/ReflectionUtils.java b/test/util/src/main/java/org/apache/shardingsphere/elasticjob/test/util/ReflectionUtils.java
similarity index 61%
rename from kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/util/ReflectionUtils.java
rename to test/util/src/main/java/org/apache/shardingsphere/elasticjob/test/util/ReflectionUtils.java
index cc93be2bec..68e9e07d08 100644
--- a/kernel/src/test/java/org/apache/shardingsphere/elasticjob/kernel/util/ReflectionUtils.java
+++ b/test/util/src/main/java/org/apache/shardingsphere/elasticjob/test/util/ReflectionUtils.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.elasticjob.kernel.util;
+package org.apache.shardingsphere.elasticjob.test.util;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -29,6 +29,25 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ReflectionUtils {
+ /**
+ * Get field value.
+ *
+ * @param target target object
+ * @param fieldName field name
+ * @return field value
+ */
+ @SneakyThrows(ReflectiveOperationException.class)
+ public static Object getFieldValue(final Object target, final String fieldName) {
+ Field field = target.getClass().getDeclaredField(fieldName);
+ boolean originAccessible = field.isAccessible();
+ if (!originAccessible) {
+ field.setAccessible(true);
+ }
+ Object result = field.get(target);
+ field.setAccessible(originAccessible);
+ return result;
+ }
+
/**
* Set field value.
*
@@ -36,11 +55,15 @@ public final class ReflectionUtils {
* @param fieldName field name
* @param fieldValue field value
*/
- @SneakyThrows
+ @SneakyThrows(ReflectiveOperationException.class)
public static void setFieldValue(final Object target, final String fieldName, final Object fieldValue) {
Field field = target.getClass().getDeclaredField(fieldName);
- field.setAccessible(true);
+ boolean originAccessible = field.isAccessible();
+ if (!originAccessible) {
+ field.setAccessible(true);
+ }
field.set(target, fieldValue);
+ field.setAccessible(originAccessible);
}
/**
@@ -50,10 +73,14 @@ public static void setFieldValue(final Object target, final String fieldName, fi
* @param fieldName field name
* @param fieldValue field value
*/
- @SneakyThrows
+ @SneakyThrows(ReflectiveOperationException.class)
public static void setSuperclassFieldValue(final Object target, final String fieldName, final Object fieldValue) {
Field field = target.getClass().getSuperclass().getDeclaredField(fieldName);
- field.setAccessible(true);
+ boolean originAccessible = field.isAccessible();
+ if (!originAccessible) {
+ field.setAccessible(true);
+ }
field.set(target, fieldValue);
+ field.setAccessible(originAccessible);
}
}