@Test public void testReadBytesFromInvalidType() throws Exception { doReadTypeFromInvalidType(RandomUtil.randomBoolean(), new TypeReader() { @Override public Object readType(final ActiveMQStreamMessage message) throws Exception { return message.readByte(); } }); }
@Test public void testReadDoubleFromInvalidType() throws Exception { doReadTypeFromInvalidType(RandomUtil.randomBoolean(), new TypeReader() { @Override public Object readType(final ActiveMQStreamMessage message) throws Exception { return message.readDouble(); } }); }
@Test public void testReadFloatFromInvalidType() throws Exception { doReadTypeFromInvalidType(RandomUtil.randomBoolean(), new TypeReader() { @Override public Object readType(final ActiveMQStreamMessage message) throws Exception { return message.readFloat(); } }); }
@Test public void testWriteObjectWithBoolean() throws Exception { doWriteObjectWithType(RandomUtil.randomBoolean(), new TypeReader() { @Override public Object readType(final ActiveMQStreamMessage message) throws Exception { return message.readBoolean(); } }); }
@Override public void run() throws ActiveMQException { session.createQueue(RandomUtil.randomSimpleString(), RandomUtil.randomSimpleString(), RandomUtil.randomBoolean()); } });
@Test public void testGetStringFromBoolean() throws Exception { boolean value = RandomUtil.randomBoolean(); ActiveMQMapMessage message = new ActiveMQMapMessage(); message.setBoolean(itemName, value); Assert.assertEquals(Boolean.toString(value), message.getString(itemName)); }
@Test public void testReadBooleanFromString() throws Exception { boolean value = RandomUtil.randomBoolean(); ActiveMQStreamMessage message = new ActiveMQStreamMessage(); message.writeString(Boolean.toString(value)); message.reset(); Assert.assertEquals(value, message.readBoolean()); }
@Test public void testReadStringFromBoolean() throws Exception { boolean value = RandomUtil.randomBoolean(); ActiveMQStreamMessage message = new ActiveMQStreamMessage(); message.writeBoolean(value); message.reset(); Assert.assertEquals(Boolean.toString(value), message.readString()); }
@Test public void testSetObjectFromBoolean() throws Exception { boolean value = RandomUtil.randomBoolean(); ActiveMQMapMessage message = new ActiveMQMapMessage(); message.setObject(itemName, value); Assert.assertEquals(value, message.getObject(itemName)); }
@Test public void testReadBooleanFromBoolean() throws Exception { boolean value = RandomUtil.randomBoolean(); ActiveMQStreamMessage message = new ActiveMQStreamMessage(); message.writeBoolean(value); message.reset(); Assert.assertEquals(value, message.readBoolean()); }
@Test public void testReadObjectFromBoolean() throws Exception { boolean value = RandomUtil.randomBoolean(); ActiveMQStreamMessage message = new ActiveMQStreamMessage(); message.writeBoolean(value); message.reset(); Assert.assertEquals(value, message.readObject()); }
@Test public void testClearInternalPropertiesIfAny() { TypedProperties properties = new TypedProperties(PROP_NAME::equals); properties.putBooleanProperty(PROP_NAME, RandomUtil.randomBoolean()); Assert.assertTrue(properties.clearInternalProperties()); Assert.assertFalse(properties.containsProperty(PROP_NAME)); }
@Test public void testCannotClearInternalPropertiesTwiceIfAny() { TypedProperties properties = new TypedProperties(PROP_NAME::equals); properties.putBooleanProperty(PROP_NAME, RandomUtil.randomBoolean()); Assert.assertTrue(properties.clearInternalProperties()); Assert.assertFalse(properties.clearInternalProperties()); }
@Test public void testBINDING_ADDED() throws Exception { SimpleString queue = RandomUtil.randomSimpleString(); SimpleString address = RandomUtil.randomSimpleString(); boolean durable = RandomUtil.randomBoolean(); NotificationTest.flush(notifConsumer); session.createQueue(address, queue, durable); //the first message received will be for the address creation ClientMessage[] notifications = NotificationTest.consumeMessages(2, notifConsumer); Assert.assertEquals(BINDING_ADDED.toString(), notifications[1].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString()); Assert.assertEquals(queue.toString(), notifications[1].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME).toString()); Assert.assertEquals(address.toString(), notifications[1].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString()); session.deleteQueue(queue); }
@Test public void testBINDING_REMOVED() throws Exception { SimpleString queue = RandomUtil.randomSimpleString(); SimpleString address = RandomUtil.randomSimpleString(); boolean durable = RandomUtil.randomBoolean(); session.createQueue(address, queue, durable); NotificationTest.flush(notifConsumer); session.deleteQueue(queue); //There will be 2 notifications, first is for binding removal, second is for address removal ClientMessage[] notifications = NotificationTest.consumeMessages(2, notifConsumer); Assert.assertEquals(BINDING_REMOVED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString()); Assert.assertEquals(queue.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_NAME).toString()); Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString()); }
@Test public void testBINDING_ADDEDWithNonMatchingFilter() throws Exception { SimpleString queue = RandomUtil.randomSimpleString(); SimpleString address = RandomUtil.randomSimpleString(); boolean durable = RandomUtil.randomBoolean(); System.out.println(queue); notifConsumer.close(); notifConsumer = session.createConsumer(notifQueue.toString(), ManagementHelper.HDR_ROUTING_NAME + " <> '" + queue + "' AND " + ManagementHelper.HDR_ADDRESS + " <> '" + address + "'"); NotificationTest.flush(notifConsumer); session.createQueue(address, queue, durable); NotificationTest.consumeMessages(0, notifConsumer); session.deleteQueue(queue); }
@Test public void testScheduleRandom() throws Exception { ScheduledDeliveryHandlerImpl handler = new ScheduledDeliveryHandlerImpl(null, new FakeQueueForScheduleUnitTest(0)); long nextMessage = 0; long NUMBER_OF_SEQUENCES = 100000; for (int i = 0; i < NUMBER_OF_SEQUENCES; i++) { int numberOfMessages = RandomUtil.randomInt() % 10; if (numberOfMessages == 0) numberOfMessages = 1; long nextScheduledTime = RandomUtil.randomPositiveLong(); for (int j = 0; j < numberOfMessages; j++) { boolean tail = RandomUtil.randomBoolean(); addMessage(handler, nextMessage++, nextScheduledTime, tail); } } debugList(true, handler, nextMessage); }
@Test public void testBytesProperty() throws Exception { byte[] val = RandomUtil.randomBytes(); props.putBytesProperty(key, val); Assert.assertArrayEquals(val, props.getBytesProperty(key)); try { props.putBooleanProperty(key, RandomUtil.randomBoolean()); props.getBytesProperty(key); Assert.fail(); } catch (ActiveMQPropertyConversionException e) { } Assert.assertNull(props.getBytesProperty(unknownKey)); }
@Test public void testBooleanProperty() throws Exception { Boolean val = RandomUtil.randomBoolean(); props.putBooleanProperty(key, val); Assert.assertEquals(val, props.getBooleanProperty(key)); Assert.assertEquals(new SimpleString(Boolean.toString(val)), props.getSimpleStringProperty(key)); props.putSimpleStringProperty(key, new SimpleString(Boolean.toString(val))); Assert.assertEquals(val, props.getBooleanProperty(key)); try { props.putByteProperty(key, RandomUtil.randomByte()); props.getBooleanProperty(key); Assert.fail(); } catch (ActiveMQPropertyConversionException e) { } Assert.assertFalse(props.getBooleanProperty(unknownKey)); }
@Override @Before public void setUp() throws Exception { super.setUp(); CoreQueueConfiguration queueConfig = new CoreQueueConfiguration().setAddress(RandomUtil.randomString()).setName(RandomUtil.randomString()).setDurable(false); CoreQueueConfiguration forwardQueueConfig = new CoreQueueConfiguration().setAddress(RandomUtil.randomString()).setName(RandomUtil.randomString()).setDurable(false); divertConfig = new DivertConfiguration().setName(RandomUtil.randomString()).setRoutingName(RandomUtil.randomString()).setAddress(queueConfig.getAddress()).setForwardingAddress(forwardQueueConfig.getAddress()).setExclusive(RandomUtil.randomBoolean()). setTransformerConfiguration(new TransformerConfiguration(AddHeadersTransformer.class.getName())); TransportConfiguration connectorConfig = new TransportConfiguration(INVM_CONNECTOR_FACTORY); Configuration config = createDefaultInVMConfig().setJMXManagementEnabled(true).addQueueConfiguration(queueConfig).addQueueConfiguration(forwardQueueConfig).addDivertConfiguration(divertConfig).addConnectorConfiguration(connectorConfig.getName(), connectorConfig); server = addServer(ActiveMQServers.newActiveMQServer(config, mbeanServer, false)); server.start(); }