protected void AssertMessageIsReadOnly(IMessage message) { IBytesMessage theMessage = message as IBytesMessage; Assert.IsNotNull(theMessage); try { theMessage.WriteBoolean(true); theMessage.WriteByte((byte)1); theMessage.WriteBytes(new byte[1]); theMessage.WriteBytes(new byte[3], 0, 2); theMessage.WriteChar('a'); theMessage.WriteDouble(1.5); theMessage.WriteSingle((float)1.5); theMessage.WriteInt32(1); theMessage.WriteInt64(1); theMessage.WriteObject("stringobj"); theMessage.WriteInt16((short)1); theMessage.WriteString("utfstring"); Assert.Fail("Message should not have been Writable"); } catch (MessageNotWriteableException) { } }
public void TestBytesMessageCompression() { using (Connection connection = CreateConnection(TEST_CLIENT_ID) as Connection) { connection.UseCompression = true; connection.Start(); using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) { IDestination destination = session.CreateTemporaryQueue(); using (IMessageConsumer consumer = session.CreateConsumer(destination)) using (IMessageProducer producer = session.CreateProducer(destination)) { IBytesMessage message = session.CreateBytesMessage(); message.WriteBoolean(a); message.WriteByte(b); message.WriteChar(c); message.WriteInt16(d); message.WriteInt32(e); message.WriteInt64(f); message.WriteString(g); message.WriteBoolean(h); message.WriteByte(i); message.WriteInt16(j); message.WriteInt32(k); message.WriteInt64(l); message.WriteSingle(m); message.WriteDouble(n); producer.Send(message); message = consumer.Receive(receiveTimeout) as IBytesMessage; Assert.IsNotNull(message); Assert.IsTrue(((ActiveMQMessage)message).Compressed); Assert.AreEqual(a, message.ReadBoolean(), "Stream Boolean Value: a"); Assert.AreEqual(b, message.ReadByte(), "Stream Byte Value: b"); Assert.AreEqual(c, message.ReadChar(), "Stream Char Value: c"); Assert.AreEqual(d, message.ReadInt16(), "Stream Int16 Value: d"); Assert.AreEqual(e, message.ReadInt32(), "Stream Int32 Value: e"); Assert.AreEqual(f, message.ReadInt64(), "Stream Int64 Value: f"); Assert.AreEqual(g, message.ReadString(), "Stream String Value: g"); Assert.AreEqual(h, message.ReadBoolean(), "Stream Boolean Value: h"); Assert.AreEqual(i, message.ReadByte(), "Stream Byte Value: i"); Assert.AreEqual(j, message.ReadInt16(), "Stream Int16 Value: j"); Assert.AreEqual(k, message.ReadInt32(), "Stream Int32 Value: k"); Assert.AreEqual(l, message.ReadInt64(), "Stream Int64 Value: l"); Assert.AreEqual(m, message.ReadSingle(), "Stream Single Value: m"); Assert.AreEqual(n, message.ReadDouble(), "Stream Double Value: n"); } } } }
protected void AssertMessageIsReadOnly(IMessage message) { Type writeableExceptionType = typeof(MessageNotWriteableException); IBytesMessage theMessage = message as IBytesMessage; Assert.IsNotNull(theMessage); Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteBoolean(true); }); Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteByte((byte)1); }); Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteBytes(new byte[1]); }); Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteBytes(new byte[3], 0, 2); }); Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteChar('a'); }); Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteDouble(1.5); }); Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteSingle((float)1.5); }); Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteInt32(1); }); Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteInt64(1); }); Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteObject("stringobj"); }); Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteInt16((short)1); }); Assert.Throws(writeableExceptionType, delegate() { theMessage.WriteString("utfstring"); }); }
public void SendReceiveBytesMessageContent( [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)] MsgDeliveryMode deliveryMode) { using (IConnection connection = CreateConnection(GetTestClientId())) { connection.Start(); using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) { IDestination destination = CreateDestination(session, DestinationType.Queue); using (IMessageConsumer consumer = session.CreateConsumer(destination)) using (IMessageProducer producer = session.CreateProducer(destination)) { producer.DeliveryMode = deliveryMode; IBytesMessage request = session.CreateBytesMessage(); request.WriteBoolean(true); request.WriteByte((byte)1); request.WriteBytes(new byte[1]); request.WriteBytes(new byte[3], 0, 2); request.WriteChar('a'); request.WriteDouble(1.5); request.WriteSingle((float)1.5); request.WriteInt32(1); request.WriteInt64(1); request.WriteObject("stringobj"); request.WriteInt16((short)1); request.WriteString("utfstring"); producer.Send(request); IMessage message = consumer.Receive(receiveTimeout); AssertMessageIsReadOnly(message); AssertBytesMessageEqual(request, message); Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match"); } } } }
public void SendReceiveBytesMessageContentTest(MsgDeliveryMode deliveryMode) { using (IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + new Random().Next())) { connection.Start(); using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) { IDestination destination = session.CreateTemporaryTopic(); using (IMessageConsumer consumer = session.CreateConsumer(destination)) using (IMessageProducer producer = session.CreateProducer(destination)) { producer.DeliveryMode = deliveryMode; producer.RequestTimeout = receiveTimeout; IBytesMessage request = session.CreateBytesMessage(); request.WriteBoolean(true); request.WriteByte((byte)1); request.WriteBytes(new byte[1]); request.WriteBytes(new byte[3], 0, 2); request.WriteChar('a'); request.WriteDouble(1.5); request.WriteSingle((float)1.5); request.WriteInt32(1); request.WriteInt64(1); request.WriteObject("stringobj"); request.WriteInt16((short)1); request.WriteString("utfstring"); producer.Send(request); IMessage message = consumer.Receive(receiveTimeout); AssertBytesMessageEqual(request, message); AssertMessageIsReadOnly(message); Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match"); } } } }
public void WriteString(string value) { message.WriteString(value); }