コード例 #1
0
        public void TestTimeout()
        {
            int           port   = 8085;
            MockWebServer server = new MockWebServer(port);

            server.StartServer();
            server.EnqueMockResponse(new MockResponse(200, "OK"));
            AdlsClient adlsClient          = AdlsClient.CreateClientWithoutAccntValidation(MockWebServer.Host + ":" + port, TestToken);
            CancellationTokenSource source = new CancellationTokenSource();
            RequestState            state  = new RequestState()
            {
                AdlsClient  = adlsClient,
                CancelToken = source.Token,
                Timeout     = 5,
                IsRetry     = false
            };
            Thread worker = new Thread(runClientTimeout);

            worker.Start(state);
            Stopwatch watch = Stopwatch.StartNew();

            worker.Join();
            watch.Stop();
            Assert.IsTrue(watch.ElapsedMilliseconds < 7000);
            Assert.IsNotNull(state.AdlsClient);
            Assert.IsInstanceOfType(state.Ex, typeof(Exception));
            Assert.IsTrue(state.Ex.Message.Contains("Operation timed out"));
            server.StopAbruptly();
        }
コード例 #2
0
        public void TestCancellation()
        {
            int           port   = 8084;
            MockWebServer server = new MockWebServer(port);

            server.StartServer();
            server.EnqueMockResponse(new MockResponse(200, "OK"));
            AdlsClient adlsClient          = AdlsClient.CreateClientWithoutAccntValidation(MockWebServer.Host + ":" + port, TestToken);
            CancellationTokenSource source = new CancellationTokenSource();
            RequestState            state  = new RequestState()
            {
                AdlsClient  = adlsClient,
                CancelToken = source.Token
            };
            Thread worker = new Thread(run);

            worker.Start(state);
            Thread.Sleep(10000);
            Stopwatch watch = Stopwatch.StartNew();

            source.Cancel();
            worker.Join();
            watch.Stop();
            Assert.IsTrue(watch.ElapsedMilliseconds < 1000);
            Assert.IsNotNull(state.AdlsClient);
            Assert.IsInstanceOfType(state.Ex, typeof(OperationCanceledException));
            server.StopAbruptly();
        }
コード例 #3
0
        public void TestConnectionBroken()
        {
            int           port   = 8086;
            MockWebServer server = new MockWebServer(port);

            server.StartServer();
            server.EnqueMockResponse(new MockResponse(200, "OK"));
            AdlsClient adlsClient          = AdlsClient.CreateClientWithoutAccntValidation(MockWebServer.Host + ":" + port, TestToken);
            CancellationTokenSource source = new CancellationTokenSource();
            RequestState            state  = new RequestState()
            {
                AdlsClient  = adlsClient,
                CancelToken = source.Token,
                IsRetry     = false
            };
            Thread worker = new Thread(run);

            worker.Start(state);
            Thread.Sleep(5000);
            server.StopAbruptly();
            worker.Join();
            Assert.IsNotNull(state.AdlsClient);
            Assert.IsTrue(state.IsConnectionFailure);
        }