From acfbb387edd50985702ab2cd68f455f14ba942d9 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Mon, 17 Sep 2018 09:43:41 +0100 Subject: [PATCH] refactor the command line executable launcher used in the test harness for running Jalview to jalview.utils --- src/jalview/bin/Jalview.java | 13 ++++- test/jalview/bin/CommandLineOperations.java | 70 +++------------------------ 2 files changed, 18 insertions(+), 65 deletions(-) diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index adf3773..789deb2 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -186,7 +186,18 @@ public class Jalview */ public static void main(String[] args) { - instance = new Jalview(); + float ONE_MB = 1048576f; + Runtime runtime = Runtime.getRuntime(); + float maxMemory = runtime.maxMemory() / ONE_MB; + if (maxMemory < 1024 * 15) + { + System.exit(); + } + + if (System.ge) + { + instance = new Jalview(); + } instance.doMain(args); } diff --git a/test/jalview/bin/CommandLineOperations.java b/test/jalview/bin/CommandLineOperations.java index d586dae..18ea312 100644 --- a/test/jalview/bin/CommandLineOperations.java +++ b/test/jalview/bin/CommandLineOperations.java @@ -21,6 +21,7 @@ package jalview.bin; import jalview.gui.JvOptionPane; +import jalview.ws.utils.Worker; import java.io.BufferedReader; import java.io.File; @@ -57,62 +58,6 @@ public class CommandLineOperations private ArrayList successfulCMDs = new ArrayList<>(); - /*** - * from - * http://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when - * -using-javas-runtime-exec - * - * @author jimp - * - */ - private static class Worker extends Thread - { - private final Process process; - - private BufferedReader outputReader; - - private BufferedReader errorReader; - - private Integer exit; - - private Worker(Process process) - { - this.process = process; - } - - @Override - public void run() - { - try - { - exit = process.waitFor(); - } catch (InterruptedException ignore) - { - return; - } - } - - public BufferedReader getOutputReader() - { - return outputReader; - } - - public void setOutputReader(BufferedReader outputReader) - { - this.outputReader = outputReader; - } - - public BufferedReader getErrorReader() - { - return errorReader; - } - - public void setErrorReader(BufferedReader errorReader) - { - this.errorReader = errorReader; - } - } - private Worker jalviewDesktopRunner(boolean withAwt, String cmd, int timeout) { @@ -196,11 +141,10 @@ public class CommandLineOperations break; } } - if (worker != null && worker.exit == null) + if (worker != null && worker.getExitValue() == null) { - worker.interrupt(); - Thread.currentThread().interrupt(); - worker.process.destroy(); + worker.destroyProcess(); + } } @@ -226,11 +170,9 @@ public class CommandLineOperations FileAssert.assertFile(file, "Didn't create an output" + type + " file.[" + harg + "]"); FileAssert.assertMinLength(new File(fileName), expectedMinFileSize); - if (worker != null && worker.exit == null) + if (worker != null && worker.getExitValue() == null) { - worker.interrupt(); - Thread.currentThread().interrupt(); - worker.process.destroy(); + worker.destroyProcess(); Assert.fail("Jalview did not exit after " + type + " generation (try running test again to verify - timeout at " -- 1.7.10.2