mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
junit: do not pull statistics events if no statistics were read
This commit is contained in:
@@ -25,6 +25,7 @@ import java.util.*;
|
||||
|
||||
class FilterCache {
|
||||
private final ArrayList<TestProxy> myList = new ArrayList<TestProxy>(4);
|
||||
private final Set<TestProxy> mySet = new HashSet<TestProxy>();
|
||||
private final Map<Filter, ArrayList<TestProxy>> myCache = new THashMap<Filter, ArrayList<TestProxy>>();
|
||||
|
||||
public TestProxy[] select(final Filter filter) {
|
||||
@@ -46,9 +47,14 @@ class FilterCache {
|
||||
|
||||
public void add(final TestProxy test) {
|
||||
myList.add(test);
|
||||
mySet.add(test);
|
||||
resetCache();
|
||||
}
|
||||
|
||||
public boolean contains(TestProxy test) {
|
||||
return mySet.contains(test);
|
||||
}
|
||||
|
||||
public AbstractTestProxy detect(final Filter filter) {
|
||||
return filter.detectIn(myList);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public class SuiteState extends TestState {
|
||||
return myCache.get(ALL_TESTS);
|
||||
}
|
||||
|
||||
public void changeStateAfterAddingChaildTo(final TestProxy test, final TestProxy child) {
|
||||
public void changeStateAfterAddingChildTo(final TestProxy test, final TestProxy child) {
|
||||
if (child.getState().getMagnitude() <= getMagnitude()) {
|
||||
test.onStatisticsChanged();
|
||||
return;
|
||||
|
||||
@@ -102,7 +102,6 @@ public class TestProxy extends CompositePrintable implements PrintableTestProxy,
|
||||
pullEvent(new StateChangedEvent(this));
|
||||
if (myParent != null)
|
||||
myParent.onChanged(this);
|
||||
fireStatisticsChanged();
|
||||
myNotifier.onChanged(this);
|
||||
}
|
||||
|
||||
@@ -163,7 +162,7 @@ public class TestProxy extends CompositePrintable implements PrintableTestProxy,
|
||||
}
|
||||
|
||||
public void addChild(final TestProxy child) {
|
||||
if (myChildren.getList().contains(child))
|
||||
if (myChildren.contains(child))
|
||||
return;
|
||||
if (child.getParent() != null)
|
||||
return;//todo throw new RuntimeException("Test: "+child + " already has parent: " + child.getParent());
|
||||
@@ -174,8 +173,7 @@ public class TestProxy extends CompositePrintable implements PrintableTestProxy,
|
||||
child.fireOnNewPrintable(child);
|
||||
}
|
||||
pullEvent(new NewChildEvent(this, child));
|
||||
fireStatisticsChanged();
|
||||
getState().changeStateAfterAddingChaildTo(this, child);
|
||||
getState().changeStateAfterAddingChildTo(this, child);
|
||||
myNotifier.onChildAdded(this, child);
|
||||
}
|
||||
|
||||
@@ -203,11 +201,6 @@ public class TestProxy extends CompositePrintable implements PrintableTestProxy,
|
||||
}
|
||||
|
||||
public void onStatisticsChanged() {
|
||||
myChildren.resetCache();
|
||||
fireStatisticsChanged();
|
||||
}
|
||||
|
||||
private void fireStatisticsChanged() {
|
||||
myChildren.resetCache();
|
||||
if (myParent != null)
|
||||
myParent.onStatisticsChanged();
|
||||
@@ -220,12 +213,11 @@ public class TestProxy extends CompositePrintable implements PrintableTestProxy,
|
||||
}
|
||||
|
||||
public void setStatistics(final Statistics statistics) {
|
||||
myChildren.resetCache();
|
||||
if (!myState.isFinal()) {
|
||||
LOG.error("" + myState.getMagnitude());
|
||||
LOG.error(String.valueOf(myState.getMagnitude()));
|
||||
}
|
||||
myStatistics = statistics;
|
||||
fireStatisticsChanged();
|
||||
onStatisticsChanged();
|
||||
}
|
||||
|
||||
public Statistics getStatisticsImpl() {
|
||||
|
||||
@@ -65,7 +65,7 @@ public abstract class TestState implements Printable {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void changeStateAfterAddingChaildTo(final TestProxy test, final TestProxy child) {
|
||||
public void changeStateAfterAddingChildTo(final TestProxy test, final TestProxy child) {
|
||||
test.setState(new SuiteState(test));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public class TestStateUpdater implements PacketConsumer {
|
||||
final List<TestProxy> children = parent.getChildren();
|
||||
final TestState parentState = parent.getState();
|
||||
LOG.assertTrue(parentState instanceof SuiteState);
|
||||
if (children.indexOf(child) == children.size() - 1) {
|
||||
if (child.equals(children.get(children.size() - 1))) {
|
||||
((SuiteState)parentState).setRunning(false);
|
||||
}
|
||||
((SuiteState)parentState).updateMagnitude(magnitude);
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.intellij.execution.junit2.ui;
|
||||
|
||||
import com.intellij.execution.junit2.NewChildEvent;
|
||||
import com.intellij.execution.junit2.StatisticsChanged;
|
||||
import com.intellij.execution.junit2.TestEvent;
|
||||
import com.intellij.execution.junit2.TestProxy;
|
||||
import com.intellij.execution.junit2.ui.actions.TestContext;
|
||||
@@ -70,9 +68,9 @@ class StatisticsPanel extends JPanel implements DataProvider{
|
||||
myTable.setVisible(true);
|
||||
// myTestCaseInfo.setVisible(false);
|
||||
if (myCurrentTest.isLeaf() && myCurrentTest.getParent() != null) {
|
||||
myChildInfo.onSelectionChanged(myCurrentTest.getParent());
|
||||
myChildInfo.updateStatistics(myCurrentTest.getParent());
|
||||
} else{
|
||||
myChildInfo.onSelectionChanged(myCurrentTest);
|
||||
myChildInfo.updateStatistics(myCurrentTest);
|
||||
}
|
||||
final int idx = myChildInfo.getIndexOf(myCurrentTest);
|
||||
TableUtil.selectRows(myTable, new int[]{idx});
|
||||
@@ -99,13 +97,7 @@ class StatisticsPanel extends JPanel implements DataProvider{
|
||||
private class MyJUnitListener extends JUnitAdapter {
|
||||
public void onTestChanged(final TestEvent event) {
|
||||
if (!StatisticsPanel.this.isShowing()) return;
|
||||
if (event instanceof StatisticsChanged) {
|
||||
if (myCurrentTest == event.getSource())
|
||||
updateStatistics();
|
||||
} else if (event instanceof NewChildEvent) {
|
||||
if (event.getSource() == myCurrentTest && !myTable.isVisible())
|
||||
updateStatistics();
|
||||
}
|
||||
if (myCurrentTest == event.getSource()) updateStatistics();
|
||||
}
|
||||
|
||||
public void onTestSelected(final TestProxy test) {
|
||||
|
||||
@@ -47,8 +47,7 @@ public class StatisticsTable extends ListTableModel {
|
||||
|
||||
private void setTest(final TestProxy test) {
|
||||
if (myTest == test) return;
|
||||
myTest = test;
|
||||
changeTableData();
|
||||
updateStatistics(test);
|
||||
}
|
||||
|
||||
private void changeTableData() {
|
||||
@@ -102,4 +101,9 @@ public class StatisticsTable extends ListTableModel {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void updateStatistics(TestProxy currentTest) {
|
||||
myTest = currentTest;
|
||||
changeTableData();
|
||||
}
|
||||
}
|
||||
|
||||
+11
-8
@@ -23,12 +23,12 @@ import com.intellij.execution.junit2.segments.DispatchListener;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class JUnitListenersNotifier implements JUnitListener, TestEventsConsumer, DispatchListener, Runnable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.execution.junit2.ui.model.JUnitListenersNotifier");
|
||||
@@ -142,7 +142,7 @@ public class JUnitListenersNotifier implements JUnitListener, TestEventsConsumer
|
||||
|
||||
private void dispatchAllEvents() {
|
||||
//long start = System.currentTimeMillis();
|
||||
final List<TestEvent> filteredEvents = removeDuplicatesFromEnd(myEventsQueue);
|
||||
final List<TestEvent> filteredEvents = removeDuplicates(myEventsQueue);
|
||||
myEventsQueue.clear();
|
||||
// MEASURER.start(DISPATCH_SINGLES);
|
||||
for (final TestEvent event : filteredEvents) {
|
||||
@@ -153,11 +153,14 @@ public class JUnitListenersNotifier implements JUnitListener, TestEventsConsumer
|
||||
//System.out.println("duration = " + (System.currentTimeMillis() - start));
|
||||
}
|
||||
|
||||
public static <T> List<T> removeDuplicatesFromEnd(final List<T> list) {
|
||||
ArrayList<T> result = new ArrayList<T>(list);
|
||||
Collections.reverse(result);
|
||||
ContainerUtil.removeDuplicates(result);
|
||||
Collections.reverse(result);
|
||||
private static <T> List<T> removeDuplicates(final List<T> list) {
|
||||
final ArrayList<T> result = new ArrayList<T>(list.size());
|
||||
final Set<T> collected = new HashSet<T>();
|
||||
for (T t : list) {
|
||||
if (collected.contains(t)) continue;
|
||||
collected.add(t);
|
||||
result.add(t);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user