Java Code Examples for jdk.testlibrary.Asserts#assertLessThan()
The following examples show how to use
jdk.testlibrary.Asserts#assertLessThan() .
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: TestThreadCpuTimeEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
static void verifyPerThreadInvariant(List<RecordedEvent> events, String threadName) { List<RecordedEvent> filteredEvents = events.stream() .filter(e -> e.getThread().getJavaName().equals(threadName)) .sorted(Comparator.comparing(RecordedEvent::getStartTime)) .collect(Collectors.toList()); int numCpus = Runtime.getRuntime().availableProcessors(); Iterator<RecordedEvent> i = filteredEvents.iterator(); while (i.hasNext()) { RecordedEvent event = i.next(); Float systemLoad = (Float)event.getValue("system"); Float userLoad = (Float)event.getValue("user"); Asserts.assertLessThan(systemLoad + userLoad, 1.01f / numCpus); // 100% + rounding errors } }
Example 2
Source File: JpsHelper.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Generate all possible combinations of {@link JpsArg} * (31 argument combinations and no arguments case) */ public static List<List<JpsArg>> generateCombinations() { final int argCount = JpsArg.values().length; // If there are more than 30 args this algorithm will overflow. Asserts.assertLessThan(argCount, 31, "Too many args"); List<List<JpsArg>> combinations = new ArrayList<>(); int combinationCount = (int) Math.pow(2, argCount); for (int currCombo = 0; currCombo < combinationCount; ++currCombo) { List<JpsArg> combination = new ArrayList<>(); for (int position = 0; position < argCount; ++position) { int bit = 1 << position; if ((bit & currCombo) != 0) { combination.add(JpsArg.values()[position]); } } combinations.add(combination); } return combinations; }
Example 3
Source File: JpsHelper.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Generate all possible combinations of {@link JpsArg} * (31 argument combinations and no arguments case) */ public static List<List<JpsArg>> generateCombinations() { final int argCount = JpsArg.values().length; // If there are more than 30 args this algorithm will overflow. Asserts.assertLessThan(argCount, 31, "Too many args"); List<List<JpsArg>> combinations = new ArrayList<>(); int combinationCount = (int) Math.pow(2, argCount); for (int currCombo = 0; currCombo < combinationCount; ++currCombo) { List<JpsArg> combination = new ArrayList<>(); for (int position = 0; position < argCount; ++position) { int bit = 1 << position; if ((bit & currCombo) != 0) { combination.add(JpsArg.values()[position]); } } combinations.add(combination); } return combinations; }
Example 4
Source File: JpsHelper.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Generate all possible combinations of {@link JpsArg} * (31 argument combinations and no arguments case) */ public static List<List<JpsArg>> generateCombinations() { final int argCount = JpsArg.values().length; // If there are more than 30 args this algorithm will overflow. Asserts.assertLessThan(argCount, 31, "Too many args"); List<List<JpsArg>> combinations = new ArrayList<>(); int combinationCount = (int) Math.pow(2, argCount); for (int currCombo = 0; currCombo < combinationCount; ++currCombo) { List<JpsArg> combination = new ArrayList<>(); for (int position = 0; position < argCount; ++position) { int bit = 1 << position; if ((bit & currCombo) != 0) { combination.add(JpsArg.values()[position]); } } combinations.add(combination); } return combinations; }
Example 5
Source File: JpsHelper.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Generate all possible combinations of {@link JpsArg} * (31 argument combinations and no arguments case) */ public static List<List<JpsArg>> generateCombinations() { final int argCount = JpsArg.values().length; // If there are more than 30 args this algorithm will overflow. Asserts.assertLessThan(argCount, 31, "Too many args"); List<List<JpsArg>> combinations = new ArrayList<>(); int combinationCount = (int) Math.pow(2, argCount); for (int currCombo = 0; currCombo < combinationCount; ++currCombo) { List<JpsArg> combination = new ArrayList<>(); for (int position = 0; position < argCount; ++position) { int bit = 1 << position; if ((bit & currCombo) != 0) { combination.add(JpsArg.values()[position]); } } combinations.add(combination); } return combinations; }
Example 6
Source File: JpsHelper.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Generate all possible combinations of {@link JpsArg} * (31 argument combinations and no arguments case) */ public static List<List<JpsArg>> generateCombinations() { final int argCount = JpsArg.values().length; // If there are more than 30 args this algorithm will overflow. Asserts.assertLessThan(argCount, 31, "Too many args"); List<List<JpsArg>> combinations = new ArrayList<>(); int combinationCount = (int) Math.pow(2, argCount); for (int currCombo = 0; currCombo < combinationCount; ++currCombo) { List<JpsArg> combination = new ArrayList<>(); for (int position = 0; position < argCount; ++position) { int bit = 1 << position; if ((bit & currCombo) != 0) { combination.add(JpsArg.values()[position]); } } combinations.add(combination); } return combinations; }
Example 7
Source File: JpsHelper.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Generate all possible combinations of {@link JpsArg} * (31 argument combinations and no arguments case) */ public static List<List<JpsArg>> generateCombinations() { final int argCount = JpsArg.values().length; // If there are more than 30 args this algorithm will overflow. Asserts.assertLessThan(argCount, 31, "Too many args"); List<List<JpsArg>> combinations = new ArrayList<>(); int combinationCount = (int) Math.pow(2, argCount); for (int currCombo = 0; currCombo < combinationCount; ++currCombo) { List<JpsArg> combination = new ArrayList<>(); for (int position = 0; position < argCount; ++position) { int bit = 1 << position; if ((bit & currCombo) != 0) { combination.add(JpsArg.values()[position]); } } combinations.add(combination); } return combinations; }
Example 8
Source File: JpsHelper.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Generate all possible combinations of {@link JpsArg} * (31 argument combinations and no arguments case) */ public static List<List<JpsArg>> generateCombinations() { final int argCount = JpsArg.values().length; // If there are more than 30 args this algorithm will overflow. Asserts.assertLessThan(argCount, 31, "Too many args"); List<List<JpsArg>> combinations = new ArrayList<>(); int combinationCount = (int) Math.pow(2, argCount); for (int currCombo = 0; currCombo < combinationCount; ++currCombo) { List<JpsArg> combination = new ArrayList<>(); for (int position = 0; position < argCount; ++position) { int bit = 1 << position; if ((bit & currCombo) != 0) { combination.add(JpsArg.values()[position]); } } combinations.add(combination); } return combinations; }
Example 9
Source File: JpsHelper.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * Generate all possible combinations of {@link JpsArg} * (31 argument combinations and no arguments case) */ public static List<List<JpsArg>> generateCombinations() { final int argCount = JpsArg.values().length; // If there are more than 30 args this algorithm will overflow. Asserts.assertLessThan(argCount, 31, "Too many args"); List<List<JpsArg>> combinations = new ArrayList<>(); int combinationCount = (int) Math.pow(2, argCount); for (int currCombo = 0; currCombo < combinationCount; ++currCombo) { List<JpsArg> combination = new ArrayList<>(); for (int position = 0; position < argCount; ++position) { int bit = 1 << position; if ((bit & currCombo) != 0) { combination.add(JpsArg.values()[position]); } } combinations.add(combination); } return combinations; }
Example 10
Source File: TestSnapshot.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static void testEmpty() throws IOException { FlightRecorder recorder = FlightRecorder.getFlightRecorder(); Instant before = Instant.now().minusNanos(1); try (Recording snapshot = recorder.takeSnapshot()) { Instant after = Instant.now().plusNanos(1); Asserts.assertEquals(snapshot.getSize(), 0L); Asserts.assertLessThan(before, snapshot.getStartTime()); Asserts.assertGreaterThan(after, snapshot.getStopTime()); Asserts.assertEquals(snapshot.getStartTime(), snapshot.getStopTime()); Asserts.assertEquals(snapshot.getDuration(), Duration.ZERO); assertStaticOptions(snapshot); Asserts.assertEquals(snapshot.getStream(null, null), null); } }
Example 11
Source File: TestThreadCpuTimeEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
static void testCompareWithMXBean() throws Throwable { Recording recording = new Recording(); recording.enable(EventNames.ThreadCPULoad).withPeriod(Duration.ofMillis(eventPeriodMillis)); recording.start(); Duration testRunTime = Duration.ofMillis(eventPeriodMillis * cpuConsumerRunFactor); CyclicBarrier barrier = new CyclicBarrier(2); CpuConsumingThread thread = new CpuConsumingThread(testRunTime, barrier); // Run a single pass thread.start(); barrier.await(); barrier.await(); recording.stop(); List<RecordedEvent> beforeEvents = Events.fromRecording(recording); verifyPerThreadInvariant(beforeEvents, cpuConsumerThreadName); // Run a second single pass barrier.await(); barrier.await(); ThreadMXBean bean = (ThreadMXBean) ManagementFactory.getThreadMXBean(); Duration cpuTime = Duration.ofNanos(bean.getThreadCpuTime(thread.getId())); Duration userTime = Duration.ofNanos(bean.getThreadUserTime(thread.getId())); // Check something that should hold even in the presence of unfortunate scheduling Asserts.assertGreaterThanOrEqual(cpuTime.toMillis(), eventPeriodMillis); Asserts.assertGreaterThanOrEqual(userTime.toMillis(), eventPeriodMillis); Duration systemTimeBefore = getAccumulatedTime(beforeEvents, cpuConsumerThreadName, "system"); Duration userTimeBefore = getAccumulatedTime(beforeEvents, cpuConsumerThreadName, "user"); Duration cpuTimeBefore = userTimeBefore.plus(systemTimeBefore); Asserts.assertLessThan(cpuTimeBefore, cpuTime); Asserts.assertLessThan(userTimeBefore, userTime); Asserts.assertGreaterThan(cpuTimeBefore, Duration.ZERO); thread.interrupt(); thread.join(); }