fix: upgrade Mockito to 4.11.0

pull/1612/head
mingri31164 11 months ago
parent 52dc1844dd
commit 047f96272b

@ -17,7 +17,8 @@
<jjwt.version>0.9.0</jjwt.version> <jjwt.version>0.9.0</jjwt.version>
<jackson-bom.version>2.11.1</jackson-bom.version> <jackson-bom.version>2.11.1</jackson-bom.version>
<h2.version>2.1.214</h2.version> <h2.version>2.1.214</h2.version>
<mockito.version>3.12.4</mockito.version> <mockito.version>4.11.0</mockito.version>
<bytebuddy.version>1.12.23</bytebuddy.version>
<dubbo.version>3.0.5</dubbo.version> <dubbo.version>3.0.5</dubbo.version>
<alibaba-dubbo.version>2.6.12</alibaba-dubbo.version> <alibaba-dubbo.version>2.6.12</alibaba-dubbo.version>
<slf4j-api.version>1.7.7</slf4j-api.version> <slf4j-api.version>1.7.7</slf4j-api.version>
@ -112,6 +113,16 @@
<version>${h2.version}</version> <version>${h2.version}</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${bytebuddy.version}</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>${bytebuddy.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-config</artifactId> <artifactId>spring-cloud-starter-consul-config</artifactId>

@ -2,13 +2,13 @@
sidebar_position: 4 sidebar_position: 4
--- ---
# Custom Blocking Queue # 阻塞队列自定义
Hippo4j extends blocking queues through SPI, allowing users to implement custom blocking queue types in Hippo4j. Hippo4j 通过 SPI 的方式对拒绝策略进行扩展,可以让用户在 Hippo4j 中完成自定义阻塞队列实现。
## 1. Define Custom Queue Class ## 1. 定义自定义队列类
Implement the interface `cn.hippo4j.common.executor.support.CustomBlockingQueue<T>`: 实现接口 `cn.hippo4j.common.executor.support.CustomBlockingQueue<T>`
```java ```java
public class MyArrayBlockingQueue implements CustomBlockingQueue<Runnable> { public class MyArrayBlockingQueue implements CustomBlockingQueue<Runnable> {
@ -30,51 +30,51 @@ public class MyArrayBlockingQueue implements CustomBlockingQueue<Runnable> {
} }
``` ```
## 2. Declare SPI File ## 2. 声明 SPI 文件
Create a file in the `src/main/resources/META-INF/services/` directory: `src/main/resources/META-INF/services/` 目录下新增文件:
``` ```
cn.hippo4j.common.executor.support.CustomBlockingQueue cn.hippo4j.common.executor.support.CustomBlockingQueue
``` ```
File content (single line): 文件内容仅一行:
``` ```
com.example.queue.MyArrayBlockingQueue com.example.queue.MyArrayBlockingQueue
``` ```
## 3. Server-side Activation ## 3. 服务端生效方式
When the `queueType` and `capacity` delivered by the server match the custom type, the framework will automatically create the queue through SPI. 当服务端下发的 `queueType``capacity` 命中自定义类型时,框架会通过 SPI 自动创建队列。
### 3.1 Queue Creation and Validation ### 3.1 队列创建与验证
```java ```java
// Create queue // 创建队列
BlockingQueue<T> q = BlockingQueueManager.createQueue(queueType, capacity); BlockingQueue<T> q = BlockingQueueManager.createQueue(queueType, capacity);
// Validate queue configuration // 验证队列配置
boolean valid = BlockingQueueManager.validateQueueConfig(queueType, capacity); boolean valid = BlockingQueueManager.validateQueueConfig(queueType, capacity);
// Dynamic capacity adjustment (only supported by ResizableCapacityLinkedBlockingQueue) // 动态调整容量(仅 ResizableCapacityLinkedBlockingQueue 支持)
boolean ok = BlockingQueueManager.changeQueueCapacity(executor.getQueue(), newCapacity); boolean ok = BlockingQueueManager.changeQueueCapacity(executor.getQueue(), newCapacity);
``` ```
### 3.2 Queue Type Switching ### 3.2 队列类型切换
When you need to switch queue types, use the `ThreadPoolRebuilder.rebuildAndSwitch` method, which creates a new thread pool instance and safely migrates tasks: 当需要切换队列类型时,使用 `ThreadPoolRebuilder.rebuildAndSwitch` 方法,该方法会创建新的线程池实例并安全地迁移任务:
```java ```java
boolean ok = ThreadPoolRebuilder.rebuildAndSwitch( boolean ok = ThreadPoolRebuilder.rebuildAndSwitch(
executor, // Current thread pool executor, // 当前线程池
newQueueType, // New queue type newQueueType, // 新队列类型
capacity, // Queue capacity capacity, // 队列容量
threadPoolId // Thread pool ID threadPoolId // 线程池ID
); );
``` ```
Server-side dynamic refresh implementation: 服务端动态刷新处的实现:
```java ```java
// ServerThreadPoolDynamicRefresh#handleQueueChanges // ServerThreadPoolDynamicRefresh#handleQueueChanges
@ -82,7 +82,7 @@ boolean queueTypeChanged = parameter.getQueueType() != null &&
!Objects.equals(BlockingQueueManager.getQueueType(executor.getQueue()), parameter.getQueueType()); !Objects.equals(BlockingQueueManager.getQueueType(executor.getQueue()), parameter.getQueueType());
if (queueTypeChanged) { if (queueTypeChanged) {
// Use safe rebuild approach for queue switching // 使用安全的重建方式切换队列
boolean ok = ThreadPoolRebuilder.rebuildAndSwitch( boolean ok = ThreadPoolRebuilder.rebuildAndSwitch(
executor, executor,
parameter.getQueueType(), parameter.getQueueType(),
@ -92,7 +92,7 @@ if (queueTypeChanged) {
if (ok) { if (ok) {
log.info("Queue type rebuilt and switched to: {}", log.info("Queue type rebuilt and switched to: {}",
BlockingQueueTypeEnum.getBlockingQueueNameByType(parameter.getQueueType())); BlockingQueueTypeEnum.getBlockingQueueNameByType(parameter.getQueueType()));
} }
} }
``` ```

@ -2,27 +2,27 @@
sidebar_position: 3 sidebar_position: 3
--- ---
# Built-in Blocking Queues # 内置阻塞队列
Hippo4j provides multiple built-in blocking queue types that are ready to use out of the box. You can also extend custom queue types through SPI. Hippo4j 内置多种常用阻塞队列类型,支持开箱即用,亦可通过 SPI 扩展自定义队列类型。
## Built-in Queue Types ## 内置类型清单
The following types can be directly selected in the server or configuration (Enum: `BlockingQueueTypeEnum`): 以下类型可直接在服务端或配置中选择(枚举:`BlockingQueueTypeEnum`
- ArrayBlockingQueue (bounded array-based queue) - ArrayBlockingQueue(数组有界队列)
- LinkedBlockingQueue (linked list queue) - LinkedBlockingQueue(链表队列)
- LinkedBlockingDeque (double-ended queue) - LinkedBlockingDeque(双端队列)
- SynchronousQueue (synchronous handoff queue) - SynchronousQueue(同步移交队列)
- LinkedTransferQueue (transferable queue) - LinkedTransferQueue(可转移队列)
- PriorityBlockingQueue (priority queue) - PriorityBlockingQueue(优先级队列)
- ResizableCapacityLinkedBlockingQueue (dynamically resizable linked list queue) - ResizableCapacityLinkedBlockingQueue(可在线动态调容量的链表队列)
Among them, `ResizableCapacityLinkedBlockingQueue` supports online capacity changes without rebuilding the thread pool, making it suitable for dynamic tuning scenarios. 其中 `ResizableCapacityLinkedBlockingQueue` 支持在线变更 `capacity`,无需重建线程池,适合动态调优场景。
## Code Reference ## 代码对应
Enum definition: 枚举定义:
```java ```java
// cn.hippo4j.common.executor.support.BlockingQueueTypeEnum // cn.hippo4j.common.executor.support.BlockingQueueTypeEnum
@ -38,7 +38,7 @@ RESIZABLE_LINKED_BLOCKING_QUEUE(9, "ResizableCapacityLinkedBlockingQueue") {
} }
``` ```
Creation and validation: 创建与验证:
```java ```java
// cn.hippo4j.common.executor.support.BlockingQueueManager // cn.hippo4j.common.executor.support.BlockingQueueManager
@ -47,13 +47,14 @@ boolean valid = BlockingQueueManager.validateQueueConfig(queueType, capacity);
boolean ok = BlockingQueueManager.changeQueueCapacity(executor.getQueue(), newCapacity); boolean ok = BlockingQueueManager.changeQueueCapacity(executor.getQueue(), newCapacity);
``` ```
## Usage Recommendations ## 使用建议
- Need online capacity adjustment: prioritize `ResizableCapacityLinkedBlockingQueue` - 需要在线调容量:优先选择 `ResizableCapacityLinkedBlockingQueue`
- Need strictly bounded: choose `ArrayBlockingQueue` - 需要严格有界:选择 `ArrayBlockingQueue`
- Need unbounded throughput: choose `LinkedBlockingQueue` - 需要无界吞吐:选择 `LinkedBlockingQueue`
- Need priority: choose `PriorityBlockingQueue` - 需要优先级:选择 `PriorityBlockingQueue`
- Need synchronous handoff: choose `SynchronousQueue` - 需要同步移交:选择 `SynchronousQueue`
如需自定义队列类型,请参考《阻塞队列自定义》。
For custom queue types, please refer to "Custom Blocking Queue".

@ -48,11 +48,6 @@
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.tomcat.embed</groupId> <groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId> <artifactId>tomcat-embed-core</artifactId>

@ -55,7 +55,7 @@
<properties> <properties>
<revision>2.0.0-SNAPSHOT</revision> <revision>2.0.0-SNAPSHOT</revision>
<mockito.version>3.12.4</mockito.version> <mockito.version>4.11.0</mockito.version>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<skip.maven.gpg.plugin>true</skip.maven.gpg.plugin> <skip.maven.gpg.plugin>true</skip.maven.gpg.plugin>
<skip.spotless.apply>false</skip.spotless.apply> <skip.spotless.apply>false</skip.spotless.apply>
@ -101,11 +101,6 @@
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
<version>${mockito.version}</version> <version>${mockito.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId> <artifactId>mockito-junit-jupiter</artifactId>

@ -41,7 +41,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId> <artifactId>mockito-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

Loading…
Cancel
Save