changeset 3932:ca18223ce9ee

8173577: JShell tests: Some testng tests check nothing Reviewed-by: jlahoda
author rfield
date Wed, 01 Feb 2017 09:10:07 -0800
parents f38d10d479c1
children ec4be8a26914
files src/jdk.jshell/share/classes/jdk/jshell/execution/FailOverExecutionControlProvider.java src/jdk.jshell/share/classes/jdk/jshell/execution/JdiDefaultExecutionControl.java test/jdk/jshell/ExecutionControlTestBase.java test/jdk/jshell/FailOverDirectExecutionControlTest.java test/jdk/jshell/FailOverExecutionControlDyingLaunchTest.java
diffstat 5 files changed, 26 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.jshell/share/classes/jdk/jshell/execution/FailOverExecutionControlProvider.java	Wed Feb 01 15:03:06 2017 +0100
+++ b/src/jdk.jshell/share/classes/jdk/jshell/execution/FailOverExecutionControlProvider.java	Wed Feb 01 09:10:07 2017 -0800
@@ -111,7 +111,8 @@
                     PrintWriter log = new PrintWriter(writer);
                     log.println("FailOverExecutionControlProvider:");
                     ex.printStackTrace(log);
-                    logger().fine(log.toString());
+                    log.flush();
+                    logger().fine(writer.toString());
                     // only care about the first, and only if they all fail
                     if (thrown == null) {
                         thrown = ex;
--- a/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiDefaultExecutionControl.java	Wed Feb 01 15:03:06 2017 +0100
+++ b/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiDefaultExecutionControl.java	Wed Feb 01 09:10:07 2017 -0800
@@ -102,7 +102,6 @@
             Process process = jdii.process();
 
             List<Consumer<String>> deathListeners = new ArrayList<>();
-            deathListeners.add(s -> env.closeDown());
             Util.detectJdiExitEvent(vm, s -> {
                 for (Consumer<String> h : deathListeners) {
                     h.accept(s);
@@ -120,7 +119,8 @@
             Map<String, InputStream> input = new HashMap<>();
             input.put("in", env.userIn());
             return remoteInputOutput(socket.getInputStream(), out, outputs, input,
-                    (objIn, objOut) -> new JdiDefaultExecutionControl(objOut, objIn, vm, process, remoteAgent, deathListeners));
+                    (objIn, objOut) -> new JdiDefaultExecutionControl(env,
+                                        objOut, objIn, vm, process, remoteAgent, deathListeners));
         }
     }
 
@@ -130,15 +130,20 @@
      * @param cmdout the output for commands
      * @param cmdin the input for responses
      */
-    private JdiDefaultExecutionControl(ObjectOutput cmdout, ObjectInput cmdin,
+    private JdiDefaultExecutionControl(ExecutionEnv env,
+            ObjectOutput cmdout, ObjectInput cmdin,
             VirtualMachine vm, Process process, String remoteAgent,
             List<Consumer<String>> deathListeners) {
         super(cmdout, cmdin);
         this.vm = vm;
         this.process = process;
         this.remoteAgent = remoteAgent;
+        // We have now succeeded in establishing the connection.
+        // If there is an exit now it propagates all the way up
+        // and the VM should be disposed of.
+        deathListeners.add(s -> env.closeDown());
         deathListeners.add(s -> disposeVM());
-    }
+     }
 
     @Override
     public String invoke(String classname, String methodname)
--- a/test/jdk/jshell/ExecutionControlTestBase.java	Wed Feb 01 15:03:06 2017 +0100
+++ b/test/jdk/jshell/ExecutionControlTestBase.java	Wed Feb 01 09:10:07 2017 -0800
@@ -23,6 +23,7 @@
 
 import javax.tools.Diagnostic;
 
+import org.testng.annotations.Test;
 import jdk.jshell.VarSnippet;
 
 import static jdk.jshell.Snippet.Status.VALID;
@@ -30,6 +31,7 @@
 
 public class ExecutionControlTestBase extends KullaTesting {
 
+    @Test
     public void classesDeclaration() {
         assertEval("interface A { }");
         assertEval("class B implements A { }");
@@ -45,6 +47,7 @@
         assertActiveKeys();
     }
 
+    @Test
     public void interfaceTest() {
         String interfaceSource
                 = "interface A {\n"
@@ -72,6 +75,7 @@
         assertEval("new B.Inner2();");
     }
 
+    @Test
     public void variables() {
         VarSnippet snx = varKey(assertEval("int x = 10;"));
         VarSnippet sny = varKey(assertEval("String y = \"hi\";"));
@@ -83,6 +87,7 @@
         assertActiveKeys();
     }
 
+    @Test
     public void methodOverload() {
         assertEval("int m() { return 1; }");
         assertEval("int m(int x) { return 2; }");
@@ -107,6 +112,7 @@
         assertActiveKeys();
     }
 
+    @Test
     public void testExprSanity() {
         assertEval("int x = 3;", "3");
         assertEval("int y = 4;", "4");
@@ -114,6 +120,7 @@
         assertActiveKeys();
     }
 
+    @Test
     public void testImportOnDemand() {
         assertImportKeyMatch("import java.util.*;", "java.util.*", TYPE_IMPORT_ON_DEMAND_SUBKIND, added(VALID));
         assertEval("List<Integer> list = new ArrayList<>();");
--- a/test/jdk/jshell/FailOverDirectExecutionControlTest.java	Wed Feb 01 15:03:06 2017 +0100
+++ b/test/jdk/jshell/FailOverDirectExecutionControlTest.java	Wed Feb 01 09:10:07 2017 -0800
@@ -61,7 +61,8 @@
 
     ClassLoader ccl;
     ExecutionControlProvider provider;
-    Map<Level, List<String>> logged = new HashMap<>();
+    LogTestHandler hndlr;
+    Map<Level, List<String>> logged;
 
     private class LogTestHandler extends Handler {
 
@@ -95,7 +96,9 @@
     public void setUp() {
         Logger logger = Logger.getLogger("jdk.jshell.execution");
         logger.setLevel(Level.ALL);
-        logger.addHandler(new LogTestHandler());
+        hndlr = new LogTestHandler();
+        logger.addHandler(hndlr);
+        logged = new HashMap<>();
         Compiler compiler = new Compiler();
         Path modDir = Paths.get("mod");
         compiler.compile(modDir,
@@ -133,6 +136,8 @@
     @Override
     public void tearDown() {
         super.tearDown();
+        Logger logger = Logger.getLogger("jdk.jshell.execution");
+        logger.removeHandler(hndlr);
         Thread.currentThread().setContextClassLoader(ccl);
     }
 
--- a/test/jdk/jshell/FailOverExecutionControlDyingLaunchTest.java	Wed Feb 01 15:03:06 2017 +0100
+++ b/test/jdk/jshell/FailOverExecutionControlDyingLaunchTest.java	Wed Feb 01 09:10:07 2017 -0800
@@ -27,7 +27,7 @@
  * @summary Test that fail-over works for fail-over ExecutionControl generators.
  * @modules jdk.jshell/jdk.jshell.execution
  *          jdk.jshell/jdk.jshell.spi
- * @build KullaTesting ExecutionControlTestBase
+ * @build KullaTesting ExecutionControlTestBase DyingRemoteAgent
  * @run testng FailOverExecutionControlDyingLaunchTest
  */