langtools/test/tools/sjavac/IdleShutdown.java
changeset 32542 f4e4f4c4f9f4
parent 32337 c9d3ab9f601c
child 36161 a025c0619f25
equal deleted inserted replaced
32457:2050b3a0aadc 32542:f4e4f4c4f9f4
    27  * @summary Tests the hooks used for detecting idleness of the sjavac server.
    27  * @summary Tests the hooks used for detecting idleness of the sjavac server.
    28  * @modules jdk.compiler/com.sun.tools.sjavac.server
    28  * @modules jdk.compiler/com.sun.tools.sjavac.server
    29  * @build Wrapper
    29  * @build Wrapper
    30  * @run main Wrapper IdleShutdown
    30  * @run main Wrapper IdleShutdown
    31  */
    31  */
       
    32 import java.io.Writer;
    32 import java.util.concurrent.atomic.AtomicLong;
    33 import java.util.concurrent.atomic.AtomicLong;
    33 
    34 
    34 import com.sun.tools.sjavac.server.CompilationResult;
       
    35 import com.sun.tools.sjavac.server.IdleResetSjavac;
    35 import com.sun.tools.sjavac.server.IdleResetSjavac;
    36 import com.sun.tools.sjavac.server.Sjavac;
    36 import com.sun.tools.sjavac.server.Sjavac;
    37 import com.sun.tools.sjavac.server.Terminable;
    37 import com.sun.tools.sjavac.server.Terminable;
    38 
    38 
    39 
    39 
    63             throw new AssertionError("Premature timeout detected.");
    63             throw new AssertionError("Premature timeout detected.");
    64 
    64 
    65         // Use Sjavac object and wait less than TIMEOUT_MS in between calls
    65         // Use Sjavac object and wait less than TIMEOUT_MS in between calls
    66         Thread.sleep(TIMEOUT_MS - 1000);
    66         Thread.sleep(TIMEOUT_MS - 1000);
    67         log("Compiling");
    67         log("Compiling");
    68         service.compile(new String[0]);
    68         service.compile(new String[0], null, null);
    69 
    69 
    70         Thread.sleep(TIMEOUT_MS - 1000);
    70         Thread.sleep(TIMEOUT_MS - 1000);
    71         log("Compiling");
    71         log("Compiling");
    72         service.compile(new String[0]);
    72         service.compile(new String[0], null, null);
    73 
    73 
    74         if (timeoutTimestamp.get() != -1)
    74         if (timeoutTimestamp.get() != -1)
    75             throw new AssertionError("Premature timeout detected.");
    75             throw new AssertionError("Premature timeout detected.");
    76 
    76 
    77         long expectedTimeout = System.currentTimeMillis() + TIMEOUT_MS;
    77         long expectedTimeout = System.currentTimeMillis() + TIMEOUT_MS;
   101     private static class NoopJavacService implements Sjavac {
   101     private static class NoopJavacService implements Sjavac {
   102         @Override
   102         @Override
   103         public void shutdown() {
   103         public void shutdown() {
   104         }
   104         }
   105         @Override
   105         @Override
   106         public CompilationResult compile(String[] args) {
   106         public int compile(String[] args, Writer out, Writer err) {
   107             // Attempt to trigger idle timeout during a call by sleeping
   107             // Attempt to trigger idle timeout during a call by sleeping
   108             try {
   108             try {
   109                 Thread.sleep(TIMEOUT_MS + 1000);
   109                 Thread.sleep(TIMEOUT_MS + 1000);
   110             } catch (InterruptedException e) {
   110             } catch (InterruptedException e) {
   111             }
   111             }
   112             return null;
   112             return 0;
   113         }
   113         }
   114     }
   114     }
   115 }
   115 }