fix: upgrade Mockito to 4.11.0

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

@ -17,7 +17,8 @@
<jjwt.version>0.9.0</jjwt.version>
<jackson-bom.version>2.11.1</jackson-bom.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>
<alibaba-dubbo.version>2.6.12</alibaba-dubbo.version>
<slf4j-api.version>1.7.7</slf4j-api.version>
@ -112,6 +113,16 @@
<version>${h2.version}</version>
<scope>runtime</scope>
</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>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-config</artifactId>

@ -2,13 +2,13 @@
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
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
```
File content (single line):
文件内容仅一行:
```
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
// Create queue
// 创建队列
BlockingQueue<T> q = BlockingQueueManager.createQueue(queueType, capacity);
// Validate queue configuration
// 验证队列配置
boolean valid = BlockingQueueManager.validateQueueConfig(queueType, capacity);
// Dynamic capacity adjustment (only supported by ResizableCapacityLinkedBlockingQueue)
// 动态调整容量(仅 ResizableCapacityLinkedBlockingQueue 支持)
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
boolean ok = ThreadPoolRebuilder.rebuildAndSwitch(
executor, // Current thread pool
newQueueType, // New queue type
capacity, // Queue capacity
threadPoolId // Thread pool ID
executor, // 当前线程池
newQueueType, // 新队列类型
capacity, // 队列容量
threadPoolId // 线程池ID
);
```
Server-side dynamic refresh implementation:
服务端动态刷新处的实现:
```java
// ServerThreadPoolDynamicRefresh#handleQueueChanges
@ -82,7 +82,7 @@ boolean queueTypeChanged = parameter.getQueueType() != null &&
!Objects.equals(BlockingQueueManager.getQueueType(executor.getQueue()), parameter.getQueueType());
if (queueTypeChanged) {
// Use safe rebuild approach for queue switching
// 使用安全的重建方式切换队列
boolean ok = ThreadPoolRebuilder.rebuildAndSwitch(
executor,
parameter.getQueueType(),
@ -92,7 +92,7 @@ if (queueTypeChanged) {
if (ok) {
log.info("Queue type rebuilt and switched to: {}",
BlockingQueueTypeEnum.getBlockingQueueNameByType(parameter.getQueueType()));
}
}
}
```

@ -2,27 +2,27 @@
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)
- LinkedBlockingQueue (linked list queue)
- LinkedBlockingDeque (double-ended queue)
- SynchronousQueue (synchronous handoff queue)
- LinkedTransferQueue (transferable queue)
- PriorityBlockingQueue (priority queue)
- ResizableCapacityLinkedBlockingQueue (dynamically resizable linked list queue)
- ArrayBlockingQueue(数组有界队列)
- LinkedBlockingQueue(链表队列)
- LinkedBlockingDeque(双端队列)
- SynchronousQueue(同步移交队列)
- LinkedTransferQueue(可转移队列)
- PriorityBlockingQueue(优先级队列)
- 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
// cn.hippo4j.common.executor.support.BlockingQueueTypeEnum
@ -38,7 +38,7 @@ RESIZABLE_LINKED_BLOCKING_QUEUE(9, "ResizableCapacityLinkedBlockingQueue") {
}
```
Creation and validation:
创建与验证:
```java
// cn.hippo4j.common.executor.support.BlockingQueueManager
@ -47,13 +47,14 @@ boolean valid = BlockingQueueManager.validateQueueConfig(queueType, capacity);
boolean ok = BlockingQueueManager.changeQueueCapacity(executor.getQueue(), newCapacity);
```
## Usage Recommendations
## 使用建议
- Need online capacity adjustment: prioritize `ResizableCapacityLinkedBlockingQueue`
- Need strictly bounded: choose `ArrayBlockingQueue`
- Need unbounded throughput: choose `LinkedBlockingQueue`
- Need priority: choose `PriorityBlockingQueue`
- Need synchronous handoff: choose `SynchronousQueue`
- 需要在线调容量:优先选择 `ResizableCapacityLinkedBlockingQueue`
- 需要严格有界:选择 `ArrayBlockingQueue`
- 需要无界吞吐:选择 `LinkedBlockingQueue`
- 需要优先级:选择 `PriorityBlockingQueue`
- 需要同步移交:选择 `SynchronousQueue`
如需自定义队列类型,请参考《阻塞队列自定义》。
For custom queue types, please refer to "Custom Blocking Queue".

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

@ -55,7 +55,7 @@
<properties>
<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>
<skip.maven.gpg.plugin>true</skip.maven.gpg.plugin>
<skip.spotless.apply>false</skip.spotless.apply>
@ -101,11 +101,6 @@
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>

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

Loading…
Cancel
Save