@@ -99,6 +99,7 @@ public class RunnerPanel {
9999 private Run currentRun ;
100100 private JPanel basePanel ;
101101 private DefaultComboBoxModel <ComboBoxItem <String , String >> runComboBoxModel ;
102+ private ToolbarButton stopButton ;
102103 private JComboBox <ComboBoxItem <String , String >> runComboBox ;
103104 private JLabel statusLabel ;
104105 private Timer elapsedTimeTimer ;
@@ -168,7 +169,7 @@ public Component getTableCellRendererComponent(final JTable table, final Object
168169 }
169170 }
170171
171- // used in mulitple components, therefore an inner class
172+ // used in multiple components, therefore an inner class
172173 private static class FailuresTableHeaderRenderer extends DefaultTableCellRenderer {
173174 private static final long serialVersionUID = 5059401447983514596L ;
174175
@@ -215,6 +216,7 @@ private void resetDerived() {
215216 testErrorStackTextPane .setText (null );
216217 testWarningsTextPane .setText (null );
217218 testServerOutputTextPane .setText (null );
219+ enableOrDisableStopButton ();
218220 }
219221
220222 private void refreshRunsComboBox () {
@@ -487,8 +489,13 @@ private void showDockable() {
487489 }
488490 }
489491
492+ private void enableOrDisableStopButton () {
493+ stopButton .setEnabled (currentRun .getEndTime () == null );
494+ }
495+
490496 public synchronized void update (final String reporterId ) {
491497 showDockable ();
498+ enableOrDisableStopButton ();
492499 setCurrentRun (runs .get (reporterId ));
493500 final int row = currentRun .getCurrentTestNumber () - 1 ;
494501 final CharSequence header = testOverviewTableModel .getTestIdColumnName ();
@@ -753,6 +760,56 @@ private void initializeGUI() {
753760 codeCoverageButton .setBorder (buttonBorder );
754761 codeCoverageButton .addActionListener (event -> runCodeCoverage (false ));
755762 toolbar .add (codeCoverageButton );
763+ stopButton = new ToolbarButton (UtplsqlResources .getIcon ("STOP_ICON" ));
764+ stopButton .setToolTipText (UtplsqlResources .getString ("RUNNER_STOP_TOOLTIP" ));
765+ stopButton .setBorder (buttonBorder );
766+ stopButton .addActionListener (event -> {
767+ if (currentRun .getConsumerConn () != null ) {
768+ // Aborts JDBC Connection. Connection might still run in the background. That's expected.
769+ DatabaseTools .abortConnection (currentRun .getConsumerConn ());
770+ for (Test test : currentRun .getTests ().values ()) {
771+ if (test .getEndTime () == null && !test .isDisabled ()) {
772+ test .setDisabled (true );
773+ test .getCounter ().setDisabled (1 );
774+ test .getCounter ().setWarning (1 );
775+ test .setWarnings (UtplsqlResources .getString ("RUNNER_STOP_TEST_MESSAGE" ));
776+ test .setStartTime (null );
777+ }
778+ }
779+ // recalculate counters and fix inconsistencies
780+ currentRun .getCounter ().setSuccess (0 );
781+ currentRun .getCounter ().setFailure (0 );
782+ currentRun .getCounter ().setError (0 );
783+ currentRun .getCounter ().setDisabled (0 );
784+ currentRun .getCounter ().setWarning (0 );
785+ for (Test test : currentRun .getTests ().values ()) {
786+ if (test .isDisabled () && test .getCounter ().getDisabled () == 0 ) {
787+ test .getCounter ().setDisabled (1 );
788+ }
789+ if (test .getFailedExpectations () != null && !test .getFailedExpectations ().isEmpty () && test .getCounter ().getFailure () == 0 ) {
790+ test .getCounter ().setFailure (1 );
791+ }
792+ if (test .getErrorStack () != null && test .getCounter ().getError () == 0 ) {
793+ test .getCounter ().setError (1 );
794+ }
795+ currentRun .getCounter ().setSuccess (currentRun .getCounter ().getSuccess () + test .getCounter ().getSuccess ());
796+ currentRun .getCounter ().setFailure (currentRun .getCounter ().getFailure () + test .getCounter ().getFailure ());
797+ currentRun .getCounter ().setError (currentRun .getCounter ().getError () + test .getCounter ().getError ());
798+ currentRun .getCounter ().setDisabled (currentRun .getCounter ().getDisabled () + test .getCounter ().getDisabled ());
799+ currentRun .getCounter ().setWarning (currentRun .getCounter ().getWarning () + test .getCounter ().getWarning ());
800+ }
801+ // terminate run
802+ currentRun .setEndTime (UtplsqlRunner .getSysdate ());
803+ double now = (double ) System .currentTimeMillis ();
804+ currentRun .setExecutionTime ((now - currentRun .getStart ()) / 1000 );
805+ currentRun .setCurrentTestNumber (0 );
806+ currentRun .setStatus (UtplsqlResources .getString ("RUNNER_STOP_RUN_MESSAGE" ));
807+ // update run in GUI
808+ update (currentRun .getReporterId ());
809+ }
810+ });
811+ stopButton .setEnabled (false );
812+ toolbar .add (stopButton );
756813 toolbar .add (Box .createHorizontalGlue ());
757814 runComboBoxModel = new DefaultComboBoxModel <>();
758815 runComboBox = new JComboBox <>(runComboBoxModel );
0 commit comments