use of com.intellij.execution.testframework.sm.runner.SMTRunnerEventsAdapter in project intellij-community by JetBrains.
the class TestDiscoveryExtension method attachToProcess.
@Override
protected void attachToProcess(@NotNull final RunConfigurationBase configuration, @NotNull final ProcessHandler handler, @Nullable RunnerSettings runnerSettings) {
if (runnerSettings == null && isApplicableFor(configuration)) {
final String frameworkPrefix = ((JavaTestConfigurationBase) configuration).getFrameworkPrefix();
final String moduleName = ((JavaTestConfigurationBase) configuration).getConfigurationModule().getModuleName();
Disposable disposable = Disposer.newDisposable();
final Alarm processTracesAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, disposable);
final MessageBusConnection connection = configuration.getProject().getMessageBus().connect();
connection.subscribe(SMTRunnerEventsListener.TEST_STATUS, new SMTRunnerEventsAdapter() {
private List<String> myCompletedMethodNames = new ArrayList<>();
@Override
public void onTestFinished(@NotNull SMTestProxy test) {
final SMTestProxy.SMRootTestProxy root = test.getRoot();
if ((root == null || root.getHandler() == handler)) {
final String fullTestName = test.getLocationUrl();
if (fullTestName != null && fullTestName.startsWith(JavaTestLocator.TEST_PROTOCOL)) {
myCompletedMethodNames.add(frameworkPrefix + fullTestName.substring(JavaTestLocator.TEST_PROTOCOL.length() + 3));
if (myCompletedMethodNames.size() > 50) {
final String[] fullTestNames = ArrayUtil.toStringArray(myCompletedMethodNames);
myCompletedMethodNames.clear();
processTracesAlarm.addRequest(() -> processAvailableTraces(fullTestNames, getTracesDirectory(configuration), moduleName, frameworkPrefix, TestDiscoveryIndex.getInstance(configuration.getProject())), 100);
}
}
}
}
@Override
public void onTestingFinished(@NotNull SMTestProxy.SMRootTestProxy testsRoot) {
if (testsRoot.getHandler() == handler) {
processTracesAlarm.cancelAllRequests();
processTracesAlarm.addRequest(() -> {
processAvailableTraces(configuration);
Disposer.dispose(disposable);
}, 0);
connection.disconnect();
}
}
});
}
}
Aggregations