Exemplo n.º 1
0
        public void Just_how_fast_are_you()
        {
            var message = new SerializationTestMessage
            {
                DecimalValue  = 123.45m,
                LongValue     = 098123213,
                BoolValue     = true,
                ByteValue     = 127,
                IntValue      = 123,
                DateTimeValue = new DateTime(2008, 9, 8, 7, 6, 5, 4),
                TimeSpanValue = TimeSpan.FromSeconds(30),
                GuidValue     = Guid.NewGuid(),
                StringValue   = "Chris's Sample Code",
                DoubleValue   = 1823.172
            };

            var            sendContext    = new MessageSendContext <SerializationTestMessage>(message);
            ReceiveContext receiveContext = null;

            //warm it up
            for (var i = 0; i < 10; i++)
            {
                byte[] data = Serialize(sendContext);

                var transportMessage = new InMemoryTransportMessage(Guid.NewGuid(), data, Serializer.ContentType.MediaType,
                                                                    TypeMetadataCache <SerializationTestMessage> .ShortName);
                receiveContext = new InMemoryReceiveContext(transportMessage, TestConsumeContext.GetContext());

                Deserialize <SerializationTestMessage>(receiveContext);
            }

            var timer = Stopwatch.StartNew();

            const int iterations = 50000;

            for (var i = 0; i < iterations; i++)
            {
                Serialize(sendContext);
            }

            timer.Stop();

            var perSecond = iterations * 1000 / timer.ElapsedMilliseconds;

            Console.WriteLine("Serialize: {0}ms, Rate: {1} m/s", timer.ElapsedMilliseconds, perSecond);


            timer = Stopwatch.StartNew();

            for (var i = 0; i < 50000; i++)
            {
                Deserialize <SerializationTestMessage>(receiveContext);
            }

            timer.Stop();

            perSecond = iterations * 1000 / timer.ElapsedMilliseconds;

            Console.WriteLine("Deserialize: {0}ms, Rate: {1} m/s", timer.ElapsedMilliseconds, perSecond);
        }
Exemplo n.º 2
0
        protected T Return <T>(byte[] serializedMessageData)
            where T : class
        {
            var message        = new InMemoryTransportMessage(Guid.NewGuid(), serializedMessageData, Serializer.ContentType.MediaType, TypeMetadataCache <T> .ShortName);
            var receiveContext = new InMemoryReceiveContext(message, TestConsumeContext.GetContext());

            var consumeContext = Deserializer.Deserialize(receiveContext);

            consumeContext.TryGetMessage(out ConsumeContext <T> messageContext);

            messageContext.ShouldNotBe(null);

            messageContext.SourceAddress.ShouldBe(_sourceAddress);
            messageContext.DestinationAddress.ShouldBe(_destinationAddress);
            messageContext.FaultAddress.ShouldBe(_faultAddress);
            messageContext.ResponseAddress.ShouldBe(_responseAddress);
            messageContext.RequestId.HasValue.ShouldBe(true);
            messageContext.RequestId.Value.ShouldBe(_requestId);

            return(messageContext.Message);
        }
Exemplo n.º 3
0
        protected T Return <T>(byte[] serializedMessageData)
            where T : class
        {
            var message        = new InMemoryTransportMessage(Guid.NewGuid(), serializedMessageData, Serializer.ContentType.MediaType, TypeMetadataCache <T> .ShortName);
            var receiveContext = new InMemoryReceiveContext(new Uri("loopback://localhost/input_queue"), message, new ReceiveObservable(), Bus, PublishEndpointProvider);

            ConsumeContext consumeContext = Deserializer.Deserialize(receiveContext);

            ConsumeContext <T> messageContext;

            consumeContext.TryGetMessage(out messageContext);

            messageContext.ShouldNotBe(null);

            messageContext.SourceAddress.ShouldBe(_sourceAddress);
            messageContext.DestinationAddress.ShouldBe(_destinationAddress);
            messageContext.FaultAddress.ShouldBe(_faultAddress);
            messageContext.ResponseAddress.ShouldBe(_responseAddress);
            messageContext.RequestId.HasValue.ShouldBe(true);
            messageContext.RequestId.Value.ShouldBe(_requestId);

            return(messageContext.Message);
        }