Ejemplo n.º 1
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();
        }
        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);
            }
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
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();
        }
        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();
        }
        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));
            }
        }