You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2017/12/20 07:46:57 UTC
qpid-broker-j git commit: QPID-6933: [System Tests] Refactor
BytesMessageTest, MapMessageTest, TextMessageTest as JMS 1.1 system tests
Repository: qpid-broker-j
Updated Branches:
refs/heads/master 8662f8cec -> 60db0d9f9
QPID-6933: [System Tests] Refactor BytesMessageTest, MapMessageTest, TextMessageTest as JMS 1.1 system tests
Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/60db0d9f
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/60db0d9f
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/60db0d9f
Branch: refs/heads/master
Commit: 60db0d9f98ffc8bd302733594d19706f2c593187
Parents: 8662f8c
Author: Keith Wall <ke...@gmail.com>
Authored: Wed Dec 20 07:46:18 2017 +0000
Committer: Keith Wall <ke...@gmail.com>
Committed: Wed Dec 20 07:46:18 2017 +0000
----------------------------------------------------------------------
.../jms_1_1/message/BytesMessageTest.java | 109 ++
.../jms_1_1/message/MapMessageTest.java | 198 +++
.../jms_1_1/message/TextMessageTest.java | 108 ++
.../qpid/test/unit/basic/BytesMessageTest.java | 290 ----
.../qpid/test/unit/basic/MapMessageTest.java | 1240 ------------------
.../qpid/test/unit/basic/TextMessageTest.java | 236 ----
.../apache/qpid/test/unit/message/UTF8Test.java | 131 --
.../org/apache/qpid/test/unit/message/UTF8En | 4 -
.../org/apache/qpid/test/unit/message/UTF8Jp | 4 -
9 files changed, 415 insertions(+), 1905 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/60db0d9f/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/BytesMessageTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/BytesMessageTest.java b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/BytesMessageTest.java
new file mode 100644
index 0000000..dc31f9b
--- /dev/null
+++ b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/BytesMessageTest.java
@@ -0,0 +1,109 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.systests.jms_1_1.message;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.charset.StandardCharsets;
+
+import javax.jms.BytesMessage;
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+
+import org.junit.Test;
+
+import org.apache.qpid.systests.JmsTestBase;
+
+public class BytesMessageTest extends JmsTestBase
+{
+ @Test
+ public void sendAndReceiveEmpty() throws Exception
+ {
+ Queue queue = createQueue(getTestName());
+ Connection connection = getConnection();
+ try
+ {
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer producer = session.createProducer(queue);
+
+ BytesMessage message = session.createBytesMessage();
+ producer.send(message);
+
+ MessageConsumer consumer = session.createConsumer(queue);
+ connection.start();
+ Message receivedMessage = consumer.receive(getReceiveTimeout());
+
+ assertTrue("BytesMessage should be received", receivedMessage instanceof BytesMessage);
+ assertEquals("Unexpected body length", 0, ((BytesMessage) receivedMessage).getBodyLength());
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ @Test
+ public void sendAndReceiveBody() throws Exception
+ {
+ final byte[] text = "euler".getBytes(StandardCharsets.US_ASCII);
+ final double value = 2.71828;
+
+ Queue queue = createQueue(getTestName());
+ Connection connection = getConnection();
+ try
+ {
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer producer = session.createProducer(queue);
+
+ BytesMessage message = session.createBytesMessage();
+
+ message.writeBytes(text);
+ message.writeDouble(value);
+
+ producer.send(message);
+
+ MessageConsumer consumer = session.createConsumer(queue);
+ connection.start();
+ Message receivedMessage = consumer.receive(getReceiveTimeout());
+
+ assertTrue("BytesMessage should be received", receivedMessage instanceof BytesMessage);
+
+ byte[] receivedBytes = new byte[text.length];
+ BytesMessage receivedBytesMessage = (BytesMessage) receivedMessage;
+ receivedBytesMessage.readBytes(receivedBytes);
+
+ assertArrayEquals("Unexpected bytes", receivedBytes, text);
+ assertEquals("Unexpected double", value, receivedBytesMessage.readDouble(), 0);
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/60db0d9f/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/MapMessageTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/MapMessageTest.java b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/MapMessageTest.java
new file mode 100644
index 0000000..28420e7
--- /dev/null
+++ b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/MapMessageTest.java
@@ -0,0 +1,198 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.systests.jms_1_1.message;
+
+import static junit.framework.TestCase.assertFalse;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+
+import org.junit.Test;
+
+import org.apache.qpid.systests.JmsTestBase;
+
+public class MapMessageTest extends JmsTestBase
+{
+ private static final byte[] BYTES = { 99, 98, 97, 96, 95 };
+ private static final String MESSAGE_ASCII = "Message";
+ private static final String MESSAGE_NON_ASCII_UTF8 = "YEN\u00A5EURO\u20AC";
+ private static final float SMALL_FLOAT = 100f;
+
+ @Test
+ public void sendAndReceiveEmpty() throws Exception
+ {
+ Queue queue = createQueue(getTestName());
+ Connection connection = getConnection();
+ try
+ {
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer producer = session.createProducer(queue);
+
+ MapMessage message = session.createMapMessage();
+ producer.send(message);
+
+ MessageConsumer consumer = session.createConsumer(queue);
+ connection.start();
+ Message receivedMessage = consumer.receive(getReceiveTimeout());
+
+ assertTrue("BytesMessage should be received", receivedMessage instanceof MapMessage);
+ assertFalse("Unexpected map content", ((MapMessage) receivedMessage).getMapNames().hasMoreElements());
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ @Test
+ public void sendAndReceiveBody() throws Exception
+ {
+ Queue queue = createQueue(getTestName());
+ Connection connection = getConnection();
+ try
+ {
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer producer = session.createProducer(queue);
+
+ MapMessage message = session.createMapMessage();
+
+ setMapValues(message);
+ producer.send(message);
+
+ MessageConsumer consumer = session.createConsumer(queue);
+ connection.start();
+ Message receivedMessage = consumer.receive(getReceiveTimeout());
+
+ assertTrue("MapMessage should be received", receivedMessage instanceof MapMessage);
+ assertTrue("Unexpected map content", ((MapMessage) receivedMessage).getMapNames().hasMoreElements());
+
+ MapMessage receivedMapMessage = (MapMessage) receivedMessage;
+ testMapValues(receivedMapMessage);
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ private void setMapValues(MapMessage message) throws JMSException
+ {
+ message.setBoolean("bool", true);
+ message.setByte("byte",Byte.MAX_VALUE);
+ message.setBytes("bytes", BYTES);
+ message.setChar("char",'c');
+ message.setDouble("double", Double.MAX_VALUE);
+ message.setFloat("float", Float.MAX_VALUE);
+ message.setFloat("smallfloat", SMALL_FLOAT);
+ message.setInt("int", Integer.MAX_VALUE);
+ message.setLong("long", Long.MAX_VALUE);
+ message.setShort("short", Short.MAX_VALUE);
+ message.setString("string-ascii", MESSAGE_ASCII);
+ message.setString("string-utf8", MESSAGE_NON_ASCII_UTF8);
+
+ // Test Setting Object Values
+ message.setObject("object-bool", true);
+ message.setObject("object-byte", Byte.MAX_VALUE);
+ message.setObject("object-bytes", BYTES);
+ message.setObject("object-char", 'c');
+ message.setObject("object-double", Double.MAX_VALUE);
+ message.setObject("object-float", Float.MAX_VALUE);
+ message.setObject("object-int", Integer.MAX_VALUE);
+ message.setObject("object-long", Long.MAX_VALUE);
+ message.setObject("object-short", Short.MAX_VALUE);
+
+ // Set a null String value
+ message.setString("nullString", null);
+ // Highlight protocol problem
+ message.setString("emptyString", "");
+ }
+
+ private void testMapValues(MapMessage m) throws JMSException
+ {
+ // Test get<Primitive>
+
+ // Boolean
+ assertEquals(true, m.getBoolean("bool"));
+ assertEquals(Boolean.TRUE.toString(), m.getString("bool"));
+
+ // Byte
+ assertEquals(Byte.MAX_VALUE, m.getByte("byte"));
+ assertEquals(String.valueOf(Byte.MAX_VALUE), m.getString("byte"));
+
+ // Bytes
+ assertArrayEquals(BYTES, m.getBytes("bytes"));
+
+ // Char
+ assertEquals('c', m.getChar("char"));
+
+ // Double
+ assertEquals(Double.MAX_VALUE, m.getDouble("double"), 0);
+ assertEquals("" + Double.MAX_VALUE, m.getString("double"));
+
+ // Float
+ assertEquals(Float.MAX_VALUE, m.getFloat("float"), 0);
+ assertEquals(SMALL_FLOAT, (float) m.getDouble("smallfloat"), 0);
+ assertEquals("" + Float.MAX_VALUE, m.getString("float"));
+
+ // Integer
+ assertEquals(Integer.MAX_VALUE, m.getInt("int"));
+ assertEquals("" + Integer.MAX_VALUE, m.getString("int"));
+
+ // long
+ assertEquals(Long.MAX_VALUE, m.getLong("long"));
+ assertEquals("" + Long.MAX_VALUE, m.getString("long"));
+
+ // Short
+ assertEquals(Short.MAX_VALUE, m.getShort("short"));
+ assertEquals("" + Short.MAX_VALUE, m.getString("short"));
+ assertEquals((int) Short.MAX_VALUE, m.getInt("short"));
+
+ // String
+ assertEquals(MESSAGE_ASCII, m.getString("string-ascii"));
+ assertEquals(MESSAGE_NON_ASCII_UTF8, m.getString("string-utf8"));
+
+ // Test getObjects
+ assertEquals(true, m.getObject("object-bool"));
+ assertEquals(Byte.MAX_VALUE, m.getObject("object-byte"));
+ assertArrayEquals(BYTES, (byte[]) m.getObject("object-bytes"));
+ assertEquals('c', m.getObject("object-char"));
+ assertEquals(Double.MAX_VALUE, m.getObject("object-double"));
+ assertEquals(Float.MAX_VALUE, m.getObject("object-float"));
+ assertEquals(Integer.MAX_VALUE, m.getObject("object-int"));
+ assertEquals(Long.MAX_VALUE, m.getObject("object-long"));
+ assertEquals(Short.MAX_VALUE, m.getObject("object-short"));
+
+ // Check Special values
+ assertTrue(m.getString("nullString") == null);
+ assertEquals("", m.getString("emptyString"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/60db0d9f/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/TextMessageTest.java
----------------------------------------------------------------------
diff --git a/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/TextMessageTest.java b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/TextMessageTest.java
new file mode 100644
index 0000000..e3849af
--- /dev/null
+++ b/systests/qpid-systests-jms_1.1/src/test/java/org/apache/qpid/systests/jms_1_1/message/TextMessageTest.java
@@ -0,0 +1,108 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.systests.jms_1_1.message;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import javax.jms.Connection;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.junit.Test;
+
+import org.apache.qpid.systests.JmsTestBase;
+
+public class TextMessageTest extends JmsTestBase
+{
+ @Test
+ public void sendAndReceiveEmpty() throws Exception
+ {
+ Queue queue = createQueue(getTestName());
+ Connection connection = getConnection();
+ try
+ {
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer producer = session.createProducer(queue);
+
+ TextMessage message = session.createTextMessage(null);
+ producer.send(message);
+
+ MessageConsumer consumer = session.createConsumer(queue);
+ connection.start();
+ Message receivedMessage = consumer.receive(getReceiveTimeout());
+
+ assertTrue("TextMessage should be received", receivedMessage instanceof TextMessage);
+ assertNull("Unexpected body", ((TextMessage) receivedMessage).getText());
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+
+ @Test
+ public void sendAndReceiveAsciiBody() throws Exception
+ {
+ sendAndReceiveBody("body");
+ }
+
+ @Test
+ public void sendAndReceiveNonAsciiUTF8Body() throws Exception
+ {
+ sendAndReceiveBody("YEN\u00A5EURO\u20AC");
+ }
+
+ private void sendAndReceiveBody(final String text) throws Exception
+ {
+ Queue queue = createQueue(getTestName());
+ Connection connection = getConnection();
+ try
+ {
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer producer = session.createProducer(queue);
+
+ TextMessage message = session.createTextMessage(text);
+ producer.send(message);
+
+ MessageConsumer consumer = session.createConsumer(queue);
+ connection.start();
+ Message receivedMessage = consumer.receive(getReceiveTimeout());
+
+ assertTrue("TextMessage should be received", receivedMessage instanceof TextMessage);
+
+ TextMessage receivedTextMessage = (TextMessage) receivedMessage;
+
+ assertEquals("Unexpected body", receivedTextMessage.getText(), text);
+ }
+ finally
+ {
+ connection.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/60db0d9f/systests/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java
----------------------------------------------------------------------
diff --git a/systests/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java b/systests/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java
deleted file mode 100644
index aa3bd5e..0000000
--- a/systests/src/test/java/org/apache/qpid/test/unit/basic/BytesMessageTest.java
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.test.unit.basic;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.jms.BytesMessage;
-import javax.jms.Connection;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.MessageNotReadableException;
-import javax.jms.MessageNotWriteableException;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-
-import org.junit.Assert;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-import org.apache.qpid.transport.util.Waiter;
-
-public class BytesMessageTest extends QpidBrokerTestCase implements MessageListener
-{
- private static final Logger LOGGER = LoggerFactory.getLogger(BytesMessageTest.class);
-
- private Connection _connection;
- private Destination _destination;
- private Session _session;
- private final List<Message> received = new ArrayList<>();
- private final List<byte[]> messages = new ArrayList<byte[]>();
- private int _count = 100;
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
- _connection = getConnection();
- _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- _destination = createTestQueue(_session);
-
- // Set up a slow consumer.
- _session.createConsumer(_destination).setMessageListener(this);
- _connection.start();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
- public void test() throws Exception
- {
- try
- {
- send(_count);
- waitFor(_count);
- check();
- LOGGER.info("Completed without failure");
- }
- finally
- {
- _connection.close();
- }
- }
-
- void send(int count) throws JMSException
- {
- // create a publisher
- MessageProducer producer = _session.createProducer(_destination);
- for (int i = 0; i < count; i++)
- {
- BytesMessage msg = _session.createBytesMessage();
-
- try
- {
- msg.readFloat();
- Assert.fail("Message should not be readable");
- }
- catch (MessageNotReadableException mnwe)
- {
- // normal execution
- }
-
- byte[] data = ("Message " + i).getBytes();
- msg.writeBytes(data);
- messages.add(data);
- producer.send(msg);
- }
- }
-
- void waitFor(int count) throws InterruptedException
- {
- synchronized (received)
- {
- Waiter w = new Waiter(received, 30000);
- while (received.size() < count && w.hasTime())
- {
- w.await();
- }
- }
- }
-
- void check() throws JMSException
- {
- List<byte[]> actual = new ArrayList<>();
- for (Message message : received)
- {
-
- BytesMessage bytesMessage = (BytesMessage)message;
-
- byte[] data = new byte[(int) bytesMessage.getBodyLength()];
- bytesMessage.readBytes(data);
- actual.add(data);
-
- // Check Body Write Status
- try
- {
- bytesMessage.writeBoolean(true);
- Assert.fail("Message should not be writeable");
- }
- catch (MessageNotWriteableException mnwe)
- {
- // normal execution
- }
-
- bytesMessage.clearBody();
-
- try
- {
- bytesMessage.writeBoolean(true);
- }
- catch (MessageNotWriteableException mnwe)
- {
- Assert.fail("Message should be writeable");
- }
-
- // Check property write status
- try
- {
- bytesMessage.setStringProperty("test", "test");
- Assert.fail("Message should not be writeable");
- }
- catch (MessageNotWriteableException mnwe)
- {
- // normal execution
- }
-
- bytesMessage.clearProperties();
-
- try
- {
- bytesMessage.setStringProperty("test", "test");
- }
- catch (MessageNotWriteableException mnwe)
- {
- Assert.fail("Message should be writeable");
- }
-
- }
-
- assertEqual(messages.iterator(), actual.iterator());
- }
-
- private static void assertEqual(Iterator expected, Iterator actual)
- {
- List<String> errors = new ArrayList<String>();
- while (expected.hasNext() && actual.hasNext())
- {
- try
- {
- assertEquivalent((byte[]) expected.next(), (byte[]) actual.next());
- }
- catch (Exception e)
- {
- errors.add(e.getMessage());
- }
- }
- while (expected.hasNext())
- {
- errors.add("Expected " + expected.next() + " but no more actual values.");
- }
- while (actual.hasNext())
- {
- errors.add("Found " + actual.next() + " but no more expected values.");
- }
-
- if (!errors.isEmpty())
- {
- throw new RuntimeException(errors.toString());
- }
- }
-
- private static void assertEquivalent(byte[] expected, byte[] actual)
- {
- if (expected.length != actual.length)
- {
- throw new RuntimeException("Expected length " + expected.length + " got " + actual.length);
- }
-
- for (int i = 0; i < expected.length; i++)
- {
- if (expected[i] != actual[i])
- {
- throw new RuntimeException("Failed on byte " + i + " of " + expected.length);
- }
- }
- }
-
- @Override
- public void onMessage(Message message)
- {
- synchronized (received)
- {
- received.add(message);
- received.notify();
- }
- }
-
-
-
- public void testModificationAfterSend() throws Exception
- {
- Connection connection = getConnection();
- Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- BytesMessage jmsMsg = producerSession.createBytesMessage();
- Destination destination = createTestQueue(producerSession, "testQ");
- Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- /* Set the constant message contents. */
-
- jmsMsg.setStringProperty("foo", "test");
-
- /* Pre-populate the message body buffer to the target size. */
- byte[] jmsMsgBodyBuffer = new byte[1024];
-
- connection.start();
-
- /* Send messages. */
- MessageProducer producer = producerSession.createProducer(destination);
-
- MessageConsumer consumer = session.createConsumer(destination);
-
- for(int writtenMsgCount = 0; writtenMsgCount < 10; writtenMsgCount++)
- {
- /* Set the per send message contents. */
- jmsMsgBodyBuffer[0] = (byte) writtenMsgCount;
- jmsMsg.writeBytes(jmsMsgBodyBuffer, 0, jmsMsgBodyBuffer.length);
- /** Try to write a message. */
- producer.send(jmsMsg);
- }
-
- producerSession.close();
-
- for(int writtenMsgCount = 0; writtenMsgCount < 10; writtenMsgCount++)
- {
- BytesMessage recvdMsg = (BytesMessage) consumer.receive(1000L);
- assertNotNull("Expected to receive message " + writtenMsgCount + " but did not", recvdMsg);
- assertEquals("Message "+writtenMsgCount+" not of expected size", (long) ((writtenMsgCount + 1)*1024),
- recvdMsg.getBodyLength());
-
- }
-
- connection.close();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/60db0d9f/systests/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java
----------------------------------------------------------------------
diff --git a/systests/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java b/systests/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java
deleted file mode 100644
index b8c636d..0000000
--- a/systests/src/test/java/org/apache/qpid/test/unit/basic/MapMessageTest.java
+++ /dev/null
@@ -1,1240 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.test.unit.basic;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.jms.Connection;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.MapMessage;
-import javax.jms.Message;
-import javax.jms.MessageFormatException;
-import javax.jms.MessageListener;
-import javax.jms.MessageNotWriteableException;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-
-import org.junit.Assert;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
-public class MapMessageTest extends QpidBrokerTestCase implements MessageListener
-{
- private static final Logger LOGGER = LoggerFactory.getLogger(MapMessageTest.class);
-
- private Connection _connection;
- private Destination _destination;
- private Session _session;
- private final List<Message> received = new ArrayList<>();
-
- private static final String MESSAGE = "Message ";
- private int _count = 100;
- private byte[] _bytes = { 99, 98, 97, 96, 95 };
- private static final float _smallfloat = 100.0f;
-
- @Override
- public void setUp() throws Exception
- {
- super.setUp();
- try
- {
- _connection = getConnection();
- _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- _destination = createTestQueue(_session);
-
- // set up a slow consumer
- _session.createConsumer(_destination).setMessageListener(this);
- _connection.start();
- }
- catch (Exception e)
- {
- fail("Unable to initialilse connection: " + e);
- }
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- LOGGER.info("Tearing Down unit.basic.MapMessageTest");
- super.tearDown();
- }
-
- public void test() throws Exception
- {
- int count = _count;
- send(count);
- waitFor(count);
- check();
- _connection.close();
- }
-
- void send(int count) throws JMSException
- {
- // create a publisher
- MessageProducer producer = _session.createProducer(_destination);
- for (int i = 0; i < count; i++)
- {
- MapMessage message = _session.createMapMessage();
-
- setMapValues(message, i);
-
- producer.send(message);
- }
- }
-
- private void setMapValues(MapMessage message, int i) throws JMSException
- {
- message.setBoolean("odd", (i / 2) == 0);
- message.setByte("byte",Byte.MAX_VALUE);
- message.setBytes("bytes", _bytes);
- message.setChar("char",'c');
- message.setDouble("double", Double.MAX_VALUE);
- message.setFloat("float", Float.MAX_VALUE);
- message.setFloat("smallfloat", 100);
- message.setInt("messageNumber", i);
- message.setInt("int", Integer.MAX_VALUE);
- message.setLong("long", Long.MAX_VALUE);
- message.setShort("short", Short.MAX_VALUE);
- message.setString("message", MESSAGE + i);
-
- // Test Setting Object Values
- message.setObject("object-bool", true);
- message.setObject("object-byte", Byte.MAX_VALUE);
- message.setObject("object-bytes", _bytes);
- message.setObject("object-char", 'c');
- message.setObject("object-double", Double.MAX_VALUE);
- message.setObject("object-float", Float.MAX_VALUE);
- message.setObject("object-int", Integer.MAX_VALUE);
- message.setObject("object-long", Long.MAX_VALUE);
- message.setObject("object-short", Short.MAX_VALUE);
-
- // Set a null String value
- message.setString("nullString", null);
- // Highlight protocol problem
- message.setString("emptyString", "");
-
- }
-
- void waitFor(int count) throws Exception
- {
- long waitTime = 30000L;
- long waitUntilTime = System.currentTimeMillis() + 30000L;
-
- synchronized (received)
- {
- while ((received.size() < count) && (waitTime > 0))
- {
- if (received.size() < count)
- {
- received.wait(waitTime);
- }
-
- if (received.size() < count)
- {
- waitTime = waitUntilTime - System.currentTimeMillis();
- }
- }
-
- if (received.size() < count)
- {
- throw new Exception("Timed-out. Waiting for " + count + " only got " + received.size());
- }
- }
- }
-
- void check() throws JMSException
- {
- int count = 0;
- for (Message message : received)
- {
- assertTrue("Message is not a MapMessage", message instanceof MapMessage);
-
- MapMessage mapMessage = (MapMessage) message;
-
- testMapValues(mapMessage, count);
-
- testCorrectExceptions(mapMessage);
-
- testMessageWriteStatus(mapMessage);
-
- testPropertyWriteStatus(mapMessage);
-
- count++;
- }
- }
-
- private void testCorrectExceptions(MapMessage m) throws JMSException
- {
- testBoolean(m);
-
- testByte(m);
-
- testBytes(m);
-
- testChar(m);
-
- testDouble(m);
-
- testFloat(m);
-
- testInt(m);
-
- testLong(m);
-
- testShort(m);
-
- testString(m);
- }
-
- private void testString(MapMessage m) throws JMSException
- {
-
- Assert.assertFalse(m.getBoolean("message"));
-
- try
- {
- m.getByte("message");
- fail("Exception Expected.");
- }
- catch (NumberFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getShort("message");
- fail("Exception Expected.");
- }
- catch (NumberFormatException nfe)
- {
- // normal execution
- }
-
- // Try bad reads
- try
- {
- m.getChar("message");
- fail("Exception Expected.");
- }
- catch (MessageFormatException npe)
- {
- // normal execution
- }
-
- try
- {
- m.getInt("message");
- fail("Exception Expected.");
- }
- catch (NumberFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getLong("message");
- fail("Exception Expected.");
- }
- catch (NumberFormatException nfe)
- {
- // normal execution
- }
-
- // Try bad reads
- try
- {
- m.getFloat("message");
- fail("Exception Expected.");
- }
- catch (NumberFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getDouble("message");
- fail("Exception Expected.");
- }
- catch (NumberFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getBytes("message");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- Assert.assertEquals(MESSAGE + m.getInt("messageNumber"), m.getString("message"));
- }
-
- private void testShort(MapMessage m) throws JMSException
- {
-
- // Try bad reads
- try
- {
- m.getBoolean("short");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getByte("short");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- Assert.assertEquals(Short.MAX_VALUE, m.getShort("short"));
-
- // Try bad reads
- try
- {
- m.getChar("short");
- fail("Exception Expected.");
- }
- catch (MessageFormatException npe)
- {
- // normal execution
- }
-
- Assert.assertEquals(Short.MAX_VALUE, m.getInt("short"));
-
- Assert.assertEquals(Short.MAX_VALUE, m.getLong("short"));
-
- // Try bad reads
- try
- {
- m.getFloat("short");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getDouble("short");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getBytes("short");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- Assert.assertEquals("" + Short.MAX_VALUE, m.getString("short"));
- }
-
- private void testLong(MapMessage m) throws JMSException
- {
-
- // Try bad reads
- try
- {
- m.getBoolean("long");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getByte("long");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getShort("long");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- // Try bad reads
- try
- {
- m.getChar("long");
- fail("Exception Expected.");
- }
- catch (MessageFormatException npe)
- {
- // normal execution
- }
-
- try
- {
- m.getInt("long");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- Assert.assertEquals(Long.MAX_VALUE, m.getLong("long"));
-
- // Try bad reads
- try
- {
- m.getFloat("long");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getDouble("long");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getBytes("long");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- Assert.assertEquals("" + Long.MAX_VALUE, m.getString("long"));
- }
-
- private void testDouble(MapMessage m) throws JMSException
- {
-
- // Try bad reads
- try
- {
- m.getBoolean("double");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getByte("double");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getShort("double");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- // Try bad reads
- try
- {
- m.getChar("double");
- fail("Exception Expected.");
- }
- catch (MessageFormatException npe)
- {
- // normal execution
- }
-
- try
- {
- m.getInt("double");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getLong("double");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- // Try bad reads
- try
- {
- m.getFloat("double");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- Assert.assertEquals(Double.MAX_VALUE, m.getDouble("double"), 0d);
-
- // Try bad reads
- try
- {
- m.getBytes("double");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- Assert.assertEquals("" + Double.MAX_VALUE, m.getString("double"));
- }
-
- private void testFloat(MapMessage m) throws JMSException
- {
-
- // Try bad reads
- try
- {
- m.getBoolean("float");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getByte("float");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getShort("float");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- // Try bad reads
- try
- {
- m.getChar("float");
- fail("Exception Expected.");
- }
- catch (MessageFormatException npe)
- {
- // normal execution
- }
-
- try
- {
- m.getInt("float");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getLong("float");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- Assert.assertEquals(Float.MAX_VALUE, m.getFloat("float"), 0f);
-
- Assert.assertEquals(_smallfloat, m.getDouble("smallfloat"), 0f);
-
- // Try bad reads
- try
- {
- m.getBytes("float");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- Assert.assertEquals("" + Float.MAX_VALUE, m.getString("float"));
- }
-
- private void testInt(MapMessage m) throws JMSException
- {
-
- // Try bad reads
- try
- {
- m.getBoolean("int");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getByte("int");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getShort("int");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- // Try bad reads
- try
- {
- m.getChar("int");
- fail("Exception Expected.");
- }
- catch (MessageFormatException npe)
- {
- // normal execution
- }
-
- Assert.assertEquals(Integer.MAX_VALUE, m.getInt("int"));
-
- Assert.assertEquals(Integer.MAX_VALUE, (int) m.getLong("int"));
-
- // Try bad reads
- try
- {
- m.getFloat("int");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getDouble("int");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getBytes("int");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- Assert.assertEquals("" + Integer.MAX_VALUE, m.getString("int"));
- }
-
- private void testChar(MapMessage m) throws JMSException
- {
-
- // Try bad reads
- try
- {
- m.getBoolean("char");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getByte("char");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getShort("char");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- Assert.assertEquals('c', m.getChar("char"));
-
- try
- {
- m.getInt("char");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getLong("char");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- // Try bad reads
- try
- {
- m.getFloat("char");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getDouble("char");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getBytes("char");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- Assert.assertEquals("" + 'c', m.getString("char"));
- }
-
- private void testBytes(MapMessage m) throws JMSException
- {
- // Try bad reads
- try
- {
- m.getBoolean("bytes");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getByte("bytes");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getShort("bytes");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- // Try bad reads
- try
- {
- m.getChar("bytes");
- fail("Exception Expected.");
- }
- catch (MessageFormatException npe)
- {
- // normal execution
- }
-
- try
- {
- m.getInt("bytes");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- try
- {
- m.getLong("bytes");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- // Try bad reads
- try
- {
- m.getFloat("bytes");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getDouble("bytes");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- assertBytesEqual(_bytes, m.getBytes("bytes"));
-
- try
- {
- m.getString("bytes");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- }
-
- private void testByte(MapMessage m) throws JMSException
- {
- // Try bad reads
- try
- {
- m.getBoolean("byte");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- Assert.assertEquals(Byte.MAX_VALUE, m.getByte("byte"));
-
- Assert.assertEquals((short) Byte.MAX_VALUE, m.getShort("byte"));
-
- // Try bad reads
- try
- {
- m.getChar("byte");
- fail("Exception Expected.");
- }
- catch (MessageFormatException npe)
- {
- // normal execution
- }
-
- // Reading a byte as an int is ok
- Assert.assertEquals((short) Byte.MAX_VALUE, m.getInt("byte"));
-
- Assert.assertEquals((short) Byte.MAX_VALUE, m.getLong("byte"));
-
- // Try bad reads
- try
- {
- m.getFloat("byte");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getDouble("byte");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getBytes("byte");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- Assert.assertEquals("" + Byte.MAX_VALUE, m.getString("byte"));
-
- }
-
- private void testBoolean(MapMessage m) throws JMSException
- {
-
- Assert.assertEquals((m.getInt("messageNumber") / 2) == 0, m.getBoolean("odd"));
-
- // Try bad reads
- try
- {
- m.getByte("odd");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- // Try bad reads
- try
- {
- m.getShort("odd");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getChar("odd");
- fail("Exception Expected.");
- }
- catch (MessageFormatException npe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getInt("odd");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getLong("odd");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getFloat("odd");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getDouble("odd");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
- // Try bad reads
- try
- {
- m.getBytes("odd");
- fail("Exception Expected.");
- }
- catch (MessageFormatException nfe)
- {
- // normal execution
- }
-
- Assert.assertEquals("" + ((m.getInt("messageNumber") / 2) == 0), m.getString("odd"));
- }
-
- private void testPropertyWriteStatus(MapMessage m) throws JMSException
- {
- // Check property write status
- try
- {
- m.setStringProperty("test", "test");
- Assert.fail("Message should not be writeable");
- }
- catch (MessageNotWriteableException mnwe)
- {
- // normal execution
- }
-
- m.clearProperties();
-
- try
- {
- m.setStringProperty("test", "test");
- }
- catch (MessageNotWriteableException mnwe)
- {
- Assert.fail("Message should be writeable");
- }
- }
-
- private void testMessageWriteStatus(MapMessage m) throws JMSException
- {
- try
- {
- m.setInt("testint", 3);
- fail("Message should not be writeable");
- }
- catch (MessageNotWriteableException mnwe)
- {
- // normal execution
- }
-
- m.clearBody();
-
- try
- {
- m.setInt("testint", 3);
- }
- catch (MessageNotWriteableException mnwe)
- {
- Assert.fail("Message should be writeable");
- }
- }
-
- private void testMapValues(MapMessage m, int count) throws JMSException
- {
- // Test get<Primiative>
-
- // Boolean
- assertEqual((count / 2) == 0, m.getBoolean("odd"));
- assertEqual("" + ((count / 2) == 0), m.getString("odd"));
-
- // Byte
- assertEqual(Byte.MAX_VALUE, m.getByte("byte"));
- assertEqual("" + Byte.MAX_VALUE, m.getString("byte"));
-
- // Bytes
- assertBytesEqual(_bytes, m.getBytes("bytes"));
-
- // Char
- assertEqual('c', m.getChar("char"));
-
- // Double
- assertEqual(Double.MAX_VALUE, m.getDouble("double"));
- assertEqual("" + Double.MAX_VALUE, m.getString("double"));
-
- // Float
- assertEqual(Float.MAX_VALUE, m.getFloat("float"));
- assertEqual(_smallfloat, (float) m.getDouble("smallfloat"));
- assertEqual("" + Float.MAX_VALUE, m.getString("float"));
-
- // Integer
- assertEqual(Integer.MAX_VALUE, m.getInt("int"));
- assertEqual("" + Integer.MAX_VALUE, m.getString("int"));
- assertEqual(count, m.getInt("messageNumber"));
-
- // long
- assertEqual(Long.MAX_VALUE, m.getLong("long"));
- assertEqual("" + Long.MAX_VALUE, m.getString("long"));
-
- // Short
- assertEqual(Short.MAX_VALUE, m.getShort("short"));
- assertEqual("" + Short.MAX_VALUE, m.getString("short"));
- assertEqual((int) Short.MAX_VALUE, m.getInt("short"));
-
- // String
- assertEqual(MESSAGE + count, m.getString("message"));
-
- // Test getObjects
- assertEqual(true, m.getObject("object-bool"));
- assertEqual(Byte.MAX_VALUE, m.getObject("object-byte"));
- assertBytesEqual(_bytes, (byte[]) m.getObject("object-bytes"));
- assertEqual('c', m.getObject("object-char"));
- assertEqual(Double.MAX_VALUE, m.getObject("object-double"));
- assertEqual(Float.MAX_VALUE, m.getObject("object-float"));
- assertEqual(Integer.MAX_VALUE, m.getObject("object-int"));
- assertEqual(Long.MAX_VALUE, m.getObject("object-long"));
- assertEqual(Short.MAX_VALUE, m.getObject("object-short"));
-
- // Check Special values
- assertTrue(m.getString("nullString") == null);
- assertEqual("", m.getString("emptyString"));
- }
-
- private void assertBytesEqual(byte[] expected, byte[] actual)
- {
- Assert.assertEquals(expected.length, actual.length);
-
- for (int index = 0; index < expected.length; index++)
- {
- Assert.assertEquals(expected[index], actual[index]);
- }
- }
-
- private static void assertEqual(Iterator expected, Iterator actual)
- {
- List<String> errors = new ArrayList<String>();
- while (expected.hasNext() && actual.hasNext())
- {
- try
- {
- assertEqual(expected.next(), actual.next());
- }
- catch (Exception e)
- {
- errors.add(e.getMessage());
- }
- }
- while (expected.hasNext())
- {
- errors.add("Expected " + expected.next() + " but no more actual values.");
- }
- while (actual.hasNext())
- {
- errors.add("Found " + actual.next() + " but no more expected values.");
- }
-
- if (!errors.isEmpty())
- {
- throw new RuntimeException(errors.toString());
- }
- }
-
- private static void assertEqual(Object expected, Object actual)
- {
- if (!expected.equals(actual))
- {
- throw new RuntimeException("Expected '" + expected + "' found '" + actual + "'");
- }
- }
-
- @Override
- public void onMessage(Message message)
- {
- synchronized (received)
- {
- LOGGER.info("****************** Recevied Messgage:" + message);
- received.add(message);
- received.notify();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/60db0d9f/systests/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java
----------------------------------------------------------------------
diff --git a/systests/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java b/systests/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java
deleted file mode 100644
index 9636b3f..0000000
--- a/systests/src/test/java/org/apache/qpid/test/unit/basic/TextMessageTest.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.test.unit.basic;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import javax.jms.Connection;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.MessageNotWriteableException;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-
-import org.junit.Assert;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
-public class TextMessageTest extends QpidBrokerTestCase implements MessageListener
-{
- private static final Logger LOGGER = LoggerFactory.getLogger(TextMessageTest.class);
-
- private Connection _connection;
- private Destination _destination;
- private Session _session;
- private final List<Message> received = new ArrayList<>();
- private final List<String> messages = new ArrayList<String>();
- private int _count = 100;
- private CountDownLatch _waitForCompletion;
- private MessageConsumer _consumer;
-
- @Override
- protected void setUp() throws Exception
- {
- super.setUp();
- try
- {
- init(getConnection());
- }
- catch (Exception e)
- {
- fail("Unable to initialilse connection: " + e);
- }
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
- private void init(Connection connection) throws Exception
- {
- _connection = connection;
- connection.start();
- final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Destination destination = createTestQueue(session);
- session.close();
- _session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- _destination = destination;
-
- // set up a slow consumer
- try
- {
- _consumer = _session.createConsumer(destination);
- _consumer.setMessageListener(this);
- }
- catch (Throwable e)
- {
- LOGGER.error("Error creating consumer", e);
- }
- }
-
- public void test() throws Exception
- {
- int count = _count;
- _waitForCompletion = new CountDownLatch(_count);
- send(count);
- _waitForCompletion.await(20, TimeUnit.SECONDS);
- check();
- LOGGER.info("Completed without failure");
- _connection.close();
- }
-
- void send(int count) throws JMSException
- {
- // create a publisher
- MessageProducer producer = _session.createProducer(_destination);
- for (int i = 0; i < count; i++)
- {
- String text = "Message " + i;
- messages.add(text);
- Message m = _session.createTextMessage(text);
- //m.setStringProperty("String", "hello");
-
- LOGGER.info("Sending Msg:" + m);
- producer.send(m);
- }
- LOGGER.info("sent " + count + " mesages");
- }
-
-
- void check() throws JMSException
- {
- List<String> actual = new ArrayList<String>();
- for (Message message : received)
- {
- assertTrue("Message is not a text message", message instanceof TextMessage);
- TextMessage textMessage = (TextMessage)message;
- actual.add(textMessage.getText());
-
- // Check body write status
- try
- {
- textMessage.setText("Test text");
- Assert.fail("Message should not be writeable");
- }
- catch (MessageNotWriteableException mnwe)
- {
- // normal execution
- }
-
- textMessage.clearBody();
-
- try
- {
- textMessage.setText("Test text");
- }
- catch (MessageNotWriteableException mnwe)
- {
- Assert.fail("Message should be writeable");
- }
-
- // Check property write status
- try
- {
- textMessage.setStringProperty("test", "test");
- Assert.fail("Message should not be writeable");
- }
- catch (MessageNotWriteableException mnwe)
- {
- // normal execution
- }
-
- textMessage.clearProperties();
-
- try
- {
- textMessage.setStringProperty("test", "test");
- }
- catch (MessageNotWriteableException mnwe)
- {
- Assert.fail("Message should be writeable");
- }
-
- }
-
- assertEqual(messages.iterator(), actual.iterator());
- }
-
- private static void assertEqual(Iterator expected, Iterator actual)
- {
- List<String> errors = new ArrayList<String>();
- while (expected.hasNext() && actual.hasNext())
- {
- try
- {
- assertEqual(expected.next(), actual.next());
- }
- catch (Exception e)
- {
- errors.add(e.getMessage());
- }
- }
- while (expected.hasNext())
- {
- errors.add("Expected " + expected.next() + " but no more actual values.");
- }
- while (actual.hasNext())
- {
- errors.add("Found " + actual.next() + " but no more expected values.");
- }
-
- if (!errors.isEmpty())
- {
- throw new RuntimeException(errors.toString());
- }
- }
-
- private static void assertEqual(Object expected, Object actual)
- {
- if (!expected.equals(actual))
- {
- throw new RuntimeException("Expected '" + expected + "' found '" + actual + "'");
- }
- }
-
- @Override
- public void onMessage(Message message)
- {
- synchronized (received)
- {
- LOGGER.info("===== received one message");
- received.add(message);
- _waitForCompletion.countDown();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/60db0d9f/systests/src/test/java/org/apache/qpid/test/unit/message/UTF8Test.java
----------------------------------------------------------------------
diff --git a/systests/src/test/java/org/apache/qpid/test/unit/message/UTF8Test.java b/systests/src/test/java/org/apache/qpid/test/unit/message/UTF8Test.java
deleted file mode 100644
index af460b3..0000000
--- a/systests/src/test/java/org/apache/qpid/test/unit/message/UTF8Test.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-package org.apache.qpid.test.unit.message;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.jms.Connection;
-import javax.jms.Destination;
-import javax.jms.JMSException;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-
-import org.apache.qpid.test.utils.QpidBrokerTestCase;
-
-
-/**
- * This test makes sure that utf8 characters can be used for
- * specifying exchange, queue name and routing key.
- *
- * those tests are related to qpid-1384
- */
-public class UTF8Test extends QpidBrokerTestCase
-{
- public void testPlainEn() throws Exception
- {
- invoke("UTF8En");
- }
-
-
- public void testUTF8Jp() throws Exception
- {
- invoke("UTF8Jp");
- }
-
- private void invoke(String name) throws Exception
- {
- InputStream stream = getClass().getClassLoader().getResourceAsStream("org/apache/qpid/test/unit/message/" + name);
-
- BufferedReader in = new BufferedReader(new InputStreamReader(stream, "UTF8"));
- runTest(in.readLine(), in.readLine(), in.readLine(), in.readLine());
- in.close();
- }
-
- private void runTest(String exchangeName, String queueName, String routingKey, String data) throws Exception
- {
- Connection con = getConnection();
- con.start();
- Session sess = con.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
- final Destination receivingDestination = getReceivingDestination(exchangeName, routingKey, queueName, sess);
- final Destination sendingDestination = getSendingDestination(exchangeName, routingKey, queueName, sess);
-
- final MessageConsumer msgCons = sess.createConsumer(receivingDestination);
-
- // Send data
- MessageProducer msgProd = sess.createProducer(sendingDestination);
- TextMessage message = sess.createTextMessage(data);
- message.setStringProperty("stringProperty", data);
- msgProd.send(message);
-
- // consume data
- TextMessage m = (TextMessage) msgCons.receive(RECEIVE_TIMEOUT);
- assertNotNull(m);
- assertEquals(data, m.getText());
- assertEquals(data, message.getStringProperty("stringProperty"));
- }
-
- private Destination getReceivingDestination(String exch, String routkey, String qname, final Session session) throws Exception
- {
- createEntitiesUsingAmqpManagement(exch, routkey, qname, session);
- if(isBroker10())
- {
- return session.createQueue(qname);
- }
- else
- {
- return session.createQueue("BURL:direct://" + exch + "//" + qname + "?autodelete='false'&durable='false'"
- + "&routingkey='" + routkey + "'");
- }
- }
-
- private Destination getSendingDestination(String exch, String routkey, String qname, final Session session) throws Exception
- {
- createEntitiesUsingAmqpManagement(exch, routkey, qname, session);
- if(isBroker10())
- {
- return session.createQueue(exch +"/" + routkey);
- }
- else
- {
- return session.createQueue("BURL:direct://" + exch + "//" + qname + "?autodelete='false'&durable='false'"
- + "&routingkey='" + routkey + "'");
- }
- }
-
- private void createEntitiesUsingAmqpManagement(final String exch,
- final String routkey,
- final String qname,
- final Session session) throws JMSException
- {
- createEntityUsingAmqpManagement(exch, session, "org.apache.qpid.DirectExchange");
- createEntityUsingAmqpManagement(qname, session, "org.apache.qpid.Queue");
- final Map<String, Object> arguments = new HashMap<>();
- arguments.put("destination",qname);
- arguments.put("bindingKey", routkey);
- performOperationUsingAmqpManagement(exch, "bind", session, "org.apache.qpid.DirectExchange", arguments);
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/60db0d9f/systests/src/test/resources/org/apache/qpid/test/unit/message/UTF8En
----------------------------------------------------------------------
diff --git a/systests/src/test/resources/org/apache/qpid/test/unit/message/UTF8En b/systests/src/test/resources/org/apache/qpid/test/unit/message/UTF8En
deleted file mode 100644
index c9734b1..0000000
--- a/systests/src/test/resources/org/apache/qpid/test/unit/message/UTF8En
+++ /dev/null
@@ -1,4 +0,0 @@
-exhangeName
-queueName
-routingkey
-data
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/60db0d9f/systests/src/test/resources/org/apache/qpid/test/unit/message/UTF8Jp
----------------------------------------------------------------------
diff --git a/systests/src/test/resources/org/apache/qpid/test/unit/message/UTF8Jp b/systests/src/test/resources/org/apache/qpid/test/unit/message/UTF8Jp
deleted file mode 100644
index ae10752..0000000
--- a/systests/src/test/resources/org/apache/qpid/test/unit/message/UTF8Jp
+++ /dev/null
@@ -1,4 +0,0 @@
-設定がそのように構成されていなければな
-的某些更新没有出现在这个 README 中。你可以访问下面的
-的发行版本包括多张光盘,其中包括安装光盘和源码光盘
-目のインストール CD は、ほとんどの最近のシス
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org