Exemple #1
0
        public void TestStreamMessageCompression()
        {
            using (Connection connection = CreateConnection(TEST_CLIENT_ID) as Connection)
            {
                connection.UseCompression = true;
                connection.Start();

                Assert.IsTrue(connection.UseCompression);

                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IStreamMessage message = session.CreateStreamMessage();

                    IDestination destination = session.CreateTemporaryQueue();

                    IMessageProducer producer = session.CreateProducer(destination);
                    IMessageConsumer consumer = session.CreateConsumer(destination);

                    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(TimeSpan.FromMilliseconds(4000)) as IStreamMessage;

                    Assert.IsNotNull(message);
                    Assert.IsTrue(((ActiveMQMessage)message).Compressed);

                    // use generic API to access entries
                    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");
                }
            }
        }
Exemple #2
0
        public void SendReceiveStreamMessage(MsgDeliveryMode deliveryMode)
        {
            using (IConnection connection = CreateConnection(TEST_CLIENT_ID))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.DeliveryMode   = deliveryMode;
                            producer.RequestTimeout = receiveTimeout;
                            IStreamMessage request = session.CreateStreamMessage();
                            request.WriteBoolean(a);
                            request.WriteByte(b);
                            request.WriteChar(c);
                            request.WriteInt16(d);
                            request.WriteInt32(e);
                            request.WriteInt64(f);
                            request.WriteString(g);
                            request.WriteBoolean(h);
                            request.WriteByte(i);
                            request.WriteInt16(j);
                            request.WriteInt32(k);
                            request.WriteInt64(l);
                            request.WriteSingle(m);
                            request.WriteDouble(n);
                            producer.Send(request);

                            IStreamMessage message = consumer.Receive(receiveTimeout) as IStreamMessage;
                            Assert.IsNotNull(message, "No message returned!");
                            Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");

                            // use generic API to access entries
                            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");
                        }
                }
            }
        }
        //[Test]
        public virtual void TestSendReceiveStreamMessage(
            //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
            MsgDeliveryMode deliveryMode, string testDestRef)
        {
            using (IConnection connection = CreateConnection(GetTestClientId()))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = GetClearDestinationByNodeReference(session, testDestRef);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.DeliveryMode = deliveryMode;
                            IStreamMessage request;

                            try
                            {
                                request = session.CreateStreamMessage();
                            }
                            catch (System.NotSupportedException)
                            {
                                return;
                            }

                            request.WriteBoolean(a);
                            request.WriteByte(b);
                            request.WriteChar(c);
                            request.WriteInt16(d);
                            request.WriteInt32(e);
                            request.WriteInt64(f);
                            request.WriteString(g);
                            request.WriteBoolean(h);
                            request.WriteByte(i);
                            request.WriteInt16(j);
                            request.WriteInt32(k);
                            request.WriteInt64(l);
                            request.WriteSingle(m);
                            request.WriteDouble(n);
                            producer.Send(request);

                            IStreamMessage message = consumer.Receive(receiveTimeout) as IStreamMessage;
                            Assert.IsNotNull(message, "No message returned!");
                            Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");

                            // use generic API to access entries
                            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");
                        }
                }
            }
        }
        public void SendReceiveForeignStreamMessageTest(
            [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
            MsgDeliveryMode deliveryMode)
        {
            using (IConnection connection = CreateConnection())
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            try
                            {
                                producer.DeliveryMode = deliveryMode;
                                StreamMessage request = new StreamMessage();
                                request.Properties[propertyName] = propertyValue;

                                request.WriteBoolean(a);
                                request.WriteByte(b);
                                request.WriteChar(c);
                                request.WriteInt16(d);
                                request.WriteInt32(e);
                                request.WriteInt64(f);
                                request.WriteString(g);
                                request.WriteBoolean(h);
                                request.WriteByte(i);
                                request.WriteInt16(j);
                                request.WriteInt32(k);
                                request.WriteInt64(l);
                                request.WriteSingle(m);
                                request.WriteDouble(n);

                                producer.Send(request);

                                IStreamMessage message = consumer.Receive(receiveTimeout) as IStreamMessage;
                                Assert.IsNotNull(message, "No message returned!");
                                Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
                                Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");

                                // Check the body
                                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");

                                // use generic API to access entries
                                Assert.AreEqual(propertyValue, message.Properties[propertyName], "generic map entry: " + propertyName);

                                // use type safe APIs
                                Assert.AreEqual(propertyValue, message.Properties.GetString(propertyName), "map entry: " + propertyName);
                            }
                            catch (NotSupportedException)
                            {
                            }
                        }
                }
            }
        }