diff --git a/agent/hippo4j-agent-bootstrap/pom.xml b/agent/hippo4j-agent-bootstrap/pom.xml
index 8504850d..ad6fb4d5 100644
--- a/agent/hippo4j-agent-bootstrap/pom.xml
+++ b/agent/hippo4j-agent-bootstrap/pom.xml
@@ -31,60 +31,60 @@
hippo4j-threadpool-agent
-
- maven-shade-plugin
-
-
- package
-
- shade
-
-
- false
- true
- true
- true
-
-
-
- ${premain.class}
- ${can.redefine.classes}
- ${can.retransform.classes}
-
-
-
-
-
- *:gson
- io.grpc:*
- io.netty:*
- io.opencensus:*
- com.google.*:*
- com.google.guava:guava
- org.checkerframework:checker-compat-qual
- org.codehaus.mojo:animal-sniffer-annotations
- io.perfmark:*
- org.slf4j:*
-
-
-
-
- ${shade.net.bytebuddy.source}
- ${shade.net.bytebuddy.target}
-
-
-
-
- net.bytebuddy:byte-buddy
-
- META-INF/versions/9/module-info.class
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
maven-antrun-plugin
@@ -122,4 +122,4 @@
-
\ No newline at end of file
+
diff --git a/agent/hippo4j-agent-core/pom.xml b/agent/hippo4j-agent-core/pom.xml
index ee49874b..d6c48270 100644
--- a/agent/hippo4j-agent-core/pom.xml
+++ b/agent/hippo4j-agent-core/pom.xml
@@ -105,68 +105,68 @@
-
- maven-shade-plugin
-
-
- package
-
- shade
-
-
-
-
- net.bytebuddy:byte-buddy:jar:
- com.google.errorprone:error_prone_annotations:jar:
- com.google.code.findbugs:jsr305:jar:
- com.google.android:annotations:jar:
- com.google.api.grpc:proto-google-common-protos:jar:
- org.checkerframework:checker-compat-qual:jar:
- org.codehaus.mojo:animal-sniffer-annotations:jar:
-
-
-
-
- ${shade.com.google.source}
- ${shade.com.google.target}
-
-
- ${shade.io.grpc.source}
- ${shade.io.grpc.target}
-
-
- ${shade.io.netty.source}
- ${shade.io.netty.target}
-
-
- ${shade.io.opencensus.source}
- ${shade.io.opencensus.target}
-
-
- ${shade.io.perfmark.source}
- ${shade.io.perfmark.target}
-
-
- ${shade.org.slf4j.source}
- ${shade.org.slf4j.target}
-
-
-
-
- com.google.protobuf:protobuf-java
-
- google/protobuf/*.proto
- google/protobuf/compiler/*.proto
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
\ No newline at end of file
+
diff --git a/agent/hippo4j-agent-plugin/pom.xml b/agent/hippo4j-agent-plugin/pom.xml
index 4a3f7954..cf2d7a05 100644
--- a/agent/hippo4j-agent-plugin/pom.xml
+++ b/agent/hippo4j-agent-plugin/pom.xml
@@ -48,29 +48,29 @@
-
- maven-shade-plugin
-
-
- package
-
- shade
-
-
- false
- true
- true
- true
-
-
- ${shade.net.bytebuddy.source}
- ${shade.net.bytebuddy.target}
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
maven-antrun-plugin
@@ -115,4 +115,4 @@
-
\ No newline at end of file
+
diff --git a/agent/hippo4j-agent-plugin/spring-plugins/pom.xml b/agent/hippo4j-agent-plugin/spring-plugins/pom.xml
index 42b725b5..ee4bf946 100644
--- a/agent/hippo4j-agent-plugin/spring-plugins/pom.xml
+++ b/agent/hippo4j-agent-plugin/spring-plugins/pom.xml
@@ -13,7 +13,7 @@
pom
- spring-boot-1x-plugin
+
spring-boot-2x-plugin
spring-plugin-common
@@ -22,4 +22,4 @@
UTF-8
/..
-
\ No newline at end of file
+
diff --git a/dependencies/pom.xml b/dependencies/pom.xml
index af91cef3..3d05caea 100644
--- a/dependencies/pom.xml
+++ b/dependencies/pom.xml
@@ -20,11 +20,11 @@
3.12.4
3.0.5
2.6.12
- 1.7.7
- 1.8.4
+ 2.0.9
+ 1.10.13
2.0.4
3.4.2
- 2.3.2.RELEASE
+ 3.0.13
1.9.1
2.2.4.RELEASE
0.7.3
@@ -32,7 +32,7 @@
2.2.2
4.1.56.Final
6.8.17
- 9.0.55
+ 10.1.16
5.1.0
2.2.6.RELEASE
3.1.0
@@ -218,4 +218,4 @@
-
\ No newline at end of file
+
diff --git a/examples/threadpool-example/config/pom.xml b/examples/threadpool-example/config/pom.xml
index c6255187..fbb9821d 100644
--- a/examples/threadpool-example/config/pom.xml
+++ b/examples/threadpool-example/config/pom.xml
@@ -21,7 +21,7 @@
config-zookeeper
config-consul-spring-boot
config-etcd
- config-nacos-spring-boot-1x
- config-apollo-spring-boot-1x
+
+
-
\ No newline at end of file
+
diff --git a/examples/threadpool-example/example-core/src/main/java/cn/hippo4j/example/core/inittest/RunStateHandlerTest.java b/examples/threadpool-example/example-core/src/main/java/cn/hippo4j/example/core/inittest/RunStateHandlerTest.java
index df1bc329..f50025b7 100644
--- a/examples/threadpool-example/example-core/src/main/java/cn/hippo4j/example/core/inittest/RunStateHandlerTest.java
+++ b/examples/threadpool-example/example-core/src/main/java/cn/hippo4j/example/core/inittest/RunStateHandlerTest.java
@@ -17,12 +17,12 @@
package cn.hippo4j.example.core.inittest;
+import jakarta.annotation.PostConstruct;
+import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.stereotype.Component;
-import javax.annotation.PostConstruct;
-import javax.annotation.Resource;
import java.util.Random;
import java.util.concurrent.Executor;
import java.util.concurrent.SynchronousQueue;
diff --git a/examples/threadpool-example/server/adapter-kafka/src/main/java/cn/hippo4j/springboot/starter/adapter/kafka/example/MessageProduce.java b/examples/threadpool-example/server/adapter-kafka/src/main/java/cn/hippo4j/springboot/starter/adapter/kafka/example/MessageProduce.java
index 133889d5..61d44371 100644
--- a/examples/threadpool-example/server/adapter-kafka/src/main/java/cn/hippo4j/springboot/starter/adapter/kafka/example/MessageProduce.java
+++ b/examples/threadpool-example/server/adapter-kafka/src/main/java/cn/hippo4j/springboot/starter/adapter/kafka/example/MessageProduce.java
@@ -17,6 +17,7 @@
package cn.hippo4j.springboot.starter.adapter.kafka.example;
+import jakarta.annotation.PostConstruct;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
@@ -24,7 +25,6 @@ import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
-import javax.annotation.PostConstruct;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
diff --git a/examples/threadpool-example/server/server/pom.xml b/examples/threadpool-example/server/server/pom.xml
index f1972f2b..2b7c1222 100644
--- a/examples/threadpool-example/server/server/pom.xml
+++ b/examples/threadpool-example/server/server/pom.xml
@@ -14,6 +14,7 @@
+
cn.hippo4j
hippo4j-example-core
@@ -47,10 +48,10 @@
spring-boot-starter-web
-
- org.apache.tomcat.embed
- tomcat-embed-core
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
com.diffplug.spotless
spotless-maven-plugin
diff --git a/starters/threadpool/adapter/web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/WebThreadPoolHandlerConfiguration.java b/starters/threadpool/adapter/web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/WebThreadPoolHandlerConfiguration.java
index 263317f7..f7c44f22 100644
--- a/starters/threadpool/adapter/web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/WebThreadPoolHandlerConfiguration.java
+++ b/starters/threadpool/adapter/web/src/main/java/cn/hippo4j/springboot/starter/adapter/web/WebThreadPoolHandlerConfiguration.java
@@ -17,14 +17,15 @@
package cn.hippo4j.springboot.starter.adapter.web;
+import cn.hippo4j.adapter.web.WebThreadPoolRunStateHandler;
import cn.hippo4j.adapter.web.jetty.DefaultJettyWebThreadPoolHandler;
import cn.hippo4j.adapter.web.jetty.JettyWebThreadPoolHandlerAdapt;
import cn.hippo4j.adapter.web.tomcat.DefaultTomcatWebThreadPoolHandler;
import cn.hippo4j.adapter.web.tomcat.TomcatWebThreadPoolHandlerAdapt;
import cn.hippo4j.adapter.web.undertow.DefaultUndertowWebThreadPoolHandler;
-import cn.hippo4j.adapter.web.WebThreadPoolRunStateHandler;
import cn.hippo4j.adapter.web.undertow.UndertowWebThreadPoolHandlerAdapt;
import io.undertow.Undertow;
+import jakarta.servlet.Servlet;
import org.apache.catalina.startup.Tomcat;
import org.apache.coyote.UpgradeProtocol;
import org.eclipse.jetty.server.Server;
@@ -42,8 +43,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.xnio.SslClientAuthMode;
-import javax.servlet.Servlet;
-
/**
* Web Thread Pool Handler Configuration
**/
diff --git a/starters/threadpool/pom.xml b/starters/threadpool/pom.xml
index 253da58c..1210cffa 100644
--- a/starters/threadpool/pom.xml
+++ b/starters/threadpool/pom.xml
@@ -15,6 +15,6 @@
server
adapter
monitor
- config-spring-boot-1x
+
diff --git a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/event/ApplicationContentPostProcessor.java b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/event/ApplicationContentPostProcessor.java
index 3dd1adf2..5ce4dac3 100644
--- a/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/event/ApplicationContentPostProcessor.java
+++ b/starters/threadpool/server/src/main/java/cn/hippo4j/springboot/starter/event/ApplicationContentPostProcessor.java
@@ -18,11 +18,11 @@
package cn.hippo4j.springboot.starter.event;
import cn.hippo4j.springboot.starter.core.ClientWorker;
+import jakarta.annotation.Resource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
-import javax.annotation.Resource;
import java.util.concurrent.atomic.AtomicBoolean;
/**
diff --git a/starters/threadpool/server/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/starters/threadpool/server/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
new file mode 100644
index 00000000..bdc22b64
--- /dev/null
+++ b/starters/threadpool/server/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -0,0 +1 @@
+cn.hippo4j.springboot.starter.config.DynamicThreadPoolAutoConfiguration
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/DynamicThreadPoolExecutorTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/DynamicThreadPoolExecutorTest.java
deleted file mode 100644
index 275cd915..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/DynamicThreadPoolExecutorTest.java
+++ /dev/null
@@ -1,177 +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 cn.hippo4j.core.executor;
-
-import cn.hippo4j.common.toolkit.ThreadUtil;
-import org.junit.Assert;
-import org.junit.Test;
-import org.springframework.core.task.TaskDecorator;
-
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.RejectedExecutionHandler;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * test for {@link DynamicThreadPoolExecutor}
- */
-public class DynamicThreadPoolExecutorTest {
-
- @Test
- public void testRedundancyHandler() {
- RejectedExecutionHandler handler = new ThreadPoolExecutor.DiscardOldestPolicy();
-
- DynamicThreadPoolExecutor executor = new DynamicThreadPoolExecutor(
- 1, 1, 1000L, TimeUnit.MILLISECONDS,
- 1000L, true, 1000L,
- new ArrayBlockingQueue<>(1), "test", Thread::new, handler);
-
- Assert.assertEquals(handler, executor.getRedundancyHandler());
- handler = new ThreadPoolExecutor.AbortPolicy();
- executor.setRedundancyHandler(handler);
- Assert.assertEquals(handler, executor.getRedundancyHandler());
- }
-
- @Test
- public void testTaskDecorator() {
- DynamicThreadPoolExecutor executor = new DynamicThreadPoolExecutor(
- 1, 1, 1000L, TimeUnit.MILLISECONDS,
- 1000L, true, 1000L,
- new ArrayBlockingQueue<>(1), "test", Thread::new, new ThreadPoolExecutor.DiscardOldestPolicy());
-
- Assert.assertNull(executor.getTaskDecorator());
- TaskDecorator decorator = runnable -> runnable;
- executor.setTaskDecorator(decorator);
- Assert.assertEquals(decorator, executor.getTaskDecorator());
-
- decorator = runnable -> runnable;
- executor.setTaskDecorator(decorator);
- Assert.assertEquals(decorator, executor.getTaskDecorator());
- }
-
- @Test
- public void testExecuteTimeOut() {
- DynamicThreadPoolExecutor executor = new DynamicThreadPoolExecutor(
- 1, 1, 1000L, TimeUnit.MILLISECONDS,
- 1000L, true, 1000L,
- new ArrayBlockingQueue<>(1), "test", Thread::new, new ThreadPoolExecutor.DiscardOldestPolicy());
-
- Assert.assertEquals(1000L, executor.getExecuteTimeOut().longValue());
- executor.setExecuteTimeOut(500L);
- Assert.assertEquals(500L, executor.getExecuteTimeOut().longValue());
- }
-
- @Test
- public void testDestroyWhenWaitForTask() {
- DynamicThreadPoolExecutor executor = new DynamicThreadPoolExecutor(
- 1, 1, 1000L, TimeUnit.MILLISECONDS,
- 1000L, true, 1000L,
- new ArrayBlockingQueue<>(1), "test", Thread::new, new ThreadPoolExecutor.DiscardOldestPolicy());
- AtomicInteger count = new AtomicInteger(0);
-
- executor.execute(() -> {
- ThreadUtil.sleep(500L);
- count.incrementAndGet();
- });
- executor.execute(() -> {
- ThreadUtil.sleep(500L);
- count.incrementAndGet();
- });
- executor.destroy();
-
- // waiting for terminated
- while (!executor.isTerminated()) {
- } ;
- Assert.assertEquals(2, count.get());
- }
-
- @Test
- public void testDestroyWhenNotWaitForTask() {
- DynamicThreadPoolExecutor executor = new DynamicThreadPoolExecutor(
- 1, 1, 1000L, TimeUnit.MILLISECONDS,
- 1000L, false, 1000L,
- new ArrayBlockingQueue<>(1), "test", Thread::new, new ThreadPoolExecutor.DiscardOldestPolicy());
- AtomicInteger count = new AtomicInteger(0);
-
- executor.execute(() -> {
- ThreadUtil.sleep(500L);
- count.incrementAndGet();
- });
- executor.execute(() -> {
- ThreadUtil.sleep(500L);
- count.incrementAndGet();
- });
- executor.destroy();
-
- // waiting for terminated
- while (!executor.isTerminated()) {
- }
- Assert.assertEquals(1, count.get());
- }
-
- @Test
- public void testRejectCount() {
- DynamicThreadPoolExecutor executor = new DynamicThreadPoolExecutor(
- 1, 1, 1000L, TimeUnit.MILLISECONDS,
- 1000L, true, 1000L,
- new ArrayBlockingQueue<>(1), "test", Thread::new, new ThreadPoolExecutor.DiscardOldestPolicy());
-
- Assert.assertEquals(0L, executor.getRejectCountNum().longValue());
- Assert.assertEquals(0L, executor.getRejectCount().get());
-
- executor.submit(() -> ThreadUtil.sleep(100L));
- executor.submit(() -> ThreadUtil.sleep(100L));
- executor.submit(() -> ThreadUtil.sleep(100L));
- ThreadUtil.sleep(200L);
- Assert.assertEquals(1L, executor.getRejectCountNum().longValue());
- Assert.assertEquals(1L, executor.getRejectCount().get());
- }
-
- @Test
- public void testSupportParam() {
- DynamicThreadPoolExecutor executor = new DynamicThreadPoolExecutor(
- 1, 1, 1000L, TimeUnit.MILLISECONDS,
- 1000L, true, 1000L,
- new ArrayBlockingQueue<>(1), "test", Thread::new, new ThreadPoolExecutor.DiscardOldestPolicy());
- Assert.assertEquals(1000L, executor.getAwaitTerminationMillis());
- Assert.assertTrue(executor.isWaitForTasksToCompleteOnShutdown());
-
- executor.setSupportParam(500L, false);
- Assert.assertEquals(500L, executor.getAwaitTerminationMillis());
- Assert.assertFalse(executor.isWaitForTasksToCompleteOnShutdown());
- }
-
- @Test
- public void testIsActive() {
- DynamicThreadPoolExecutor executor = new DynamicThreadPoolExecutor(
- 1, 1, 1000L, TimeUnit.MILLISECONDS,
- 1000L, true, 1000L,
- new ArrayBlockingQueue<>(1), "test", Thread::new, new ThreadPoolExecutor.DiscardOldestPolicy());
- Assert.assertTrue(executor.isActive());
-
- // waiting for terminated
- executor.destroy();
- while (!executor.isTerminated()) {
- }
- Assert.assertFalse(executor.isActive());
- executor.destroy();
- Assert.assertFalse(executor.isActive());
- }
-
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/ExtensibleThreadPoolExecutorTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/ExtensibleThreadPoolExecutorTest.java
deleted file mode 100644
index ee0e8e14..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/ExtensibleThreadPoolExecutorTest.java
+++ /dev/null
@@ -1,240 +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 cn.hippo4j.core.executor;
-
-import cn.hippo4j.common.toolkit.ThreadUtil;
-import cn.hippo4j.core.executor.plugin.ExecuteAwarePlugin;
-import cn.hippo4j.core.executor.plugin.RejectedAwarePlugin;
-import cn.hippo4j.core.executor.plugin.ShutdownAwarePlugin;
-import cn.hippo4j.core.executor.plugin.TaskAwarePlugin;
-import cn.hippo4j.core.executor.plugin.manager.DefaultThreadPoolPluginManager;
-import cn.hippo4j.core.executor.plugin.manager.ThreadPoolPluginManager;
-import lombok.Getter;
-import org.checkerframework.checker.nullness.qual.NonNull;
-import org.checkerframework.checker.nullness.qual.Nullable;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.List;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.Callable;
-import java.util.concurrent.RejectedExecutionHandler;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * test for {@link ExtensibleThreadPoolExecutor}
- */
-public class ExtensibleThreadPoolExecutorTest {
-
- private final RejectedExecutionHandler originalHandler = new ThreadPoolExecutor.DiscardPolicy();
-
- private ExtensibleThreadPoolExecutor executor;
-
- private ThreadPoolPluginManager manager;
-
- @Before
- public void initExecutor() {
- manager = new DefaultThreadPoolPluginManager();
- executor = new ExtensibleThreadPoolExecutor(
- "test", manager,
- 5, 5, 1000L, TimeUnit.MILLISECONDS,
- new ArrayBlockingQueue<>(1), Thread::new, originalHandler);
- }
-
- @Test
- public void testGetThreadPoolId() {
- Assert.assertEquals("test", executor.getThreadPoolId());
- }
-
- @Test
- public void testGetThreadPoolExecutor() {
- Assert.assertSame(executor, executor.getThreadPoolExecutor());
- }
-
- @Test
- public void testGetThreadPoolPluginManager() {
- Assert.assertSame(manager, executor.getThreadPoolPluginManager());
- }
-
- @Test
- public void testGetOrSetRejectedHandler() {
- RejectedExecutionHandler handler = new ThreadPoolExecutor.AbortPolicy();
- executor.setRejectedExecutionHandler(handler);
- Assert.assertSame(handler, executor.getRejectedExecutionHandler());
- }
-
- @Test
- public void testInvokeTaskAwarePlugin() {
- TestTaskAwarePlugin plugin = new TestTaskAwarePlugin();
- executor.register(plugin);
- executor.submit(() -> {
- });
- executor.submit(() -> true);
- executor.submit(() -> {
- }, false);
- executor.execute(() -> {
- });
- Assert.assertEquals(7, plugin.getInvokeCount().get());
- }
-
- @Test
- public void testInvokeExecuteAwarePlugin() {
- TestExecuteAwarePlugin plugin = new TestExecuteAwarePlugin();
- executor.register(plugin);
- executor.execute(() -> {
- });
- ThreadUtil.sleep(500L);
- Assert.assertEquals(2, plugin.getInvokeCount().get());
-
- // no task will be executed because it has been replaced with null
- executor.register(new TestTaskToNullAwarePlugin());
- executor.execute(() -> {
- });
- ThreadUtil.sleep(500L);
- Assert.assertEquals(2, plugin.getInvokeCount().get());
- }
-
- @Test
- public void testInvokeRejectedAwarePlugin() {
- executor.setCorePoolSize(1);
- executor.setMaximumPoolSize(1);
-
- TestRejectedAwarePlugin plugin = new TestRejectedAwarePlugin();
- executor.register(plugin);
- // blocking pool and queue
- executor.submit(() -> ThreadUtil.sleep(500L));
- executor.submit(() -> ThreadUtil.sleep(500L));
- // reject 3 tasks
- executor.submit(() -> {
- });
- executor.submit(() -> {
- });
- executor.submit(() -> {
- });
-
- ThreadUtil.sleep(500L);
- Assert.assertEquals(3, plugin.getInvokeCount().get());
- }
-
- @Test
- public void testInvokeTestShutdownAwarePluginWhenShutdown() throws InterruptedException {
- TestShutdownAwarePlugin plugin = new TestShutdownAwarePlugin();
- executor.register(plugin);
- executor.shutdown();
- executor.submit(() -> {
- throw new IllegalArgumentException("???");
- });
- if (executor.awaitTermination(500L, TimeUnit.MILLISECONDS)) {
- Assert.assertEquals(3, plugin.getInvokeCount().get());
- }
- }
-
- @Test
- public void testInvokeTestShutdownAwarePluginWhenShutdownNow() throws InterruptedException {
- TestShutdownAwarePlugin plugin = new TestShutdownAwarePlugin();
- executor.register(plugin);
- executor.shutdownNow();
- if (executor.awaitTermination(500L, TimeUnit.MILLISECONDS)) {
- Assert.assertEquals(3, plugin.getInvokeCount().get());
- }
- }
-
- private final static class TestTaskToNullAwarePlugin implements TaskAwarePlugin {
-
- @Override
- public @Nullable Runnable beforeTaskExecute(@NonNull Runnable runnable) {
- return null;
- }
- }
-
- @Getter
- private final static class TestTaskAwarePlugin implements TaskAwarePlugin {
-
- private final AtomicInteger invokeCount = new AtomicInteger(0);
- private final String id = "TestTaskAwarePlugin";
- @Override
- public Runnable beforeTaskCreate(ThreadPoolExecutor executor, Runnable runnable, V value) {
- invokeCount.incrementAndGet();
- return TaskAwarePlugin.super.beforeTaskCreate(executor, runnable, value);
- }
- @Override
- public Callable beforeTaskCreate(ThreadPoolExecutor executor, Callable future) {
- invokeCount.incrementAndGet();
- return TaskAwarePlugin.super.beforeTaskCreate(executor, future);
- }
- @Override
- public Runnable beforeTaskExecute(@NonNull Runnable runnable) {
- invokeCount.incrementAndGet();
- return TaskAwarePlugin.super.beforeTaskExecute(runnable);
- }
- }
-
- @Getter
- private final static class TestExecuteAwarePlugin implements ExecuteAwarePlugin {
-
- private final AtomicInteger invokeCount = new AtomicInteger(0);
- private final String id = "TestExecuteAwarePlugin";
- @Override
- public void beforeExecute(Thread thread, Runnable runnable) {
- invokeCount.incrementAndGet();
- ExecuteAwarePlugin.super.beforeExecute(thread, runnable);
- }
- @Override
- public void afterExecute(Runnable runnable, Throwable throwable) {
- invokeCount.incrementAndGet();
- ExecuteAwarePlugin.super.afterExecute(runnable, throwable);
- }
- }
-
- @Getter
- private final static class TestRejectedAwarePlugin implements RejectedAwarePlugin {
-
- private final AtomicInteger invokeCount = new AtomicInteger(0);
- private final String id = "TestRejectedAwarePlugin";
- @Override
- public void beforeRejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
- invokeCount.incrementAndGet();
- }
- }
-
- @Getter
- private final static class TestShutdownAwarePlugin implements ShutdownAwarePlugin {
-
- private final AtomicInteger invokeCount = new AtomicInteger(0);
- private final String id = "TestShutdownAwarePlugin";
- @Override
- public void beforeShutdown(ThreadPoolExecutor executor) {
- invokeCount.incrementAndGet();
- ShutdownAwarePlugin.super.beforeShutdown(executor);
- }
- @Override
- public void afterShutdown(ThreadPoolExecutor executor, List remainingTasks) {
- invokeCount.incrementAndGet();
- ShutdownAwarePlugin.super.afterShutdown(executor, remainingTasks);
- }
- @Override
- public void afterTerminated(ThreadPoolExecutor executor) {
- invokeCount.incrementAndGet();
- ShutdownAwarePlugin.super.afterTerminated(executor);
- }
- }
-
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/handler/DynamicThreadPoolBannerHandlerTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/handler/DynamicThreadPoolBannerHandlerTest.java
deleted file mode 100644
index a988cc04..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/handler/DynamicThreadPoolBannerHandlerTest.java
+++ /dev/null
@@ -1,28 +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 cn.hippo4j.core.executor.handler;
-
-import org.junit.Test;
-
-public final class DynamicThreadPoolBannerHandlerTest {
-
- @Test
- public void assertGetVersion() {
- // Assert.assertTrue(StringUtil.isEmpty(DynamicThreadPoolBannerHandler.getVersion()));
- }
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/PluginRuntimeTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/PluginRuntimeTest.java
deleted file mode 100644
index 24428752..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/PluginRuntimeTest.java
+++ /dev/null
@@ -1,41 +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 cn.hippo4j.core.executor.plugin;
-
-import cn.hippo4j.core.executor.plugin.PluginRuntime;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * test for {@link PluginRuntime}
- */
-public class PluginRuntimeTest {
-
- @Test
- public void test() {
- PluginRuntime runtime = new PluginRuntime("test");
- Assert.assertEquals("test", runtime.getPluginId());
- Assert.assertTrue(runtime.getInfoList().isEmpty());
-
- runtime.addInfo("item", "item");
- PluginRuntime.Info info = runtime.getInfoList().get(0);
- Assert.assertEquals("item", info.getName());
- Assert.assertEquals("item", info.getValue());
- }
-
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/ThreadPoolPluginTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/ThreadPoolPluginTest.java
deleted file mode 100644
index d0c2968b..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/ThreadPoolPluginTest.java
+++ /dev/null
@@ -1,93 +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 cn.hippo4j.core.executor.plugin;
-
-import cn.hippo4j.common.toolkit.ThreadUtil;
-import cn.hippo4j.core.executor.ExtensibleThreadPoolExecutor;
-import cn.hippo4j.core.executor.plugin.*;
-import cn.hippo4j.core.executor.plugin.manager.DefaultThreadPoolPluginManager;
-import lombok.Getter;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * test for default method of {@link ThreadPoolPlugin} and it's subclass
- */
-public class ThreadPoolPluginTest {
-
- @Test
- public void testDefaultMethod() {
- ExtensibleThreadPoolExecutor executor = new ExtensibleThreadPoolExecutor(
- "test", new DefaultThreadPoolPluginManager(),
- 1, 1, 1000L, TimeUnit.MILLISECONDS,
- new ArrayBlockingQueue<>(1), Thread::new, new ThreadPoolExecutor.DiscardPolicy());
-
- executor.register(new TestTaskAwarePlugin());
- executor.register(new TestExecuteAwarePlugin());
- executor.register(new TestRejectedAwarePlugin());
- executor.register(new TestShutdownAwarePlugin());
-
- AtomicInteger count = new AtomicInteger(0);
- executor.submit(() -> {
- ThreadUtil.sleep(100L);
- return count.incrementAndGet();
- });
- executor.submit(() -> {
- ThreadUtil.sleep(100L);
- count.incrementAndGet();
- });
- executor.submit(count::incrementAndGet, 2);
-
- // waiting for shutdown
- executor.shutdown();
- while (!executor.isTerminated()) {
- }
-
- Assert.assertEquals(2, count.get());
- }
-
- @Getter
- private final static class TestTaskAwarePlugin implements TaskAwarePlugin {
-
- private final String id = this.getClass().getSimpleName();
- }
-
- @Getter
- private final static class TestExecuteAwarePlugin implements ExecuteAwarePlugin {
-
- private final String id = this.getClass().getSimpleName();
- }
-
- @Getter
- private final static class TestRejectedAwarePlugin implements RejectedAwarePlugin {
-
- private final String id = this.getClass().getSimpleName();
- }
-
- @Getter
- private final static class TestShutdownAwarePlugin implements ShutdownAwarePlugin {
-
- private final String id = this.getClass().getSimpleName();
- }
-
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/TaskDecoratorPluginTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/TaskDecoratorPluginTest.java
deleted file mode 100644
index 5668947d..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/TaskDecoratorPluginTest.java
+++ /dev/null
@@ -1,104 +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 cn.hippo4j.core.executor.plugin.impl;
-
-import cn.hippo4j.common.toolkit.ThreadUtil;
-import cn.hippo4j.core.executor.ExtensibleThreadPoolExecutor;
-import cn.hippo4j.core.executor.plugin.PluginRuntime;
-import cn.hippo4j.core.executor.plugin.ThreadPoolPlugin;
-import cn.hippo4j.core.executor.plugin.impl.TaskDecoratorPlugin;
-import cn.hippo4j.core.executor.plugin.manager.DefaultThreadPoolPluginManager;
-import org.junit.Assert;
-import org.junit.Test;
-import org.springframework.core.task.TaskDecorator;
-
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * test for {@link TaskDecoratorPlugin}
- */
-public class TaskDecoratorPluginTest {
-
- private final AtomicInteger taskExecuteCount = new AtomicInteger(0);
-
- @Test
- public void testGetId() {
- Assert.assertEquals(TaskDecoratorPlugin.PLUGIN_NAME, new TaskDecoratorPlugin().getId());
- }
-
- @Test
- public void testGetRuntime() {
- ThreadPoolPlugin plugin = new TaskDecoratorPlugin();
- PluginRuntime runtime = new TaskDecoratorPlugin().getPluginRuntime();
- Assert.assertNotNull(runtime);
- Assert.assertEquals(plugin.getId(), runtime.getPluginId());
- }
-
- @Test
- public void testAddDecorator() {
- TaskDecoratorPlugin plugin = new TaskDecoratorPlugin();
- plugin.addDecorator(runnable -> runnable);
- plugin.addDecorator(runnable -> runnable);
- Assert.assertEquals(2, plugin.getDecorators().size());
- }
-
- @Test
- public void testRemoveDecorator() {
- TaskDecoratorPlugin plugin = new TaskDecoratorPlugin();
- TaskDecorator decorator = runnable -> runnable;
- plugin.addDecorator(decorator);
- plugin.removeDecorator(decorator);
- Assert.assertTrue(plugin.getDecorators().isEmpty());
- }
-
- @Test
- public void testClear() {
- TaskDecoratorPlugin plugin = new TaskDecoratorPlugin();
- TaskDecorator decorator = runnable -> runnable;
- plugin.addDecorator(decorator);
- plugin.addDecorator(decorator);
- plugin.clearDecorators();
- Assert.assertTrue(plugin.getDecorators().isEmpty());
- }
-
- @Test
- public void testBeforeTaskExecute() {
- ExtensibleThreadPoolExecutor executor = new ExtensibleThreadPoolExecutor(
- "test", new DefaultThreadPoolPluginManager(),
- 5, 5, 1000L, TimeUnit.MILLISECONDS,
- new ArrayBlockingQueue<>(1), Thread::new, new ThreadPoolExecutor.DiscardPolicy());
- TaskDecoratorPlugin plugin = new TaskDecoratorPlugin();
- plugin.addDecorator(runnable -> () -> {
- taskExecuteCount.incrementAndGet();
- runnable.run();
- });
- plugin.addDecorator(runnable -> () -> {
- taskExecuteCount.incrementAndGet();
- runnable.run();
- });
- executor.register(plugin);
- executor.execute(() -> {
- });
- ThreadUtil.sleep(500L);
- Assert.assertEquals(2, taskExecuteCount.get());
- }
-
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/TaskRejectCountRecordPluginTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/TaskRejectCountRecordPluginTest.java
deleted file mode 100644
index 6f5f7603..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/TaskRejectCountRecordPluginTest.java
+++ /dev/null
@@ -1,84 +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 cn.hippo4j.core.executor.plugin.impl;
-
-import cn.hippo4j.common.toolkit.ThreadUtil;
-import cn.hippo4j.core.executor.ExtensibleThreadPoolExecutor;
-import cn.hippo4j.core.executor.plugin.impl.TaskRejectCountRecordPlugin;
-import cn.hippo4j.core.executor.plugin.manager.DefaultThreadPoolPluginManager;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * test for {@link TaskRejectCountRecordPlugin}
- */
-public class TaskRejectCountRecordPluginTest {
-
- @Test
- public void testGetId() {
- Assert.assertEquals(TaskRejectCountRecordPlugin.PLUGIN_NAME, new TaskRejectCountRecordPlugin().getId());
- }
-
- @Test
- public void testGetRuntime() {
- Assert.assertNotNull(new TaskRejectCountRecordPlugin().getPluginRuntime());
- }
-
- @Test
- public void testGetRejectCountNum() {
- TaskRejectCountRecordPlugin plugin = new TaskRejectCountRecordPlugin();
- Assert.assertEquals((Long) 0L, plugin.getRejectCountNum());
- }
-
- @Test
- public void testGetRejectCount() {
- TaskRejectCountRecordPlugin plugin = new TaskRejectCountRecordPlugin();
- Assert.assertEquals(0L, plugin.getRejectCount().get());
- }
-
- @Test
- public void testSetRejectCount() {
- TaskRejectCountRecordPlugin plugin = new TaskRejectCountRecordPlugin();
- AtomicLong atomicLong = new AtomicLong(0);
- plugin.setRejectCount(atomicLong);
- Assert.assertSame(atomicLong, plugin.getRejectCount());
- }
-
- @Test
- public void testBeforeRejectedExecution() {
- ExtensibleThreadPoolExecutor executor = new ExtensibleThreadPoolExecutor(
- "test", new DefaultThreadPoolPluginManager(),
- 1, 1, 1000L, TimeUnit.MILLISECONDS,
- new ArrayBlockingQueue<>(1), Thread::new, new ThreadPoolExecutor.DiscardPolicy());
-
- TaskRejectCountRecordPlugin plugin = new TaskRejectCountRecordPlugin();
- executor.register(plugin);
- executor.submit(() -> ThreadUtil.sleep(500L));
- executor.submit(() -> ThreadUtil.sleep(500L));
- executor.submit(() -> ThreadUtil.sleep(500L));
-
- ThreadUtil.sleep(500L);
- Assert.assertEquals((Long) 1L, plugin.getRejectCountNum());
- }
-
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/TaskRejectNotifyAlarmPluginTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/TaskRejectNotifyAlarmPluginTest.java
deleted file mode 100644
index aa35cdd0..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/TaskRejectNotifyAlarmPluginTest.java
+++ /dev/null
@@ -1,94 +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 cn.hippo4j.core.executor.plugin.impl;
-
-import cn.hippo4j.common.toolkit.ThreadUtil;
-import cn.hippo4j.core.executor.ExtensibleThreadPoolExecutor;
-import cn.hippo4j.core.executor.plugin.manager.DefaultThreadPoolPluginManager;
-import cn.hippo4j.threadpool.alarm.api.ThreadPoolCheckAlarm;
-import lombok.Getter;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * test for {@link TaskRejectNotifyAlarmPlugin}
- */
-public class TaskRejectNotifyAlarmPluginTest {
-
- @Test
- public void testGetId() {
- Assert.assertEquals(TaskRejectNotifyAlarmPlugin.PLUGIN_NAME, new TaskRejectNotifyAlarmPlugin().getId());
- }
-
- @Test
- public void testGetRuntime() {
- Assert.assertNotNull(new TaskRejectNotifyAlarmPlugin().getPluginRuntime());
- }
-
- @Test
- public void testBeforeRejectedExecution() {
- ExtensibleThreadPoolExecutor executor = new ExtensibleThreadPoolExecutor(
- "test", new DefaultThreadPoolPluginManager(),
- 1, 1, 1000L, TimeUnit.MILLISECONDS,
- new ArrayBlockingQueue<>(1), Thread::new, new ThreadPoolExecutor.DiscardPolicy());
-
- TestAlarm alarm = new TestAlarm();
- executor.register(new TaskRejectNotifyAlarmPlugin(alarm));
- executor.submit(() -> ThreadUtil.sleep(200L));
- executor.submit(() -> ThreadUtil.sleep(200L));
- executor.submit(() -> ThreadUtil.sleep(200L));
-
- // waiting for shutdown
- executor.shutdown();
- while (!executor.isTerminated()) {
- }
- Assert.assertEquals(1, alarm.getNumberOfAlarms().get());
- }
-
- private static class TestAlarm implements ThreadPoolCheckAlarm {
-
- @Getter
- private final AtomicInteger numberOfAlarms = new AtomicInteger(0);
-
- @Override
- public void checkPoolCapacityAlarm(String threadPoolId, ThreadPoolExecutor threadPoolExecutor) {
- // do noting
- }
-
- @Override
- public void checkPoolActivityAlarm(String threadPoolId, ThreadPoolExecutor threadPoolExecutor) {
- // do noting
- }
-
- @Override
- public void asyncSendRejectedAlarm(String threadPoolId) {
- numberOfAlarms.incrementAndGet();
- }
-
- @Override
- public void asyncSendExecuteTimeOutAlarm(String threadPoolId, long executeTime, long executeTimeOut, ThreadPoolExecutor threadPoolExecutor) {
- // do noting
- }
- }
-
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/TaskTimeRecordPluginTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/TaskTimeRecordPluginTest.java
deleted file mode 100644
index ea839368..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/TaskTimeRecordPluginTest.java
+++ /dev/null
@@ -1,103 +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 cn.hippo4j.core.executor.plugin.impl;
-
-import cn.hippo4j.common.toolkit.ThreadUtil;
-import cn.hippo4j.core.executor.ExtensibleThreadPoolExecutor;
-import cn.hippo4j.core.executor.plugin.manager.DefaultThreadPoolPluginManager;
-import lombok.extern.slf4j.Slf4j;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-/**
- * test for {@link TaskTimeRecordPlugin}
- */
-@Slf4j
-public class TaskTimeRecordPluginTest {
-
- @Test
- public void testGetId() {
- Assert.assertEquals(TaskTimeRecordPlugin.PLUGIN_NAME, new TaskTimeRecordPlugin().getId());
- }
-
- @Test
- public void testGetRuntime() {
- Assert.assertNotNull(new TaskTimeRecordPlugin().getPluginRuntime());
- }
-
- @Test
- public void testSummarize() {
- ExtensibleThreadPoolExecutor executor = new ExtensibleThreadPoolExecutor(
- "test", new DefaultThreadPoolPluginManager(),
- 3, 3, 1000L, TimeUnit.MILLISECONDS,
- new ArrayBlockingQueue<>(1), Thread::new, new ThreadPoolExecutor.DiscardPolicy());
-
- TaskTimeRecordPlugin plugin = new TaskTimeRecordPlugin(3);
- executor.register(plugin);
- executor.submit(() -> ThreadUtil.sleep(1000L));
- executor.submit(() -> ThreadUtil.sleep(3000L));
- executor.submit(() -> ThreadUtil.sleep(2000L));
- executor.submit(() -> ThreadUtil.sleep(2000L));
-
- // waiting for shutdown
- executor.shutdown();
- while (!executor.isTerminated()) {
- }
- TaskTimeRecordPlugin.Summary summary = plugin.summarize();
- Assert.assertTrue(summary.getMinTaskTimeMillis() > 0L);
- Assert.assertTrue(summary.getMaxTaskTimeMillis() > 0L);
- Assert.assertTrue(summary.getAvgTaskTimeMillis() > 0L);
- Assert.assertTrue(summary.getTotalTaskTimeMillis() > 0L);
- // Assert.assertTrue(testInDeviation(summary.getMinTaskTimeMillis(), 1000L, 300L));
- // Assert.assertTrue(testInDeviation(summary.getMaxTaskTimeMillis(), 3000L, 300L));
- // Assert.assertTrue(testInDeviation(summary.getAvgTaskTimeMillis(), 2000L, 300L));
- // Assert.assertTrue(testInDeviation(summary.getTotalTaskTimeMillis(), 8000L, 300L));
- }
-
- private boolean testInDeviation(long except, long actual, long offer) {
- long exceptLower = except - offer;
- long exceptUpper = except + offer;
- log.info("test {} < [{}] < {}", exceptLower, actual, exceptUpper);
- return exceptLower < actual && actual < exceptUpper;
- }
-
- @Test
- public void testTableSizeFor() {
- int maxCap = 1 << 30;
- for (int i = 0; i <= maxCap; i++) {
- int tabSize1 = tabSizeFor_JDK8(i);
- int tabSize2 = TaskTimeRecordPlugin.tableSizeFor(i);
- Assert.assertTrue(tabSize1 == tabSize2);
- }
- }
-
- private static int tabSizeFor_JDK8(int cap) {
- int n = cap - 1;
- n |= n >>> 1;
- n |= n >>> 2;
- n |= n >>> 4;
- n |= n >>> 8;
- n |= n >>> 16;
- return (n < 0) ? 1 : (n >= 1073741824) ? 1073741824 : n + 1;
- }
-
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/TaskTimeoutNotifyAlarmPluginTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/TaskTimeoutNotifyAlarmPluginTest.java
deleted file mode 100644
index c8d6de43..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/TaskTimeoutNotifyAlarmPluginTest.java
+++ /dev/null
@@ -1,113 +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 cn.hippo4j.core.executor.plugin.impl;
-
-import cn.hippo4j.common.toolkit.ThreadUtil;
-import cn.hippo4j.core.executor.ExtensibleThreadPoolExecutor;
-import cn.hippo4j.core.executor.plugin.manager.DefaultThreadPoolPluginManager;
-import cn.hippo4j.threadpool.alarm.api.ThreadPoolCheckAlarm;
-import lombok.Getter;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * test for {@link TaskTimeoutNotifyAlarmPlugin}
- */
-public class TaskTimeoutNotifyAlarmPluginTest {
-
- private final ExtensibleThreadPoolExecutor executor = new ExtensibleThreadPoolExecutor(
- "test", new DefaultThreadPoolPluginManager(),
- 5, 5, 1000L, TimeUnit.MILLISECONDS,
- new ArrayBlockingQueue<>(1), Thread::new, new ThreadPoolExecutor.AbortPolicy());
-
- private final TestAlarm testAlarm = new TestAlarm();
-
- private final TaskTimeoutNotifyAlarmPlugin plugin = new TaskTimeoutNotifyAlarmPlugin(
- executor.getThreadPoolId(), 1L, executor, testAlarm);
-
- @Test
- public void testGetId() {
- Assert.assertEquals(TaskTimeoutNotifyAlarmPlugin.PLUGIN_NAME, plugin.getId());
- }
-
- @Test
- public void testGetRuntime() {
- Assert.assertNotNull(plugin.getPluginRuntime());
- }
-
- @Test
- public void testGetExecuteTimeOut() {
- Assert.assertEquals(1L, plugin.getExecuteTimeOut().longValue());
- }
-
- @Test
- public void testSetExecuteTimeOut() {
- plugin.setExecuteTimeOut(2L);
- Assert.assertEquals(2L, plugin.getExecuteTimeOut().longValue());
- }
-
- @Test
- public void testProcessTaskTime() {
- executor.register(plugin);
-
- executor.submit(() -> {
- ThreadUtil.sleep(100L);
- });
- executor.submit(() -> {
- ThreadUtil.sleep(300L);
- });
-
- // waiting for shutdown
- executor.shutdown();
- while (!executor.isTerminated()) {
- }
- Assert.assertEquals(2, testAlarm.getNumberOfAlarms().get());
- }
-
- private static class TestAlarm implements ThreadPoolCheckAlarm {
-
- @Getter
- private final AtomicInteger numberOfAlarms = new AtomicInteger(0);
-
- @Override
- public void checkPoolCapacityAlarm(String threadPoolId, ThreadPoolExecutor threadPoolExecutor) {
- // do noting
- }
-
- @Override
- public void checkPoolActivityAlarm(String threadPoolId, ThreadPoolExecutor threadPoolExecutor) {
- // do noting
- }
-
- @Override
- public void asyncSendRejectedAlarm(String threadPoolId) {
- // do noting
- }
-
- @Override
- public void asyncSendExecuteTimeOutAlarm(String threadPoolId, long executeTime, long executeTimeOut, ThreadPoolExecutor threadPoolExecutor) {
- numberOfAlarms.incrementAndGet();
- }
- }
-
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/ThreadPoolExecutorShutdownPluginTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/ThreadPoolExecutorShutdownPluginTest.java
deleted file mode 100644
index 424e4a7f..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/impl/ThreadPoolExecutorShutdownPluginTest.java
+++ /dev/null
@@ -1,92 +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 cn.hippo4j.core.executor.plugin.impl;
-
-import cn.hippo4j.common.toolkit.ThreadUtil;
-import cn.hippo4j.core.executor.ExtensibleThreadPoolExecutor;
-import cn.hippo4j.core.executor.plugin.ThreadPoolPlugin;
-import cn.hippo4j.core.executor.plugin.impl.ThreadPoolExecutorShutdownPlugin;
-import cn.hippo4j.core.executor.plugin.manager.DefaultThreadPoolPluginManager;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * test for {@link ThreadPoolExecutorShutdownPlugin}
- */
-public class ThreadPoolExecutorShutdownPluginTest {
-
- @Test
- public void testGetId() {
- Assert.assertEquals(ThreadPoolExecutorShutdownPlugin.PLUGIN_NAME, new ThreadPoolExecutorShutdownPlugin(1000L).getId());
- }
-
- @Test
- public void testGetRuntime() {
- Assert.assertNotNull(new ThreadPoolExecutorShutdownPlugin(1000L).getPluginRuntime());
- }
-
- @Test
- public void testGetAwaitTerminationMillis() {
- ThreadPoolExecutorShutdownPlugin plugin = new ThreadPoolExecutorShutdownPlugin(1000L);
- Assert.assertEquals(1000L, plugin.getAwaitTerminationMillis());
- }
-
- @Test
- public void testSetAwaitTerminationMillis() {
- ThreadPoolExecutorShutdownPlugin plugin = new ThreadPoolExecutorShutdownPlugin(1000L);
- plugin.setAwaitTerminationMillis(5000L);
- Assert.assertEquals(5000L, plugin.getAwaitTerminationMillis());
- }
-
- public ExtensibleThreadPoolExecutor getExecutor(ThreadPoolPlugin plugin) {
- ExtensibleThreadPoolExecutor executor = new ExtensibleThreadPoolExecutor(
- "test", new DefaultThreadPoolPluginManager(),
- 2, 2, 1000L, TimeUnit.MILLISECONDS,
- new ArrayBlockingQueue<>(1), Thread::new, new ThreadPoolExecutor.DiscardPolicy());
- executor.register(plugin);
- return executor;
- }
-
- private static Callable getCallable(AtomicInteger completedCount) {
- return () -> {
- ThreadUtil.sleep(1000L);
- return completedCount.incrementAndGet();
- };
- }
-
- @Test
- public void testShutdown() {
- ExtensibleThreadPoolExecutor executor = getExecutor(
- new ThreadPoolExecutorShutdownPlugin(2000L));
-
- AtomicInteger completedCount = new AtomicInteger(0);
- executor.submit(getCallable(completedCount));
- executor.submit(getCallable(completedCount));
- executor.submit(getCallable(completedCount));
-
- executor.shutdownNow();
- Assert.assertEquals(2, completedCount.get());
- }
-
-}
\ No newline at end of file
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/manager/DefaultGlobalThreadPoolPluginManagerTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/manager/DefaultGlobalThreadPoolPluginManagerTest.java
deleted file mode 100644
index 06e49b24..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/manager/DefaultGlobalThreadPoolPluginManagerTest.java
+++ /dev/null
@@ -1,238 +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 cn.hippo4j.core.executor.plugin.manager;
-
-import cn.hippo4j.core.executor.plugin.ThreadPoolPlugin;
-import cn.hippo4j.core.executor.plugin.manager.*;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-/**
- * test for {@link DefaultGlobalThreadPoolPluginManager}
- */
-public class DefaultGlobalThreadPoolPluginManagerTest {
-
- @Test
- public void testDoRegister() {
- GlobalThreadPoolPluginManager manager = new DefaultGlobalThreadPoolPluginManager();
- manager.enableThreadPoolPlugin(new TestPlugin("1"));
- manager.enableThreadPoolPlugin(new TestPlugin("2"));
- manager.enableThreadPoolPluginRegistrar(new TestRegistrar("1"));
-
- TestSupport support = new TestSupport("1");
- manager.doRegister(support);
- Assert.assertEquals(3, support.getAllPlugins().size());
- }
-
- @Test
- public void testRegisterThreadPoolPluginSupport() {
- GlobalThreadPoolPluginManager manager = new DefaultGlobalThreadPoolPluginManager();
- Assert.assertTrue(manager.enableThreadPoolPlugin(new TestPlugin("1")));
-
- TestSupport support = new TestSupport("1");
- Assert.assertTrue(manager.registerThreadPoolPluginSupport(support));
- Assert.assertFalse(manager.registerThreadPoolPluginSupport(support));
- Assert.assertEquals(1, support.getAllPlugins().size());
-
- // incremental update
- manager.enableThreadPoolPlugin(new TestPlugin("2"));
- manager.enableThreadPoolPluginRegistrar(new TestRegistrar("1"));
- Assert.assertEquals(3, support.getAllPlugins().size());
- }
-
- @Test
- public void testCancelManagement() {
- GlobalThreadPoolPluginManager manager = new DefaultGlobalThreadPoolPluginManager();
- manager.enableThreadPoolPlugin(new TestPlugin("1"));
-
- TestSupport support = new TestSupport("1");
- manager.registerThreadPoolPluginSupport(support);
- Assert.assertEquals(1, support.getAllPlugins().size());
-
- manager.cancelManagement(support.getThreadPoolId());
- manager.enableThreadPoolPlugin(new TestPlugin("2"));
- Assert.assertEquals(1, support.getAllPlugins().size());
- }
-
- @Test
- public void testGetManagedThreadPoolPluginSupport() {
- GlobalThreadPoolPluginManager manager = new DefaultGlobalThreadPoolPluginManager();
-
- TestSupport support = new TestSupport("1");
- manager.registerThreadPoolPluginSupport(support);
- Assert.assertSame(support, manager.getManagedThreadPoolPluginSupport(support.getThreadPoolId()));
-
- support = new TestSupport("2");
- manager.registerThreadPoolPluginSupport(support);
- Assert.assertSame(support, manager.getManagedThreadPoolPluginSupport(support.getThreadPoolId()));
- }
-
- @Test
- public void testGetAllManagedThreadPoolPluginSupports() {
- GlobalThreadPoolPluginManager manager = new DefaultGlobalThreadPoolPluginManager();
- manager.registerThreadPoolPluginSupport(new TestSupport("1"));
- manager.registerThreadPoolPluginSupport(new TestSupport("2"));
- Assert.assertEquals(2, manager.getAllManagedThreadPoolPluginSupports().size());
- }
-
- @Test
- public void testEnableThreadPoolPlugin() {
- GlobalThreadPoolPluginManager manager = new DefaultGlobalThreadPoolPluginManager();
- TestSupport support1 = new TestSupport("1");
- manager.registerThreadPoolPluginSupport(support1);
- TestSupport support2 = new TestSupport("2");
- manager.registerThreadPoolPluginSupport(support2);
-
- Assert.assertTrue(manager.enableThreadPoolPlugin(new TestPlugin("1")));
- Assert.assertFalse(manager.enableThreadPoolPlugin(new TestPlugin("1")));
- Assert.assertEquals(1, support1.getAllPlugins().size());
- }
-
- @Test
- public void testGetAllEnableThreadPoolPlugins() {
- GlobalThreadPoolPluginManager manager = new DefaultGlobalThreadPoolPluginManager();
- manager.enableThreadPoolPlugin(new TestPlugin("1"));
- manager.enableThreadPoolPlugin(new TestPlugin("2"));
- Assert.assertEquals(2, manager.getAllEnableThreadPoolPlugins().size());
- }
-
- @Test
- public void testDisableThreadPoolPlugin() {
- GlobalThreadPoolPluginManager manager = new DefaultGlobalThreadPoolPluginManager();
- manager.enableThreadPoolPlugin(new TestPlugin("1"));
- manager.enableThreadPoolPlugin(new TestPlugin("2"));
- manager.disableThreadPoolPlugin("2");
- Assert.assertEquals(1, manager.getAllEnableThreadPoolPlugins().size());
- }
-
- @Test
- public void testEnableThreadPoolPluginRegistrar() {
- GlobalThreadPoolPluginManager manager = new DefaultGlobalThreadPoolPluginManager();
- Assert.assertTrue(manager.enableThreadPoolPluginRegistrar(new TestRegistrar("1")));
- Assert.assertFalse(manager.enableThreadPoolPluginRegistrar(new TestRegistrar("1")));
- Assert.assertEquals(1, manager.getAllEnableThreadPoolPluginRegistrar().size());
- }
-
- @Test
- public void testGetAllEnableThreadPoolPluginRegistrar() {
- GlobalThreadPoolPluginManager manager = new DefaultGlobalThreadPoolPluginManager();
- manager.enableThreadPoolPluginRegistrar(new TestRegistrar("1"));
- manager.enableThreadPoolPluginRegistrar(new TestRegistrar("2"));
- Assert.assertEquals(2, manager.getAllEnableThreadPoolPluginRegistrar().size());
- }
-
- @Test
- public void testDisableThreadPoolPluginRegistrar() {
- GlobalThreadPoolPluginManager manager = new DefaultGlobalThreadPoolPluginManager();
- manager.enableThreadPoolPluginRegistrar(new TestRegistrar("1"));
- manager.enableThreadPoolPluginRegistrar(new TestRegistrar("2"));
- manager.disableThreadPoolPluginRegistrar("2");
- Assert.assertEquals(1, manager.getAllEnableThreadPoolPluginRegistrar().size());
- }
-
- @Test
- public void testGetAllPluginsFromManagers() {
- GlobalThreadPoolPluginManager manager = new DefaultGlobalThreadPoolPluginManager();
- manager.enableThreadPoolPluginRegistrar(new TestRegistrar("1"));
- manager.enableThreadPoolPlugin(new TestPlugin("1"));
-
- TestSupport support1 = new TestSupport("1");
- manager.registerThreadPoolPluginSupport(support1);
- TestSupport support2 = new TestSupport("2");
- manager.registerThreadPoolPluginSupport(support2);
-
- Assert.assertEquals(4, manager.getAllPluginsFromManagers().size());
- }
-
- @Test
- public void testGetPluginsOfTypeFromManagers() {
- GlobalThreadPoolPluginManager manager = new DefaultGlobalThreadPoolPluginManager();
- manager.enableThreadPoolPluginRegistrar(new TestRegistrar("1"));
- manager.enableThreadPoolPlugin(new TestPlugin("1"));
-
- TestSupport support1 = new TestSupport("1");
- manager.registerThreadPoolPluginSupport(support1);
- TestSupport support2 = new TestSupport("2");
- manager.registerThreadPoolPluginSupport(support2);
-
- Assert.assertEquals(4, manager.getPluginsOfTypeFromManagers(TestPlugin.class).size());
- }
-
- @Test
- public void testGetPluginsFromManagers() {
- GlobalThreadPoolPluginManager manager = new DefaultGlobalThreadPoolPluginManager();
- manager.enableThreadPoolPluginRegistrar(new TestRegistrar("1"));
- manager.enableThreadPoolPlugin(new TestPlugin("1"));
-
- TestSupport support1 = new TestSupport("1");
- manager.registerThreadPoolPluginSupport(support1);
- TestSupport support2 = new TestSupport("2");
- manager.registerThreadPoolPluginSupport(support2);
-
- Assert.assertEquals(2, manager.getPluginsFromManagers("1").size());
- }
-
- @Test
- public void testUnregisterForAllManagers() {
- GlobalThreadPoolPluginManager manager = new DefaultGlobalThreadPoolPluginManager();
- manager.enableThreadPoolPluginRegistrar(new TestRegistrar("1"));
- manager.enableThreadPoolPlugin(new TestPlugin("1"));
-
- TestSupport support1 = new TestSupport("1");
- manager.registerThreadPoolPluginSupport(support1);
- TestSupport support2 = new TestSupport("2");
- manager.registerThreadPoolPluginSupport(support2);
-
- manager.unregisterForAllManagers("1");
- Assert.assertEquals(2, manager.getAllPluginsFromManagers().size());
- }
-
- @RequiredArgsConstructor
- @Getter
- private static class TestSupport implements ThreadPoolPluginSupport {
-
- private final String threadPoolId;
- private final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue());
- private final ThreadPoolPluginManager threadPoolPluginManager = new DefaultThreadPoolPluginManager();
- }
-
- @Getter
- @RequiredArgsConstructor
- private static class TestRegistrar implements ThreadPoolPluginRegistrar {
-
- private final String id;
- @Override
- public void doRegister(ThreadPoolPluginSupport support) {
- support.register(new TestPlugin("TestRegistrar"));
- }
- }
-
- @Getter
- @RequiredArgsConstructor
- private static class TestPlugin implements ThreadPoolPlugin {
-
- private final String id;
- }
-
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/manager/DefaultThreadPoolPluginManagerTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/manager/DefaultThreadPoolPluginManagerTest.java
deleted file mode 100644
index ebb63bc3..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/manager/DefaultThreadPoolPluginManagerTest.java
+++ /dev/null
@@ -1,250 +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 cn.hippo4j.core.executor.plugin.manager;
-
-import cn.hippo4j.core.executor.plugin.ExecuteAwarePlugin;
-import cn.hippo4j.core.executor.plugin.RejectedAwarePlugin;
-import cn.hippo4j.core.executor.plugin.ShutdownAwarePlugin;
-import cn.hippo4j.core.executor.plugin.TaskAwarePlugin;
-import cn.hippo4j.core.executor.plugin.ThreadPoolPlugin;
-import cn.hippo4j.core.executor.plugin.manager.DefaultThreadPoolPluginManager;
-import lombok.Getter;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.springframework.core.annotation.AnnotationAwareOrderComparator;
-import org.springframework.core.annotation.Order;
-
-import java.util.Iterator;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-/**
- * test for {@link DefaultThreadPoolPluginManager}
- */
-public class DefaultThreadPoolPluginManagerTest {
-
- private DefaultThreadPoolPluginManager manager;
-
- @Before
- public void initRegistry() {
- manager = new DefaultThreadPoolPluginManager(new ReentrantReadWriteLock(), null);
- }
-
- @Test
- public void testRegister() {
- manager.register(new TestShutdownAwarePlugin());
- Assert.assertEquals(1, manager.getAllPlugins().size());
- }
-
- @Test
- public void testGetAllPlugins() {
- manager.register(new TestExecuteAwarePlugin());
- manager.register(new TestRejectedAwarePlugin());
- Assert.assertEquals(2, manager.getAllPlugins().size());
- }
-
- @Test
- public void testClear() {
- manager.register(new TestExecuteAwarePlugin());
- manager.clear();
- Assert.assertTrue(manager.getAllPlugins().isEmpty());
- }
-
- @Test
- public void testTryRegister() {
- Assert.assertTrue(manager.tryRegister(new TestExecuteAwarePlugin()));
- Assert.assertFalse(manager.tryRegister(new TestExecuteAwarePlugin()));
- }
-
- @Test
- public void testIsRegistered() {
- Assert.assertFalse(manager.isRegistered(TestExecuteAwarePlugin.class.getSimpleName()));
- manager.register(new TestExecuteAwarePlugin());
- Assert.assertTrue(manager.isRegistered(TestExecuteAwarePlugin.class.getSimpleName()));
- }
-
- @Test
- public void testUnregister() {
- manager.register(new TestTaskAwarePlugin());
- manager.unregister(TestTaskAwarePlugin.class.getSimpleName());
- Assert.assertFalse(manager.isRegistered(TestTaskAwarePlugin.class.getSimpleName()));
-
- manager.register(new TestRejectedAwarePlugin());
- manager.unregister(TestRejectedAwarePlugin.class.getSimpleName());
- Assert.assertFalse(manager.isRegistered(TestRejectedAwarePlugin.class.getSimpleName()));
-
- manager.register(new TestShutdownAwarePlugin());
- manager.unregister(TestShutdownAwarePlugin.class.getSimpleName());
- Assert.assertFalse(manager.isRegistered(TestShutdownAwarePlugin.class.getSimpleName()));
-
- manager.register(new TestExecuteAwarePlugin());
- manager.unregister(TestExecuteAwarePlugin.class.getSimpleName());
- Assert.assertFalse(manager.isRegistered(TestExecuteAwarePlugin.class.getSimpleName()));
- }
-
- @Test
- public void testGetPlugin() {
- ThreadPoolPlugin plugin = new TestExecuteAwarePlugin();
- manager.register(plugin);
- Assert.assertSame(plugin, manager.getPlugin(plugin.getId()).orElse(null));
- }
-
- @Test
- public void testGetRejectedAwarePluginList() {
- manager.register(new TestRejectedAwarePlugin());
- Assert.assertEquals(1, manager.getRejectedAwarePluginList().size());
- }
-
- @Test
- public void testGetShutdownAwarePluginList() {
- manager.register(new TestShutdownAwarePlugin());
- Assert.assertEquals(1, manager.getShutdownAwarePluginList().size());
- }
-
- @Test
- public void testGetTaskAwarePluginList() {
- manager.register(new TestTaskAwarePlugin());
- Assert.assertEquals(1, manager.getTaskAwarePluginList().size());
- }
-
- @Test
- public void testGetExecuteAwarePluginList() {
- manager.register(new TestExecuteAwarePlugin());
- Assert.assertEquals(1, manager.getExecuteAwarePluginList().size());
- }
-
- @Test
- public void testGetAllPluginsOfType() {
- manager.register(new TestExecuteAwarePlugin());
- manager.register(new TestRejectedAwarePlugin());
- Assert.assertEquals(1, manager.getAllPluginsOfType(TestExecuteAwarePlugin.class).size());
- Assert.assertEquals(1, manager.getAllPluginsOfType(TestRejectedAwarePlugin.class).size());
- Assert.assertEquals(2, manager.getAllPluginsOfType(ThreadPoolPlugin.class).size());
- }
-
- @Test
- public void testGetAllPluginRuntimes() {
- manager.register(new TestExecuteAwarePlugin());
- manager.register(new TestRejectedAwarePlugin());
- Assert.assertEquals(2, manager.getAllPluginRuntimes().size());
- }
-
- @Test
- public void testGetPluginRuntime() {
- manager.register(new TestExecuteAwarePlugin());
- Assert.assertTrue(manager.getRuntime(TestExecuteAwarePlugin.class.getSimpleName()).isPresent());
- }
-
- @Test
- public void testGetPluginOfType() {
- manager.register(new TestExecuteAwarePlugin());
- Assert.assertTrue(manager.getPluginOfType(TestExecuteAwarePlugin.class.getSimpleName(), TestExecuteAwarePlugin.class).isPresent());
- Assert.assertTrue(manager.getPluginOfType(TestExecuteAwarePlugin.class.getSimpleName(), ThreadPoolPlugin.class).isPresent());
- Assert.assertFalse(manager.getPluginOfType(TestExecuteAwarePlugin.class.getSimpleName(), RejectedAwarePlugin.class).isPresent());
- }
-
- @Test
- public void testEnable() {
- ThreadPoolPlugin plugin = new TestExecuteAwarePlugin();
- Assert.assertFalse(manager.enable(plugin.getId()));
- manager.register(plugin);
- Assert.assertFalse(manager.enable(plugin.getId()));
- manager.disable(plugin.getId());
- Assert.assertTrue(manager.enable(plugin.getId()));
- }
-
- @Test
- public void testDisable() {
- ThreadPoolPlugin plugin = new TestExecuteAwarePlugin();
- Assert.assertFalse(manager.disable(plugin.getId()));
-
- manager.register(plugin);
- Assert.assertTrue(manager.disable(plugin.getId()));
- Assert.assertFalse(manager.disable(plugin.getId()));
-
- Assert.assertTrue(manager.getExecuteAwarePluginList().isEmpty());
- Assert.assertEquals(1, manager.getAllPlugins().size());
- }
-
- @Test
- public void testIsDisable() {
- ThreadPoolPlugin plugin = new TestExecuteAwarePlugin();
- Assert.assertFalse(manager.isDisabled(plugin.getId()));
-
- manager.register(plugin);
- Assert.assertTrue(manager.disable(plugin.getId()));
- Assert.assertTrue(manager.isDisabled(plugin.getId()));
- }
-
- @Test
- public void testGetDisabledPluginIds() {
- ThreadPoolPlugin plugin = new TestExecuteAwarePlugin();
- Assert.assertTrue(manager.getAllDisabledPluginIds().isEmpty());
-
- manager.register(plugin);
- Assert.assertTrue(manager.disable(plugin.getId()));
- Assert.assertEquals(1, manager.getAllDisabledPluginIds().size());
- }
-
- @Test
- public void testSetPluginComparator() {
- Assert.assertFalse(manager.isEnableSort());
-
- manager.register(new TestExecuteAwarePlugin());
- manager.register(new TestTaskAwarePlugin());
- manager.setPluginComparator(AnnotationAwareOrderComparator.INSTANCE);
- manager.register(new TestRejectedAwarePlugin());
- manager.register(new TestShutdownAwarePlugin());
- Assert.assertTrue(manager.isEnableSort());
-
- Iterator iterator = manager.getAllPlugins().iterator();
- Assert.assertEquals(TestTaskAwarePlugin.class, iterator.next().getClass());
- Assert.assertEquals(TestRejectedAwarePlugin.class, iterator.next().getClass());
- Assert.assertEquals(TestExecuteAwarePlugin.class, iterator.next().getClass());
- Assert.assertEquals(TestShutdownAwarePlugin.class, iterator.next().getClass());
- }
-
- @Order(0)
- @Getter
- private final static class TestTaskAwarePlugin implements TaskAwarePlugin {
-
- private final String id = this.getClass().getSimpleName();
- }
-
- @Order(2)
- @Getter
- private final static class TestExecuteAwarePlugin implements ExecuteAwarePlugin {
-
- private final String id = this.getClass().getSimpleName();
- }
-
- @Order(1)
- @Getter
- private final static class TestRejectedAwarePlugin implements RejectedAwarePlugin {
-
- private final String id = this.getClass().getSimpleName();
- }
-
- @Order(3)
- @Getter
- private final static class TestShutdownAwarePlugin implements ShutdownAwarePlugin {
-
- private final String id = this.getClass().getSimpleName();
- }
-
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/manager/DefaultThreadPoolPluginRegistrarTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/manager/DefaultThreadPoolPluginRegistrarTest.java
deleted file mode 100644
index c968e735..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/manager/DefaultThreadPoolPluginRegistrarTest.java
+++ /dev/null
@@ -1,65 +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 cn.hippo4j.core.executor.plugin.manager;
-
-import cn.hippo4j.core.executor.ExtensibleThreadPoolExecutor;
-import cn.hippo4j.core.executor.plugin.impl.TaskDecoratorPlugin;
-import cn.hippo4j.core.executor.plugin.impl.TaskRejectCountRecordPlugin;
-import cn.hippo4j.core.executor.plugin.impl.TaskRejectNotifyAlarmPlugin;
-import cn.hippo4j.core.executor.plugin.impl.TaskTimeoutNotifyAlarmPlugin;
-import cn.hippo4j.core.executor.plugin.impl.ThreadPoolExecutorShutdownPlugin;
-import cn.hippo4j.core.executor.plugin.manager.DefaultThreadPoolPluginManager;
-import cn.hippo4j.core.executor.plugin.manager.DefaultThreadPoolPluginRegistrar;
-import cn.hippo4j.core.executor.plugin.manager.ThreadPoolPluginManager;
-import cn.hippo4j.core.executor.plugin.manager.ThreadPoolPluginRegistrar;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-/**
- * test for {@link DefaultThreadPoolPluginRegistrar}
- */
-public class DefaultThreadPoolPluginRegistrarTest {
-
- @Test
- public void testGetId() {
- ThreadPoolPluginRegistrar registrar = new DefaultThreadPoolPluginRegistrar();
- Assert.assertEquals(registrar.getClass().getSimpleName(), registrar.getId());
- }
-
- @Test
- public void testDoRegister() {
- ThreadPoolPluginRegistrar registrar = new DefaultThreadPoolPluginRegistrar(100L, 100L);
- ThreadPoolPluginManager manager = new DefaultThreadPoolPluginManager();
- ExtensibleThreadPoolExecutor executor = new ExtensibleThreadPoolExecutor(
- "test", manager,
- 5, 5, 1000L, TimeUnit.MILLISECONDS,
- new ArrayBlockingQueue<>(1), Thread::new, new ThreadPoolExecutor.AbortPolicy());
- registrar.doRegister(executor);
-
- Assert.assertTrue(manager.getPlugin(TaskDecoratorPlugin.PLUGIN_NAME).isPresent());
- Assert.assertTrue(manager.getPlugin(TaskTimeoutNotifyAlarmPlugin.PLUGIN_NAME).isPresent());
- Assert.assertTrue(manager.getPlugin(TaskRejectCountRecordPlugin.PLUGIN_NAME).isPresent());
- Assert.assertTrue(manager.getPlugin(TaskRejectNotifyAlarmPlugin.PLUGIN_NAME).isPresent());
- Assert.assertTrue(manager.getPlugin(ThreadPoolExecutorShutdownPlugin.PLUGIN_NAME).isPresent());
- }
-
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/manager/EmptyThreadPoolPluginManagerTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/manager/EmptyThreadPoolPluginManagerTest.java
deleted file mode 100644
index ce80299c..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/manager/EmptyThreadPoolPluginManagerTest.java
+++ /dev/null
@@ -1,155 +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 cn.hippo4j.core.executor.plugin.manager;
-
-import cn.hippo4j.core.executor.plugin.manager.EmptyThreadPoolPluginManager;
-import cn.hippo4j.core.executor.plugin.ThreadPoolPlugin;
-import cn.hippo4j.core.executor.plugin.manager.ThreadPoolPluginManager;
-import lombok.Getter;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.Collections;
-import java.util.Optional;
-
-/**
- * test for {@link EmptyThreadPoolPluginManager}
- */
-public class EmptyThreadPoolPluginManagerTest {
-
- private final ThreadPoolPluginManager manager = EmptyThreadPoolPluginManager.INSTANCE;
-
- @Test
- public void testEmpty() {
- Assert.assertSame(manager, ThreadPoolPluginManager.empty());
- }
-
- @Test
- public void testGetAllPlugins() {
- Assert.assertEquals(Collections.emptyList(), manager.getAllPluginRuntimes());
- }
-
- @Test
- public void testClear() {
- manager.clear();
- Assert.assertTrue(isEmpty(manager));
- }
-
- @Test
- public void testRegister() {
- manager.register(new TestPlugin());
- Assert.assertTrue(isEmpty(manager));
- }
-
- @Test
- public void testTryRegister() {
- Assert.assertFalse(manager.tryRegister(new TestPlugin()));
- }
-
- @Test
- public void testIsRegistered() {
- manager.register(new TestPlugin());
- Assert.assertFalse(manager.isRegistered(TestPlugin.class.getSimpleName()));
- }
-
- @Test
- public void testUnregister() {
- manager.register(new TestPlugin());
- manager.unregister(TestPlugin.class.getSimpleName());
- Assert.assertTrue(isEmpty(manager));
- }
-
- @Test
- public void testGetPlugin() {
- Assert.assertSame(Optional.empty(), manager.getPlugin(""));
- }
-
- @Test
- public void testGetRejectedAwarePluginList() {
- Assert.assertEquals(Collections.emptyList(), manager.getRejectedAwarePluginList());
- }
-
- @Test
- public void testGetShutdownAwarePluginList() {
- Assert.assertEquals(Collections.emptyList(), manager.getShutdownAwarePluginList());
- }
-
- @Test
- public void testGetTaskAwarePluginList() {
- Assert.assertEquals(Collections.emptyList(), manager.getTaskAwarePluginList());
- }
-
- @Test
- public void testGetExecuteAwarePluginList() {
- Assert.assertEquals(Collections.emptyList(), manager.getExecuteAwarePluginList());
- }
-
- @Test
- public void testEnable() {
- ThreadPoolPlugin plugin = new TestPlugin();
- Assert.assertFalse(manager.enable(plugin.getId()));
- manager.register(plugin);
- Assert.assertFalse(manager.enable(plugin.getId()));
- manager.disable(plugin.getId());
- Assert.assertFalse(manager.enable(plugin.getId()));
- }
-
- @Test
- public void testDisable() {
- ThreadPoolPlugin plugin = new TestPlugin();
- Assert.assertFalse(manager.disable(plugin.getId()));
-
- manager.register(plugin);
- Assert.assertFalse(manager.disable(plugin.getId()));
- Assert.assertFalse(manager.disable(plugin.getId()));
-
- Assert.assertTrue(manager.getExecuteAwarePluginList().isEmpty());
- Assert.assertTrue(manager.getAllPlugins().isEmpty());
- }
-
- @Test
- public void testIsDisable() {
- ThreadPoolPlugin plugin = new TestPlugin();
- Assert.assertTrue(manager.isDisabled(plugin.getId()));
-
- manager.register(plugin);
- Assert.assertFalse(manager.disable(plugin.getId()));
- Assert.assertTrue(manager.isDisabled(plugin.getId()));
- }
-
- @Test
- public void testGetDisabledPluginIds() {
- ThreadPoolPlugin plugin = new TestPlugin();
- Assert.assertTrue(manager.getAllDisabledPluginIds().isEmpty());
-
- manager.register(plugin);
- Assert.assertFalse(manager.disable(plugin.getId()));
- Assert.assertTrue(manager.getAllDisabledPluginIds().isEmpty());
- }
-
- private static boolean isEmpty(ThreadPoolPluginManager manager) {
- return manager.getAllPlugins().isEmpty();
- }
-
- @Getter
- private static class TestPlugin implements ThreadPoolPlugin {
-
- private final String id = TestPlugin.class.getSimpleName();
- }
-
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/manager/ThreadPoolPluginSupportTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/manager/ThreadPoolPluginSupportTest.java
deleted file mode 100644
index 0d5c2e87..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/plugin/manager/ThreadPoolPluginSupportTest.java
+++ /dev/null
@@ -1,239 +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 cn.hippo4j.core.executor.plugin.manager;
-
-import cn.hippo4j.core.executor.ExtensibleThreadPoolExecutor;
-import cn.hippo4j.core.executor.plugin.ExecuteAwarePlugin;
-import cn.hippo4j.core.executor.plugin.RejectedAwarePlugin;
-import cn.hippo4j.core.executor.plugin.ShutdownAwarePlugin;
-import cn.hippo4j.core.executor.plugin.TaskAwarePlugin;
-import cn.hippo4j.core.executor.plugin.ThreadPoolPlugin;
-import cn.hippo4j.core.executor.plugin.manager.DefaultThreadPoolPluginManager;
-import cn.hippo4j.core.executor.plugin.manager.ThreadPoolPluginManager;
-import cn.hippo4j.core.executor.plugin.manager.ThreadPoolPluginSupport;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-/**
- * test for default method of {@link ThreadPoolPluginSupport}
- */
-public class ThreadPoolPluginSupportTest {
-
- private final ThreadPoolPluginManager manager = new DefaultThreadPoolPluginManager();
- private final ExtensibleThreadPoolExecutor executor = new ExtensibleThreadPoolExecutor(
- "test", manager,
- 5, 5, 1000L, TimeUnit.MILLISECONDS,
- new ArrayBlockingQueue<>(1), Thread::new, new ThreadPoolExecutor.AbortPolicy());
- private final ThreadPoolPluginSupport support = new TestSupport(executor.getThreadPoolId(), executor, manager);
-
- @Test
- public void testGetThreadPoolId() {
- Assert.assertEquals(executor.getThreadPoolId(), support.getThreadPoolId());
- }
-
- @Test
- public void testGetThreadPoolPluginManager() {
- Assert.assertEquals(manager, support.getThreadPoolPluginManager());
- }
-
- @Getter
- @RequiredArgsConstructor
- private static class TestSupport implements ThreadPoolPluginSupport {
-
- private final String threadPoolId;
- private final ExtensibleThreadPoolExecutor threadPoolExecutor;
- private final ThreadPoolPluginManager threadPoolPluginManager;
- }
-
- // ================ default delegate method ================
-
- @Test
- public void testRegister() {
- support.register(new TestShutdownAwarePlugin());
- Assert.assertEquals(1, support.getAllPlugins().size());
- }
-
- @Test
- public void testGetAllPlugins() {
- support.register(new TestExecuteAwarePlugin());
- support.register(new TestRejectedAwarePlugin());
- Assert.assertEquals(2, support.getAllPlugins().size());
- }
-
- @Test
- public void testClear() {
- support.register(new TestExecuteAwarePlugin());
- support.clear();
- Assert.assertTrue(support.getAllPlugins().isEmpty());
- }
-
- @Test
- public void testTryRegister() {
- Assert.assertTrue(support.tryRegister(new TestExecuteAwarePlugin()));
- Assert.assertFalse(support.tryRegister(new TestExecuteAwarePlugin()));
- }
-
- @Test
- public void testIsRegistered() {
- Assert.assertFalse(support.isRegistered(TestExecuteAwarePlugin.class.getSimpleName()));
- support.register(new TestExecuteAwarePlugin());
- Assert.assertTrue(support.isRegistered(TestExecuteAwarePlugin.class.getSimpleName()));
- }
-
- @Test
- public void testUnregister() {
- support.register(new TestExecuteAwarePlugin());
- support.unregister(TestExecuteAwarePlugin.class.getSimpleName());
- Assert.assertFalse(support.isRegistered(TestExecuteAwarePlugin.class.getSimpleName()));
- }
-
- @Test
- public void testGetPlugin() {
- ThreadPoolPlugin plugin = new TestExecuteAwarePlugin();
- support.register(plugin);
- Assert.assertSame(plugin, support.getPlugin(plugin.getId()).orElse(null));
- }
-
- @Test
- public void testGetRejectedAwarePluginList() {
- support.register(new TestRejectedAwarePlugin());
- Assert.assertEquals(1, support.getRejectedAwarePluginList().size());
- }
-
- @Test
- public void testGetShutdownAwarePluginList() {
- support.register(new TestShutdownAwarePlugin());
- Assert.assertEquals(1, support.getShutdownAwarePluginList().size());
- }
-
- @Test
- public void testGetTaskAwarePluginList() {
- support.register(new TestTaskAwarePlugin());
- Assert.assertEquals(1, support.getTaskAwarePluginList().size());
- }
-
- @Test
- public void testGetExecuteAwarePluginList() {
- support.register(new TestExecuteAwarePlugin());
- Assert.assertEquals(1, support.getExecuteAwarePluginList().size());
- }
-
- @Test
- public void testGetAllPluginsOfType() {
- support.register(new TestExecuteAwarePlugin());
- support.register(new TestRejectedAwarePlugin());
- Assert.assertEquals(1, support.getAllPluginsOfType(TestExecuteAwarePlugin.class).size());
- Assert.assertEquals(1, support.getAllPluginsOfType(TestRejectedAwarePlugin.class).size());
- Assert.assertEquals(2, support.getAllPluginsOfType(ThreadPoolPlugin.class).size());
- }
-
- @Test
- public void testGetAllPluginRuntimes() {
- support.register(new TestExecuteAwarePlugin());
- support.register(new TestRejectedAwarePlugin());
- Assert.assertEquals(2, support.getAllPluginRuntimes().size());
- }
-
- @Test
- public void testGetPluginRuntime() {
- support.register(new TestExecuteAwarePlugin());
- Assert.assertTrue(support.getRuntime(TestExecuteAwarePlugin.class.getSimpleName()).isPresent());
- }
-
- @Test
- public void testGetPluginOfType() {
- support.register(new TestExecuteAwarePlugin());
- Assert.assertTrue(support.getPluginOfType(TestExecuteAwarePlugin.class.getSimpleName(), TestExecuteAwarePlugin.class).isPresent());
- Assert.assertTrue(support.getPluginOfType(TestExecuteAwarePlugin.class.getSimpleName(), ThreadPoolPlugin.class).isPresent());
- Assert.assertFalse(support.getPluginOfType(TestExecuteAwarePlugin.class.getSimpleName(), RejectedAwarePlugin.class).isPresent());
- }
-
- @Test
- public void testEnable() {
- ThreadPoolPlugin plugin = new TestExecuteAwarePlugin();
- Assert.assertFalse(support.enable(plugin.getId()));
- support.register(plugin);
- Assert.assertFalse(support.enable(plugin.getId()));
- support.disable(plugin.getId());
- Assert.assertTrue(support.enable(plugin.getId()));
- }
-
- @Test
- public void testDisable() {
- ThreadPoolPlugin plugin = new TestExecuteAwarePlugin();
- Assert.assertFalse(support.disable(plugin.getId()));
-
- support.register(plugin);
- Assert.assertTrue(support.disable(plugin.getId()));
- Assert.assertFalse(support.disable(plugin.getId()));
-
- Assert.assertTrue(support.getExecuteAwarePluginList().isEmpty());
- Assert.assertEquals(1, support.getAllPlugins().size());
- }
-
- @Test
- public void testIsDisable() {
- ThreadPoolPlugin plugin = new TestExecuteAwarePlugin();
- Assert.assertFalse(support.isDisabled(plugin.getId()));
-
- support.register(plugin);
- Assert.assertTrue(support.disable(plugin.getId()));
- Assert.assertTrue(support.isDisabled(plugin.getId()));
- }
-
- @Test
- public void testGetDisabledPluginIds() {
- ThreadPoolPlugin plugin = new TestExecuteAwarePlugin();
- Assert.assertTrue(support.getAllDisabledPluginIds().isEmpty());
-
- support.register(plugin);
- Assert.assertTrue(support.disable(plugin.getId()));
- Assert.assertEquals(1, support.getAllDisabledPluginIds().size());
- }
-
- @Getter
- private final static class TestTaskAwarePlugin implements TaskAwarePlugin {
-
- private final String id = this.getClass().getSimpleName();
- }
-
- @Getter
- private final static class TestExecuteAwarePlugin implements ExecuteAwarePlugin {
-
- private final String id = this.getClass().getSimpleName();
- }
-
- @Getter
- private final static class TestRejectedAwarePlugin implements RejectedAwarePlugin {
-
- private final String id = this.getClass().getSimpleName();
- }
-
- @Getter
- private final static class TestShutdownAwarePlugin implements ShutdownAwarePlugin {
-
- private final String id = this.getClass().getSimpleName();
- }
-
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/proxy/RejectedProxyInvocationHandlerTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/proxy/RejectedProxyInvocationHandlerTest.java
deleted file mode 100644
index 548c24a4..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/proxy/RejectedProxyInvocationHandlerTest.java
+++ /dev/null
@@ -1,74 +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 cn.hippo4j.core.executor.proxy;
-
-import cn.hippo4j.core.config.ApplicationContextHolder;
-import cn.hippo4j.threadpool.alarm.api.ThreadPoolCheckAlarm;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.jupiter.api.Assertions;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockedStatic;
-import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.springframework.context.ApplicationContext;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.concurrent.atomic.AtomicLong;
-
-@RunWith(MockitoJUnitRunner.class)
-public class RejectedProxyInvocationHandlerTest {
-
- @Mock
- private ThreadPoolCheckAlarm mockAlarmHandler;
-
- @Mock
- private ApplicationContext applicationContext;
-
- @Mock
- private Object target;
-
- @Mock
- private Method mockMethod;
-
- private RejectedProxyInvocationHandler handler;
-
- private AtomicLong rejectCount;
-
- @Before
- public void setUp() {
- String threadPoolId = "test-pool";
- rejectCount = new AtomicLong(0);
- handler = new RejectedProxyInvocationHandler(target, threadPoolId, rejectCount);
- }
-
- @Test
- public void testInvoke() throws Throwable {
- Object[] mockArgs = new Object[]{"arg1", "arg2"};
- MockedStatic mockedStatic = Mockito.mockStatic(ApplicationContextHolder.class);
- mockedStatic.when(ApplicationContextHolder::getInstance).thenReturn(applicationContext);
- mockedStatic.when(() -> ApplicationContextHolder.getBean(ThreadPoolCheckAlarm.class)).thenReturn(mockAlarmHandler);
- Mockito.doNothing().when(mockAlarmHandler).asyncSendRejectedAlarm("test-pool");
- handler.invoke(null, mockMethod, mockArgs);
- Mockito.doThrow(new InvocationTargetException(new Throwable())).when(mockMethod).invoke(target, mockArgs);
- Assertions.assertThrows(Throwable.class, () -> handler.invoke(null, mockMethod, mockArgs));
- Assertions.assertSame(rejectCount.get(), 2L);
- }
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/state/AbstractThreadPoolRuntimeTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/state/AbstractThreadPoolRuntimeTest.java
deleted file mode 100644
index 27424979..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/state/AbstractThreadPoolRuntimeTest.java
+++ /dev/null
@@ -1,56 +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 cn.hippo4j.core.executor.state;
-
-import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
-import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
-import cn.hippo4j.common.support.AbstractThreadPoolRuntime;
-import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
-import org.junit.Test;
-import org.junit.jupiter.api.Assertions;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-@RunWith(MockitoJUnitRunner.class)
-public class AbstractThreadPoolRuntimeTest {
-
- @Test
- public void testPoolRunState() {
- AbstractThreadPoolRuntime threadPoolRuntime = new AbstractThreadPoolRuntime() {
-
- @Override
- public ThreadPoolRunStateInfo supplement(ThreadPoolRunStateInfo threadPoolRunStateInfo) {
- return threadPoolRunStateInfo;
- }
- };
- final String threadPoolId = "test";
- DynamicThreadPoolExecutor executor = new DynamicThreadPoolExecutor(
- 1, 1, 1000L, TimeUnit.MILLISECONDS,
- 1000L, true, 1000L,
- new ArrayBlockingQueue<>(1), threadPoolId, Thread::new, new ThreadPoolExecutor.DiscardOldestPolicy());
- ThreadPoolExecutorRegistry.putHolder(threadPoolId, executor, null);
- ThreadPoolRunStateInfo threadPoolRunStateInfo = threadPoolRuntime.getPoolRunState(threadPoolId);
- Assertions.assertNotNull(threadPoolRunStateInfo);
- threadPoolRunStateInfo = threadPoolRuntime.getPoolRunState(threadPoolId, executor);
- Assertions.assertNotNull(threadPoolRunStateInfo);
- }
-}
\ No newline at end of file
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/state/ThreadPoolRunStateHandlerTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/state/ThreadPoolRunStateHandlerTest.java
deleted file mode 100644
index de54d213..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/state/ThreadPoolRunStateHandlerTest.java
+++ /dev/null
@@ -1,127 +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 cn.hippo4j.core.executor.state;
-
-import cn.hippo4j.common.executor.ThreadPoolExecutorHolder;
-import cn.hippo4j.common.executor.ThreadPoolExecutorRegistry;
-import cn.hippo4j.common.handler.ThreadPoolStatusHandler;
-import cn.hippo4j.common.model.ManyThreadPoolRunStateInfo;
-import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
-import cn.hippo4j.common.toolkit.BeanUtil;
-import cn.hippo4j.common.toolkit.ByteConvertUtil;
-import cn.hippo4j.common.toolkit.MemoryUtil;
-import cn.hippo4j.common.toolkit.StringUtil;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.Mock;
-import org.mockito.MockedStatic;
-import org.mockito.MockitoAnnotations;
-import org.mockito.junit.jupiter.MockitoExtension;
-import org.springframework.core.env.ConfigurableEnvironment;
-
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-import static cn.hippo4j.core.toolkit.IdentifyUtil.CLIENT_IDENTIFICATION_VALUE;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.mockStatic;
-import static org.mockito.Mockito.when;
-
-@ExtendWith(MockitoExtension.class)
-public class ThreadPoolRunStateHandlerTest {
-
- @Mock
- ConfigurableEnvironment environment;
-
- ThreadPoolRunStateInfo poolRunStateInfo = new ThreadPoolRunStateInfo();
-
- @BeforeEach
- void setUp() {
- MockitoAnnotations.openMocks(this);
- poolRunStateInfo.setCurrentLoad(poolRunStateInfo.getCurrentLoad() + "%");
- poolRunStateInfo.setPeakLoad(poolRunStateInfo.getPeakLoad() + "%");
- poolRunStateInfo.setTpId("1");
- }
-
- @Test
- void testSupplement() {
- long used = MemoryUtil.heapMemoryUsed();
- long max = MemoryUtil.heapMemoryMax();
- String memoryProportion = StringUtil.newBuilder(
- "Allocation: ",
- ByteConvertUtil.getPrintSize(used),
- " / Maximum available: ",
- ByteConvertUtil.getPrintSize(max));
-
- String ipAddress = "127.0.0.1";
-
- poolRunStateInfo.setHost(ipAddress);
- poolRunStateInfo.setMemoryProportion(memoryProportion);
- poolRunStateInfo.setFreeMemory(ByteConvertUtil.getPrintSize(Math.subtractExact(max, used)));
-
- String threadPoolId = poolRunStateInfo.getTpId();
-
- try (final MockedStatic globalThreadPoolManage = mockStatic(ThreadPoolExecutorRegistry.class)) {
- globalThreadPoolManage.when(() -> ThreadPoolExecutorRegistry.getHolder("1")).thenReturn(new ThreadPoolExecutorHolder());
- ThreadPoolExecutorHolder executorHolder = ThreadPoolExecutorRegistry.getHolder(threadPoolId);
- Assertions.assertNotNull(executorHolder);
- }
-
- ThreadPoolExecutorHolder threadPoolExecutorHolderMock = mock(ThreadPoolExecutorHolder.class);
- when(threadPoolExecutorHolderMock.getExecutor()).thenReturn(new ThreadPoolExecutor(2, 2, 2000, TimeUnit.SECONDS, new SynchronousQueue<>()));
- ThreadPoolExecutor pool = threadPoolExecutorHolderMock.getExecutor();
- Assertions.assertNotNull(pool);
-
- String rejectedName;
- rejectedName = "java.util.concurrent.ThreadPoolExecutor.AbortPolicy";
- poolRunStateInfo.setRejectedName(rejectedName);
-
- ManyThreadPoolRunStateInfo manyThreadPoolRunStateInfo = BeanUtil.convert(poolRunStateInfo, ManyThreadPoolRunStateInfo.class);
- manyThreadPoolRunStateInfo.setIdentify(CLIENT_IDENTIFICATION_VALUE);
- String active = environment.getProperty("spring.profiles.active", "UNKNOWN");
- manyThreadPoolRunStateInfo.setActive("TRUE");
- String threadPoolState = ThreadPoolStatusHandler.getThreadPoolState(pool);
- manyThreadPoolRunStateInfo.setState(threadPoolState);
- Assertions.assertNotNull(manyThreadPoolRunStateInfo);
- }
-
- @Test
- void testGetHeapMemory() {
- try (MockedStatic memoryUtil = mockStatic(MemoryUtil.class)) {
- memoryUtil.when(MemoryUtil::heapMemoryUsed).thenReturn(57534464L);
- memoryUtil.when(MemoryUtil::heapMemoryMax).thenReturn(8566865920L);
- Assertions.assertEquals(8566865920L, MemoryUtil.heapMemoryMax());
- Assertions.assertEquals(57534464L, MemoryUtil.heapMemoryUsed());
- }
- }
-
- @Test
- void testMemoryProportion() {
- long used = 57534464L;
- long max = 8566865920L;
- String memoryProportion = StringUtil.newBuilder(
- "Allocation: ",
- ByteConvertUtil.getPrintSize(used),
- " / Maximum available: ",
- ByteConvertUtil.getPrintSize(max));
- Assertions.assertEquals("Allocation: 54.87MB / Maximum available: 7.98GB", memoryProportion);
- }
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/executor/support/AbstractBuildThreadPoolTemplateTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/executor/support/AbstractBuildThreadPoolTemplateTest.java
deleted file mode 100644
index 2db5ea4e..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/executor/support/AbstractBuildThreadPoolTemplateTest.java
+++ /dev/null
@@ -1,98 +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 cn.hippo4j.core.executor.support;
-
-import cn.hippo4j.common.toolkit.ThreadUtil;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.concurrent.Executors;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * test for {@link AbstractBuildThreadPoolTemplate}
- *
- * @author dmego
- */
-public class AbstractBuildThreadPoolTemplateTest {
-
- AbstractBuildThreadPoolTemplate.ThreadPoolInitParam initParam;
-
- @Before
- public void before() {
- initParam = new AbstractBuildThreadPoolTemplate.ThreadPoolInitParam(Executors.defaultThreadFactory());
- initParam.setCorePoolNum(1)
- .setMaximumPoolSize(1)
- .setKeepAliveTime(1000L)
- .setCapacity(10)
- .setExecuteTimeOut(5000L)
- .setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy())
- .setWorkQueue(new LinkedBlockingQueue<>(1))
- .setTimeUnit(TimeUnit.MILLISECONDS)
- .setAllowCoreThreadTimeOut(false)
- .setThreadPoolId("test")
- .setTaskDecorator(runnable -> runnable);
- }
-
- @Test
- public void testBuildPool() {
- ThreadPoolExecutor executor = AbstractBuildThreadPoolTemplate.buildPool(initParam);
- AtomicInteger count = new AtomicInteger(0);
- executor.submit(() -> {
- ThreadUtil.sleep(100L);
- return count.incrementAndGet();
- });
- executor.submit(() -> {
- ThreadUtil.sleep(100L);
- count.incrementAndGet();
- });
-
- // waiting for shutdown
- executor.shutdown();
- while (!executor.isTerminated()) {
- }
- Assert.assertEquals(2, count.get());
-
- }
-
- @Test
- public void testBuildDynamicPool() {
- initParam.setWaitForTasksToCompleteOnShutdown(true);
- initParam.setAwaitTerminationMillis(5000L);
- ThreadPoolExecutor executor = AbstractBuildThreadPoolTemplate.buildDynamicPool(initParam);
- AtomicInteger count = new AtomicInteger(0);
- executor.submit(() -> {
- ThreadUtil.sleep(100L);
- return count.incrementAndGet();
- });
- executor.submit(() -> {
- ThreadUtil.sleep(100L);
- count.incrementAndGet();
- });
- // waiting for shutdown
- executor.shutdown();
- while (!executor.isTerminated()) {
- }
-
- Assert.assertEquals(2, count.get());
- }
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/extension/ExtensionInvokerTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/extension/ExtensionInvokerTest.java
deleted file mode 100644
index 673c3464..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/extension/ExtensionInvokerTest.java
+++ /dev/null
@@ -1,84 +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 cn.hippo4j.core.extension;
-
-import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry;
-import cn.hippo4j.core.extension.anymatch.AnyMatchExtImplA;
-import cn.hippo4j.core.extension.anymatch.AnyMatchExtImplB;
-import cn.hippo4j.core.extension.anymatch.IAnyMatchExtension;
-import cn.hippo4j.core.extension.firstof.FirstOfExtImplA;
-import cn.hippo4j.core.extension.firstof.FirstOfExtImplB;
-import cn.hippo4j.core.extension.firstof.IFirstOfExtension;
-import cn.hippo4j.core.extension.reducer.Reducers;
-import cn.hippo4j.core.extension.spi.IOldSpi;
-import cn.hippo4j.core.extension.support.ExtensionInvoker;
-import cn.hippo4j.core.extension.support.ExtensionRegistry;
-import org.assertj.core.util.Lists;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.List;
-import java.util.Objects;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-public class ExtensionInvokerTest {
-
- @Before
- public void before() {
- ExtensionRegistry.getInstance().register(new FirstOfExtImplA());
- ExtensionRegistry.getInstance().register(new FirstOfExtImplB());
- ExtensionRegistry.getInstance().register(new AnyMatchExtImplA());
- ExtensionRegistry.getInstance().register(new AnyMatchExtImplB());
-
- ServiceLoaderRegistry.register(IOldSpi.class);
- }
-
- @Test
- public void test() {
-
- Integer arg = 20;
- // first-of
- Integer res1 = ExtensionInvoker.reduceExecute(IFirstOfExtension.class, (ext) -> ext.foo(arg),
- Reducers.firstOfNotNull());
- assertEquals(arg, res1);
-
- // any-match
- Boolean res2 = ExtensionInvoker.reduceExecute(IAnyMatchExtension.class, (ext) -> ext.foo(arg),
- Reducers.anyMatch(Objects::nonNull));
- assertTrue(res2);
-
- // none
- List res3 = ExtensionInvoker.reduceExecute(IFirstOfExtension.class, (ext) -> ext.foo(arg));
- assertArrayEquals(res3.toArray(new Integer[0]), Lists.newArrayList(null, arg).toArray());
-
- // all-match
- Boolean res4 = ExtensionInvoker.reduceExecute(IAnyMatchExtension.class, (ext) -> ext.foo(arg),
- Reducers.allMatch(Objects::nonNull));
- assertTrue(res4);
-
- }
-
- @Test
- public void test_spi_old() {
- Boolean res1 = ExtensionInvoker.reduceExecute(IOldSpi.class, IOldSpi::foo, Reducers.firstOfNotNull());
- assertTrue(res1);
- }
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/extension/anymatch/AnyMatchExtImplA.java b/threadpool/core/src/test/java/cn/hippo4j/core/extension/anymatch/AnyMatchExtImplA.java
deleted file mode 100644
index b9492a6e..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/extension/anymatch/AnyMatchExtImplA.java
+++ /dev/null
@@ -1,29 +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 cn.hippo4j.core.extension.anymatch;
-
-import cn.hippo4j.core.extension.annotation.Realization;
-
-@Realization
-public class AnyMatchExtImplA implements IAnyMatchExtension {
-
- @Override
- public Integer foo(Integer arg) {
- return arg > 0 ? arg : null;
- }
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/extension/anymatch/AnyMatchExtImplB.java b/threadpool/core/src/test/java/cn/hippo4j/core/extension/anymatch/AnyMatchExtImplB.java
deleted file mode 100644
index 74a8d844..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/extension/anymatch/AnyMatchExtImplB.java
+++ /dev/null
@@ -1,29 +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 cn.hippo4j.core.extension.anymatch;
-
-import cn.hippo4j.core.extension.annotation.Realization;
-
-@Realization
-public class AnyMatchExtImplB implements IAnyMatchExtension {
-
- @Override
- public Integer foo(Integer arg) {
- return arg > 0 ? arg : null;
- }
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/extension/anymatch/IAnyMatchExtension.java b/threadpool/core/src/test/java/cn/hippo4j/core/extension/anymatch/IAnyMatchExtension.java
deleted file mode 100644
index 8d4f3caf..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/extension/anymatch/IAnyMatchExtension.java
+++ /dev/null
@@ -1,25 +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 cn.hippo4j.core.extension.anymatch;
-
-import cn.hippo4j.core.extension.IExtension;
-
-public interface IAnyMatchExtension extends IExtension {
-
- Integer foo(Integer arg);
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/extension/firstof/FirstOfExtImplA.java b/threadpool/core/src/test/java/cn/hippo4j/core/extension/firstof/FirstOfExtImplA.java
deleted file mode 100644
index a702e28d..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/extension/firstof/FirstOfExtImplA.java
+++ /dev/null
@@ -1,29 +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 cn.hippo4j.core.extension.firstof;
-
-import cn.hippo4j.core.extension.annotation.Realization;
-
-@Realization
-public class FirstOfExtImplA implements IFirstOfExtension {
-
- @Override
- public Integer foo(Integer arg) {
- return null;
- }
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/extension/firstof/FirstOfExtImplB.java b/threadpool/core/src/test/java/cn/hippo4j/core/extension/firstof/FirstOfExtImplB.java
deleted file mode 100644
index 9fb0ad87..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/extension/firstof/FirstOfExtImplB.java
+++ /dev/null
@@ -1,29 +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 cn.hippo4j.core.extension.firstof;
-
-import cn.hippo4j.core.extension.annotation.Realization;
-
-@Realization
-public class FirstOfExtImplB implements IFirstOfExtension {
-
- @Override
- public Integer foo(Integer arg) {
- return arg;
- }
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/extension/firstof/IFirstOfExtension.java b/threadpool/core/src/test/java/cn/hippo4j/core/extension/firstof/IFirstOfExtension.java
deleted file mode 100644
index ff720d5c..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/extension/firstof/IFirstOfExtension.java
+++ /dev/null
@@ -1,25 +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 cn.hippo4j.core.extension.firstof;
-
-import cn.hippo4j.core.extension.IExtension;
-
-public interface IFirstOfExtension extends IExtension {
-
- Integer foo(Integer arg);
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/extension/spi/IOldSpi.java b/threadpool/core/src/test/java/cn/hippo4j/core/extension/spi/IOldSpi.java
deleted file mode 100644
index e90facc6..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/extension/spi/IOldSpi.java
+++ /dev/null
@@ -1,25 +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 cn.hippo4j.core.extension.spi;
-
-import cn.hippo4j.core.extension.IExtension;
-
-public interface IOldSpi extends IExtension {
-
- Boolean foo();
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/extension/spi/IOldSpiImplA.java b/threadpool/core/src/test/java/cn/hippo4j/core/extension/spi/IOldSpiImplA.java
deleted file mode 100644
index d17fd13d..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/extension/spi/IOldSpiImplA.java
+++ /dev/null
@@ -1,27 +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 cn.hippo4j.core.extension.spi;
-
-public class IOldSpiImplA implements IOldSpi {
-
- @Override
- public Boolean foo() {
- System.out.println(this.getClass().getName());
- return true;
- }
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/spi/DynamicThreadPoolServiceLoaderTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/spi/DynamicThreadPoolServiceLoaderTest.java
deleted file mode 100644
index 86b0e5ae..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/spi/DynamicThreadPoolServiceLoaderTest.java
+++ /dev/null
@@ -1,74 +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 cn.hippo4j.core.spi;
-
-import java.util.Collection;
-
-import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry;
-import org.junit.Test;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertTrue;
-
-/**
- * test {@link ServiceLoaderRegistry}
- */
-public final class DynamicThreadPoolServiceLoaderTest {
-
- @Test
- public void assertRegister() {
- ServiceLoaderRegistry.register(Collection.class);
- Collection> collections = ServiceLoaderRegistry.getSingletonServiceInstances(Collection.class);
- assertTrue(collections.isEmpty());
- }
-
- @Test
- public void assertGetSingletonServiceInstances() {
- ServiceLoaderRegistry.register(TestSingletonInterfaceSPI.class);
- Collection instances = ServiceLoaderRegistry.getSingletonServiceInstances(TestSingletonInterfaceSPI.class);
- assertThat(instances.size(), equalTo(1));
- assertThat(instances.iterator().next(), is(ServiceLoaderRegistry.getSingletonServiceInstances(TestSingletonInterfaceSPI.class).iterator().next()));
- }
-
- @Test
- public void assertNewServiceInstances() {
- ServiceLoaderRegistry.register(TestSingletonInterfaceSPI.class);
- Collection instances = ServiceLoaderRegistry.newServiceInstances(TestSingletonInterfaceSPI.class);
- assertThat(instances.size(), equalTo(1));
- assertThat(instances.iterator().next(), not(ServiceLoaderRegistry.getSingletonServiceInstances(TestSingletonInterfaceSPI.class).iterator().next()));
- }
-
- @Test
- public void assertGetServiceInstancesWhenIsSingleton() {
- ServiceLoaderRegistry.register(TestSingletonInterfaceSPI.class);
- Collection instances = ServiceLoaderRegistry.getServiceInstances(TestSingletonInterfaceSPI.class);
- assertThat(instances.iterator().next(), is(ServiceLoaderRegistry.getSingletonServiceInstances(TestSingletonInterfaceSPI.class).iterator().next()));
-
- }
-
- @Test
- public void assertGetServiceInstancesWhenNotSingleton() {
- ServiceLoaderRegistry.register(TestInterfaceSPI.class);
- Collection instances = ServiceLoaderRegistry.getServiceInstances(TestInterfaceSPI.class);
- assertThat(instances.iterator().next(), not(ServiceLoaderRegistry.getSingletonServiceInstances(TestInterfaceSPI.class).iterator().next()));
-
- }
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/spi/MyArrayBlockingQueue.java b/threadpool/core/src/test/java/cn/hippo4j/core/spi/MyArrayBlockingQueue.java
deleted file mode 100644
index 153d0c74..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/spi/MyArrayBlockingQueue.java
+++ /dev/null
@@ -1,44 +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 cn.hippo4j.core.spi;
-
-import cn.hippo4j.common.executor.support.CustomBlockingQueue;
-
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-
-/**
- * SPI whit generic type test.
- */
-public class MyArrayBlockingQueue implements CustomBlockingQueue {
-
- @Override
- public Integer getType() {
- return null;
- }
-
- @Override
- public String getName() {
- return this.getClass().getSimpleName();
- }
-
- @Override
- public BlockingQueue generateBlockingQueue() {
- return new LinkedBlockingQueue<>(20);
- }
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/spi/TestInterfaceSPI.java b/threadpool/core/src/test/java/cn/hippo4j/core/spi/TestInterfaceSPI.java
deleted file mode 100644
index 1fc9368e..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/spi/TestInterfaceSPI.java
+++ /dev/null
@@ -1,26 +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 cn.hippo4j.core.spi;
-
-import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry;
-
-/**
- * test {@link ServiceLoaderRegistry}
- */
-public interface TestInterfaceSPI {
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/spi/TestInterfaceSPIImpl.java b/threadpool/core/src/test/java/cn/hippo4j/core/spi/TestInterfaceSPIImpl.java
deleted file mode 100644
index 85a8fda6..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/spi/TestInterfaceSPIImpl.java
+++ /dev/null
@@ -1,26 +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 cn.hippo4j.core.spi;
-
-import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry;
-
-/**
- * test {@link ServiceLoaderRegistry}
- */
-public class TestInterfaceSPIImpl implements TestInterfaceSPI {
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/spi/TestSingletonInterfaceSPI.java b/threadpool/core/src/test/java/cn/hippo4j/core/spi/TestSingletonInterfaceSPI.java
deleted file mode 100644
index 8fe82bad..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/spi/TestSingletonInterfaceSPI.java
+++ /dev/null
@@ -1,28 +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 cn.hippo4j.core.spi;
-
-import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry;
-import cn.hippo4j.common.extension.spi.SingletonSPI;
-
-/**
- * test {@link ServiceLoaderRegistry}
- */
-@SingletonSPI
-public interface TestSingletonInterfaceSPI {
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/spi/TestSingletonInterfaceSPIImpl.java b/threadpool/core/src/test/java/cn/hippo4j/core/spi/TestSingletonInterfaceSPIImpl.java
deleted file mode 100644
index 8398109f..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/spi/TestSingletonInterfaceSPIImpl.java
+++ /dev/null
@@ -1,26 +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 cn.hippo4j.core.spi;
-
-import cn.hippo4j.common.extension.spi.ServiceLoaderRegistry;
-
-/**
- * test {@link ServiceLoaderRegistry}
- */
-public class TestSingletonInterfaceSPIImpl implements TestSingletonInterfaceSPI {
-}
diff --git a/threadpool/core/src/test/java/cn/hippo4j/core/toolkit/FileUtilTest.java b/threadpool/core/src/test/java/cn/hippo4j/core/toolkit/FileUtilTest.java
deleted file mode 100644
index 3160c0bc..00000000
--- a/threadpool/core/src/test/java/cn/hippo4j/core/toolkit/FileUtilTest.java
+++ /dev/null
@@ -1,52 +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 cn.hippo4j.core.toolkit;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-
-public class FileUtilTest {
-
- @Test
- public void assertReadUtf8String() {
- String testFilePath = "test/test_utf8.txt";
- String contentByFileUtil = FileUtil.readUtf8String(testFilePath);
- Assert.assertFalse(contentByFileUtil.isEmpty());
- }
-
- @Test
- public void assertReadUtf8String2() {
- String linebreaks = System.getProperty("line.separator");
- String testText = "abcd简体繁体\uD83D\uDE04\uD83D\uDD25& *" + linebreaks +
- "second line" + linebreaks +
- "empty line next" + linebreaks;
- String testFilePath = "test/test_utf8.txt";
- String contentByFileUtil = FileUtil.readUtf8String(testFilePath);
- Assert.assertTrue(testText.equals(contentByFileUtil));
- }
-
- @Test
- public void assertReadLines() {
- String testFilePath = "test/test_utf8.txt";
- List readLines = FileUtil.readLines(testFilePath, StandardCharsets.UTF_8);
- Assert.assertEquals(3, readLines.size());
- }
-}
diff --git a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractDynamicThreadPoolMonitor.java b/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractDynamicThreadPoolMonitor.java
index c8dfe781..22e82065 100644
--- a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractDynamicThreadPoolMonitor.java
+++ b/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractDynamicThreadPoolMonitor.java
@@ -22,7 +22,6 @@ import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.threadpool.monitor.api.DynamicThreadPoolMonitor;
-import javax.annotation.Resource;
import java.util.List;
/**
diff --git a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractWebThreadPoolMonitor.java b/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractWebThreadPoolMonitor.java
index f6b84ee4..e506d287 100644
--- a/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractWebThreadPoolMonitor.java
+++ b/threadpool/monitor/base/src/main/java/cn/hippo4j/monitor/base/AbstractWebThreadPoolMonitor.java
@@ -20,8 +20,7 @@ package cn.hippo4j.monitor.base;
import cn.hippo4j.adapter.web.WebThreadPoolService;
import cn.hippo4j.common.model.ThreadPoolRunStateInfo;
import cn.hippo4j.threadpool.monitor.api.WebThreadPoolMonitor;
-
-import javax.annotation.Resource;
+import jakarta.annotation.Resource;
/**
* Abstract web thread-pool monitor.
diff --git a/threadpool/server/auth/pom.xml b/threadpool/server/auth/pom.xml
index aff6a5d5..ca9c578f 100644
--- a/threadpool/server/auth/pom.xml
+++ b/threadpool/server/auth/pom.xml
@@ -28,8 +28,8 @@
mybatis-plus-boot-starter
- mysql
- mysql-connector-java
+ com.mysql
+ mysql-connector-j
runtime
diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/config/GlobalSecurityConfig.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/config/GlobalSecurityConfig.java
index 83b3d1ca..683dd479 100644
--- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/config/GlobalSecurityConfig.java
+++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/config/GlobalSecurityConfig.java
@@ -23,26 +23,27 @@ import cn.hippo4j.auth.filter.JWTAuthorizationFilter;
import cn.hippo4j.auth.filter.LdapAuthenticationFilter;
import cn.hippo4j.auth.security.JwtTokenManager;
import cn.hippo4j.auth.service.impl.UserDetailsServiceImpl;
+import jakarta.annotation.Resource;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.BeanIds;
-import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
+import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
+import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
-import javax.annotation.Resource;
import java.util.stream.Stream;
/**
@@ -51,7 +52,7 @@ import java.util.stream.Stream;
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
-public class GlobalSecurityConfig extends WebSecurityConfigurerAdapter {
+public class GlobalSecurityConfig {
@Value("${hippo4j.core.auth.enabled:true}")
private Boolean enableAuthentication;
@@ -65,6 +66,8 @@ public class GlobalSecurityConfig extends WebSecurityConfigurerAdapter {
@Resource
private JwtTokenManager tokenManager;
+ private AuthenticationConfiguration authenticationConfiguration;
+
@Bean
public UserDetailsService customUserService() {
return new UserDetailsServiceImpl();
@@ -76,9 +79,10 @@ public class GlobalSecurityConfig extends WebSecurityConfigurerAdapter {
}
@Bean(name = BeanIds.AUTHENTICATION_MANAGER)
- @Override
- public AuthenticationManager authenticationManagerBean() throws Exception {
- return super.authenticationManagerBean();
+ @Autowired
+ public AuthenticationManager authenticationManagerBean(AuthenticationConfiguration authenticationConfiguration) throws Exception {
+ this.authenticationConfiguration = authenticationConfiguration;
+ return authenticationConfiguration.getAuthenticationManager();
}
@Bean
@@ -91,39 +95,43 @@ public class GlobalSecurityConfig extends WebSecurityConfigurerAdapter {
return source;
}
- @Override
- protected void configure(HttpSecurity http) throws Exception {
+ @Bean
+ SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable()
.authorizeRequests()
- .antMatchers("/static/**", "/index.html", "/favicon.ico", "/avatar.jpg").permitAll()
- .antMatchers("/doc.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs").anonymous()
+ .requestMatchers("/static/**", "/index.html", "/favicon.ico", "/avatar.jpg").permitAll()
+ .requestMatchers("/doc.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs").anonymous()
+
.and()
+ .authenticationProvider(authenticationProvider())
+ .authenticationProvider(ldapAuthenticationProvider())
// .addFilter(new JWTAuthenticationFilter(authenticationManager())).authenticationProvider(authenticationProvider())
.addFilter(JWTAuthenticationFilter()).authenticationProvider(ldapAuthenticationProvider())
.addFilter(LdapAuthenticationFilter()).authenticationProvider(ldapAuthenticationProvider())
- .addFilter(new JWTAuthorizationFilter(tokenManager, authenticationManager()))
+ .addFilter(new JWTAuthorizationFilter(tokenManager, authenticationManagerBean(authenticationConfiguration)))
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
disableAuthenticationIfNeeded(http);
http.authorizeRequests().anyRequest().authenticated();
+ return http.build();
}
- @Override
- public void configure(WebSecurity web) throws Exception {
+ @Bean
+ public WebSecurityCustomizer webSecurityCustomizer() {
String[] ignores = Stream.of("/hippo4j/v1/cs/auth/users/apply/token/**").toArray(String[]::new);
- web.ignoring().antMatchers(ignores);
+ return (web) -> web.ignoring().requestMatchers(ignores);
}
private LdapAuthenticationFilter LdapAuthenticationFilter() throws Exception {
- LdapAuthenticationFilter filter = new LdapAuthenticationFilter(authenticationManager());
+ LdapAuthenticationFilter filter = new LdapAuthenticationFilter(authenticationManagerBean(authenticationConfiguration));
filter.setLdapUserDetailsService(ldapUserDetailsService);
- filter.setAuthenticationManager(authenticationManagerBean());
+ filter.setAuthenticationManager(authenticationManagerBean(authenticationConfiguration));
return filter;
}
private JWTAuthenticationFilter JWTAuthenticationFilter() throws Exception {
- JWTAuthenticationFilter filter = new JWTAuthenticationFilter(authenticationManager());
+ JWTAuthenticationFilter filter = new JWTAuthenticationFilter(authenticationManagerBean(authenticationConfiguration));
filter.setLdapUserDetailsService(userDetailsService);
- filter.setAuthenticationManager(authenticationManagerBean());
+ filter.setAuthenticationManager(authenticationManagerBean(authenticationConfiguration));
return filter;
}
@@ -149,15 +157,9 @@ public class GlobalSecurityConfig extends WebSecurityConfigurerAdapter {
return authProvider;
}
- @Override
- protected void configure(AuthenticationManagerBuilder auth) throws Exception {
- auth.authenticationProvider(authenticationProvider())
- .authenticationProvider(ldapAuthenticationProvider());
- }
-
private void disableAuthenticationIfNeeded(HttpSecurity http) throws Exception {
if (Boolean.FALSE.equals(enableAuthentication)) {
- http.authorizeRequests().antMatchers("/hippo4j/v1/cs/**").permitAll();
+ http.authorizeRequests().requestMatchers("/hippo4j/v1/cs/**").permitAll();
}
}
}
diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java
index d9f270b5..c3cf4178 100644
--- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java
+++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthenticationFilter.java
@@ -25,6 +25,9 @@ import cn.hippo4j.auth.toolkit.ReturnT;
import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.server.common.base.Results;
import com.fasterxml.jackson.databind.ObjectMapper;
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.codec.DecodingException;
@@ -39,9 +42,6 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
-import javax.servlet.FilterChain;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collection;
diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthorizationFilter.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthorizationFilter.java
index ccd04f61..91690c1f 100644
--- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthorizationFilter.java
+++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/JWTAuthorizationFilter.java
@@ -24,6 +24,10 @@ import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.common.toolkit.UserContext;
import cn.hippo4j.server.common.base.Results;
import cn.hippo4j.server.common.base.exception.ServiceException;
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.ServletException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -32,10 +36,6 @@ import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collections;
diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/LdapAuthenticationFilter.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/LdapAuthenticationFilter.java
index 1b86b34f..232113dc 100644
--- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/LdapAuthenticationFilter.java
+++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/LdapAuthenticationFilter.java
@@ -25,6 +25,9 @@ import cn.hippo4j.auth.toolkit.ReturnT;
import cn.hippo4j.common.toolkit.JSONUtil;
import cn.hippo4j.server.common.base.Results;
import com.fasterxml.jackson.databind.ObjectMapper;
+import jakarta.servlet.FilterChain;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationServiceException;
@@ -38,9 +41,6 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
-import javax.servlet.FilterChain;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/RewriteUserInfoApiFilter.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/RewriteUserInfoApiFilter.java
index 57885bd5..ddcee05e 100644
--- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/RewriteUserInfoApiFilter.java
+++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/filter/RewriteUserInfoApiFilter.java
@@ -18,13 +18,9 @@
package cn.hippo4j.auth.filter;
import cn.hippo4j.auth.toolkit.AuthUtil;
+import jakarta.servlet.*;
+import jakarta.servlet.http.HttpServletRequest;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
/**
diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/security/AuthManager.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/security/AuthManager.java
index c2ac9be0..75160a7b 100644
--- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/security/AuthManager.java
+++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/security/AuthManager.java
@@ -18,6 +18,7 @@
package cn.hippo4j.auth.security;
import cn.hippo4j.auth.model.biz.user.LoginUser;
+import jakarta.servlet.http.HttpServletRequest;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.expression.AccessException;
@@ -29,8 +30,6 @@ import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
-import javax.servlet.http.HttpServletRequest;
-
/**
* Auth manager.
*/
diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/LdapUserDetailsServiceImpl.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/LdapUserDetailsServiceImpl.java
index a66a4872..42a79ce8 100644
--- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/LdapUserDetailsServiceImpl.java
+++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/LdapUserDetailsServiceImpl.java
@@ -23,6 +23,8 @@ import cn.hippo4j.auth.model.biz.user.JwtUser;
import cn.hippo4j.auth.model.biz.user.LoginUser;
import cn.hippo4j.auth.service.LdapService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
@@ -35,8 +37,6 @@ import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
diff --git a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/UserDetailsServiceImpl.java b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/UserDetailsServiceImpl.java
index 9a8e7ccd..c4c9a50e 100644
--- a/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/UserDetailsServiceImpl.java
+++ b/threadpool/server/auth/src/main/java/cn/hippo4j/auth/service/impl/UserDetailsServiceImpl.java
@@ -22,6 +22,8 @@ import cn.hippo4j.auth.model.UserInfo;
import cn.hippo4j.auth.model.biz.user.JwtUser;
import cn.hippo4j.auth.model.biz.user.LoginUser;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
@@ -36,8 +38,6 @@ import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
diff --git a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/filter/JWTAuthenticationFilterTest.java b/threadpool/server/auth/src/test/java/cn/hippo4j/auth/filter/JWTAuthenticationFilterTest.java
deleted file mode 100644
index debc76a1..00000000
--- a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/filter/JWTAuthenticationFilterTest.java
+++ /dev/null
@@ -1,36 +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 cn.hippo4j.auth.filter;
-
-import cn.hippo4j.common.toolkit.ReflectUtil;
-import org.junit.Test;
-import org.junit.jupiter.api.Assertions;
-import org.springframework.security.authentication.BadCredentialsException;
-import org.springframework.security.core.userdetails.UsernameNotFoundException;
-
-public class JWTAuthenticationFilterTest {
-
- @Test
- public void getMessageTest() {
- JWTAuthenticationFilter filter = new JWTAuthenticationFilter(null);
- Assertions.assertEquals("用户不存在", ReflectUtil.invoke(filter,
- "getMessage", new UsernameNotFoundException("")));
- Assertions.assertEquals("密码错误", ReflectUtil.invoke(filter,
- "getMessage", new BadCredentialsException("")));
- }
-}
diff --git a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/secuity/JwtTokenManagerTest.java b/threadpool/server/auth/src/test/java/cn/hippo4j/auth/secuity/JwtTokenManagerTest.java
deleted file mode 100644
index 77ad19b6..00000000
--- a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/secuity/JwtTokenManagerTest.java
+++ /dev/null
@@ -1,66 +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 cn.hippo4j.auth.secuity;
-
-import cn.hippo4j.auth.security.JwtTokenManager;
-import cn.hippo4j.common.toolkit.Assert;
-import cn.hippo4j.common.toolkit.CollectionUtil;
-import cn.hippo4j.common.toolkit.StringUtil;
-import org.apache.commons.lang3.ObjectUtils;
-import org.junit.Test;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.GrantedAuthority;
-
-import java.util.Collection;
-
-public final class JwtTokenManagerTest {
-
- private static final String USERNAME = "test";
-
- @Test
- public void createTokenTest() {
- JwtTokenManager jwtTokenManager = new JwtTokenManager();
- String token = jwtTokenManager.createToken(USERNAME);
- Assert.isTrue(StringUtil.isNotBlank(token));
- }
-
- @Test
- public void validateTokenTest() {
- JwtTokenManager jwtTokenManager = new JwtTokenManager();
- String token = jwtTokenManager.createToken(USERNAME);
- jwtTokenManager.validateToken(token);
- }
-
- @Test
- public void getAuthenticationTest() {
- JwtTokenManager jwtTokenManager = new JwtTokenManager();
- String token = jwtTokenManager.createToken(USERNAME);
- Authentication authentication = jwtTokenManager.getAuthentication(token);
- Assert.isTrue(authentication.isAuthenticated());
- Collection extends GrantedAuthority> authorities = authentication.getAuthorities();
- Assert.isTrue(CollectionUtil.isEmpty(authorities));
- Object credentials = authentication.getCredentials();
- Assert.isTrue(ObjectUtils.isEmpty(credentials));
- Object details = authentication.getDetails();
- Assert.isTrue(ObjectUtils.isEmpty(details));
- Object principal = authentication.getPrincipal();
- Assert.isTrue(ObjectUtils.isNotEmpty(principal));
- String name = authentication.getName();
- Assert.isTrue(StringUtil.isNotBlank(name));
- }
-}
diff --git a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/service/impl/UserServiceImplTest.java b/threadpool/server/auth/src/test/java/cn/hippo4j/auth/service/impl/UserServiceImplTest.java
deleted file mode 100644
index 42c9cd91..00000000
--- a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/service/impl/UserServiceImplTest.java
+++ /dev/null
@@ -1,37 +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 cn.hippo4j.auth.service.impl;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class UserServiceImplTest {
-
- @Test
- public void testCheckPasswordLength() {
- // 密码为null、空串、过短、过长都会抛出异常
- UserServiceImpl userService = new UserServiceImpl(null, null, null);
- Assert.assertThrows(RuntimeException.class, () -> userService.checkPasswordLength(null));
- Assert.assertThrows(RuntimeException.class, () -> userService.checkPasswordLength(""));
- String shortPassword = "12345";
- Assert.assertThrows(RuntimeException.class, () -> userService.checkPasswordLength(shortPassword));
- String LongPassword = "fjhdjfghdsgahfgajdhsgafghdsbvhbervjdsvhdsbhfbhsdbhfbhsdbavbsbdhjfbhjsdbhfbsdbf";
- Assert.assertThrows(RuntimeException.class, () -> userService.checkPasswordLength(LongPassword));
- }
-
-}
\ No newline at end of file
diff --git a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/AuthUtilTest.java b/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/AuthUtilTest.java
deleted file mode 100644
index f831a2f7..00000000
--- a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/AuthUtilTest.java
+++ /dev/null
@@ -1,38 +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 cn.hippo4j.auth.toolkit;
-
-import cn.hippo4j.common.toolkit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public final class AuthUtilTest {
-
- private AuthUtil authUtil;
-
- @Before
- public void beforeInit() {
- authUtil = new AuthUtil();
- authUtil.setEnableAuthentication(true);
- }
-
- @Test
- public void assertGetEnableAuthentication() {
- Assert.isTrue(AuthUtil.isEnableAuthentication());
- }
-}
diff --git a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/BCryptPasswordEncoderTest.java b/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/BCryptPasswordEncoderTest.java
deleted file mode 100644
index fe0d3195..00000000
--- a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/BCryptPasswordEncoderTest.java
+++ /dev/null
@@ -1,37 +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 cn.hippo4j.auth.toolkit;
-
-import cn.hippo4j.common.toolkit.Assert;
-import org.junit.Test;
-import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
-
-public class BCryptPasswordEncoderTest {
-
- @Test
- public void bCryptPasswordEncoderTest() {
-
- String password = "12345abc";
-
- BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
- String encode = bCryptPasswordEncoder.encode(password);
- boolean matches = bCryptPasswordEncoder.matches(password, encode);
- Assert.isTrue(matches);
- }
-
-}
diff --git a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/JwtTokenUtilTest.java b/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/JwtTokenUtilTest.java
deleted file mode 100644
index 8066d859..00000000
--- a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/JwtTokenUtilTest.java
+++ /dev/null
@@ -1,75 +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 cn.hippo4j.auth.toolkit;
-
-import cn.hippo4j.common.toolkit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public final class JwtTokenUtilTest {
-
- private Long userId = 1L;
-
- private String username = "baymax";
-
- private String role = "";
-
- private boolean isRememberMe = true;
-
- private String token;
-
- @Before
- public void setUp() {
- token = JwtTokenUtil.createToken(userId, username, role, isRememberMe);
- }
-
- @Test
- public void createToken() {
- String name = JwtTokenUtil.getUsername(token);
- Assert.isTrue(username.equals(name));
- Integer userId = JwtTokenUtil.getUserId(token);
- String userRole = JwtTokenUtil.getUserRole(token);
- Assert.isTrue(username.equals(name));
- Assert.isTrue(this.userId.intValue() == userId);
- Assert.isTrue(role.equals(userRole));
- }
-
- @Test
- public void getUsername() {
- String name = JwtTokenUtil.getUsername(token);
- Assert.isTrue(username.equals(name));
- }
-
- @Test
- public void getUserId() {
- Integer id = JwtTokenUtil.getUserId(token);
- Assert.isTrue(userId.intValue() == id);
- }
-
- @Test
- public void getUserRole() {
- String userRole = JwtTokenUtil.getUserRole(token);
- Assert.isTrue(role.equals(userRole));
- }
-
- @Test
- public void isExpiration() {
- boolean isExpiration = JwtTokenUtil.isExpiration(token);
- Assert.isTrue(!isExpiration);
- }
-}
diff --git a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/ReturnTTest.java b/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/ReturnTTest.java
deleted file mode 100644
index 695c714d..00000000
--- a/threadpool/server/auth/src/test/java/cn/hippo4j/auth/toolkit/ReturnTTest.java
+++ /dev/null
@@ -1,49 +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 cn.hippo4j.auth.toolkit;
-
-import cn.hippo4j.common.toolkit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Objects;
-
-public final class ReturnTTest {
-
- private ReturnT returnT;
-
- @Before
- public void beforeInit() {
- returnT = new ReturnT("success");
- }
-
- @Test
- public void assertGetCode() {
- Assert.isTrue(Objects.equals(returnT.getCode(), 200));
- }
-
- @Test
- public void assertGetMessage() {
- Assert.isNull(returnT.getMessage());
- }
-
- @Test
- public void assertGetContent() {
- Assert.isTrue(Objects.equals(returnT.getContent(), "success"));
- }
-}
diff --git a/threadpool/server/common/src/test/java/cn/hippo4j/server/common/base/ResultsTest.java b/threadpool/server/common/src/test/java/cn/hippo4j/server/common/base/ResultsTest.java
deleted file mode 100644
index 9837439d..00000000
--- a/threadpool/server/common/src/test/java/cn/hippo4j/server/common/base/ResultsTest.java
+++ /dev/null
@@ -1,103 +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 cn.hippo4j.server.common.base;
-
-import cn.hippo4j.common.model.Result;
-import cn.hippo4j.common.toolkit.Assert;
-import cn.hippo4j.server.common.base.exception.AbstractException;
-import cn.hippo4j.server.common.base.exception.ErrorCode;
-import org.junit.Test;
-
-import static cn.hippo4j.server.common.base.exception.ErrorCodeEnum.SERVICE_ERROR;
-
-public class ResultsTest {
-
- @Test
- public void success() {
- Assert.isTrue(Result.SUCCESS_CODE.equals(Results.success().getCode()));
- }
-
- @Test
- public void testSuccess() {
- Object o = new Object();
- Assert.isTrue(o.equals(Results.success(o).getData()));
- Assert.isTrue(Result.SUCCESS_CODE.equals(Results.success().getCode()));
- }
-
- @Test
- public void failure() {
- Assert.isTrue(SERVICE_ERROR.getCode().equals(Results.failure().getCode()));
- Assert.isTrue(SERVICE_ERROR.getMessage().equals(Results.failure().getMessage()));
- }
-
- @Test
- public void testFailure() {
- String code = "500";
- String msg = "message";
- AbstractException abstractException = new AbstractException(msg, new Throwable(), new ErrorCode() {
-
- @Override
- public String getCode() {
- return code;
- }
-
- @Override
- public String getMessage() {
- return "errorMsg";
- }
- });
- Assert.isTrue(code.equals(Results.failure(abstractException).getCode()));
- Assert.isTrue(msg.equals(Results.failure(abstractException).getMessage()));
- }
-
- @Test
- public void testFailure1() {
- String msg = "throwableMsg";
- Throwable throwable = new Throwable(msg);
- Assert.isTrue(SERVICE_ERROR.getCode().equals(Results.failure(throwable).getCode()));
- Assert.isTrue(msg.equals(Results.failure(throwable).getMessage()));
- }
-
- @Test
- public void testFailure2() {
- String code = "500";
- String msg = "message";
- ErrorCode errorCode = new ErrorCode() {
-
- @Override
- public String getCode() {
- return code;
- }
-
- @Override
- public String getMessage() {
- return msg;
- }
- };
- Assert.isTrue(code.equals(Results.failure(errorCode).getCode()));
- Assert.isTrue(msg.equals(Results.failure(errorCode).getMessage()));
- }
-
- @Test
- public void testFailure3() {
- String code = "500";
- String msg = "message";
- Assert.isTrue(code.equals(Results.failure(code, msg).getCode()));
- Assert.isTrue(msg.equals(Results.failure(code, msg).getMessage()));
- }
-}
\ No newline at end of file
diff --git a/threadpool/server/common/src/test/java/cn/hippo4j/server/common/base/ServiceExceptionTest.java b/threadpool/server/common/src/test/java/cn/hippo4j/server/common/base/ServiceExceptionTest.java
deleted file mode 100644
index 833afe1b..00000000
--- a/threadpool/server/common/src/test/java/cn/hippo4j/server/common/base/ServiceExceptionTest.java
+++ /dev/null
@@ -1,100 +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 cn.hippo4j.server.common.base;
-
-import cn.hippo4j.common.toolkit.Assert;
-import cn.hippo4j.server.common.base.exception.ErrorCode;
-import cn.hippo4j.server.common.base.exception.ErrorCodeEnum;
-import cn.hippo4j.server.common.base.exception.ServiceException;
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import org.checkerframework.checker.units.qual.A;
-import org.junit.jupiter.api.Test;
-import java.util.Objects;
-
-/**
- * Service exception test
- */
-public class ServiceExceptionTest {
-
- @Test
- public void ServiceExceptionTest1() {
- ServiceException serviceException = new ServiceException();
- Assert.isTrue(Objects.equals(serviceException.getErrorCode().getCode(), "3"));
- Assert.isTrue(Objects.equals(serviceException.getMessage(), "SERVICE_ERROR"));
- }
-
- @Test
- public void ServiceExceptionTest2() {
- ErrorCode errorCode = ErrorCodeEnum.LOGIN_TIMEOUT;
- ServiceException serviceException = new ServiceException(errorCode);
- Assert.isTrue(Objects.equals(serviceException.getErrorCode().getCode(), ErrorCodeEnum.LOGIN_TIMEOUT.getCode()));
- Assert.isTrue(Objects.equals(serviceException.getMessage(), ErrorCodeEnum.LOGIN_TIMEOUT.getMessage()));
- }
-
- @Test
- public void ServiceExceptionTest3() {
- String message = ErrorCodeEnum.SERVICE_ERROR.getMessage();
- ServiceException serviceException = new ServiceException(message);
- Assert.isTrue(Objects.equals(serviceException.getMessage(), message));
- }
-
- @Test
- public void ServiceExceptionTest4() {
- Throwable cause = new Throwable();
- ServiceException serviceException = new ServiceException(cause);
- Assert.isTrue(Objects.equals(serviceException.getCause().getMessage(), cause.getMessage()));
- }
-
- @Test
- public void ServiceExceptionTest5() {
- String message = ErrorCodeEnum.SERVICE_ERROR.getMessage();
- Throwable cause = new Throwable();
- ServiceException serviceException = new ServiceException(message, cause);
- Assert.isTrue(Objects.equals(serviceException.getCause().getMessage(), cause.getMessage()));
- Assert.isTrue(Objects.equals(serviceException.getMessage(), message));
- }
-
- @Test
- public void ServiceExceptionTest6() {
- String message = ErrorCodeEnum.SERVICE_ERROR.getMessage();
- Throwable cause = new Throwable();
- ServiceException serviceException = new ServiceException(cause, message);
- Assert.isTrue(Objects.equals(serviceException.getCause().getMessage(), cause.getMessage()));
- Assert.isTrue(Objects.equals(serviceException.getMessage(), message));
- }
-
- @Test
- public void ServiceExceptionTest7() {
- Throwable cause = new Throwable();
- ErrorCode errorCode = ErrorCodeEnum.LOGIN_TIMEOUT;
- ServiceException serviceException = new ServiceException(cause, errorCode);
- Assert.isTrue(Objects.equals(serviceException.getCause().getMessage(), cause.getMessage()));
- Assert.isTrue(Objects.equals(serviceException.getErrorCode().getCode(), ErrorCodeEnum.LOGIN_TIMEOUT.getCode()));
- }
-
- @Test
- public void ServiceExceptionTest8() {
- Throwable cause = new Throwable();
- ErrorCode errorCode = ErrorCodeEnum.LOGIN_TIMEOUT;
- String message = ErrorCodeEnum.SERVICE_ERROR.getMessage();
- ServiceException serviceException = new ServiceException(message, cause, errorCode);
- Assert.isTrue(Objects.equals(serviceException.getCause().getMessage(), cause.getMessage()));
- Assert.isTrue(Objects.equals(serviceException.getErrorCode().getCode(), ErrorCodeEnum.LOGIN_TIMEOUT.getCode()));
- Assert.isTrue(Objects.equals(serviceException.getMessage(), message));
- }
-}
diff --git a/threadpool/server/config/pom.xml b/threadpool/server/config/pom.xml
index 75740382..414c35dd 100644
--- a/threadpool/server/config/pom.xml
+++ b/threadpool/server/config/pom.xml
@@ -32,8 +32,8 @@
mybatis-plus-boot-starter
- mysql
- mysql-connector-java
+ com.mysql
+ mysql-connector-j
runtime
diff --git a/threadpool/server/config/src/main/java/cn/hippo4j/config/controller/ConfigController.java b/threadpool/server/config/src/main/java/cn/hippo4j/config/controller/ConfigController.java
index b0a299f4..fe7849a5 100644
--- a/threadpool/server/config/src/main/java/cn/hippo4j/config/controller/ConfigController.java
+++ b/threadpool/server/config/src/main/java/cn/hippo4j/config/controller/ConfigController.java
@@ -17,19 +17,13 @@
package cn.hippo4j.config.controller;
-import java.net.URLDecoder;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
import cn.hippo4j.common.constant.ConfigModifyTypeConstants;
import cn.hippo4j.common.constant.Constants;
+import cn.hippo4j.common.model.Result;
import cn.hippo4j.common.model.register.DynamicThreadPoolRegisterWrapper;
import cn.hippo4j.common.toolkit.BeanUtil;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.common.toolkit.UserContext;
-import cn.hippo4j.common.model.Result;
import cn.hippo4j.config.model.ConfigAllInfo;
import cn.hippo4j.config.model.ConfigInfoBase;
import cn.hippo4j.config.model.biz.threadpool.ConfigModifySaveReqDTO;
@@ -39,16 +33,15 @@ import cn.hippo4j.config.service.biz.ConfigService;
import cn.hippo4j.config.toolkit.Md5ConfigUtil;
import cn.hippo4j.config.verify.ConfigModificationVerifyServiceChoose;
import cn.hippo4j.server.common.base.Results;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
-
import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
+import java.net.URLDecoder;
+import java.util.Map;
/**
* Server configuration controller.
diff --git a/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/item/ItemSaveReqDTO.java b/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/item/ItemSaveReqDTO.java
index e7b92784..b059a2e7 100644
--- a/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/item/ItemSaveReqDTO.java
+++ b/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/item/ItemSaveReqDTO.java
@@ -17,9 +17,9 @@
package cn.hippo4j.config.model.biz.item;
+import jakarta.validation.constraints.Pattern;
import lombok.Data;
-import javax.validation.constraints.Pattern;
/**
* Item save req dto.
diff --git a/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/tenant/TenantSaveReqDTO.java b/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/tenant/TenantSaveReqDTO.java
index d857746e..571c235a 100644
--- a/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/tenant/TenantSaveReqDTO.java
+++ b/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/tenant/TenantSaveReqDTO.java
@@ -17,9 +17,9 @@
package cn.hippo4j.config.model.biz.tenant;
+import jakarta.validation.constraints.Pattern;
import lombok.Data;
-import javax.validation.constraints.Pattern;
/**
* Tenant save req DTO.
diff --git a/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModifySaveReqDTO.java b/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModifySaveReqDTO.java
index 44fbb066..ee4d54a7 100644
--- a/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModifySaveReqDTO.java
+++ b/threadpool/server/config/src/main/java/cn/hippo4j/config/model/biz/threadpool/ConfigModifySaveReqDTO.java
@@ -17,9 +17,9 @@
package cn.hippo4j.config.model.biz.threadpool;
+import jakarta.validation.constraints.Pattern;
import lombok.Data;
-import javax.validation.constraints.Pattern;
/**
* Config Modify Save Req DTO
diff --git a/threadpool/server/config/src/main/java/cn/hippo4j/config/service/ConfigServletInner.java b/threadpool/server/config/src/main/java/cn/hippo4j/config/service/ConfigServletInner.java
index 30b86346..07469e8a 100644
--- a/threadpool/server/config/src/main/java/cn/hippo4j/config/service/ConfigServletInner.java
+++ b/threadpool/server/config/src/main/java/cn/hippo4j/config/service/ConfigServletInner.java
@@ -19,11 +19,11 @@ package cn.hippo4j.config.service;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import static cn.hippo4j.common.constant.Constants.WEIGHT_CONFIGS;
diff --git a/threadpool/server/config/src/main/java/cn/hippo4j/config/service/LongPollingService.java b/threadpool/server/config/src/main/java/cn/hippo4j/config/service/LongPollingService.java
index 21d8256c..5852d533 100644
--- a/threadpool/server/config/src/main/java/cn/hippo4j/config/service/LongPollingService.java
+++ b/threadpool/server/config/src/main/java/cn/hippo4j/config/service/LongPollingService.java
@@ -17,11 +17,7 @@
package cn.hippo4j.config.service;
-import cn.hippo4j.common.toolkit.CollectionUtil;
-import cn.hippo4j.common.toolkit.JSONUtil;
-import cn.hippo4j.common.toolkit.MapUtil;
-import cn.hippo4j.common.toolkit.Md5Util;
-import cn.hippo4j.common.toolkit.StringUtil;
+import cn.hippo4j.common.toolkit.*;
import cn.hippo4j.config.event.AbstractEvent;
import cn.hippo4j.config.event.LocalDataChangeEvent;
import cn.hippo4j.config.notify.NotifyCenter;
@@ -30,19 +26,15 @@ import cn.hippo4j.config.toolkit.ConfigExecutor;
import cn.hippo4j.config.toolkit.Md5ConfigUtil;
import cn.hippo4j.config.toolkit.RequestUtil;
import cn.hippo4j.server.common.base.Results;
+import jakarta.servlet.AsyncContext;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.stereotype.Service;
-import javax.servlet.AsyncContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Future;
diff --git a/threadpool/server/config/src/main/java/cn/hippo4j/config/service/biz/impl/AbstractConfigModificationVerifyService.java b/threadpool/server/config/src/main/java/cn/hippo4j/config/service/biz/impl/AbstractConfigModificationVerifyService.java
index 62315301..89e465d8 100644
--- a/threadpool/server/config/src/main/java/cn/hippo4j/config/service/biz/impl/AbstractConfigModificationVerifyService.java
+++ b/threadpool/server/config/src/main/java/cn/hippo4j/config/service/biz/impl/AbstractConfigModificationVerifyService.java
@@ -31,8 +31,8 @@ import cn.hippo4j.config.service.biz.ConfigModificationVerifyService;
import cn.hippo4j.discovery.core.BaseInstanceRegistry;
import cn.hippo4j.discovery.core.Lease;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import jakarta.annotation.Resource;
-import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
diff --git a/threadpool/server/config/src/main/java/cn/hippo4j/config/toolkit/Md5ConfigUtil.java b/threadpool/server/config/src/main/java/cn/hippo4j/config/toolkit/Md5ConfigUtil.java
index ef9d66de..6fecb5f5 100644
--- a/threadpool/server/config/src/main/java/cn/hippo4j/config/toolkit/Md5ConfigUtil.java
+++ b/threadpool/server/config/src/main/java/cn/hippo4j/config/toolkit/Md5ConfigUtil.java
@@ -20,11 +20,11 @@ package cn.hippo4j.config.toolkit;
import cn.hippo4j.common.toolkit.GroupKey;
import cn.hippo4j.common.toolkit.Md5Util;
import cn.hippo4j.common.toolkit.StringUtil;
-import cn.hippo4j.config.service.ConfigCacheService;
import cn.hippo4j.config.model.ConfigAllInfo;
+import cn.hippo4j.config.service.ConfigCacheService;
+import jakarta.servlet.http.HttpServletRequest;
import org.springframework.util.StringUtils;
-import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
@@ -34,11 +34,7 @@ import java.util.Map;
import static cn.hippo4j.common.constant.Constants.LINE_SEPARATOR;
import static cn.hippo4j.common.constant.Constants.WORD_SEPARATOR;
-import static cn.hippo4j.common.constant.MagicNumberConstants.INDEX_0;
-import static cn.hippo4j.common.constant.MagicNumberConstants.INDEX_1;
-import static cn.hippo4j.common.constant.MagicNumberConstants.INDEX_2;
-import static cn.hippo4j.common.constant.MagicNumberConstants.INDEX_3;
-import static cn.hippo4j.common.constant.MagicNumberConstants.SIZE_4;
+import static cn.hippo4j.common.constant.MagicNumberConstants.*;
/**
* Md5 config util.
diff --git a/threadpool/server/config/src/main/java/cn/hippo4j/config/toolkit/RequestUtil.java b/threadpool/server/config/src/main/java/cn/hippo4j/config/toolkit/RequestUtil.java
index cf79e888..ab6dd864 100644
--- a/threadpool/server/config/src/main/java/cn/hippo4j/config/toolkit/RequestUtil.java
+++ b/threadpool/server/config/src/main/java/cn/hippo4j/config/toolkit/RequestUtil.java
@@ -18,8 +18,7 @@
package cn.hippo4j.config.toolkit;
import cn.hippo4j.common.toolkit.StringUtil;
-
-import javax.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletRequest;
import static cn.hippo4j.common.constant.Constants.LONG_PULLING_CLIENT_IDENTIFICATION;
diff --git a/threadpool/server/console/src/main/java/cn/hippo4j/console/config/GlobalExceptionHandler.java b/threadpool/server/console/src/main/java/cn/hippo4j/console/config/GlobalExceptionHandler.java
index cf91bcb4..b3972ae9 100644
--- a/threadpool/server/console/src/main/java/cn/hippo4j/console/config/GlobalExceptionHandler.java
+++ b/threadpool/server/console/src/main/java/cn/hippo4j/console/config/GlobalExceptionHandler.java
@@ -17,12 +17,13 @@
package cn.hippo4j.console.config;
+import cn.hippo4j.common.model.Result;
import cn.hippo4j.common.toolkit.CollectionUtil;
import cn.hippo4j.common.toolkit.StringUtil;
-import cn.hippo4j.common.model.Result;
import cn.hippo4j.server.common.base.Results;
import cn.hippo4j.server.common.base.exception.AbstractException;
import cn.hippo4j.server.common.base.exception.ServiceException;
+import jakarta.servlet.http.HttpServletRequest;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
@@ -32,7 +33,6 @@ import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
-import javax.servlet.http.HttpServletRequest;
import java.util.Optional;
/**
diff --git a/threadpool/server/discovery/src/main/java/cn/hippo4j/discovery/config/RegistryConfiguration.java b/threadpool/server/discovery/src/main/java/cn/hippo4j/discovery/config/RegistryConfiguration.java
index cae2e40d..6a6cd6f6 100644
--- a/threadpool/server/discovery/src/main/java/cn/hippo4j/discovery/config/RegistryConfiguration.java
+++ b/threadpool/server/discovery/src/main/java/cn/hippo4j/discovery/config/RegistryConfiguration.java
@@ -18,11 +18,10 @@
package cn.hippo4j.discovery.config;
import cn.hippo4j.discovery.core.BaseInstanceRegistry;
+import jakarta.annotation.PostConstruct;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration;
-import javax.annotation.PostConstruct;
-
/**
* Registry configuration.
*/