Skip to content

Commit 31c75a5

Browse files
committed
fix test case
1 parent 7d43789 commit 31c75a5

File tree

1 file changed

+2
-45
lines changed

1 file changed

+2
-45
lines changed

test/test-core/src/test/java/org/dromara/dynamictp/test/core/notify/capture/CapturedBlockingQueueTest.java

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@
1717

1818
package org.dromara.dynamictp.test.core.notify.capture;
1919

20-
import org.dromara.dynamictp.common.queue.VariableLinkedBlockingQueue;
20+
import org.dromara.dynamictp.core.executor.DtpExecutor;
2121
import org.dromara.dynamictp.core.notifier.capture.CapturedBlockingQueue;
2222
import org.dromara.dynamictp.core.support.ThreadPoolBuilder;
23-
import org.dromara.dynamictp.core.executor.DtpExecutor;
2423
import org.junit.jupiter.api.Assertions;
2524
import org.junit.jupiter.api.BeforeAll;
26-
import org.junit.jupiter.api.RepeatedTest;
2725
import org.junit.jupiter.api.Test;
2826

29-
import java.util.concurrent.BlockingQueue;
3027
import java.util.concurrent.TimeUnit;
3128

3229
import static org.dromara.dynamictp.common.em.QueueTypeEnum.VARIABLE_LINKED_BLOCKING_QUEUE;
@@ -61,59 +58,19 @@ public static void setUp() {
6158
public void testBlockingQueueDefaultCapacity() {
6259
CapturedBlockingQueue capturedBlockingQueue = new CapturedBlockingQueue(dtpExecutor);
6360
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());
7362
}
7463

7564
@Test
7665
public void testPut() {
77-
BlockingQueue<Runnable> queue = new VariableLinkedBlockingQueue<>();
7866
CapturedBlockingQueue capturedBlockingQueue = new CapturedBlockingQueue(dtpExecutor);
7967
Assertions.assertThrows(UnsupportedOperationException.class, () ->
8068
capturedBlockingQueue.put(() -> System.out.println("can't put Runnable to CapturedBlockingQueue")));
8169
}
8270

8371
@Test
8472
public void testTake() {
85-
BlockingQueue<Runnable> queue = new VariableLinkedBlockingQueue<>();
8673
CapturedBlockingQueue capturedBlockingQueue = new CapturedBlockingQueue(dtpExecutor);
8774
Assertions.assertThrows(UnsupportedOperationException.class, capturedBlockingQueue::take);
8875
}
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-
}
11976
}

0 commit comments

Comments
 (0)