作者 crossoverJie

:white_check_mark: Adding tests.

@@ -186,12 +186,15 @@ public final class RingBufferWheel { @@ -186,12 +186,15 @@ public final class RingBufferWheel {
186 } 186 }
187 187
188 private void size2Notify() { 188 private void size2Notify() {
189 - lock.lock();  
190 - int size = taskSize.decrementAndGet();  
191 - if (size == 0) {  
192 - condition.signal(); 189 + try {
  190 + lock.lock();
  191 + int size = taskSize.decrementAndGet();
  192 + if (size == 0) {
  193 + condition.signal();
  194 + }
  195 + }finally {
  196 + lock.unlock();
193 } 197 }
194 - lock.unlock();  
195 } 198 }
196 199
197 private boolean powerOf2(int target) { 200 private boolean powerOf2(int target) {
1 package com.crossoverjie.cim.common.data.construct; 1 package com.crossoverjie.cim.common.data.construct;
2 2
3 -import org.junit.Test;  
4 import org.slf4j.Logger; 3 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory; 4 import org.slf4j.LoggerFactory;
6 5
@@ -21,7 +20,7 @@ public class RingBufferWheelTest { @@ -21,7 +20,7 @@ public class RingBufferWheelTest {
21 private static void test1() throws InterruptedException { 20 private static void test1() throws InterruptedException {
22 ExecutorService executorService = Executors.newFixedThreadPool(2) ; 21 ExecutorService executorService = Executors.newFixedThreadPool(2) ;
23 22
24 - Task task = new Task() ; 23 + RingBufferWheel.Task task = new Task() ;
25 task.setKey(10); 24 task.setKey(10);
26 RingBufferWheel wheel = new RingBufferWheel(executorService) ; 25 RingBufferWheel wheel = new RingBufferWheel(executorService) ;
27 wheel.addTask(task) ; 26 wheel.addTask(task) ;
@@ -40,7 +39,7 @@ public class RingBufferWheelTest { @@ -40,7 +39,7 @@ public class RingBufferWheelTest {
40 private static void test2() throws InterruptedException { 39 private static void test2() throws InterruptedException {
41 ExecutorService executorService = Executors.newFixedThreadPool(2) ; 40 ExecutorService executorService = Executors.newFixedThreadPool(2) ;
42 41
43 - Task task = new Task() ; 42 + RingBufferWheel.Task task = new Task() ;
44 task.setKey(10); 43 task.setKey(10);
45 RingBufferWheel wheel = new RingBufferWheel(executorService) ; 44 RingBufferWheel wheel = new RingBufferWheel(executorService) ;
46 wheel.addTask(task) ; 45 wheel.addTask(task) ;
@@ -70,7 +69,7 @@ public class RingBufferWheelTest { @@ -70,7 +69,7 @@ public class RingBufferWheelTest {
70 private static void test3() throws InterruptedException { 69 private static void test3() throws InterruptedException {
71 ExecutorService executorService = Executors.newFixedThreadPool(2) ; 70 ExecutorService executorService = Executors.newFixedThreadPool(2) ;
72 71
73 - Task task = new Task() ; 72 + RingBufferWheel.Task task = new Task() ;
74 task.setKey(10); 73 task.setKey(10);
75 RingBufferWheel wheel = new RingBufferWheel(executorService) ; 74 RingBufferWheel wheel = new RingBufferWheel(executorService) ;
76 wheel.addTask(task) ; 75 wheel.addTask(task) ;
@@ -93,7 +92,7 @@ public class RingBufferWheelTest { @@ -93,7 +92,7 @@ public class RingBufferWheelTest {
93 RingBufferWheel wheel = new RingBufferWheel(executorService) ; 92 RingBufferWheel wheel = new RingBufferWheel(executorService) ;
94 93
95 for (int i = 0; i < 65; i++) { 94 for (int i = 0; i < 65; i++) {
96 - Job task = new Job(i) ; 95 + RingBufferWheel.Task task = new Job(i) ;
97 task.setKey(i); 96 task.setKey(i);
98 wheel.addTask(task); 97 wheel.addTask(task);
99 } 98 }
@@ -112,7 +111,7 @@ public class RingBufferWheelTest { @@ -112,7 +111,7 @@ public class RingBufferWheelTest {
112 RingBufferWheel wheel = new RingBufferWheel(executorService,512) ; 111 RingBufferWheel wheel = new RingBufferWheel(executorService,512) ;
113 112
114 for (int i = 0; i < 65; i++) { 113 for (int i = 0; i < 65; i++) {
115 - Job task = new Job(i) ; 114 + RingBufferWheel.Task task = new Job(i) ;
116 task.setKey(i); 115 task.setKey(i);
117 wheel.addTask(task); 116 wheel.addTask(task);
118 } 117 }