Java Code Examples for jdk.test.lib.Asserts#fail()
The following examples show how to use
jdk.test.lib.Asserts#fail() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestDestFileReadOnly.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Path dest = FileHelper.createReadOnlyFile(Paths.get(".", "readonly.txt")); System.out.println("dest=" + dest.toFile().getAbsolutePath()); if (!FileHelper.isReadOnlyPath(dest)) { System.out.println("Failed to create a read-only file. Test ignored."); return; } Recording r = new Recording(); r.setToDisk(true); try { r.setDestination(dest); Asserts.fail("No exception when destination is read-only"); } catch (IOException e) { // Expected exception } r.close(); }
Example 2
Source File: TestEventTypes.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void assertSame(List<EventTypeInfo> infos, List<EventType> types) { List<Long> ids = new ArrayList<>(); for (EventTypeInfo info : infos) { long id = info.getId(); Asserts.assertFalse(ids.contains(id), "EventTypeInfo.id not unique:" + id); ids.add(id); boolean isFound = false; for (EventType type : types) { if (type.getId() == id) { assertSame(info, type); isFound = true; break; } } if (!isFound) { String msg = "No EventType for EventTypeInfo"; System.out.println(msg + ": " + info); Asserts.fail(msg); } } Asserts.assertEquals(infos.size(), types.size(), "Number of EventTypeInfos != EventTypes"); }
Example 3
Source File: TestMetadataRetention.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static void validateOldObjectEvent(List<RecordedEvent> events, Instant chunkRotation) throws Throwable { for (RecordedEvent event : events) { if (event.getEventType().getName().equals(EventNames.OldObjectSample)) { // Only check event after the rotation if (!event.getStartTime().isBefore(chunkRotation)) { System.out.println(event); RecordedThread rt = event.getThread(); if (rt.getJavaName().equals(ALLOCATOR_THREAD_NAME)) { RecordedStackTrace s = event.getStackTrace(); assertStackTrace(s, "startRecurse"); assertStackTrace(s, "recurse"); return; } } } } Asserts.fail("Did not find an old object event with thread " + ALLOCATOR_THREAD_NAME); }
Example 4
Source File: TestRecordingFileReadEventEof.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Recording r = new Recording(); r.start(); SimpleEvent t = new SimpleEvent(); t.commit(); r.stop(); RecordingFile file = Events.copyTo(r); r.close(); file.readEvent(); try { file.readEvent(); Asserts.fail("Expected EOFException not thrown"); } catch (EOFException x) { // OK, as expected } }
Example 5
Source File: TestRecordingFileReadEventEof.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Recording r = new Recording(); r.start(); SimpleEvent t = new SimpleEvent(); t.commit(); r.stop(); RecordingFile file = Events.copyTo(r); r.close(); file.readEvent(); try { file.readEvent(); Asserts.fail("Expected EOFException not thrown"); } catch (EOFException x) { // OK, as expected } }
Example 6
Source File: TestAssemble.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static long countEventInRecording(Path file) throws IOException { Integer lastId = -1; try (RecordingFile rf = new RecordingFile(file)) { long count = 0; while (rf.hasMoreEvents()) { RecordedEvent re = rf.readEvent(); if (re.getEventType().getName().equals("Correlation")) { Integer id = re.getValue("id"); if (id < lastId) { Asserts.fail("Expected chunk number to increase"); } lastId = id; } count++; } return count; } }
Example 7
Source File: TestStreamClosed.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean(); long recId = bean.newRecording(); bean.startRecording(recId); SimpleEventHelper.createEvent(1); bean.stopRecording(recId); long streamId = bean.openStream(recId, null); bean.closeStream(streamId); try { bean.readStream(streamId); Asserts.fail("No exception whean reading closed stream"); } catch (IOException e) { // Expected exception. String msg = e.getMessage().toLowerCase(); Asserts.assertTrue(msg.contains("stream") && msg.contains("closed"), "No 'stream closed' in " + msg); } bean.closeRecording(recId); }
Example 8
Source File: TestNotificationListenerPermission.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { try { System.getProperty("user.name"); Asserts.fail("Didn't get security exception. Test not configured propertly?"); } catch (SecurityException se) { // as expected } FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean(); TestListener testListener = new TestListener(); ManagementFactory.getPlatformMBeanServer().addNotificationListener(new ObjectName(FlightRecorderMXBean.MXBEAN_NAME), testListener, null, null); long id = bean.newRecording(); bean.startRecording(id); testListener.awaitNotication(); Asserts.assertTrue(gotSecurityException, "Should not get elevated privileges in notification handler!"); bean.stopRecording(id); bean.closeRecording(id); }
Example 9
Source File: TestGetSettings.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { EventType eventType = EventType.getEventType(EventWithCustomSettings.class); List<SettingDescriptor> settings = eventType.getSettingDescriptors(); Asserts.assertEquals(settings.size(), 5, "Wrong number of settings"); // test immutability try { settings.add(settings.get(0)); Asserts.fail("Should not be able to modify list returned by getSettings()"); } catch (UnsupportedOperationException uoe) { // OK, as expected } }
Example 10
Source File: TestDumpOnCrash.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { try { Field theUnsafeRefLocation = Unsafe.class.getDeclaredField("theUnsafe"); theUnsafeRefLocation.setAccessible(true); ((Unsafe)theUnsafeRefLocation.get(null)).putInt(0L, 0); } catch(Exception ex) { Asserts.fail("cannot execute"); } }
Example 11
Source File: TestEventTypes.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void verifyMyEventType(List<EventTypeInfo> infos) { for (EventTypeInfo info : infos) { if ("MyEvent.name".equals(info.getName())) { System.out.println("EventTypeInfo for MyEvent: " + info); Asserts.assertEquals("MyEvent.label", info.getLabel()); Asserts.assertEquals("MyEvent.description", info.getDescription()); for (SettingDescriptorInfo si : info.getSettingDescriptors()) { System.out.println("si=" + si); } return; } } Asserts.fail("Missing EventTypeInfo for MyEvent"); }
Example 12
Source File: TestCopyToRunning.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static Recording getRecording(long recId) { for (Recording r : FlightRecorder.getFlightRecorder().getRecordings()) { if (r.getId() == recId) { return r; } } Asserts.fail("Could not find recording with id " + recId); return null; }
Example 13
Source File: TestVMInfoEvent.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { RuntimeMXBean mbean = ManagementFactory.getRuntimeMXBean(); Recording recording = new Recording(); recording.enable(EVENT_NAME); recording.start(); recording.stop(); List<RecordedEvent> events = Events.fromRecording(recording); Events.hasEvents(events); for (RecordedEvent event : events) { System.out.println("Event:" + event); Events.assertField(event, "jvmName").equal(mbean.getVmName()); String jvmVersion = Events.assertField(event, "jvmVersion").notEmpty().getValue(); if (!jvmVersion.contains(mbean.getVmVersion())) { Asserts.fail(String.format("%s does not contain %s", jvmVersion, mbean.getVmVersion())); } String jvmArgs = Events.assertField(event, "jvmArguments").notNull().getValue(); String jvmFlags = Events.assertField(event, "jvmFlags").notNull().getValue(); Long pid = Events.assertField(event, "pid").atLeast(0L).getValue(); Asserts.assertEquals(pid, ProcessTools.getProcessId()); String eventArgs = (jvmFlags.trim() + " " + jvmArgs).trim(); String beanArgs = mbean.getInputArguments().stream().collect(Collectors.joining(" ")); Asserts.assertEquals(eventArgs, beanArgs, "Wrong inputArgs"); final String javaCommand = mbean.getSystemProperties().get("sun.java.command"); Events.assertField(event, "javaArguments").equal(javaCommand); Events.assertField(event, "jvmStartTime").equal(mbean.getStartTime()); } }
Example 14
Source File: TestEventFactoryRegisterTwice.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void verifyRegistered(EventType eventType) { // Verify the event is registered boolean found = false; for (EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) { if (eventType.getId() == type.getId()) { found = true; } } if(!found) { Asserts.fail("Event not registered"); } }
Example 15
Source File: TestDumpOnCrash.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { try { Field theUnsafeRefLocation = Unsafe.class.getDeclaredField("theUnsafe"); theUnsafeRefLocation.setAccessible(true); ((Unsafe)theUnsafeRefLocation.get(null)).putInt(0L, 0); } catch(Exception ex) { Asserts.fail("cannot execute"); } }
Example 16
Source File: FileHelper.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void verifyRecording(File file) throws Exception { Asserts.assertTrue(file.exists(), file.getAbsolutePath() + " does not exist"); Asserts.assertTrue(file.isFile(), file.getAbsolutePath() + " is not a file"); Asserts.assertGreaterThan(file.length(), 0L, "Size of recording is 0."); List<RecordedEvent> events = RecordingFile.readAllEvents(file.toPath()); for (RecordedEvent event : events) { System.out.printf("First event in recording '%s':%n%s", file.getName(), event); return; } Asserts.fail("No events in file " + file.getName()); }
Example 17
Source File: TestShutdownEvent.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static Unsafe getUnsafe() { try { Field f = Unsafe.class.getDeclaredField("theUnsafe"); f.setAccessible(true); return (Unsafe)f.get(null); } catch (Exception e) { Asserts.fail("Could not access Unsafe"); } return null; }
Example 18
Source File: Events.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public static void hasNotEvent(List<RecordedEvent> events, String name) throws IOException { if (containsEvent(events, name)) { Asserts.fail("Rercording should not contain event " + name + " " + events.toString()); } }
Example 19
Source File: TestFormatMissingValue.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private static void assertNotContains(String t, String text) { if (t.contains(text)) { Asserts.fail("Found unexpected value '" + text + "' in text '" + t + "'"); } }
Example 20
Source File: TestSetConfigurationInvalid.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean(); long recId = bean.newRecording(); final String correctConfig = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" + "<configuration version=\"2.0\" label=\"TestName\" description='TestDesc' provider='TestProvider'>\n" + " <event name=\"" + EventNames.ClassLoad + "\">\r" + " \t <setting name=\"enabled\" control='class-loading-enabled'>false</setting>\r\n" + " <setting name=\"stackTrace\">true</setting>\t\r\n" + " <setting name=\"threshold\">5 ms</setting> \n" + " </event> " + " <control> " + " <flag name=\"class-loading-enabled\" label=\"Class Loading\">false</flag>\n" + " </control>" + "</configuration>"; Map<String, String> expectedSetting = new HashMap<>(); expectedSetting.put(EventNames.ClassLoad + "#enabled", "false"); expectedSetting.put(EventNames.ClassLoad + "#stackTrace", "true"); expectedSetting.put(EventNames.ClassLoad + "#threshold", "5 ms"); // First set a few invalid configs. Should get Exceptions. try { bean.setConfiguration(recId, null); Asserts.fail("Expected NullPointerException"); } catch (NullPointerException e) { // Expected exception } setInvalidConfig(recId, "Dummy text"); setInvalidConfig(recId, correctConfig.replace("/event", "event")); setInvalidConfig(recId, correctConfig.replace("<control>", "")); // Verify that we can set a correct setting after the failed attempts. bean.setConfiguration(recId, correctConfig); RecordingInfo jmxRecording = JmxHelper.getJmxRecording(recId); Recording javaRecording = JmxHelper.getJavaRecording(recId); JmxHelper.verifyEquals(jmxRecording, javaRecording); Map<String, String> settings = jmxRecording.getSettings(); for (String name : expectedSetting.keySet()) { String value = settings.remove(name); Asserts.assertNotNull(value, "No setting with name " + name); Asserts.assertEquals(value, expectedSetting.get(name), "Wrong setting value"); } Asserts.assertTrue(settings.isEmpty(), "Extra settings found " + settings.keySet()); }