176 .read(new ByteArrayInputStream(b))
177 .requires()
178 .stream()
179 .map(mdr -> mdr.name())
180 .filter(nm -> !nm.equals("java.base"))
181 .collect(Collectors.toSet());
182 Assert.assertEquals(requires, Set.of("java.logging"));
183
184 // do we have the right resource?
185 b = reader.getResource("/m1/resource.txt");
186 Assert.assertEquals(b, resource);
187
188 // do we have the right class?
189 b = reader.getResource("/m1/p/Main.class");
190 Class<?> clazz = (new ByteArrayClassLoader()).loadClass("p.Main", b);
191 MethodHandle getVersion = MethodHandles.lookup()
192 .findVirtual(clazz, "getVersion", MethodType.methodType(int.class));
193 int version = (int) getVersion.invoke(clazz.getConstructor().newInstance());
194 Assert.assertEquals(version, JarFile.runtimeVersion().major());
195 }
196 // Very rarely this test fails on Windows due to:
197 // Error. failed to clean up files after test
198 // and this mesg shows the problem file (variable jimage):
199 // Can't delete T:\\testOutput\\test-support\\jtreg_open_test_jdk_core_tools\\scratch\\0\\myimage\\lib\\modules
200 // The failure happens more with async monitor deflation
201 // so I think that an inflated monitor is keeping the above
202 // try-with-resources block from cleaning up in a timely
203 // fashion. Forcing a GC here appears to solve the problem.
204 System.gc();
205 }
206
207 @Test
208 public void noLoggingTest() throws Throwable {
209 if (ignoreTest()) return;
210
211 jlink("m1-no-logging.jar", "no-logging-image");
212 runImage("no-logging-image", false);
213 }
214
215 @Test
216 public void loggingTest() throws Throwable {
217 if (ignoreTest()) return;
218
219 jlink("m1-logging.jar", "logging-image");
220 runImage("logging-image", true);
221
222 }
223
224 // java.base.jmod must exist for this test to make sense
|
176 .read(new ByteArrayInputStream(b))
177 .requires()
178 .stream()
179 .map(mdr -> mdr.name())
180 .filter(nm -> !nm.equals("java.base"))
181 .collect(Collectors.toSet());
182 Assert.assertEquals(requires, Set.of("java.logging"));
183
184 // do we have the right resource?
185 b = reader.getResource("/m1/resource.txt");
186 Assert.assertEquals(b, resource);
187
188 // do we have the right class?
189 b = reader.getResource("/m1/p/Main.class");
190 Class<?> clazz = (new ByteArrayClassLoader()).loadClass("p.Main", b);
191 MethodHandle getVersion = MethodHandles.lookup()
192 .findVirtual(clazz, "getVersion", MethodType.methodType(int.class));
193 int version = (int) getVersion.invoke(clazz.getConstructor().newInstance());
194 Assert.assertEquals(version, JarFile.runtimeVersion().major());
195 }
196 }
197
198 @Test
199 public void noLoggingTest() throws Throwable {
200 if (ignoreTest()) return;
201
202 jlink("m1-no-logging.jar", "no-logging-image");
203 runImage("no-logging-image", false);
204 }
205
206 @Test
207 public void loggingTest() throws Throwable {
208 if (ignoreTest()) return;
209
210 jlink("m1-logging.jar", "logging-image");
211 runImage("logging-image", true);
212
213 }
214
215 // java.base.jmod must exist for this test to make sense
|