public static String toSimpleString(byte[] bytes) { SimpleString simpleString = new SimpleString(bytes); String value = simpleString.toString(); for (char c : value.toCharArray()) { if (c < ' ' || c > 127) { return NON_ASCII_STRING; } } return value; }
@Override protected void createClient() { try { if (!session.addressQuery(address).isExists() && autoCreateQueue) { log.warn("{}: queue does not exist - creating queue: address = {}, name = {}", this.getClass().getSimpleName(), address.toString(), address.toString()); session.createQueue(address, address); } producer = session.createProducer(address); } catch (ActiveMQException amqEx) { throw new ActiveMQClientResourceException(String.format("Error creating producer for address %s", address.toString()), amqEx); } }
@Test public void testString() throws Exception { final String str = "hello123ABC__524`16254`6125!%^$!%$!%$!%$!%!$%!$$!\uA324"; SimpleString s = new SimpleString(str); Assert.assertEquals(str, s.toString()); Assert.assertEquals(2 * str.length(), s.getData().length); byte[] data = s.getData(); SimpleString s2 = new SimpleString(data); Assert.assertEquals(str, s2.toString()); }
/** The message is received, then sent to the other side untouched */ @Test public void testPassThrough() { CoreMessage decodedMessage = decodeMessage(); Assert.assertEquals(TEXT, TextMessageUtil.readBodyText(decodedMessage.getReadOnlyBodyBuffer()).toString()); }
@Test public void testDeleteQueueDoesNotExist() throws Exception { SimpleString queueName = new SimpleString("deleteQueue"); DeleteQueue delete = new DeleteQueue(); delete.setName(queueName.toString()); delete.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); checkExecutionFailure(delete, "AMQ229017"); assertFalse(server.queueQuery(queueName).isExists()); }
@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); }
private CoreMessage decodeMessage() { ByteBuf newBuffer = Unpooled.buffer(BYTE_ENCODE.capacity()); newBuffer.writeBytes(BYTE_ENCODE, 0, BYTE_ENCODE.writerIndex()); CoreMessage coreMessage = internalDecode(newBuffer); int encodeSize = coreMessage.getEncodeSize(); Assert.assertEquals(newBuffer.capacity(), encodeSize); Assert.assertEquals(ADDRESS, coreMessage.getAddressSimpleString()); Assert.assertEquals(PROP1_VALUE.toString(), coreMessage.getStringProperty(PROP1_NAME)); ByteBuf destinedBuffer = Unpooled.buffer(BYTE_ENCODE.array().length); coreMessage.sendBuffer(destinedBuffer, 0); byte[] destinedArray = destinedBuffer.array(); byte[] sourceArray = BYTE_ENCODE.array(); CoreMessage newDecoded = internalDecode(Unpooled.wrappedBuffer(destinedArray)); Assert.assertEquals(encodeSize, newDecoded.getEncodeSize()); Assert.assertArrayEquals(sourceArray, destinedArray); return coreMessage; }
protected void doTestK(final ClientSessionFactory sf, final int threadNum) throws Exception { ClientSession s = sf.createSession(false, false, false); s.addMetaData("data", RandomUtil.randomString()); s.createQueue(MultiThreadRandomReattachTestBase.ADDRESS, new SimpleString(threadNum + MultiThreadRandomReattachTestBase.ADDRESS.toString()), (SimpleString) null, false); final int numConsumers = 100; for (int i = 0; i < numConsumers; i++) { ClientConsumer consumer = s.createConsumer(new SimpleString(threadNum + MultiThreadRandomReattachTestBase.ADDRESS.toString())); consumer.close(); } s.deleteQueue(new SimpleString(threadNum + MultiThreadRandomReattachTestBase.ADDRESS.toString())); s.close(); }
@Test public void testUnicodeWithSurrogates() throws Exception { String myString = "abcdef&^*&!^ghijkl\uD900\uDD00"; SimpleString s = new SimpleString(myString); byte[] data = s.getData(); s = new SimpleString(data); Assert.assertEquals(myString, s.toString()); }
@Test public void testReceiveContentType() throws Exception { MessageConsumer consumer = session.createConsumer(queue); conn.connect(defUser, defPass); ClientStompFrame response = send(conn, getQueuePrefix() + getQueueName(), "text/plain", "Hello World"); TextMessage message = (TextMessage) consumer.receive(1000); Assert.assertNotNull(message); Assert.assertEquals("text/plain", message.getStringProperty(org.apache.activemq.artemis.api.core.Message.HDR_CONTENT_TYPE.toString())); }
@Test public void testNoDelayOnDefault() throws Exception { sendMessage(normalQueueName); ConnectionFactory fact = getCF(); Connection connection = fact.createConnection(); try { Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); connection.start(); Destination queue = session.createQueue(normalQueueName.toString()); MessageConsumer consumer1 = session.createConsumer(queue); Assert.assertNotNull(receive(consumer1)); } finally { connection.close(); } }
@Test public void testUpdateCoreQueueDoesNotExist() throws Exception { SimpleString queueName = new SimpleString("updateQueue"); UpdateQueue updateQueue = new UpdateQueue(); updateQueue.setName(queueName.toString()); updateQueue.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error))); checkExecutionFailure(updateQueue, "AMQ229017: Queue " + queueName + " does not exist"); assertFalse(server.queueQuery(queueName).isExists()); }
@Test public void testAddressDoesNotExist() throws Exception { ClientSession sendSession = cf.createSession(false, true, true); server.getAddressSettingsRepository().addMatch(addressA.toString(), new AddressSettings().setAutoCreateAddresses(false)); Set<RoutingType> routingTypes = new HashSet<>(); routingTypes.add(RoutingType.ANYCAST); try { sendSession.createQueue(addressA, RoutingType.MULTICAST, queueA); fail("Creating a queue here should fail since the queue's address doesn't exist and auto-create-addresses = false."); } catch (Exception e) { assertTrue(e instanceof ActiveMQException); ActiveMQException ae = (ActiveMQException) e; assertEquals(ActiveMQExceptionType.ADDRESS_DOES_NOT_EXIST, ae.getType()); } sendSession.close(); } }
public void testChangeBodyString(String newString) { CoreMessage coreMessage = decodeMessage(); coreMessage.putStringProperty("newProperty", "newValue"); ActiveMQBuffer legacyBuffer = coreMessage.getBodyBuffer(); legacyBuffer.resetWriterIndex(); legacyBuffer.clear(); TextMessageUtil.writeBodyText(legacyBuffer, SimpleString.toSimpleString(newString)); ByteBuf newbuffer = Unpooled.buffer(150000); coreMessage.sendBuffer(newbuffer, 0); newbuffer.readerIndex(0); CoreMessage newCoreMessage = new CoreMessage(); newCoreMessage.receiveBuffer(newbuffer); SimpleString newText = TextMessageUtil.readBodyText(newCoreMessage.getReadOnlyBodyBuffer()); Assert.assertEquals(newString, newText.toString()); // coreMessage.putStringProperty() }
@Override public Object getObject(final String name) throws JMSException { Object val = map.getProperty(new SimpleString(name)); if (val instanceof SimpleString) { val = ((SimpleString) val).toString(); } return val; }
protected void doTestO(final ClientSessionFactory sf, final int threadNum) throws Exception { ClientSession sessCreate = sf.createSession(false, true, true); sessCreate.createQueue(MultiThreadRandomReattachTestBase.ADDRESS, new SimpleString(threadNum + MultiThreadRandomReattachTestBase.ADDRESS.toString()), (SimpleString) null, false); ClientSession sess = sf.createSession(false, true, true); sess.start(); ClientConsumer consumer = sess.createConsumer(new SimpleString(threadNum + MultiThreadRandomReattachTestBase.ADDRESS.toString())); for (int i = 0; i < 100; i++) { Assert.assertNull(consumer.receiveImmediate()); } sess.close(); sessCreate.deleteQueue(new SimpleString(threadNum + MultiThreadRandomReattachTestBase.ADDRESS.toString())); sessCreate.close(); }
@Override protected void createClient() { try { if (!session.addressQuery(address).isExists() && autoCreateQueue) { log.warn("{}: queue does not exist - creating queue: address = {}, name = {}", this.getClass().getSimpleName(), address.toString(), address.toString()); session.createQueue(address, address); } producer = session.createProducer(address); } catch (ActiveMQException amqEx) { throw new ActiveMQClientResourceException(String.format("Error creating producer for address %s", address.toString()), amqEx); } }
@Test public void testUnicode() throws Exception { String myString = "abcdef&^*&!^ghijkl\uB5E2\uCAC7\uB2BB\uB7DD\uB7C7\uB3A3\uBCE4\uB5A5"; SimpleString s = new SimpleString(myString); byte[] data = s.getData(); s = new SimpleString(data); Assert.assertEquals(myString, s.toString()); }
@Test public void testAddressAdded() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); NotificationTest.flush(notifConsumer); session.createAddress(address, RoutingType.ANYCAST, true); ClientMessage[] notifications = NotificationTest.consumeMessages(1, notifConsumer); Assert.assertEquals(ADDRESS_ADDED.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_NOTIFICATION_TYPE).toString()); Assert.assertEquals(RoutingType.ANYCAST.getType(), notifications[0].getObjectProperty(ManagementHelper.HDR_ROUTING_TYPE)); Assert.assertEquals(address.toString(), notifications[0].getObjectProperty(ManagementHelper.HDR_ADDRESS).toString()); }