Ejemplo n.º 1
0
        public async Task StreamChannelTest()
        {
            var mock             = new SimulatedSFRP();
            var wrpStreamChannel = new WrpStreamChannel(
                new System.Uri("http://dummyUri"),
                Guid.NewGuid().ToString(),
                new DummyConfigStore(),
                string.Empty);

            wrpStreamChannel.MockTestHandler = mock;
            mock.MoveNext(new StreamRequest()
            {
                PingRequest = true
            });

            var token = new CancellationTokenSource(5 * 1000).Token;
            await wrpStreamChannel.StartStreamChannelNoThrowAsync <TaskCanceledException>(token);

            var status = mock.VerifyResponse(1, null);

            if (!status)
            {
                Assert.IsTrue(status);
            }

            var request2 = new StreamRequest()
            {
                ClusterQueryUri = "http://ClusterQueryUri",
                Content         = "TestContent",
                Headers         = new Dictionary <string, string>()
                {
                    { "a", "b" }
                },
                Method               = "POST",
                RequestId            = Guid.NewGuid().ToString(),
                RequestReceivedStamp = DateTime.Now,
                CharSet              = "utf-8",
                MediaType            = "text/plain"
            };

            mock.MoveNext(request2);

            token = new CancellationTokenSource(5 * 1000).Token;
            await wrpStreamChannel.StartStreamChannelNoThrowAsync <TaskCanceledException>(token);

            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));

            status = mock.VerifyResponse(3, request2);

            if (!status)
            {
                Assert.IsTrue(status);
            }
        }
Ejemplo n.º 2
0
 static public async Task StartStreamChannelNoThrowAsync <T>(this WrpStreamChannel wrpStreamChannel, CancellationToken token)
 {
     try
     {
         await wrpStreamChannel.StartStreamChannel(token).ConfigureAwait(false);
     }
     catch (Exception e)
     {
         if (e is T)
         {
             return;
         }
         else
         {
             throw;
         }
     }
 }