Beispiel #1
0
        public async Task DequeueFromEmptyResponseQueueTimeoutDurationTest()
        {
            var timeout = TimeSpan.FromMilliseconds(1000);
            var options = new Options("irrelevant")
            {
                CommandQueueLength = 1,
                Timeout            = timeout
            };

            var cache   = new PacketCache(options);
            var request = new Packet();
            var watch   = new Stopwatch();

            try
            {
                watch.Start();
                await cache.DequeueAsync(request);
            }
            catch (TimeoutException)
            {
                watch.Stop();
            }
            catch (Exception)
            {
                throw;
            }

            Assert.True(watch.ElapsedMilliseconds > timeout.TotalMilliseconds);
        }
Beispiel #2
0
        /// <summary>
        /// Create a new publisher
        /// </summary>
        /// <remarks>The publisher is a very central class; generally there should be only one per process.
        /// More specifically, there should be a one to one relationship between publisher, packet cache, and
        /// messengers to ensure integrity of the message output.</remarks>
        public Publisher(string sessionName, AgentConfiguration configuration, SessionSummary sessionSummary)
        {
            if (string.IsNullOrEmpty(sessionName))
            {
                throw new ArgumentNullException(nameof(sessionName));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (sessionSummary == null)
            {
                throw new ArgumentNullException(nameof(sessionSummary));
            }

            //store off all our input
            m_SessionName    = sessionName;
            m_SessionSummary = sessionSummary;
            m_Configuration  = configuration;

            //create our queue, cache, and messenger objects
            m_MessageQueue         = new Queue <PacketEnvelope>(50); //a more or less arbitrary initial queue size.
            m_MessageOverflowQueue = new Queue <PacketEnvelope>(50); //a more or less arbitrary initial queue size.
            m_CachedTypes          = new PacketDefinitionList();
            m_PacketCache          = new PacketCache();
            m_Messengers           = new List <IMessenger>();

            m_MessageQueueMaxLength = Math.Max(configuration.Publisher.MaxQueueLength, 1); //make sure there's no way to get it below 1.

            //create the thread we use for dispatching messages
            CreateMessageDispatchThread();
        }
Beispiel #3
0
        public async Task DequeueFromEmptyRequestQueueThrowsExceptionTest()
        {
            var options = new Options("irrelevant")
            {
                CommandQueueLength = 1,
                Timeout            = TimeSpan.FromMilliseconds(100)
            };

            var cache = new PacketCache(options);

            await Assert.ThrowsAsync <QueueIsEmptyException>(async() => await cache.DequeueAsync());
        }
Beispiel #4
0
        public void OverfillRequestQueueTest()
        {
            var options = new Options("irrelevant")
            {
                CommandQueueLength = 1,
                Timeout            = TimeSpan.FromMilliseconds(100)
            };

            var cache          = new PacketCache(options);
            var expectedPacket = new Packet();

            cache.Enqueue(expectedPacket);

            Assert.Throws <QueueIsFullException>(() => cache.Enqueue(expectedPacket));
        }
Beispiel #5
0
        public async Task EnqueueAndDequeueResponseNotMatchingPacketTest()
        {
            var options = new Options("irrelevant")
            {
                CommandQueueLength = 1,
                Timeout            = TimeSpan.FromMilliseconds(100)
            };

            var cache         = new PacketCache(options);
            var wrongRequest  = new Packet();
            var wrongResponse = Packet.CreateResponseFor(wrongRequest);
            var request       = new Packet();

            await cache.EnqueueAsync(wrongRequest, wrongResponse);

            await Assert.ThrowsAsync <TimeoutException>(async() => await cache.DequeueAsync(request));
        }
Beispiel #6
0
        public async Task EnqueueAndDequeueRequestPacketTest()
        {
            var options = new Options("irrelevant")
            {
                CommandQueueLength = 1,
                Timeout            = TimeSpan.FromMilliseconds(100)
            };

            var cache          = new PacketCache(options);
            var expectedPacket = new Packet();

            cache.Enqueue(expectedPacket);
            var actualPacket = await cache.DequeueAsync();

            Assert.NotNull(actualPacket);
            Assert.Equal(expectedPacket.Id, actualPacket.Id);
        }
Beispiel #7
0
        /// <summary>
        /// Create a new publisher
        /// </summary>
        /// <remarks>The publisher is a very central class; generally there should be only one per process.
        /// More specifically, there should be a one to one relationship between publisher, packet cache, and
        /// messengers to ensure integrity of the message output.</remarks>
        internal Publisher(string sessionName, AgentConfiguration configuration, SessionSummary sessionSummary, IPrincipalResolver principalResolver, IApplicationUserProvider userProvider)
        {
            if (string.IsNullOrEmpty(sessionName))
            {
                throw new ArgumentNullException(nameof(sessionName));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (sessionSummary == null)
            {
                throw new ArgumentNullException(nameof(sessionSummary));
            }

            //store off all our input
            m_SessionName    = sessionName;
            m_SessionSummary = sessionSummary;
            m_Configuration  = configuration;

            var serverConfig = Log.Configuration.Server;

            if (serverConfig.AutoSendOnError && serverConfig.AutoSendSessions && serverConfig.Enabled)
            {
                m_AutoSendOnError = true;
            }

            //create our queue, cache, and messenger objects
            m_MessageQueue         = new Queue <PacketEnvelope>(50); //a more or less arbitrary initial queue size.
            m_MessageOverflowQueue = new Queue <PacketEnvelope>(50); //a more or less arbitrary initial queue size.
            m_CachedTypes          = new PacketDefinitionList();
            m_PacketCache          = new PacketCache();
            m_Messengers           = new List <IMessenger>();
            m_Filters = new List <ILoupeFilter>();

            m_MessageQueueMaxLength = Math.Max(configuration.Publisher.MaxQueueLength, 1); //make sure there's no way to get it below 1.

            m_PrincipalResolver       = principalResolver;
            m_ApplicationUserProvider = userProvider;

            //create the thread we use for dispatching messages
            CreateMessageDispatchThread();
        }
Beispiel #8
0
        public async Task EnqueueAndDequeueResponsePacketTest()
        {
            var options = new Options("irrelevant")
            {
                CommandQueueLength = 1,
                Timeout            = TimeSpan.FromMilliseconds(100)
            };

            var cache            = new PacketCache(options);
            var expectedRequest  = new Packet();
            var expectedResponse = Packet.CreateResponseFor(expectedRequest);

            await cache.EnqueueAsync(expectedRequest, expectedResponse);

            var actualResponse = await cache.DequeueAsync(expectedRequest);

            Assert.NotNull(actualResponse);
            Assert.Equal(expectedResponse.Id, actualResponse.Id);
        }