merge build tree events (IDEA-144141)
authorAnna Kozlova <anna.kozlova@jetbrains.com>
Thu, 20 Aug 2015 19:43:03 +0000 (21:43 +0200)
committerAnna Kozlova <anna.kozlova@jetbrains.com>
Thu, 20 Aug 2015 19:47:32 +0000 (21:47 +0200)
platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralTestEventsProcessor.java
platform/smRunner/src/com/intellij/execution/testframework/sm/runner/GeneralToSMTRunnerEventsConvertor.java
platform/smRunner/src/com/intellij/execution/testframework/sm/runner/OutputToGeneralTestEventsConverter.java
plugins/junit_rt/src/com/intellij/junit4/JUnit4TestListener.java

index c872ae00a67e4da708f3d871db6c613885df98e1..10ab12550c644ea1edccd87702209d97ad4f51a4 100644 (file)
@@ -69,6 +69,7 @@ public abstract class GeneralTestEventsProcessor implements Disposable {
   public void onSuiteTreeStarted(String suiteName, String locationHint) { }
 
   public void onSuiteTreeEnded(String suiteName) { }
+  public void onBuildTreeEnded() { }
 
   // progress events
 
index 26e52ebe1336403e04e006a70cc7095c20c827bf..6f3edea3ca72454652da8129e579eaa61a9cd64b 100644 (file)
@@ -126,10 +126,12 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso
     });
   }
 
+  private final List<Runnable> myBuildTreeRunnables = new ArrayList<Runnable>();
+  
   @Override
   public void onSuiteTreeNodeAdded(final String testName, final String locationHint) {
     myTreeBuildBeforeStart = true;
-    addToInvokeLater(new Runnable() {
+    myBuildTreeRunnables.add(new Runnable() {
       @Override
       public void run() {
         final SMTestProxy testProxy = new SMTestProxy(testName, false, locationHint);
@@ -148,7 +150,7 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso
   @Override
   public void onSuiteTreeStarted(final String suiteName, final String locationHint) {
     myTreeBuildBeforeStart = true;
-    addToInvokeLater(new Runnable() {
+    myBuildTreeRunnables.add(new Runnable() {
       @Override
       public void run() {
         final SMTestProxy parentSuite = getCurrentSuite();
@@ -170,12 +172,35 @@ public class GeneralToSMTRunnerEventsConvertor extends GeneralTestEventsProcesso
 
   @Override
   public void onSuiteTreeEnded(final String suiteName) {
-    addToInvokeLater(new Runnable() {
+    myBuildTreeRunnables.add(new Runnable() {
       @Override
       public void run() {
         mySuitesStack.popSuite(suiteName);
       }
     });
+    
+    if (myBuildTreeRunnables.size() > 100) {
+      final ArrayList<Runnable> runnables = new ArrayList<Runnable>(myBuildTreeRunnables);
+      myBuildTreeRunnables.clear();
+      processTreeBuildEvents(runnables);
+    }
+  }
+
+  @Override
+  public void onBuildTreeEnded() {
+    processTreeBuildEvents(myBuildTreeRunnables);
+  }
+
+  private void processTreeBuildEvents(final List<Runnable> runnables) {
+    addToInvokeLater(new Runnable() {
+      @Override
+      public void run() {
+        for (Runnable runnable : runnables) {
+          runnable.run();
+        }
+        runnables.clear();
+      }
+    });
   }
 
   @Override
index 4f686045b82f46a65bf9cb631f5bcb40820d34b4..46c6a77f390829107c2d2f8f9ad08d0e8f74df36 100644 (file)
@@ -247,6 +247,13 @@ public class OutputToGeneralTestEventsConverter implements ProcessOutputConsumer
       processor.onSuiteTreeEnded(suiteName);
     }
   }
+  
+  private void fireOnBuildTreeEnded() {
+    final GeneralTestEventsProcessor processor = myProcessor;
+    if (processor != null) {
+      processor.onBuildTreeEnded();
+    }
+  }
 
   private void fireOnTestOutput(@NotNull TestOutputEvent testOutputEvent) {
     // local variable is used to prevent concurrent modification
@@ -330,6 +337,7 @@ public class OutputToGeneralTestEventsConverter implements ProcessOutputConsumer
     @NonNls private static final String SUITE_TREE_STARTED = "suiteTreeStarted";
     @NonNls private static final String SUITE_TREE_ENDED = "suiteTreeEnded";
     @NonNls private static final String SUITE_TREE_NODE = "suiteTreeNode";
+    @NonNls private static final String BUILD_TREE_ENDED_NODE = "treeEnded";
     @NonNls private static final String ROOT_PRESENTATION = "rootName";
 
     @NonNls private static final String ATTR_KEY_STATUS = "status";
@@ -519,6 +527,9 @@ public class OutputToGeneralTestEventsConverter implements ProcessOutputConsumer
       else if (SUITE_TREE_NODE.equals(name)) {
         fireOnSuiteTreeNodeAdded(msg.getAttributes().get("name"), msg.getAttributes().get(ATTR_KEY_LOCATION_URL));
       }
+      else if (BUILD_TREE_ENDED_NODE.equals(name)) {
+        fireOnBuildTreeEnded();
+      }
       else if (ROOT_PRESENTATION.equals(name)) {
         final Map<String, String> attributes = msg.getAttributes();
         fireRootPresentationAdded(attributes.get("name"), attributes.get("comment"), attributes.get("location"));
index 44b9a7f192b881b798041f4f56fbb20ff06caaea..df62691bf7f47c76c358ab44e04efab336fd205d 100644 (file)
@@ -366,6 +366,7 @@ public class JUnit4TestListener extends RunListener {
   public void sendTree(Description description) {
     myRootName = JUnit4ReflectionUtil.getClassName((Description)description);
     sendTree(description, null, new ArrayList());
+    myPrintStream.println("##teamcity[treeEnded]");
   }
 
   private static String getShortName(String fqName) {