Example #1
0
        public void TestRetry()
        {
            int           port       = 8080;
            AdlsClient    adlsClient = AdlsClient.CreateClientWithoutAccntValidation(MockWebServer.Host + ":" + port, TestToken);
            MockWebServer server     = new MockWebServer(port);

            server.StartServer();
            server.EnqueMockResponse(new MockResponse(502, "Bad Gateway"));
            server.EnqueMockResponse(new MockResponse(503, "Service Unavailable"));
            server.EnqueMockResponse(new MockResponse(504, "Gateway Timeout"));
            server.EnqueMockResponse(new MockResponse(503, "Service Unavailable"));
            server.EnqueMockResponse(new MockResponse(503, "Service Unavailable"));
            RequestOptions    req  = new RequestOptions(new ExponentialRetryPolicy());
            OperationResponse resp = new OperationResponse();

            adlsClient.SetInsecureHttp();
            Stopwatch watch = Stopwatch.StartNew();

            Core.AppendAsync("/Test/dir", null, null, SyncFlag.DATA, 0, null, -1, 0, adlsClient, req, resp).GetAwaiter()
            .GetResult();
            watch.Stop();
            long time = watch.ElapsedMilliseconds;

            Assert.IsTrue(time >= 83500 && time <= 86500);
            Assert.IsTrue(resp.HttpStatus == (HttpStatusCode)503);
            Assert.IsTrue(resp.HttpMessage.Equals("Service Unavailable"));
            Assert.IsTrue(resp.Retries == 4);
            server.StopServer();
        }
Example #2
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();
        }
Example #3
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();
        }
Example #4
0
        public void TestRestry2()
        {
            int           port       = 8082;
            AdlsClient    adlsClient = AdlsClient.CreateClientWithoutAccntValidation(MockWebServer.Host + ":" + port, TestToken);
            MockWebServer server     = new MockWebServer(port);

            server.StartServer();
            server.EnqueMockResponse(new MockResponse(429, "Too Many Requests"));
            server.EnqueMockResponse(new MockResponse(429, "Too Many Requests"));
            RequestOptions    req  = new RequestOptions(new ExponentialRetryPolicy(1, 1000));
            OperationResponse resp = new OperationResponse();

            adlsClient.SetInsecureHttp();
            Core.AppendAsync("/Test/dir", null, null, SyncFlag.DATA, 0, null, -1, 0, adlsClient, req, resp).GetAwaiter()
            .GetResult();
            Assert.IsTrue(resp.HttpStatus == (HttpStatusCode)429);
            Assert.IsTrue(resp.HttpMessage.Equals("Too Many Requests"));
            Assert.IsTrue(resp.Retries == 1);
            server.StopServer();
        }
Example #5
0
        public void TestRestry3()
        {
            int           port       = 8083;
            AdlsClient    adlsClient = AdlsClient.CreateClientWithoutAccntValidation(MockWebServer.Host + ":" + port, TestToken);
            MockWebServer server     = new MockWebServer(port);

            server.StartServer();
            server.EnqueMockResponse(new MockResponse(502, "Bad Gateway"));
            server.EnqueMockResponse(new MockResponse(200, "OK"));

            adlsClient.SetInsecureHttp();
            AdlsOutputStream ostream = null;

            try
            {
                ostream = adlsClient.CreateFile("/Test/dir", IfExists.Overwrite, "");
            }
            catch (IOException)
            {
                Assert.Fail("The request should have passed");
            }
            server.EnqueMockResponse(new MockResponse(502, "Bad Gateway"));
            server.EnqueMockResponse(new MockResponse(503, "Service Unavailable"));
            server.EnqueMockResponse(new MockResponse(504, "Gateway Timeout"));
            server.EnqueMockResponse(new MockResponse(503, "Service Unavailable"));
            server.EnqueMockResponse(new MockResponse(503, "Service Unavailable"));
            try
            {
                byte[] buff = Encoding.UTF8.GetBytes(SdkUnitTest.RandomString(5 * 1024 * 1024));
                ostream.Write(buff, 0, buff.Length);
                Assert.Fail("The request should not have passed");
            }
            catch (IOException)
            {
            }
            server.EnqueMockResponse(new MockResponse(200, "OK"));
            try
            {
                ostream.Dispose();
            }
            catch (IOException) { Assert.Fail("This request should have passed"); }
            server.StopServer();
        }
Example #6
0
        public void testListStatusWithMultipleArrayInResponse()
        {
            int           port       = 8088;
            AdlsClient    adlsClient = AdlsClient.CreateClientWithoutAccntValidation(MockWebServer.Host + ":" + port, TestToken);
            MockWebServer server     = new MockWebServer(port);

            server.StartServer();
            string liststatusOutput = "{\"FileStatuses\":{\"FileStatus\":[{\"length\":0,\"pathSuffix\":\"Test01\",\"type\":\"DIRECTORY\",\"blockSize\":0,\"accessTime\":1528320290048,\"modificationTime\":1528320362596,\"replication\":0,\"permission\":\"770\",\"owner\":\"owner1\",\"group\":\"ownergroup1\",\"aclBit\":true},{\"length\":0,\"pathSuffix\":\"Test02\",\"type\":\"DIRECTORY\",\"blockSize\":0,\"accessTime\":1531515372559,\"modificationTime\":1531523888360,\"replication\":0,\"permission\":\"770\",\"owner\":\"owner2\",\"group\":\"ownergroup2\",\"aclBit\":true,\"attributes\":[\"Link\"]}]}}";

            server.EnqueMockResponse(new MockResponse(200, "Success", liststatusOutput));

            adlsClient.SetInsecureHttp();
            HashSet <string> hset = new HashSet <string>();

            foreach (var entry in adlsClient.EnumerateDirectory("/ShareTest"))
            {
                hset.Add(entry.FullName);
            }
            Assert.IsTrue(hset.Count == 2);
            Assert.IsTrue(hset.Contains("/ShareTest/Test01"));
            Assert.IsTrue(hset.Contains("/ShareTest/Test02"));
            server.StopServer();
        }
Example #7
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);
        }