29 * @summary Tests the hooks used for detecting idleness of the sjavac server. |
29 * @summary Tests the hooks used for detecting idleness of the sjavac server. |
30 * @modules jdk.compiler/com.sun.tools.sjavac.server |
30 * @modules jdk.compiler/com.sun.tools.sjavac.server |
31 * @build Wrapper |
31 * @build Wrapper |
32 * @run main Wrapper IdleShutdown |
32 * @run main Wrapper IdleShutdown |
33 */ |
33 */ |
34 import java.io.File; |
|
35 import java.net.URI; |
|
36 import java.util.Collections; |
|
37 import java.util.List; |
|
38 import java.util.Set; |
|
39 import java.util.concurrent.atomic.AtomicLong; |
34 import java.util.concurrent.atomic.AtomicLong; |
40 |
35 |
41 import com.sun.tools.sjavac.server.CompilationResult; |
36 import com.sun.tools.sjavac.server.CompilationResult; |
42 import com.sun.tools.sjavac.server.IdleResetSjavac; |
37 import com.sun.tools.sjavac.server.IdleResetSjavac; |
43 import com.sun.tools.sjavac.server.Sjavac; |
38 import com.sun.tools.sjavac.server.Sjavac; |
44 import com.sun.tools.sjavac.server.SysInfo; |
|
45 import com.sun.tools.sjavac.server.Terminable; |
39 import com.sun.tools.sjavac.server.Terminable; |
46 |
40 |
47 |
41 |
48 public class IdleShutdown { |
42 public class IdleShutdown { |
49 |
43 |
68 |
62 |
69 // Make sure it didn't timeout immediately |
63 // Make sure it didn't timeout immediately |
70 if (timeoutTimestamp.get() != -1) |
64 if (timeoutTimestamp.get() != -1) |
71 throw new AssertionError("Premature timeout detected."); |
65 throw new AssertionError("Premature timeout detected."); |
72 |
66 |
73 // Call various methods and wait less than TIMEOUT_MS in between |
67 // Use Sjavac object and wait less than TIMEOUT_MS in between calls |
74 Thread.sleep(TIMEOUT_MS - 1000); |
68 Thread.sleep(TIMEOUT_MS - 1000); |
75 log("Getting sys info"); |
69 log("Compiling"); |
76 service.getSysInfo(); |
70 service.compile(new String[0]); |
77 |
|
78 Thread.sleep(TIMEOUT_MS - 1000); |
|
79 log("Getting sys info"); |
|
80 service.getSysInfo(); |
|
81 |
|
82 if (timeoutTimestamp.get() != -1) |
|
83 throw new AssertionError("Premature timeout detected."); |
|
84 |
71 |
85 Thread.sleep(TIMEOUT_MS - 1000); |
72 Thread.sleep(TIMEOUT_MS - 1000); |
86 log("Compiling"); |
73 log("Compiling"); |
87 service.compile("", |
74 service.compile(new String[0]); |
88 "", |
|
89 new String[0], |
|
90 Collections.<File>emptyList(), |
|
91 Collections.<URI>emptySet(), |
|
92 Collections.<URI>emptySet()); |
|
93 |
|
94 Thread.sleep(TIMEOUT_MS - 1000); |
|
95 log("Compiling"); |
|
96 service.compile("", |
|
97 "", |
|
98 new String[0], |
|
99 Collections.<File>emptyList(), |
|
100 Collections.<URI>emptySet(), |
|
101 Collections.<URI>emptySet()); |
|
102 |
75 |
103 if (timeoutTimestamp.get() != -1) |
76 if (timeoutTimestamp.get() != -1) |
104 throw new AssertionError("Premature timeout detected."); |
77 throw new AssertionError("Premature timeout detected."); |
105 |
78 |
106 long expectedTimeout = System.currentTimeMillis() + TIMEOUT_MS; |
79 long expectedTimeout = System.currentTimeMillis() + TIMEOUT_MS; |
127 System.out.printf("After %5d ms: %s%n", logTime, msg); |
100 System.out.printf("After %5d ms: %s%n", logTime, msg); |
128 } |
101 } |
129 |
102 |
130 private static class NoopJavacService implements Sjavac { |
103 private static class NoopJavacService implements Sjavac { |
131 @Override |
104 @Override |
132 public SysInfo getSysInfo() { |
105 public void shutdown() { |
|
106 } |
|
107 @Override |
|
108 public CompilationResult compile(String[] args) { |
133 // Attempt to trigger idle timeout during a call by sleeping |
109 // Attempt to trigger idle timeout during a call by sleeping |
134 try { |
110 try { |
135 Thread.sleep(TIMEOUT_MS + 1000); |
111 Thread.sleep(TIMEOUT_MS + 1000); |
136 } catch (InterruptedException e) { |
112 } catch (InterruptedException e) { |
137 } |
113 } |
138 return null; |
114 return null; |
139 } |
115 } |
140 @Override |
|
141 public void shutdown() { |
|
142 } |
|
143 @Override |
|
144 public CompilationResult compile(String protocolId, |
|
145 String invocationId, |
|
146 String[] args, |
|
147 List<File> explicitSources, |
|
148 Set<URI> sourcesToCompile, |
|
149 Set<URI> visibleSources) { |
|
150 return null; |
|
151 } |
|
152 @Override |
|
153 public String serverSettings() { |
|
154 return ""; |
|
155 } |
|
156 } |
116 } |
157 } |
117 } |