|
17 | 17 |
|
18 | 18 | package org.dromara.dynamictp.test.core.notify.capture; |
19 | 19 |
|
20 | | -import org.dromara.dynamictp.common.queue.VariableLinkedBlockingQueue; |
| 20 | +import org.dromara.dynamictp.core.executor.DtpExecutor; |
21 | 21 | import org.dromara.dynamictp.core.notifier.capture.CapturedBlockingQueue; |
22 | 22 | import org.dromara.dynamictp.core.support.ThreadPoolBuilder; |
23 | | -import org.dromara.dynamictp.core.executor.DtpExecutor; |
24 | 23 | import org.junit.jupiter.api.Assertions; |
25 | 24 | import org.junit.jupiter.api.BeforeAll; |
26 | | -import org.junit.jupiter.api.RepeatedTest; |
27 | 25 | import org.junit.jupiter.api.Test; |
28 | 26 |
|
29 | | -import java.util.concurrent.BlockingQueue; |
30 | 27 | import java.util.concurrent.TimeUnit; |
31 | 28 |
|
32 | 29 | import static org.dromara.dynamictp.common.em.QueueTypeEnum.VARIABLE_LINKED_BLOCKING_QUEUE; |
@@ -61,59 +58,19 @@ public static void setUp() { |
61 | 58 | public void testBlockingQueueDefaultCapacity() { |
62 | 59 | CapturedBlockingQueue capturedBlockingQueue = new CapturedBlockingQueue(dtpExecutor); |
63 | 60 | Assertions.assertEquals(0, capturedBlockingQueue.size()); |
64 | | - Assertions.assertEquals(Integer.MAX_VALUE, capturedBlockingQueue.remainingCapacity()); |
65 | | - } |
66 | | - |
67 | | - @Test |
68 | | - public void testBlockingQueueCapacitySet() { |
69 | | - final int capacity = 100; |
70 | | - BlockingQueue<Runnable> queue = new VariableLinkedBlockingQueue<>(capacity); |
71 | | - CapturedBlockingQueue capturedBlockingQueue = new CapturedBlockingQueue(dtpExecutor); |
72 | | - Assertions.assertEquals(capacity, capturedBlockingQueue.remainingCapacity()); |
| 61 | + Assertions.assertEquals(100, capturedBlockingQueue.remainingCapacity()); |
73 | 62 | } |
74 | 63 |
|
75 | 64 | @Test |
76 | 65 | public void testPut() { |
77 | | - BlockingQueue<Runnable> queue = new VariableLinkedBlockingQueue<>(); |
78 | 66 | CapturedBlockingQueue capturedBlockingQueue = new CapturedBlockingQueue(dtpExecutor); |
79 | 67 | Assertions.assertThrows(UnsupportedOperationException.class, () -> |
80 | 68 | capturedBlockingQueue.put(() -> System.out.println("can't put Runnable to CapturedBlockingQueue"))); |
81 | 69 | } |
82 | 70 |
|
83 | 71 | @Test |
84 | 72 | public void testTake() { |
85 | | - BlockingQueue<Runnable> queue = new VariableLinkedBlockingQueue<>(); |
86 | 73 | CapturedBlockingQueue capturedBlockingQueue = new CapturedBlockingQueue(dtpExecutor); |
87 | 74 | Assertions.assertThrows(UnsupportedOperationException.class, capturedBlockingQueue::take); |
88 | 75 | } |
89 | | - |
90 | | - @RepeatedTest(100) |
91 | | - public void testBlockingQueuePut() throws InterruptedException { |
92 | | - final int capacity = 100; |
93 | | - final int firstPutSize = 30; |
94 | | - final int secondPutSize = 40; |
95 | | - |
96 | | - BlockingQueue<Runnable> queue = new VariableLinkedBlockingQueue<>(capacity); |
97 | | - putTaskToQueue(firstPutSize, queue); |
98 | | - CapturedBlockingQueue capturedBlockingQueue = new CapturedBlockingQueue(dtpExecutor); |
99 | | - |
100 | | - Assertions.assertEquals(capacity - firstPutSize, capturedBlockingQueue.remainingCapacity()); |
101 | | - Assertions.assertEquals(firstPutSize, capturedBlockingQueue.size()); |
102 | | - |
103 | | - putTaskToQueue(secondPutSize, queue); |
104 | | - |
105 | | - //The status of VariableLinkedBlockingQueue changes dynamically as tasks are added to it. |
106 | | - Assertions.assertEquals(capacity - firstPutSize - secondPutSize, queue.remainingCapacity()); |
107 | | - Assertions.assertEquals(firstPutSize + secondPutSize, queue.size()); |
108 | | - |
109 | | - //The status of CapturedBlockingQueue remains unchanged after creation. |
110 | | - Assertions.assertEquals(capacity - firstPutSize, capturedBlockingQueue.remainingCapacity()); |
111 | | - Assertions.assertEquals(firstPutSize, capturedBlockingQueue.size()); |
112 | | - } |
113 | | - |
114 | | - private void putTaskToQueue(int size, BlockingQueue<Runnable> queue) throws InterruptedException { |
115 | | - for (int i = 0; i < size; i++) { |
116 | | - queue.put(() -> System.out.println("i am mock task")); |
117 | | - } |
118 | | - } |
119 | 76 | } |
0 commit comments