Java Code Examples for jdk.test.lib.Asserts#assertNotEquals()
The following examples show how to use
jdk.test.lib.Asserts#assertNotEquals() .
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: TestArrayAllocatorMallocLimit.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void testDefaultValue() throws Exception { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( "-XX:+UnlockExperimentalVMOptions", "-XX:+PrintFlagsFinal", "-version"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); String value = output.firstMatch(printFlagsFinalPattern, 1); try { Asserts.assertNotNull(value, "Couldn't find size_t flag " + flagName); // A size_t is not always parseable with Long.parseValue, // use BigInteger instead. BigInteger biValue = new BigInteger(value); // Sanity check that we got a non-zero value. Asserts.assertNotEquals(biValue, "0"); output.shouldHaveExitValue(0); } catch (Exception e) { System.err.println(output.getOutput()); throw e; } }
Example 2
Source File: TestParallelGCThreads.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void testDefaultValue() throws Exception { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( "-XX:+UnlockExperimentalVMOptions", "-XX:+PrintFlagsFinal", "-version"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); String value = output.firstMatch(printFlagsFinalPattern, 1); try { Asserts.assertNotNull(value, "Couldn't find uint flag " + flagName); Long longValue = new Long(value); // Sanity check that we got a non-zero value. Asserts.assertNotEquals(longValue, "0"); output.shouldHaveExitValue(0); } catch (Exception e) { System.err.println(output.getOutput()); throw e; } }
Example 3
Source File: TestDestWithDuration.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Path dest = Paths.get(".", "my.jfr"); Recording r = new Recording(); SimpleEventHelper.enable(r, true); r.setDestination(dest); r.start(); SimpleEventHelper.createEvent(1); // Waiting for recording to auto close after duration r.setDuration(Duration.ofSeconds(1)); System.out.println("Waiting for recording to auto close after duration"); CommonHelper.waitForRecordingState(r, RecordingState.CLOSED); System.out.println("recording state = " + r.getState()); Asserts.assertEquals(r.getState(), RecordingState.CLOSED, "Recording not closed"); Asserts.assertTrue(Files.exists(dest), "No recording file: " + dest); System.out.printf("Recording file size=%d%n", Files.size(dest)); Asserts.assertNotEquals(Files.size(dest), 0L, "File length 0. Should at least be some bytes"); List<RecordedEvent> events = RecordingFile.readAllEvents(dest); Asserts.assertFalse(events.isEmpty(), "No event found"); System.out.printf("Found event %s%n", events.get(0).getEventType().getName()); }
Example 4
Source File: TestDestToDiskTrue.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Path dest = Paths.get(".", "my.jfr"); Recording r = new Recording(); r.enable(EventNames.OSInformation); r.setToDisk(true); r.setDestination(dest); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set destination"); r.start(); r.stop(); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set destination after stop"); Asserts.assertTrue(Files.exists(dest), "No recording file: " + dest); List<RecordedEvent> events = RecordingFile.readAllEvents(dest); Asserts.assertFalse(events.isEmpty(), "No event found"); System.out.printf("Found event %s%n", events.get(0).getEventType().getName()); System.out.printf("File size=%d, getSize()=%d%n", Files.size(dest), r.getSize()); assertEquals(r.getSize(), 0L, "getSize() should return 0, chunks should have be released at stop"); Asserts.assertNotEquals(Files.size(dest), 0L, "File length 0. Should at least be some bytes"); r.close(); }
Example 5
Source File: TestEventMetadata.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void verifyName(String name) { System.out.println("Verifying name: " + name); Asserts.assertNotEquals(name, null, "Name not allowed to be null"); Asserts.assertTrue(name.length() > 1, "Name must be at least two characters"); Asserts.assertTrue(name.length() < 32, "Name should not exceed 32 characters"); Asserts.assertFalse(isReservedKeyword(name),"Name must not be reserved keyword in the Java language (" + name + ")"); char firstChar = name.charAt(0); Asserts.assertTrue(Character.isAlphabetic(firstChar), "Name must start with a character"); Asserts.assertTrue(Character.isLowerCase(firstChar), "Name must start with lower case letter"); Asserts.assertTrue(Character.isJavaIdentifierStart(firstChar), "Not valid first character for Java identifier"); for (int i = 1; i < name.length(); i++) { Asserts.assertTrue(Character.isJavaIdentifierPart(name.charAt(i)), "Not valid character for a Java identifier"); Asserts.assertTrue(Character.isAlphabetic(name.charAt(i)), "Name must consists of characters, found '" + name.charAt(i) + "'"); } Asserts.assertFalse(name.contains("ID"), "'ID' should not be used in name, consider using 'Id'"); checkCommonAbbreviations(name); }
Example 6
Source File: TestEventMetadata.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static void verifyEventType(EventType eventType) { System.out.println("Verifying event: " + eventType.getName()); verifyDescription(eventType.getDescription()); verifyLabel(eventType.getLabel()); Asserts.assertNotEquals(eventType.getName(), null, "Name not allowed to be null"); Asserts.assertTrue(eventType.getName().startsWith(EventNames.PREFIX), "OpenJDK events must start with " + EventNames.PREFIX); String name = eventType.getName().substring(EventNames.PREFIX.length()); Asserts.assertFalse(isReservedKeyword(name),"Name must not be reserved keyword in the Java language (" + name + ")"); checkCommonAbbreviations(name); char firstChar = name.charAt(0); Asserts.assertFalse(name.contains("ID"), "'ID' should not be used in name, consider using 'Id'"); Asserts.assertTrue(Character.isAlphabetic(firstChar), "Name " + name + " must start with a character"); Asserts.assertTrue(Character.isUpperCase(firstChar), "Name " + name + " must start with upper case letter"); for (int i = 0; i < name.length(); i++) { char c = name.charAt(i); Asserts.assertTrue(Character.isAlphabetic(c) || Character.isDigit(c), "Name " + name + " must consists of characters or numbers, found '" + name.charAt(i) + "'"); } }
Example 7
Source File: TestEventMetadata.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static void verifyName(String name) { System.out.println("Verifying name: " + name); Asserts.assertNotEquals(name, null, "Name not allowed to be null"); Asserts.assertTrue(name.length() > 1, "Name must be at least two characters"); Asserts.assertTrue(name.length() < 32, "Name should not exceed 32 characters"); Asserts.assertFalse(isReservedKeyword(name),"Name must not be reserved keyword in the Java language (" + name + ")"); char firstChar = name.charAt(0); Asserts.assertTrue(Character.isAlphabetic(firstChar), "Name must start with a character"); Asserts.assertTrue(Character.isLowerCase(firstChar), "Name must start with lower case letter"); Asserts.assertTrue(Character.isJavaIdentifierStart(firstChar), "Not valid first character for Java identifier"); for (int i = 1; i < name.length(); i++) { Asserts.assertTrue(Character.isJavaIdentifierPart(name.charAt(i)), "Not valid character for a Java identifier"); Asserts.assertTrue(Character.isAlphabetic(name.charAt(i)), "Name must consists of characters, found '" + name.charAt(i) + "'"); } Asserts.assertFalse(name.contains("ID"), "'ID' should not be used in name, consider using 'Id'"); checkCommonAbbreviations(name); }
Example 8
Source File: TestEventMetadata.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void verifyEventType(EventType eventType) { System.out.println("Verifying event: " + eventType.getName()); verifyDescription(eventType.getDescription()); verifyLabel(eventType.getLabel()); Asserts.assertNotEquals(eventType.getName(), null, "Name not allowed to be null"); Asserts.assertTrue(eventType.getName().startsWith(EventNames.PREFIX), "OpenJDK events must start with " + EventNames.PREFIX); String name = eventType.getName().substring(EventNames.PREFIX.length()); Asserts.assertFalse(isReservedKeyword(name),"Name must not be reserved keyword in the Java language (" + name + ")"); checkCommonAbbreviations(name); char firstChar = name.charAt(0); Asserts.assertFalse(name.contains("ID"), "'ID' should not be used in name, consider using 'Id'"); Asserts.assertTrue(Character.isAlphabetic(firstChar), "Name " + name + " must start with a character"); Asserts.assertTrue(Character.isUpperCase(firstChar), "Name " + name + " must start with upper case letter"); for (int i = 0; i < name.length(); i++) { char c = name.charAt(i); Asserts.assertTrue(Character.isAlphabetic(c) || Character.isDigit(c), "Name " + name + " must consists of characters or numbers, found '" + name.charAt(i) + "'"); } }
Example 9
Source File: TestDestToDiskTrue.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Path dest = Paths.get(".", "my.jfr"); Recording r = new Recording(); r.enable(EventNames.OSInformation); r.setToDisk(true); r.setDestination(dest); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set destination"); r.start(); r.stop(); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set destination after stop"); Asserts.assertTrue(Files.exists(dest), "No recording file: " + dest); List<RecordedEvent> events = RecordingFile.readAllEvents(dest); Asserts.assertFalse(events.isEmpty(), "No event found"); System.out.printf("Found event %s%n", events.get(0).getEventType().getName()); System.out.printf("File size=%d, getSize()=%d%n", Files.size(dest), r.getSize()); assertEquals(r.getSize(), 0L, "getSize() should return 0, chunks should have be released at stop"); Asserts.assertNotEquals(Files.size(dest), 0L, "File length 0. Should at least be some bytes"); r.close(); }
Example 10
Source File: TestEventMetadata.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void verifyLabel(String label) { Asserts.assertNotEquals(label, null, "Label not allowed to be null"); Asserts.assertTrue(label.length() > 1, "Name must be at least two characters"); Asserts.assertTrue(label.length() < 45, "Label should not exceed 45 characters, use description to explain " + label); Asserts.assertTrue(label.length() == label.trim().length(), "Label should not have trim character at start and end"); Asserts.assertTrue(Character.isUpperCase(label.charAt(0)), "Label should start with upper case letter"); for (int i = 0; i < label.length(); i++) { char c = label.charAt(i); Asserts.assertTrue(Character.isDigit(c) || Character.isAlphabetic(label.charAt(i)) || c == ' ' || c == '(' || c == ')' || c == '-', "Label should only consist of letters or space, found '" + label.charAt(i) + "'"); } }
Example 11
Source File: TestEventMetadata.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void verifyLabel(String label) { Asserts.assertNotEquals(label, null, "Label not allowed to be null"); Asserts.assertTrue(label.length() > 1, "Name must be at least two characters"); Asserts.assertTrue(label.length() < 45, "Label should not exceed 45 characters, use description to explain " + label); Asserts.assertTrue(label.length() == label.trim().length(), "Label should not have trim character at start and end"); Asserts.assertTrue(Character.isUpperCase(label.charAt(0)), "Label should start with upper case letter"); for (int i = 0; i < label.length(); i++) { char c = label.charAt(i); Asserts.assertTrue(Character.isDigit(c) || Character.isAlphabetic(label.charAt(i)) || c == ' ' || c == '(' || c == ')' || c == '-', "Label should only consist of letters or space, found '" + label.charAt(i) + "'"); } }
Example 12
Source File: TestGetStackTraceId.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String... args) { FlightRecorder.getFlightRecorder(); JVM jvm = JVM.getJVM(); long id10 = getStackIdOfDepth(10); assertValid(id10); long id5 = getStackIdOfDepth(5); assertValid(id5); Asserts.assertNotEquals(id5, id10, "Different stack depth must return different stack trace ids"); assertMaxSkip(jvm); }
Example 13
Source File: TestGetSizeToMem.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { Path dest = Paths.get(".", "my.jfr"); Recording r = new Recording(); r.setToDisk(false); r.setDestination(dest); r.enable(EventNames.OSInformation); r.start(); r.stop(); r.close(); assertTrue(Files.exists(dest), "TestGetSize recording missing: " + dest); System.out.printf("%s size: %d%n", dest, Files.size(dest)); System.out.printf("r.getSize(): %d%n", r.getSize()); Asserts.assertNotEquals(Files.size(dest), 0L, "File should not be empty"); assertEquals(r.getSize(), 0L, "r.getSize() should be 0 after setToDisk(false)"); }
Example 14
Source File: TestClone.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean(); long orgId = bean.newRecording(); bean.startRecording(orgId); SimpleEventHelper.createEvent(1); // Should be in both org and clone long cloneId = bean.cloneRecording(orgId, false); Asserts.assertNotEquals(orgId, cloneId, "clone id should not be same as org id"); List<RecordingInfo> recordings = bean.getRecordings(); JmxHelper.verifyState(orgId, RecordingState.RUNNING, recordings); JmxHelper.verifyState(cloneId, RecordingState.RUNNING, recordings); bean.stopRecording(orgId); recordings = bean.getRecordings(); JmxHelper.verifyState(orgId, RecordingState.STOPPED, recordings); JmxHelper.verifyState(cloneId, RecordingState.RUNNING, recordings); SimpleEventHelper.createEvent(2); // Should only be in clone bean.stopRecording(cloneId); recordings = bean.getRecordings(); JmxHelper.verifyState(orgId, RecordingState.STOPPED, recordings); JmxHelper.verifyState(cloneId, RecordingState.STOPPED, recordings); Path orgPath = Paths.get(".", "org.jfr"); Path clonePath = Paths.get(".", "clone.jfr"); bean.copyTo(orgId, orgPath.toString()); bean.copyTo(cloneId, clonePath.toString()); verifyEvents(orgPath, 1); verifyEvents(clonePath, 1, 2); bean.closeRecording(orgId); bean.closeRecording(cloneId); }
Example 15
Source File: TestStreamMultiple.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean(); SimpleEventHelper.createEvent(0); // No recordings long recIdA = bean.newRecording(); bean.startRecording(recIdA); SimpleEventHelper.createEvent(1); // recA long recIdB = bean.newRecording(); Asserts.assertNotEquals(recIdA, recIdB, "Recording Ids should be unique"); bean.startRecording(recIdB); SimpleEventHelper.createEvent(2); // recA and recB bean.stopRecording(recIdA); SimpleEventHelper.createEvent(3); // recB bean.stopRecording(recIdB); SimpleEventHelper.createEvent(4); // No recordings // Check recA long streamIdA = bean.openStream(recIdA, null); List<RecordedEvent> events = JmxHelper.parseStream(streamIdA, bean); SimpleEventHelper.verifyContains(events, 1, 2); SimpleEventHelper.verifyNotContains(events, 0, 3, 4); bean.closeStream(streamIdA); // check recB long streamIdB = bean.openStream(recIdB, null); events = JmxHelper.parseStream(streamIdB, bean); SimpleEventHelper.verifyContains(events, 2, 3); SimpleEventHelper.verifyNotContains(events, 0, 1, 4); bean.closeStream(streamIdB); bean.closeRecording(recIdA); bean.closeRecording(recIdB); }
Example 16
Source File: TestGetSizeToMem.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { Path dest = Paths.get(".", "my.jfr"); Recording r = new Recording(); r.setToDisk(false); r.setDestination(dest); r.enable(EventNames.OSInformation); r.start(); r.stop(); r.close(); assertTrue(Files.exists(dest), "TestGetSize recording missing: " + dest); System.out.printf("%s size: %d%n", dest, Files.size(dest)); System.out.printf("r.getSize(): %d%n", r.getSize()); Asserts.assertNotEquals(Files.size(dest), 0L, "File should not be empty"); assertEquals(r.getSize(), 0L, "r.getSize() should be 0 after setToDisk(false)"); }
Example 17
Source File: TestStreamMultiple.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean(); SimpleEventHelper.createEvent(0); // No recordings long recIdA = bean.newRecording(); bean.startRecording(recIdA); SimpleEventHelper.createEvent(1); // recA long recIdB = bean.newRecording(); Asserts.assertNotEquals(recIdA, recIdB, "Recording Ids should be unique"); bean.startRecording(recIdB); SimpleEventHelper.createEvent(2); // recA and recB bean.stopRecording(recIdA); SimpleEventHelper.createEvent(3); // recB bean.stopRecording(recIdB); SimpleEventHelper.createEvent(4); // No recordings // Check recA long streamIdA = bean.openStream(recIdA, null); List<RecordedEvent> events = JmxHelper.parseStream(streamIdA, bean); SimpleEventHelper.verifyContains(events, 1, 2); SimpleEventHelper.verifyNotContains(events, 0, 3, 4); bean.closeStream(streamIdA); // check recB long streamIdB = bean.openStream(recIdB, null); events = JmxHelper.parseStream(streamIdB, bean); SimpleEventHelper.verifyContains(events, 2, 3); SimpleEventHelper.verifyNotContains(events, 0, 1, 4); bean.closeStream(streamIdB); bean.closeRecording(recIdA); bean.closeRecording(recIdB); }
Example 18
Source File: OverflowCodeCacheTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void test() { System.out.printf("type %s%n", type); System.out.println("allocating till possible..."); ArrayList<Long> blobs = new ArrayList<>(); int compilationActivityMode = -1; try { long addr; int size = (int) (getHeapSize() >> 7); while ((addr = WHITE_BOX.allocateCodeBlob(size, type.id)) != 0) { blobs.add(addr); BlobType actualType = CodeBlob.getCodeBlob(addr).code_blob_type; if (actualType != type) { // check we got allowed overflow handling Asserts.assertTrue(type.allowTypeWhenOverflow(actualType), type + " doesn't allow using " + actualType + " when overflow"); } } /* now, remember compilationActivityMode to check it later, after freeing, since we possibly have no free cache for futher work */ compilationActivityMode = WHITE_BOX.getCompilationActivityMode(); } finally { for (Long blob : blobs) { WHITE_BOX.freeCodeBlob(blob); } } Asserts.assertNotEquals(compilationActivityMode, 1 /* run_compilation*/, "Compilation must be disabled when CodeCache(CodeHeap) overflows"); }
Example 19
Source File: TestGetTypeId.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { EventType type = EventType.getEventType(CustomEvent.class); SettingDescriptor plain = Events.getSetting(type, "plain"); long plainId = plain.getTypeId(); Asserts.assertGreaterThan(plainId, 0L); SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType"); long annotatedId = annotatedType.getTypeId(); Asserts.assertGreaterThan(annotatedId, 0L); Asserts.assertNotEquals(annotatedId, plainId); SettingDescriptor newName = Events.getSetting(type, "newName"); Asserts.assertEquals(newName.getTypeId(), annotatedId); SettingDescriptor overridden = Events.getSetting(type, "overridden"); Asserts.assertEquals(overridden.getTypeId(), plainId); SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase"); Asserts.assertEquals(protectedBase.getTypeId(), plainId); SettingDescriptor publicBase = Events.getSetting(type, "publicBase"); Asserts.assertEquals(publicBase.getTypeId(), annotatedId); SettingDescriptor packageProtectedBase = Events.getSetting(type, "packageProtectedBase"); Asserts.assertEquals(packageProtectedBase.getTypeId(), plainId); CustomEvent.assertOnDisk((x, y) -> Long.compare(x.getTypeId(), y.getTypeId())); }
Example 20
Source File: CiReplayBase.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public boolean generateReplay(boolean needCoreDump, String... vmopts) { OutputAnalyzer crashOut; String crashOutputString; try { List<String> options = new ArrayList<>(); options.addAll(Arrays.asList(REPLAY_GENERATION_OPTIONS)); options.addAll(Arrays.asList(vmopts)); options.add(needCoreDump ? ENABLE_COREDUMP_ON_CRASH : DISABLE_COREDUMP_ON_CRASH); options.add(VERSION_OPTION); if (needCoreDump) { crashOut = ProcessTools.executeProcess(getTestJavaCommandlineWithPrefix( RUN_SHELL_NO_LIMIT, options.toArray(new String[0]))); } else { crashOut = ProcessTools.executeProcess(ProcessTools.createJavaProcessBuilder(true, options.toArray(new String[0]))); } crashOutputString = crashOut.getOutput(); Asserts.assertNotEquals(crashOut.getExitValue(), 0, "Crash JVM exits gracefully"); Files.write(Paths.get("crash.out"), crashOutputString.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); } catch (Throwable t) { throw new Error("Can't create replay: " + t, t); } if (needCoreDump) { String coreFileLocation = getCoreFileLocation(crashOutputString); if (coreFileLocation == null) { if (Platform.isOSX()) { File coresDir = new File("/cores"); if (!coresDir.isDirectory() || !coresDir.canWrite()) { return false; } } throw new Error("Couldn't find core file location in: '" + crashOutputString + "'"); } try { Asserts.assertGT(new File(coreFileLocation).length(), 0L, "Unexpected core size"); Files.move(Paths.get(coreFileLocation), Paths.get(TEST_CORE_FILE_NAME)); } catch (IOException ioe) { throw new Error("Can't move core file: " + ioe, ioe); } } removeFromCurrentDirectoryStartingWith(HS_ERR_NAME); return true; }