/** * Randomizes a {@code short} value. */ public short nextShort() { return (short) nextInt(); }
/** * Randomizes a {@code byte} value. */ public byte nextByte() { return (byte) nextInt(); }
/** * Randomize a {@code short} value between 0 (inclusive) and the specified value (exclusive). */ public short nextShort(short s) { return (short) nextInt(s); }
/** * Randomize a {@code byte} value between 0 (inclusive) and the specified value (exclusive). */ public byte nextByte(byte b) { return (byte) nextInt(b); }
/** * Randomize an {@code int} value in the given range [min, max]. */ public int nextInt(int min, int max) { if (min > max) { throw new IllegalArgumentException(MIN_MAX_ERROR); } return min + nextInt(max - min + 1); }
/** * Randomize a valid XML Element name. * * @param length * The requested length of the string. */ public String nextXmlString(int length) { byte[] data = new byte[length]; for (int i = 0; i < length; ++i) { data[i] = (byte) nextInt(FIRST_XML_PRINTABLE_CHAR, LAST_XML_PRINTABLE_CHAR); } return new String(data); }
/** * Picks a random element from the given {@code Collection}. */ public <T> T pickRandom(Collection<T> c) { int elementIndex = nextInt(c.size()); Iterator<T> iter = c.iterator(); for (int i = 0; i < elementIndex; ++i) { iter.next(); } return iter.next(); }
/** * @return A random MAC address. */ public String nextMacAddress() { return IntStream.range(0, 6).mapToObj(i -> Integer.toHexString(nextInt(0x10, 0x100))).collect(Collectors.joining(":")); }
/** * Randomize a {@code String} of a length in the given range [min, max]. * * @param printable * Whether or not, the string should contain only printable characters. */ public String nextString(int min, int max, boolean printable) { return nextString(nextInt(min, max), printable); }
/** * Randomize a printable {@code String} of a length in the given range [min, max]. */ public String nextString(int min, int max) { return nextString(nextInt(min, max), true); }
public static int rand(int ceiling) { return RandomUtils.instance().nextInt(ceiling); }
public static Stream<Arguments> data() { // XmlUtils.getXYZValue support recursive searching from a depth of 2 and above, e.g.: // <tag><innerTag>value</innerTag><tag> return IntStream.range(2, 10).mapToObj(i -> Arguments.of(i, String.valueOf(RandomUtils.instance().nextInt()))); }
/** * Randomize a {@code String}. * * @param length * The requested length of the string. * @param printable * Whether or not, the string should contain only printable characters. */ public String nextString(int length, boolean printable) { if (printable) { byte[] data = new byte[length]; for (int i = 0; i < length; ++i) { data[i] = (byte) nextInt(FIRST_PRINTABLE_CHAR, LAST_PRINTABLE_CHAR); } return new String(data); } return new String(nextBytes(length)); }
private VdsNetworkInterface createVlan(String baseIfaceName) { VdsNetworkInterface iface = new Vlan(); iface.setVlanId(RandomUtils.instance().nextInt(100)); iface.setBaseInterface(baseIfaceName); return iface; }
private MemoryStatus getMemoryStatus(int listSize) { MemoryStatus memStatus = new MemoryStatus(); memStatus.setMallInfo(new MallInfo()); memStatus.getMallInfo().setArena(RandomUtils.instance().nextInt()); memStatus.getMallInfo().setUordblks(RandomUtils.instance().nextInt()); ArrayList<Mempool> memPoolsList = new ArrayList<>(); for(int i=0; i < listSize; i++) { Mempool pool = new Mempool(); pool.setAllocCount(RandomUtils.instance().nextInt()); pool.setHotCount(0); pool.setName(RandomUtils.instance().nextString(5)); memPoolsList.add(pool); } memStatus.setMemPools(memPoolsList); return memStatus; }
private List<GlusterClientInfo> getClientList(int listSize) { ArrayList<GlusterClientInfo> list = new ArrayList<>(); for(int i=0; i < listSize; i++) { GlusterClientInfo clientInfo = new GlusterClientInfo(); clientInfo.setBytesRead(RandomUtils.instance().nextLong()); clientInfo.setBytesWritten(RandomUtils.instance().nextLong()); clientInfo.setClientPort(RandomUtils.instance().nextInt()); clientInfo.setHostname(RandomUtils.instance().nextString(7)); list.add(clientInfo); } return list; }
private static VdsStatistics randomVdsStatistics() { RandomUtils random = RandomUtils.instance(); VdsStatistics vdsStatistics = new VdsStatistics(); vdsStatistics.setCpuIdle(random.nextDouble()); vdsStatistics.setCpuLoad(random.nextDouble()); vdsStatistics.setCpuSys(random.nextDouble()); vdsStatistics.setCpuUser(random.nextDouble()); vdsStatistics.setMemAvailable(random.nextLong()); vdsStatistics.setMemFree(random.nextLong()); vdsStatistics.setMemShared(random.nextLong()); vdsStatistics.setUsageCpuPercent(random.nextInt()); vdsStatistics.setUsageMemPercent(random.nextInt()); vdsStatistics.setUsageNetworkPercent(random.nextInt()); vdsStatistics.setCpuOverCommitTimeStamp(new Date(random.nextLong())); return vdsStatistics; }
public static Stream<BusinessEntity<?>> data() { RandomUtils random = RandomUtils.instance(); VdsStatic vdsStatic = new VdsStatic(random.nextString(10), random.nextString(10), random.nextInt(), random.nextInt(), random.nextString(10), Guid.newGuid(), Guid.newGuid(), random.nextString(10), random.nextBoolean(), random.nextEnum(VDSType.class), Guid.newGuid()); return Stream.of( vdsStatic, randomVdsDynamic(), randomVdsStatistics(), new VdsSpmIdMap(Guid.newGuid(), Guid.newGuid(), random.nextInt()), randomStorageDomainStatic(), new StorageDomainDynamic(random.nextInt(), Guid.newGuid(), random.nextInt()), randomStoragePool(), new StoragePoolIsoMap(Guid.newGuid(), Guid.newGuid(), random.nextEnum(StorageDomainStatus.class)), randomRole(), new IdContainerClass<>(new VdsSpmIdMap(Guid.newGuid(), Guid.newGuid(), random.nextInt())), new IdContainerClass<>(Guid.newGuid()) ); }
/** * Construct a new POJO initialized with random values. */ public JsonSerializablePojo() { integer = RandomUtils.instance().nextInt(); setGuid(Guid.newGuid()); setString(RandomUtils.instance().nextString(100, 100000)); setObject(Guid.newGuid()); }
@Test public void testMasshUpdateStatisticsForVds() { List<VdsNetworkInterface> interfaces = dao.getAllInterfacesForVds(VDS_ID); List<VdsNetworkStatistics> statistics = new ArrayList<>(interfaces.size()); for (VdsNetworkInterface iface : interfaces) { VdsNetworkStatistics stats = iface.getStatistics(); stats.setReceiveDropRate(RandomUtils.instance().nextInt() * 1.0); stats.setStatus(RandomUtils.instance().nextEnum(InterfaceStatus.class)); statistics.add(stats); } dao.massUpdateStatisticsForVds(statistics); List<VdsNetworkInterface> after = dao.getAllInterfacesForVds(VDS_ID); for (VdsNetworkInterface iface : after) { boolean found = false; for (VdsNetworkStatistics stats : statistics) { if (iface.getId().equals(stats.getId())) { found = true; assertEquals(stats.getReceiveDropRate(), iface.getStatistics().getReceiveDropRate()); assertEquals(stats.getStatus(), iface.getStatistics().getStatus()); } } assertTrue(found); } }