panzhi33 commented on a change in pull request #3746:
URL: https://github.com/apache/rocketmq/pull/3746#discussion_r812600551
##########
File path:
store/src/test/java/org/apache/rocketmq/store/ha/WaitNotifyObjectTest.java
##########
@@ -40,4 +40,57 @@ public void run() {
Assert.assertEquals(0, waitNotifyObject.waitingThreadTable.size());
}
+ @Test
+ public void allWaitForRunning() throws Exception {
+
+ final int threadNum = 5;
+ final long waitIntervalMs = 100L;
+ final CountDownLatch latch = new CountDownLatch(threadNum);
+ final WaitNotifyObject waitNotifyObject = new WaitNotifyObject() {
+ @Override
+ protected void onWaitEnd() {
+ latch.countDown();
+ }
+ };
+ long start = System.nanoTime();
+ for (int i = 0; i < threadNum; i++) {
+ Thread t = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ waitNotifyObject.allWaitForRunning(waitIntervalMs);
+ }
+ });
+ t.start();
+ t.join();
+ }
+
+ latch.await();
+ long elapsed = (System.nanoTime() - start) / 1000000;
+ Assert.assertEquals(threadNum,
waitNotifyObject.waitingThreadTable.size());
+ Assert.assertTrue(elapsed >= threadNum * waitIntervalMs);
+ }
+
+ @Test
+ public void wakeup() throws Exception {
+ final long waitIntervalMs = 3000L;
+ final long sleepMs = 500L;
+ final WaitNotifyObject waitNotifyObject = new WaitNotifyObject();
+ long start = System.nanoTime();
+ Thread t = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Thread.currentThread().sleep(sleepMs);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ waitNotifyObject.wakeup();
+ }
+ });
+ t.start();
+ waitNotifyObject.waitForRunning(waitIntervalMs);
+ long elapsed = (System.nanoTime() - start) / 1000000;
+ Assert.assertTrue(elapsed >= sleepMs && elapsed < waitIntervalMs);
+ }
+
Review comment:
This unit test has nothing to do with this pr, you can mention a pr again
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]