コード例 #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();
        }
コード例 #2
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();
        }
コード例 #3
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();
        }
コード例 #4
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();
        }