浏览代码

AMBARI-2416. Test Concurrent operations fail intermittently on trunk. (Myroslav Papirkovskyy via swagle)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1494301 13f79535-47bb-0310-9956-ffa450edef68
Siddharth Wagle 12 年之前
父节点
当前提交
be1d871d1d
共有 1 个文件被更改,包括 15 次插入0 次删除
  1. 15 0
      ambari-server/src/test/java/org/apache/ambari/server/agent/TestActionQueue.java

+ 15 - 0
ambari-server/src/test/java/org/apache/ambari/server/agent/TestActionQueue.java

@@ -19,6 +19,7 @@ package org.apache.ambari.server.agent;
 
 import static org.junit.Assert.*;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import org.junit.Test;
@@ -133,10 +134,14 @@ public class TestActionQueue {
     ActionQueueOperation[] dequeOperators = new ActionQueueOperation[threadCount];
     ActionQueueOperation[] dequeAllOperators = new ActionQueueOperation[threadCount];
 
+    List<Thread> producers = new ArrayList<Thread>();
+    List<Thread> consumers = new ArrayList<Thread>();
+
     for (int i = 0; i < threadCount; i++) {
       dequeOperators[i] = new ActionQueueOperation(aq, hosts,
           ActionQueueOperation.OpType.DEQUEUE);
       Thread t = new Thread(dequeOperators[i]);
+      consumers.add(t);
       t.start();
     }
 
@@ -144,6 +149,7 @@ public class TestActionQueue {
       enqueOperators[i] = new ActionQueueOperation(aq, hosts,
           ActionQueueOperation.OpType.ENQUEUE);
       Thread t = new Thread(enqueOperators[i]);
+      producers.add(t);
       t.start();
     }
 
@@ -151,6 +157,7 @@ public class TestActionQueue {
       dequeAllOperators[i] = new ActionQueueOperation(aq, hosts,
           ActionQueueOperation.OpType.DEQUEUEALL);
       Thread t = new Thread(dequeAllOperators[i]);
+      consumers.add(t);
       t.start();
     }
 
@@ -162,6 +169,10 @@ public class TestActionQueue {
       enqueOperators[i].stop();
     }
 
+    for (Thread producer : producers) {
+      producer.join();
+    }
+
     // Give time to get everything dequeued
     boolean allDequeued = false;
     while (!allDequeued) {
@@ -180,6 +191,10 @@ public class TestActionQueue {
       dequeOperators[i].stop();
       dequeAllOperators[i].stop();
     }
+
+    for (Thread consumer : consumers) {
+      consumer.join();
+    }
     
     for (int h = 0; h<hosts.length; h++) {
       long opsEnqueued = 0;