public static int randomPositiveInt() { return Math.abs(RandomUtil.randomInt()); }
public static long randomPositiveLong() { return Math.abs(RandomUtil.randomLong()); }
public static byte[] randomBytes() { return RandomUtil.randomString().getBytes(); }
public static byte[] randomBytes(final int length) { byte[] bytes = new byte[length]; for (int i = 0; i < bytes.length; i++) { bytes[i] = RandomUtil.randomByte(); } return bytes; }
public byte[] getSalt() throws NoSuchAlgorithmException { byte[] salt = RandomUtil.randomBytes(this.saltLength); return salt; }
public static int randomMax(final int max) { int value = randomPositiveInt() % max; if (value == 0) { value = max; } return value; }
/** * Returns a pseudo random number between {@code 0} (inclusive) and {@code max} exclusive. * * @param max the upper limit of the random number selection * @see java.util.Random#nextInt(int) */ @Override public int select(final int max) { return RandomUtil.randomInterval(0, max); } }
@Override @Before public void setUp() throws Exception { super.setUp(); TransportConfiguration connectorConfiguration = new TransportConfiguration(NETTY_CONNECTOR_FACTORY); List<String> connectorInfos = new ArrayList<>(); connectorInfos.add(connectorConfiguration.getName()); broadcastGroupConfig = new BroadcastGroupConfiguration().setName(RandomUtil.randomString()).setBroadcastPeriod(RandomUtil.randomPositiveInt()).setConnectorInfos(connectorInfos).setEndpointFactory(new UDPBroadcastEndpointFactory().setGroupAddress(getUDPDiscoveryAddress()).setGroupPort(getUDPDiscoveryPort()).setLocalBindPort(1198)); Configuration config = createDefaultInVMConfig().setJMXManagementEnabled(true).addConnectorConfiguration(connectorConfiguration.getName(), connectorConfiguration).addBroadcastGroupConfiguration(broadcastGroupConfig); server = addServer(ActiveMQServers.newActiveMQServer(config, mbeanServer, false)); server.start(); broadcastGroupControl = createManagementControl(broadcastGroupConfig.getName()); } }
@Test public void testReadData() throws Exception { ActiveMQBuffer dynamic = ActiveMQBuffers.dynamicBuffer(1); String str1 = RandomUtil.randomString(); String str2 = RandomUtil.randomString(); double d1 = RandomUtil.randomDouble(); float f1 = RandomUtil.randomFloat(); dynamic.writeUTF(str1); dynamic.writeString(str2); dynamic.writeDouble(d1); dynamic.writeFloat(f1); LargeMessageControllerImpl readBuffer = splitBuffer(3, dynamic.toByteBuffer().array()); Assert.assertEquals(str1, readBuffer.readUTF()); Assert.assertEquals(str2, readBuffer.readString()); Assert.assertEquals(d1, readBuffer.readDouble(), 0.000001); Assert.assertEquals(f1, readBuffer.readFloat(), 0.000001); }
@Test public void testSetDeadLetterAddress() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); SimpleString queue = RandomUtil.randomSimpleString(); String deadLetterAddress = RandomUtil.randomString(); session.createQueue(address, RoutingType.MULTICAST, queue, null, durable); QueueControl queueControl = createManagementControl(address, queue); AddressSettings addressSettings = new AddressSettings().setDeadLetterAddress(new SimpleString(deadLetterAddress)); server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings); Assert.assertEquals(deadLetterAddress, queueControl.getDeadLetterAddress()); session.deleteQueue(queue); }
@Test public void testWriteObjectWithDouble() throws Exception { doWriteObjectWithType(RandomUtil.randomDouble(), new TypeReader() { @Override public Object readType(final ActiveMQStreamMessage message) throws Exception { return message.readDouble(); } }); }
@Test public void testReadBytesFromInvalidType() throws Exception { doReadTypeFromInvalidType(RandomUtil.randomBoolean(), new TypeReader() { @Override public Object readType(final ActiveMQStreamMessage message) throws Exception { return message.readByte(); } }); }
@Override public void run() throws ActiveMQException { session.createTemporaryQueue(RandomUtil.randomSimpleString(), RandomUtil.randomSimpleString()); } });
@Override public void run() throws ActiveMQException { session.createQueue(RandomUtil.randomSimpleString(), RandomUtil.randomSimpleString(), RandomUtil.randomBoolean()); } });
@Test public void testValidateUTFOnDataInput() throws Exception { for (int i = 0; i < 100; i++) { // Random size between 15k and 20K byte[] bytes = new byte[15000 + RandomUtil.randomPositiveInt() % 5000]; RandomUtil.getRandom().nextBytes(bytes); String str = new String(bytes); // The maximum size the encoded UTF string would reach is str.length * 3 (look at the UTF8 implementation) testValidateUTFOnDataInputStream(str, ActiveMQBuffers.wrappedBuffer(ByteBuffer.allocate(str.length() * 3 + DataConstants.SIZE_SHORT))); testValidateUTFOnDataInputStream(str, ActiveMQBuffers.dynamicBuffer(100)); testValidateUTFOnDataInputStream(str, ActiveMQBuffers.fixedBuffer(100 * 1024)); } }
public static ActiveMQBuffer randomBuffer(final int size, final long... data) { ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(size + 8 * data.length); for (long d : data) { buffer.writeLong(d); } for (int i = 0; i < size; i++) { buffer.writeByte(randomByte()); } return buffer; }
@Test public void testWriteObjectWithBytes() throws Exception { final byte[] value = RandomUtil.randomBytes(); doWriteObjectWithType(value, new TypeReader() { @Override public Object readType(final ActiveMQStreamMessage message) throws Exception { byte[] bytes = new byte[value.length]; message.readBytes(bytes); return bytes; } }); }
public static int randomMax(final int max) { int value = randomPositiveInt() % max; if (value == 0) { value = max; } return value; }
/** * @see java.util.Random#nextInt(int) */ @Override public int select(final int max) { if (pos == -1) { pos = RandomUtil.randomInterval(0, max); } return pos; } }
@Test public void testSetObjectFromDouble() throws Exception { doTestSetObject(RandomUtil.randomDouble()); }