Java Code Examples for jdk.test.lib.Asserts#assertNotNull()
The following examples show how to use
jdk.test.lib.Asserts#assertNotNull() .
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 testSetValue() throws Exception { long flagValue = 2048; ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( "-XX:+UnlockExperimentalVMOptions", "-XX:" + flagName + "=" + flagValue, "-XX:+PrintFlagsFinal", "-version"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); String value = output.firstMatch(printFlagsFinalPattern, 1); try { Asserts.assertNotNull("Couldn't find size_t flag " + flagName); long longValue = Long.parseLong(value); Asserts.assertEquals(longValue, flagValue); output.shouldHaveExitValue(0); } catch (Exception e) { System.err.println(output.getOutput()); throw e; } }
Example 2
Source File: TestGetConfigurations.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { List<Configuration> predefinedConfigs = Configuration.getConfigurations(); Asserts.assertNotNull(predefinedConfigs, "List of predefined configs is null"); Asserts.assertEquals(predefinedConfigs.size(), 2, "Expected exactly two predefined configurations"); Configuration defaultConfig = findConfigByName(predefinedConfigs, DEFAULT_CONFIG_NAME); Asserts.assertNotNull(defaultConfig, "Config '" + DEFAULT_CONFIG_NAME + "' not found"); Asserts.assertEquals(defaultConfig.getLabel(), DEFAULT_CONFIG_LABEL); Asserts.assertEquals(defaultConfig.getDescription(), DEFAULT_CONFIG_DESCRIPTION); Asserts.assertEquals(defaultConfig.getProvider(), DEFAULT_CONFIG_PROVIDER); Configuration profileConfig = findConfigByName(predefinedConfigs, PROFILE_CONFIG_NAME); Asserts.assertNotNull(profileConfig, "Config '" + PROFILE_CONFIG_NAME + "' not found"); Asserts.assertEquals(profileConfig.getLabel(), PROFILE_CONFIG_LABEL); Asserts.assertEquals(profileConfig.getDescription(), PROFILE_CONFIG_DESCRIPTION); Asserts.assertEquals(profileConfig.getProvider(), PROFILE_CONFIG_PROVIDER); }
Example 3
Source File: MemoryPoolsPresenceTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
protected void runTest() { List<MemoryManagerMXBean> beans = ManagementFactory.getMemoryManagerMXBeans(); Optional<MemoryManagerMXBean> any = beans .stream() .filter(bean -> CC_MANAGER.equals(bean.getName())) .findAny(); Asserts.assertTrue(any.isPresent(), "Bean not found: " + CC_MANAGER); MemoryManagerMXBean ccManager = any.get(); Asserts.assertNotNull(ccManager, "Found null for " + CC_MANAGER); String names[] = ccManager.getMemoryPoolNames(); for (String name : names) { counters.put(name, counters.containsKey(name) ? counters.get(name) + 1 : 1); } for (BlobType btype : BlobType.getAvailable()) { Asserts.assertEQ(counters.get(btype.getMemoryPool().getName()), 1, "Found unexpected amount of beans for pool " + btype.getMemoryPool().getName()); } Asserts.assertEQ(BlobType.getAvailable().size(), counters.keySet().size(), "Unexpected amount of bean names"); }
Example 4
Source File: TestConstructor.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { ValueDescriptor vdSimple = new ValueDescriptor(String.class, "message"); Asserts.assertNull(vdSimple.getAnnotation(Label.class), "Expected getAnnotation()==null"); Asserts.assertEquals(0, vdSimple.getAnnotationElements().size(), "Expected getAnnotations().size() == 0"); // Add labelA and verify we can read it back List<AnnotationElement> annos = new ArrayList<>(); AnnotationElement labelA = new AnnotationElement(Label.class, "labelA"); annos.add(labelA); System.out.println("labelA.getClass()" + labelA.getClass()); ValueDescriptor vdComplex = new ValueDescriptor(String.class, "message", annos); final Label outLabel = vdComplex.getAnnotation(Label.class); Asserts.assertFalse(outLabel == null, "getLabel(Label.class) was null"); System.out.println("outLabel.value() = " + outLabel.value()); // Get labelA from getAnnotations() list Asserts.assertEquals(1, vdComplex.getAnnotationElements().size(), "Expected getAnnotations().size() == 1"); final AnnotationElement outAnnotation = vdComplex.getAnnotationElements().get(0); Asserts.assertNotNull(outAnnotation, "outAnnotation was null"); System.out.printf("Annotation: %s = %s%n", outAnnotation.getTypeName(), outAnnotation.getValue("value")); Asserts.assertEquals(outAnnotation, labelA, "Expected firstAnnotation == labelA"); }
Example 5
Source File: TestStartDelay.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Instant testStart = Instant.now(); System.out.println("Test started at " + testStart); Recording r = StartupHelper.getRecording("TestStartDelay"); CommonHelper.verifyRecordingState(r, RecordingState.DELAYED); Asserts.assertNotNull(r.getStartTime(), "Recording start time should not be null for a delayed recording"); Asserts.assertLessThanOrEqual(r.getStartTime(), testStart.plus(Duration.ofSeconds(5000)), "Recording start time should not exceed test start time + delay"); Asserts.assertGreaterThanOrEqual(r.getStartTime(), testStart, "Recording start time should not happen before test start time"); r.close(); }
Example 6
Source File: TestTimeScheduleStart.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void testScheduledRecordingIsRunning() throws Exception { Recording r = new Recording(); r.scheduleStart(Duration.ofSeconds(2)); Asserts.assertNotNull(r.getStartTime(), "start time is null after scheduleStart()"); CommonHelper.waitForRecordingState(r, RecordingState.RUNNING); Asserts.assertLessThanOrEqual(r.getStartTime(), Instant.now(), "start time should not exceed current time"); r.stop(); r.close(); }
Example 7
Source File: TestSetConfiguration.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 recId = bean.newRecording(); final String configContents = "<?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"); bean.setConfiguration(recId, configContents); 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()); }
Example 8
Source File: GCEventAll.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Verifies field "cause" in garbage_collection event. * Only check that at cause is not null and that at least 1 cause is "System.gc()" * We might want to check more cause reasons later. */ private void verifyCollectionCause(List<GCHelper.GcBatch> batches) { int systemGcCount = 0; for (GCHelper.GcBatch batch : batches) { RecordedEvent endEvent = batch.getEndEvent(); String cause = Events.assertField(endEvent, "cause").notEmpty().getValue(); // A System.GC() can be consolidated into a GCLocker GC if (cause.equals("System.gc()") || cause.equals("GCLocker Initiated GC")) { systemGcCount++; } Asserts.assertNotNull(batch.getName(), "garbage_collection.name was null"); } final String msg = "No event with cause=System.gc(), collectors(%s, %s)"; Asserts.assertTrue(systemGcCount > 0, String.format(msg, youngCollector, oldCollector)); }
Example 9
Source File: TestClassDefineEvent.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { Recording recording = new Recording(); recording.enable(EVENT_NAME); TestClassLoader cl = new TestClassLoader(); recording.start(); cl.loadClass(TEST_CLASS_NAME); recording.stop(); List<RecordedEvent> events = Events.fromRecording(recording); boolean foundTestClasses = false; for (RecordedEvent event : events) { System.out.println(event); RecordedClass definedClass = event.getValue("definedClass"); if (TEST_CLASS_NAME.equals(definedClass.getName())) { RecordedClassLoader definingClassLoader = definedClass.getClassLoader(); Asserts.assertNotNull(definingClassLoader, "Defining Class Loader should not be null"); RecordedClass definingClassLoaderType = definingClassLoader.getType(); Asserts.assertNotNull(definingClassLoaderType, "The defining Class Loader type should not be null"); Asserts.assertEquals(cl.getClass().getName(), definingClassLoaderType.getName(), "Expected type " + cl.getClass().getName() + ", got type " + definingClassLoaderType.getName()); //Asserts.assertEquals(cl.getName(), definingClassLoader.getName(), // "Defining Class Loader should have the same name as the original class loader"); foundTestClasses = true; } } Asserts.assertTrue(foundTestClasses, "No class define event found for " + TEST_CLASS_NAME); }
Example 10
Source File: TestSnapshot.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void testOngoing(boolean disk) throws IOException { FlightRecorder recorder = FlightRecorder.getFlightRecorder(); try (Recording r = new Recording()) { r.setToDisk(disk); r.enable(SimpleEvent.class); r.start(); SimpleEvent se = new SimpleEvent(); se.commit(); try (Recording snapshot = recorder.takeSnapshot()) { Asserts.assertGreaterThan(snapshot.getSize(), 0L); Asserts.assertGreaterThanOrEqual(snapshot.getStartTime(), r.getStartTime()); Asserts.assertGreaterThanOrEqual(snapshot.getStopTime(), r.getStartTime()); Asserts.assertGreaterThanOrEqual(snapshot.getDuration(), Duration.ZERO); assertStaticOptions(snapshot); try (InputStream is = snapshot.getStream(null, null)) { Asserts.assertNotNull(is); } List<RecordedEvent> events = Events.fromRecording(snapshot); Events.hasEvents(events); Asserts.assertEquals(events.size(), 1); Asserts.assertEquals(events.get(0).getEventType().getName(), SimpleEvent.class.getName()); } r.stop(); } }
Example 11
Source File: GetStackTraceElementTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void runSanityTest(Executable aMethod, int[] bcis) { HotSpotResolvedJavaMethod method = CTVMUtilities .getResolvedMethod(aMethod); String className = aMethod.getDeclaringClass().getName(); String methodName = aMethod.getName().equals(className) ? "<init>" : aMethod.getName(); String fileName = getFileName(className); Map<Integer, Integer> bciWithLineNumber = CTVMUtilities .getBciToLineNumber(aMethod); boolean isNative = Modifier.isNative(aMethod.getModifiers()); int lineNumber = -1; for (int bci : bcis) { StackTraceElement ste = CompilerToVMHelper .getStackTraceElement(method, bci); Asserts.assertNotNull(ste, aMethod + " : got null StackTraceElement" + " at bci " + bci); Asserts.assertEQ(className, ste.getClassName(), aMethod + " : unexpected class name"); Asserts.assertEQ(fileName, ste.getFileName(), aMethod + " : unexpected filename"); Asserts.assertEQ(methodName, ste.getMethodName(), aMethod + " : unexpected method name"); Asserts.assertEQ(isNative, ste.isNativeMethod(), aMethod + " : unexpected 'isNative' value"); if (bciWithLineNumber.size() > 0) { if (bciWithLineNumber.containsKey(bci)) { lineNumber = bciWithLineNumber.get(bci); } Asserts.assertEQ(lineNumber, ste.getLineNumber(), aMethod + " : unexpected line number"); } else { // native and abstract function Asserts.assertGT(0, ste.getLineNumber(), aMethod + " : unexpected line number for abstract " + "or native method"); } } }
Example 12
Source File: TestGetFields.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Throwable { // Test simple ValueDescriptor final ValueDescriptor vdSimple = new ValueDescriptor(int.class, "id"); Asserts.assertNotNull(vdSimple.getFields(), "getFields() returned null"); Asserts.assertTrue(vdSimple.getFields().isEmpty(), "getFields() not empty for vdSimple"); }
Example 13
Source File: TestRecordedClassLoader.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Recording recording = new Recording(); recording.enable(EVENT_NAME).withoutStackTrace(); TestClassLoader cl = new TestClassLoader(); recording.start(); cl.loadClass(TEST_CLASS_NAME); recording.stop(); List<RecordedEvent> events = Events.fromRecording(recording); boolean isDefined = false; for (RecordedEvent event : events) { RecordedClass definedClass = event.getValue("definedClass"); if (TEST_CLASS_NAME.equals(definedClass.getName())) { System.out.println(event); // get the RecordedClassLoader from the RecordedClass, the "definedClass" RecordedClassLoader definingClassLoader = definedClass.getClassLoader(); Asserts.assertNotNull(definingClassLoader, "Defining Class Loader should not be null"); // invoke RecordedClassLoader.getType() in order to validate the type of the RecordedClassLoader RecordedClass definingClassLoaderType = definingClassLoader.getType(); Asserts.assertNotNull(definingClassLoaderType, "The defining Class Loader type should not be null"); // verify matching types Asserts.assertEquals(cl.getClass().getName(), definingClassLoaderType.getName(), "Expected type " + cl.getClass().getName() + ", got type " + definingClassLoaderType.getName()); // get a RecordedClassLoader directly from the "definingClassLoader" field as well RecordedClassLoader definingClassLoaderFromField = event.getValue("definingClassLoader"); Asserts.assertNotNull(definingClassLoaderFromField, "Defining Class Loader instantatiated from field should not be null"); // ensure that the class loader instance used in the test actually has a name //Asserts.assertNotNull(cl.getName(), // "Expected a valid name for the TestClassLoader"); // invoke RecordedClassLoader.getName() to get the name of the class loader instance //Asserts.assertEquals(cl.getName(), definingClassLoader.getName(), // "Defining Class Loader should have the same name as the original class loader"); Asserts.assertEquals(definingClassLoaderFromField.getName(), definingClassLoader.getName(), "Defining Class Loader representations should have the same class loader name"); // invoke uniqueID() Asserts.assertGreaterThan(definingClassLoader.getId(), 0L, "Invalid id assignment"); // second order class loader information ("check class loader of the class loader") RecordedClassLoader classLoaderOfDefClassLoader = definingClassLoaderType.getClassLoader(); Asserts.assertNotNull(classLoaderOfDefClassLoader, "The class loader for the definining class loader should not be null"); // Asserts.assertEquals(cl.getClass().getClassLoader().getName(), classLoaderOfDefClassLoader.getName(), // "Expected class loader name " + cl.getClass().getClassLoader().getName() + ", got name " + classLoaderOfDefClassLoader.getName()); RecordedClass classLoaderOfDefClassLoaderType = classLoaderOfDefClassLoader.getType(); Asserts.assertNotNull(classLoaderOfDefClassLoaderType, "The class loader type for the defining class loader should not be null"); Asserts.assertEquals(cl.getClass().getClassLoader().getClass().getName(), classLoaderOfDefClassLoaderType.getName(), "Expected type " + cl.getClass().getClassLoader().getClass().getName() + ", got type " + classLoaderOfDefClassLoaderType.getName()); Asserts.assertGreaterThan(definingClassLoader.getId(), classLoaderOfDefClassLoader.getId(), "expected id assignment invariant broken for Class Loaders"); isDefined = true; } } Asserts.assertTrue(isDefined, "No class define event found to verify RecordedClassLoader"); }
Example 14
Source File: SunBootClassPathEmptyTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static void testWithObsoleteClassPathOption(String obsoleteClassPath) throws Exception { PathSearchingVirtualMachine vm = connector.launchVm("TestClass", makeClassPathOptions(obsoleteClassPath)); List<String> bootClassPath = vm.bootClassPath(); Asserts.assertNotNull(bootClassPath, "Expected bootClassPath to be empty but was null"); Asserts.assertEquals(0, bootClassPath.size(), "Expected bootClassPath.size() 0 but was: " + bootClassPath.size()); }
Example 15
Source File: TestRTMDeoptOnLowAbortRatio.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void verifyRTMDeopt(boolean useStackLock) throws Throwable { CompilableTest test = new Test(); String logFileName = String.format("rtm_deopt_%s_stack_lock.xml", useStackLock ? "use" : "no"); OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest( logFileName, test, "-XX:+UseRTMDeopt", CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks", useStackLock), CommandLineOptionTest.prepareNumericFlag("RTMLockingThreshold", TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD), CommandLineOptionTest.prepareNumericFlag("RTMAbortThreshold", TestRTMDeoptOnLowAbortRatio.ABORT_THRESHOLD), "-XX:RTMAbortRatio=100", "-XX:CompileThreshold=1", "-XX:RTMRetryCount=0", "-XX:RTMTotalCountIncrRate=1", "-XX:+PrintPreciseRTMLockingStatistics", Test.class.getName(), Boolean.toString(!useStackLock) ); outputAnalyzer.shouldHaveExitValue(0); int firedTraps = RTMTestBase.firedRTMStateChangeTraps(logFileName); Asserts.assertEQ(firedTraps, 1, "Expected to get only one deoptimization due to rtm" + " state change"); List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString( test.getMethodWithLockName(), outputAnalyzer.getOutput()); Asserts.assertEQ(statistics.size(), 2, "VM output should contain two RTM locking " + "statistics entries for method " + test.getMethodWithLockName()); RTMLockingStatistics statisticsBeforeDeopt = null; for (RTMLockingStatistics s : statistics) { if (s.getTotalLocks() == TestRTMDeoptOnLowAbortRatio.LOCKING_THRESHOLD) { Asserts.assertNull(statisticsBeforeDeopt, "Only one abort was expected during test run"); statisticsBeforeDeopt = s; } } Asserts.assertNotNull(statisticsBeforeDeopt, "After LockThreshold was reached, method should be recompiled " + "with rtm lock eliding."); }
Example 16
Source File: JcmdAsserts.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public static void assertDurationEqualsMBeanValue(String name, long duration) throws Exception { Recording recording = findRecording(name); Asserts.assertNotNull(recording, "No recording found"); Asserts.assertEquals(duration, recording.getDuration().toMillis()); }
Example 17
Source File: TestRTMLockingThreshold.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void verifyLockingThreshold(int lockingThreshold, boolean useStackLock) throws Throwable { CompilableTest test = new Test(); int abortThreshold = Math.max(lockingThreshold / 2, TestRTMLockingThreshold.MIN_ABORT_THRESHOLD); OutputAnalyzer outputAnalyzer = RTMTestBase.executeRTMTest( test, "-XX:CompileThreshold=1", CommandLineOptionTest.prepareBooleanFlag("UseRTMForStackLocks", useStackLock), "-XX:+UseRTMDeopt", "-XX:RTMTotalCountIncrRate=1", "-XX:RTMRetryCount=0", CommandLineOptionTest.prepareNumericFlag("RTMAbortThreshold", abortThreshold), CommandLineOptionTest.prepareNumericFlag("RTMLockingThreshold", lockingThreshold), "-XX:RTMAbortRatio=100", "-XX:+PrintPreciseRTMLockingStatistics", Test.class.getName(), Boolean.toString(!useStackLock), Integer.toString(lockingThreshold) ); outputAnalyzer.shouldHaveExitValue(0); List<RTMLockingStatistics> statistics = RTMLockingStatistics.fromString( test.getMethodWithLockName(), outputAnalyzer.getOutput()); Asserts.assertEQ(statistics.size(), 2, "VM output should contain two " + "RTM locking statistics entries."); /** * If RTMLockingThreshold==0, then we have to make at least 1 call. */ long expectedValue = lockingThreshold; if (expectedValue == 0) { expectedValue++; } RTMLockingStatistics statBeforeDeopt = null; for (RTMLockingStatistics s : statistics) { if (s.getTotalLocks() == expectedValue) { Asserts.assertNull(statBeforeDeopt, "Only one statistics entry should contain aborts"); statBeforeDeopt = s; } } Asserts.assertNotNull(statBeforeDeopt, "There should be exactly one " + "statistics entry corresponding to ProfileRTM state."); }
Example 18
Source File: TestTimeMultiple.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Throwable { Recording rA = new Recording(); Asserts.assertNull(rA.getStartTime(), "getStartTime() not null before start"); Asserts.assertNull(rA.getStopTime(), "getStopTime() not null before start"); final Instant beforeStartA = Instant.now(); rA.start(); final Instant afterStartA = Instant.now(); Recording rB = new Recording(); Asserts.assertNull(rB.getStartTime(), "getStartTime() not null before start"); Asserts.assertNull(rB.getStopTime(), "getStopTime() not null before start"); final Instant beforeStartB = Instant.now(); rB.start(); final Instant afterStartB = Instant.now(); final Instant beforeStopB = Instant.now(); rB.stop(); final Instant afterStopB = Instant.now(); final Instant beforeStopA = Instant.now(); rA.stop(); final Instant afterStopA = Instant.now(); rA.close(); rB.close(); Asserts.assertNotNull(rA.getStartTime(), "getStartTime() null after start"); Asserts.assertNotNull(rA.getStopTime(), "getStopTime() null after stop"); Asserts.assertGreaterThanOrEqual(rA.getStartTime(), beforeStartA, "getStartTime() < beforeStart"); Asserts.assertLessThanOrEqual(rA.getStartTime(), afterStartA, "getStartTime() > afterStart"); Asserts.assertGreaterThanOrEqual(rA.getStopTime(), beforeStopA, "getStopTime() < beforeStop"); Asserts.assertLessThanOrEqual(rA.getStopTime(), afterStopA, "getStopTime() > afterStop"); Asserts.assertNotNull(rB.getStartTime(), "getStartTime() null after start"); Asserts.assertNotNull(rB.getStopTime(), "getStopTime() null after stop"); Asserts.assertGreaterThanOrEqual(rB.getStartTime(), beforeStartB, "getStartTime() < beforeStart"); Asserts.assertLessThanOrEqual(rB.getStartTime(), afterStartB, "getStartTime() > afterStart"); Asserts.assertGreaterThanOrEqual(rB.getStopTime(), beforeStopB, "getStopTime() < beforeStop"); Asserts.assertLessThanOrEqual(rB.getStopTime(), afterStopB, "getStopTime() > afterStop"); }
Example 19
Source File: TestSetConfigurationInvalid.java From TencentKona-8 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()); }
Example 20
Source File: CollectCountersTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private void runTest() { long[] counters = CompilerToVMHelper.collectCounters(); Asserts.assertNotNull(counters, "Expected not-null counters array"); int ctvmData = counters.length; Asserts.assertEQ(EXPECTED, ctvmData, "Unexpected counters amount"); }