コード例 #1
0
        public void TestHeaderMissingInErrorResponse()
        {
            var body = MakeErrorPB("Sample Error Code", "Sample Error Message");

            OTSClientTestHelper.SetHTTPResponseBody(body);
            OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.BadRequest);
            var headers = MakeResponseHeaders("/ListTable", body);

            headers.Remove("x-ots-contentmd5");
            headers.Remove("x-ots-requestid");
            headers.Remove("x-ots-date");
            headers.Remove("x-ots-contenttype");
            headers["Authorization"] = String.Format("OTS {0}:{1}",
                                                     TestAccessKeyID,
                                                     MakeSignature("/ListTable", headers, TestAccessKeySecret));
            OTSClientTestHelper.SetHttpRequestHeaders(headers);

            var request = new ListTableRequest();

            try {
                var response = OTSClient.ListTable(request);
                Assert.Fail();
            } catch (OTSServerException e) {
                AssertOTSServerException(
                    new OTSServerException("/ListTable", HttpStatusCode.BadRequest, "Sample Error Code", "Sample Error Message"),
                    e);
            }
        }
コード例 #2
0
        public void TestRetryBackOffWithOtherExceptions()
        {
            OTSClientTestHelper.TurnOnRetryTimesAndBackOffRecording();

            var e1 = new OTSServerException("/ListTable",
                                            HttpStatusCode.ServiceUnavailable,
                                            "OTSRowOperationConflict",
                                            "Data is being modified by the other request.");
            var e2 = new OTSServerException("/ListTable",
                                            HttpStatusCode.ServiceUnavailable,
                                            "OTSTimeout",
                                            "Operation timeout.");

            testRetryWithException(new OTSServerException[] { e1, e1, e1, e1 });
            assertRetryDelay(0, 100, 200);
            assertRetryDelay(1, 200, 400);
            assertRetryDelay(2, 400, 800);
            OTSClientTestHelper.Reset();
            OTSClientTestHelper.TurnOnRetryTimesAndBackOffRecording();

            testRetryWithException(new OTSServerException[] { e2, e2, e2, e2 });
            assertRetryDelay(0, 100, 200);
            assertRetryDelay(1, 200, 400);
            assertRetryDelay(2, 400, 800);
            OTSClientTestHelper.Reset();
            OTSClientTestHelper.TurnOnRetryTimesAndBackOffRecording();
        }
コード例 #3
0
        public void TestInvalidPBInError()
        {
            OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.BadRequest);
            OTSClientTestHelper.SetHTTPResponseBody(new byte[] {});

            var request = new ListTableRequest();

            try {
                var response = OTSClient.ListTable(request);
                Assert.Fail();
            } catch (OTSServerException e) {
                AssertOTSServerException(new OTSServerException("/ListTable", HttpStatusCode.BadRequest), e);
            }

            var body = new byte[20];

            OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.BadRequest);
            OTSClientTestHelper.SetHTTPResponseBody(body);
            var headers = MakeResponseHeaders("/ListTable", body);

            OTSClientTestHelper.SetHttpRequestHeaders(headers);

            request = new ListTableRequest();

            try {
                var response = OTSClient.ListTable(request);
                Assert.Fail();
            } catch (OTSServerException e) {
                AssertOTSServerException(new OTSServerException("/ListTable", HttpStatusCode.BadRequest), e);
            }
        }
コード例 #4
0
        public void TestAsyncOperations()
        {
            var clientConfig = new OTSClientConfig(
                TestEndPoint,
                TestAccessKeyID,
                TestAccessKeySecret,
                TestInstanceName
                );

            clientConfig.OTSDebugLogHandler = null;
            clientConfig.OTSErrorLogHandler = null;
            OTSClient = new OTSClient(clientConfig);
            OTSClientTestHelper.Reset();

            CreateTestTableWith4PK(new CapacityUnit(0, 0));

            var putRowTaskList = new List <Task <PutRowResponse> >();

            for (int i = 0; i < 1000; i++)
            {
                var request = new PutRowRequest(TestTableName, new Condition(RowExistenceExpectation.IGNORE),
                                                GetPredefinedPrimaryKeyWith4PK(i),
                                                GetPredefinedAttributeWith5PK(i));
                putRowTaskList.Add(OTSClient.PutRowAsync(request));
            }

            foreach (var task in putRowTaskList)
            {
                task.Wait();
                AssertCapacityUnit(new CapacityUnit(0, 1), task.Result.ConsumedCapacityUnit);
            }

            var getRowTaskList = new List <Task <GetRowResponse> >();

            for (int i = 0; i < 1000; i++)
            {
                var request = new GetRowRequest(TestTableName,
                                                GetPredefinedPrimaryKeyWith4PK(i));
                getRowTaskList.Add(OTSClient.GetRowAsync(request));
            }

            for (int i = 0; i < 1000; i++)
            {
                var task = getRowTaskList[i];
                task.Wait();
                var response = task.Result;
                AssertCapacityUnit(new CapacityUnit(1, 0), response.ConsumedCapacityUnit);
                AssertPrimaryKey(GetPredefinedPrimaryKeyWith4PK(i), response.PrimaryKey);
                AssertAttribute(GetPredefinedAttributeWith5PK(i), response.Attribute);
            }
        }
コード例 #5
0
        public void TestNoContentMD5InHeader()
        {
            var body = MakeListTableResponseBody();

            OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.OK);
            var headers = MakeResponseHeaders("/ListTable", body, hasContentMd5: false);

            OTSClientTestHelper.SetHttpRequestHeaders(headers);

            var request = new ListTableRequest();

            try {
                var response = OTSClient.ListTable(request);
                Assert.Fail();
            } catch (OTSClientException e) {
                Assert.AreEqual("x-ots-contentmd5 is missing in response header. HTTP Status: OK.", e.Message);
            }
        }
コード例 #6
0
        public void TestRetryWithExceptionChanged()
        {
            var e1 = new OTSServerException("/ListTable",
                                            HttpStatusCode.ServiceUnavailable,
                                            "OTSRowOperationConflict",
                                            "Data is being modified by the other request.");

            var e3 = new OTSServerException("/ListTable",
                                            HttpStatusCode.ServiceUnavailable,
                                            "OTSQuotaExhausted",
                                            "Too frequent table operations.");

            OTSClientTestHelper.TurnOnRetryTimesAndBackOffRecording();
            testRetry(new OTSServerException[] { e1, e3, e3 });
            assertRetryDelay(0, 100, 200);
            assertRetryDelay(1, 500, 1000);
            assertRetryDelay(2, 1000, 2000);
            OTSClientTestHelper.Reset();
        }
コード例 #7
0
        public void TestDateDifference()
        {
            var body = MakeListTableResponseBody();

            OTSClientTestHelper.SetHTTPResponseBody(body);
            OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.OK);
            var headers = MakeResponseHeaders("/ListTable", body);

            headers["x-ots-date"]    = Util.OtsUtils.FormatDateTimeStr(DateTime.UtcNow.AddMinutes(16));
            headers["Authorization"] = String.Format("OTS {0}:{1}",
                                                     TestAccessKeyID,
                                                     MakeSignature("/ListTable", headers, TestAccessKeySecret));
            OTSClientTestHelper.SetHttpRequestHeaders(headers);

            var request = new ListTableRequest();

            try {
                var response = OTSClient.ListTable(request);
                Assert.Fail();
            } catch (OTSClientException e) {
                Assert.AreEqual("The difference between date in response and system time is more than 15 minutes. HTTP Status: OK.", e.Message);
            }

            body = MakeListTableResponseBody();

            OTSClientTestHelper.SetHTTPResponseBody(body);
            OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.OK);
            headers = MakeResponseHeaders("/ListTable", body);
            headers["x-ots-date"]    = Util.OtsUtils.FormatDateTimeStr(DateTime.UtcNow.AddMinutes(-16));
            headers["Authorization"] = String.Format("OTS {0}:{1}",
                                                     TestAccessKeyID,
                                                     MakeSignature("/ListTable", headers, TestAccessKeySecret));
            OTSClientTestHelper.SetHttpRequestHeaders(headers);

            request = new ListTableRequest();

            try {
                var response = OTSClient.ListTable(request);
                Assert.Fail();
            } catch (OTSClientException e) {
                Assert.AreEqual("The difference between date in response and system time is more than 15 minutes. HTTP Status: OK.", e.Message);
            }
        }
コード例 #8
0
        public void TestContentMD5MismatchInResponse()
        {
            var body = MakeListTableResponseBody();

            OTSClientTestHelper.SetHTTPResponseBody(body);
            OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.OK);
            var headers = MakeResponseHeaders("/ListTable", new byte[20]);

            OTSClientTestHelper.SetHttpRequestHeaders(headers);

            var request = new ListTableRequest();

            try {
                var response = OTSClient.ListTable(request);
                Assert.Fail();
            } catch (OTSClientException e) {
                Assert.AreEqual("MD5 mismatch in response. HTTP Status: OK.", e.Message);
            }
        }
コード例 #9
0
        public void TestInvalidDateInResponse()
        {
            var body = MakeListTableResponseBody();

            OTSClientTestHelper.SetHTTPResponseBody(body);
            OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.OK);
            var headers = MakeResponseHeaders("/ListTable", body);

            headers["x-ots-date"] = "Invalid Date String";
            OTSClientTestHelper.SetHttpRequestHeaders(headers);

            var request = new ListTableRequest();

            try {
                var response = OTSClient.ListTable(request);
                Assert.Fail();
            } catch (OTSClientException e) {
                Assert.AreEqual("Invalid date format in response: Invalid Date String HTTP Status: OK.", e.Message);
            }
        }
コード例 #10
0
        public void TestInvalidAuthorizationFormat()
        {
            var body = MakeListTableResponseBody();

            OTSClientTestHelper.SetHTTPResponseBody(body);
            OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.OK);
            var headers = MakeResponseHeaders("/ListTable", body);

            headers["Authorization"] = String.Format("blahblah");
            OTSClientTestHelper.SetHttpRequestHeaders(headers);

            var request = new ListTableRequest();

            try {
                var response = OTSClient.ListTable(request);
                Assert.Fail();
            } catch (OTSClientException e) {
                Assert.IsTrue(true);
            }
        }
コード例 #11
0
        public void TestNoRequestIDInErrorResponse()
        {
            var body = MakeErrorPB("Sample Error Code", "Sample Error Message");

            OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.BadRequest);
            OTSClientTestHelper.SetHTTPResponseBody(body);
            var headers = MakeResponseHeaders("/ListTable", body, hasRequestID: false);

            OTSClientTestHelper.SetHttpRequestHeaders(headers);

            var request = new ListTableRequest();

            try {
                var response = OTSClient.ListTable(request);
                Assert.Fail();
            } catch (OTSServerException e) {
                AssertOTSServerException(
                    new OTSServerException("/ListTable", HttpStatusCode.BadRequest, "Sample Error Code", "Sample Error Message"),
                    e);
            }
        }
コード例 #12
0
        public void TestInvalidPBInError()
        {
            OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.BadRequest);
            OTSClientTestHelper.SetHTTPResponseBody(new byte[] { });

            var request = new ListTableRequest();

            try
            {
                var response = OTSClient.ListTable(request);
                Assert.Fail();
            }
            catch (OTSServerException e)
            {
                AssertOTSServerException(new OTSServerException("/ListTable", HttpStatusCode.BadRequest), e);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #13
0
        public void TestUnicodeInErrorCode()
        {
            var body = MakeErrorPB("中文错误码", "Sample Error Message");

            OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.BadRequest);
            OTSClientTestHelper.SetHTTPResponseBody(body);
            var headers = MakeResponseHeaders("/ListTable", body);

            OTSClientTestHelper.SetHttpRequestHeaders(headers);

            var request = new ListTableRequest();

            try {
                var response = OTSClient.ListTable(request);
                Assert.Fail();
            } catch (OTSServerException e) {
                AssertOTSServerException(
                    new OTSServerException("/ListTable", HttpStatusCode.BadRequest, "中文错误码", "Sample Error Message"),
                    e);
                Assert.AreEqual("fake-request-id-for-test", e.RequestID);
            }
        }
コード例 #14
0
        public void TestAccessIDInAuthorizationMismatch()
        {
            var body = MakeListTableResponseBody();

            OTSClientTestHelper.SetHTTPResponseBody(body);
            OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.OK);
            var headers = MakeResponseHeaders("/ListTable", body);

            headers["Authorization"] = String.Format("OTS {0}:{1}",
                                                     "AnotherAccessKeyID",
                                                     MakeSignature("/ListTable", headers, TestAccessKeySecret));
            OTSClientTestHelper.SetHttpRequestHeaders(headers);

            var request = new ListTableRequest();

            try {
                var response = OTSClient.ListTable(request);
                Assert.Fail();
            } catch (OTSClientException) {
                Assert.IsTrue(true);
            }
        }
コード例 #15
0
        public void TestAuthorizationHeaderMissingWhenForbidden()
        {
            var body = MakeErrorPB("Sample Error Code", "Sample Error Message");

            OTSClientTestHelper.SetHTTPResponseBody(body);
            OTSClientTestHelper.SetHttpStatusCode(HttpStatusCode.Forbidden);
            var headers = MakeResponseHeaders("/ListTable", body);

            headers.Remove("x-ots-authorization");
            OTSClientTestHelper.SetHttpRequestHeaders(headers);

            var request = new ListTableRequest();

            try {
                var response = OTSClient.ListTable(request);
                Assert.Fail();
            } catch (OTSServerException e) {
                AssertOTSServerException(
                    new OTSServerException("/ListTable", HttpStatusCode.Forbidden, "Sample Error Code", "Sample Error Message"),
                    e);
            }
        }
コード例 #16
0
        public void TestRetryBackOffWithServerThrottlingException()
        {
            OTSClientTestHelper.TurnOnRetryTimesAndBackOffRecording();

            var e1 = new OTSServerException("/ListTable",
                                            HttpStatusCode.ServiceUnavailable,
                                            "OTSServerBusy",
                                            "Server is busy.");
            var e2 = new OTSServerException("/ListTable",
                                            HttpStatusCode.ServiceUnavailable,
                                            "OTSNotEnoughCapacityUnit",
                                            "Remaining capacity unit is not enough.");
            var e3 = new OTSServerException("/ListTable",
                                            HttpStatusCode.ServiceUnavailable,
                                            "OTSQuotaExhausted",
                                            "Too frequent table operations.");

            testRetryWithException(new OTSServerException[] { e1, e1, e1, e1 });
            assertRetryDelay(0, 250, 500);
            assertRetryDelay(1, 500, 1000);
            assertRetryDelay(2, 1000, 2000);
            OTSClientTestHelper.Reset();
            OTSClientTestHelper.TurnOnRetryTimesAndBackOffRecording();

            testRetryWithException(new OTSServerException[] { e2, e2, e2, e2 });
            assertRetryDelay(0, 250, 500);
            assertRetryDelay(1, 500, 1000);
            assertRetryDelay(2, 1000, 2000);
            OTSClientTestHelper.Reset();
            OTSClientTestHelper.TurnOnRetryTimesAndBackOffRecording();

            testRetryWithException(new OTSServerException[] { e3, e3, e3, e3 });
            assertRetryDelay(0, 250, 500);
            assertRetryDelay(1, 500, 1000);
            assertRetryDelay(2, 1000, 2000);
            OTSClientTestHelper.Reset();
        }
コード例 #17
0
        public void TestRetryTwice()
        {
            OTSClientTestHelper.TurnOnRetryTimesAndBackOffRecording();

            var e1 = new OTSServerException("/ListTable",
                                            HttpStatusCode.ServiceUnavailable,
                                            "OTSRowOperationConflict",
                                            "Data is being modified by the other request.");
            var e2 = new OTSServerException("/ListTable",
                                            HttpStatusCode.ServiceUnavailable,
                                            "OTSTimeout",
                                            "Operation timeout.");

            var e3 = new OTSServerException("/ListTable",
                                            HttpStatusCode.ServiceUnavailable,
                                            "OTSQuotaExhausted",
                                            "Too frequent table operations.");

            TestRetry(new OTSServerException[] { e1, e1 });
            AssertRetryDelay(0, 99, 200);
            AssertRetryDelay(1, 199, 400);
            OTSClientTestHelper.Reset();
            OTSClientTestHelper.TurnOnRetryTimesAndBackOffRecording();

            TestRetry(new OTSServerException[] { e2, e2 });
            AssertRetryDelay(0, 99, 200);
            AssertRetryDelay(1, 199, 400);
            OTSClientTestHelper.Reset();
            OTSClientTestHelper.TurnOnRetryTimesAndBackOffRecording();


            TestRetry(new OTSServerException[] { e3, e3, e3 });
            AssertRetryDelay(0, 249, 500);
            AssertRetryDelay(1, 499, 1000);
            OTSClientTestHelper.Reset();
        }
コード例 #18
0
        public void Setup()
        {
            Thread.Sleep(1000);

            TestTableName = "SampleTestName";


            var clientConfig = new OTSClientConfig(
                TestEndPoint,
                TestAccessKeyID,
                TestAccessKeySecret,
                TestInstanceName
                );

            Console.WriteLine("Endpoint: {0}", TestEndPoint);
            Console.WriteLine("TestAccessKeyID: {0}", TestAccessKeyID);
            Console.WriteLine("TestAccessKeySecret: {0}", TestAccessKeySecret);
            Console.WriteLine("TestInstanceName: {0}", TestInstanceName);
            clientConfig.OTSDebugLogHandler = LogToFileHandler.DefaultDebugLogHandler;
            clientConfig.OTSErrorLogHandler = LogToFileHandler.DefaultErrorLogHandler;
            OTSClient = new OTSClient(clientConfig);
            OTSClientTestHelper.Reset();

            foreach (var tableName in OTSClient.ListTable(new ListTableRequest()).TableNames)
            {
                OTSClient.DeleteTable(new DeleteTableRequest(tableName));
            }

            PrimaryKeyWith4Columns = new PrimaryKey();
            PrimaryKeyWith4Columns.Add("PK0", new ColumnValue("ABC"));
            PrimaryKeyWith4Columns.Add("PK1", new ColumnValue("DEF"));
            PrimaryKeyWith4Columns.Add("PK2", new ColumnValue(123));
            PrimaryKeyWith4Columns.Add("PK3", new ColumnValue(456));

            MinPrimaryKeyWith4Columns = new PrimaryKey();
            MinPrimaryKeyWith4Columns.Add("PK0", ColumnValue.INF_MIN);
            MinPrimaryKeyWith4Columns.Add("PK1", new ColumnValue("DEF"));
            MinPrimaryKeyWith4Columns.Add("PK2", new ColumnValue(123));
            MinPrimaryKeyWith4Columns.Add("PK3", new ColumnValue(456));

            MaxPrimaryKeyWith4Columns = new PrimaryKey();
            MaxPrimaryKeyWith4Columns.Add("PK0", ColumnValue.INF_MAX);
            MaxPrimaryKeyWith4Columns.Add("PK1", new ColumnValue("DEF"));
            MaxPrimaryKeyWith4Columns.Add("PK2", new ColumnValue(123));
            MaxPrimaryKeyWith4Columns.Add("PK3", new ColumnValue(456));

            AttributeWith5Columns = new AttributeColumns();
            AttributeWith5Columns.Add("Col0", new ColumnValue("ABC"));
            AttributeWith5Columns.Add("Col1", new ColumnValue(123));
            AttributeWith5Columns.Add("Col2", new ColumnValue(3.14));
            AttributeWith5Columns.Add("Col3", new ColumnValue(true));
            AttributeWith5Columns.Add("Col4", new ColumnValue(new byte[] { 0x20, 0x20 }));

            PrimaryKeyList       = new List <PrimaryKey>();
            AttributeColumnsList = new List <AttributeColumns>();


            for (int i = 0; i < 1000; i++)
            {
                PrimaryKeyList.Add(GetPredefinedPrimaryKeyWith4PK(i));
                AttributeColumnsList.Add(GetPredefinedAttributeWith5PK(i));
            }
        }