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);
            }
        }
        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);
            }
        }
        private void TestRetryWithException(OTSServerException[] exceptions)
        {
            foreach (var e in exceptions)
            {
                OTSClientTestHelper.RetryExceptions.Add(e);
            }

            var lastException = exceptions[exceptions.Count() - 1];
            var request       = new ListTableRequest();

            try
            {
                OTSClient.ListTable(request);
                Assert.Fail();
            }
            catch (OTSServerException e)
            {
                AssertOTSServerException(lastException, e);
            }

            Assert.AreEqual(3, OTSClientTestHelper.RetryTimes);
            for (int i = 0; i < OTSClientTestHelper.RetryTimes; i++)
            {
                AssertOTSServerException(exceptions[i], OTSClientTestHelper.RetryExceptions[i]);
            }
        }
Exemplo n.º 4
0
        public void ListTableTest()
        {
            var otsClient = OTSClient;
            var request   = new ListTableRequest();
            var response  = otsClient.ListTable(request);

            Assert.GreaterOrEqual(response.TableNames.Count, 0);
        }
Exemplo n.º 5
0
        public void ListTableTest()
        {
            var otsClient = OTSClient;

            var request  = new ListTableRequest();
            var response = otsClient.ListTable(request);

            foreach (var tableName in response.TableNames)
            {
                // Do something
            }
        }
        public void TestDisableDebugLog()
        {
            var clientConfig = new OTSClientConfig(
                TestEndPoint,
                TestAccessKeyID,
                TestAccessKeySecret,
                TestInstanceName);

            clientConfig.OTSDebugLogHandler = null;
            var otsClient = new OTSClient(clientConfig);

            var request = new ListTableRequest();

            otsClient.ListTable(request);
        }
        public void TestAuthorizationHeaderNormalWhenForbidden()
        {
            var otsClient = new OTSClient(TestEndPoint, TestAccessKeyID, "abc", TestInstanceName);
            var request   = new ListTableRequest();

            try {
                otsClient.ListTable(request);
            } catch (OTSServerException exception) {
                AssertOTSServerException(new OTSServerException(
                                             "/ListTable",
                                             HttpStatusCode.Forbidden,
                                             "OTSAuthFailed",
                                             "Signature mismatch."), exception);
            }
        }
        public void CreateTableAndDelete()
        {
            string tableName = "SampleTableName";

            var primaryKeys = new PrimaryKeySchema
            {
                { "PK0", ColumnValueType.String },
                { "PK1", ColumnValueType.Integer }
            };

            var tableOption = new TableOptions
            {
                MaxVersions = 1,
                TimeToLive  = -1
            };

            var tableMeta          = new TableMeta(tableName, primaryKeys);
            var reservedThroughput = new CapacityUnit(0, 0);
            var request1           = new CreateTableRequest(tableMeta, reservedThroughput)
            {
                TableOptions = tableOption
            };

            var response1 = OTSClient.CreateTable(request1);

            var request2  = new ListTableRequest();
            var response2 = OTSClient.ListTable(request2);

            Assert.IsTrue(response2.TableNames.Contains(tableName));

            Thread.Sleep(1000);
            var request3  = new DescribeTableRequest(tableName);
            var response3 = OTSClient.DescribeTable(request3);

            Assert.AreEqual(tableName, response3.TableMeta.TableName);
            Assert.AreEqual(primaryKeys, response3.TableMeta.PrimaryKeySchema);
            Assert.AreEqual(reservedThroughput.Read, response3.ReservedThroughputDetails.CapacityUnit.Read);
            Assert.AreEqual(reservedThroughput.Write, response3.ReservedThroughputDetails.CapacityUnit.Write);


            OTSClient.DeleteTable(new DeleteTableRequest(tableName));

            var request4  = new ListTableRequest();
            var response4 = OTSClient.ListTable(request4);

            Assert.IsFalse(response4.TableNames.Contains(tableName));
        }
        public static void InitializeClient()
        {
            OTSClientConfig config = new OTSClientConfig(Config.Endpoint, Config.AccessKeyId, Config.AccessKeySecret, Config.InstanceName);

            config.AccessKeyID        = Config.AccessKeyId;     // 访问OTS服务所需的云账号的accessid
            config.AccessKeySecret    = Config.AccessKeySecret; // 访问OTS服务所需的云账号的accesskey
            config.InstanceName       = Config.InstanceName;    // OTS的实例名
            config.EndPoint           = Config.Endpoint;        // OTS的服务访问地址
            config.ConnectionLimit    = 300;                    // Client内部的连接池的连接数上限
            config.OTSDebugLogHandler = null;                   // 将DebugLogHandler设置为null,可关闭client内部的debug log的输出,否则默认会输出到标准输出
            config.OTSErrorLogHandler = ErrorLog;               // 也可自定义LogHandler,将日志输出进行定制

            OTSClient client = new OTSClient(config);           // 初始化ots client

            ListTableRequest request = new ListTableRequest();

            client.ListTable(request);
        }
        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);
            }
        }
Exemplo n.º 11
0
        void testRetry(OTSServerException[] exceptions)
        {
            foreach (var e in exceptions)
            {
                OTSClientTestHelper.RetryExceptions.Add(e);
            }

            var lastException = exceptions[exceptions.Count() - 1];
            var request       = new ListTableRequest();

            OTSClient.ListTable(request);

            Assert.AreEqual(exceptions.Count(), OTSClientTestHelper.RetryTimes);
            for (int i = 0; i < OTSClientTestHelper.RetryTimes; i++)
            {
                AssertOTSServerException(exceptions[i], OTSClientTestHelper.RetryExceptions[i]);
            }
        }
        public void TestServerNotAvaliable()
        {
            try{
                var otsClient = new OTSClient("http://blahblah", "abc", "def", "ghi");
                var request   = new ListTableRequest();
                var response  = otsClient.ListTable(request);
                Assert.Fail();
            } catch (HttpRequestException) {
            }

            try{
                var otsClient = new OTSClient("http://10.10.10.10", "abc", "def", "ghi");
                var request   = new ListTableRequest();
                var response  = otsClient.ListTable(request);
                Assert.Fail();
            } catch (HttpRequestException) {
            }
        }
        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);
            }
        }
        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);
            }
        }
        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);
            }
        }
        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);
            }
        }
        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);
            }
        }
        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);
            }
        }
        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);
            }
        }
        public void CreateTableAndDelete()
        {
            var primaryKeys = new PrimaryKeySchema();

            primaryKeys.Add("PK0", ColumnValueType.String);
            primaryKeys.Add("PK1", ColumnValueType.Integer);

            var tableMeta          = new TableMeta("SampleTableName", primaryKeys);
            var reservedThroughput = new CapacityUnit(0, 0);
            var request1           = new CreateTableRequest(tableMeta, reservedThroughput);
            var response1          = OTSClient.CreateTable(request1);

            var request2  = new ListTableRequest();
            var response2 = OTSClient.ListTable(request2);

            Assert.AreEqual(new List <string>()
            {
                "SampleTableName"
            }, response2.TableNames);

            Thread.Sleep(1000);
            var request3  = new DescribeTableRequest("SampleTableName");
            var response3 = OTSClient.DescribeTable(request3);

            Assert.AreEqual("SampleTableName", response3.TableMeta.TableName);
            Assert.AreEqual(primaryKeys, response3.TableMeta.PrimaryKeySchema);
            Assert.AreEqual(reservedThroughput.Read, response3.ReservedThroughputDetails.CapacityUnit.Read);
            Assert.AreEqual(reservedThroughput.Write, response3.ReservedThroughputDetails.CapacityUnit.Write);


            OTSClient.DeleteTable(new DeleteTableRequest("SampleTableName"));

            var request4  = new ListTableRequest();
            var response4 = OTSClient.ListTable(request4);

            Assert.AreEqual(new List <string>()
            {
            }, response4.TableNames);
        }
        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);
            }
        }
        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);
            }
        }
        public void TestAPIWithParameter(string apiName)
        {
            var tableName                  = TestContext.tableName;
            var pkSchema                   = TestContext.pkSchema;
            var reservedThroughput         = TestContext.reservedThroughput;
            var primaryKey                 = TestContext.primaryKey;
            var attribute                  = TestContext.attribute;
            var condition                  = TestContext.condition;
            var startPrimaryKey            = TestContext.startPrimaryKey;
            var endPrimaryKey              = TestContext.endPrimaryKey;
            var putRowConsumed             = TestContext.putRowConsumed;
            var getRowConsumed             = TestContext.getRowConsumed;
            var updateRowConsumed          = TestContext.updateRowConsumed;
            var deleteRowConsumed          = TestContext.deleteRowConsumed;
            var getRangeConsumed           = TestContext.getRangeConsumed;
            var updateOfAttributeForPut    = TestContext.updateOfAttributeForPut;
            var updateOfAttributeForDelete = TestContext.updateOfAttributeForDelete;
            var columnsToGet               = TestContext.columnsToGet;
            var limit     = TestContext.limit;
            var direction = TestContext.direction;

            var tableMeta = new TableMeta(tableName, pkSchema);

            switch (apiName)
            {
            case "CreateTable":
                var request0 = new CreateTableRequest(tableMeta, reservedThroughput);
                OTSClient.CreateTable(request0);
                return;

            case "ListTable":
                var request1  = new ListTableRequest();
                var response1 = OTSClient.ListTable(request1);
                Assert.AreEqual(new List <string>()
                {
                    tableName
                }, response1.TableNames);
                return;

            case "UpdateTable":
                var request2  = new UpdateTableRequest(tableName, reservedThroughput);
                var response2 = OTSClient.UpdateTable(request2);

                if (reservedThroughput.Read.HasValue && reservedThroughput.Write.HasValue)
                {
                    AssertCapacityUnit(
                        reservedThroughput,
                        response2.ReservedThroughputDetails.CapacityUnit);
                }
                Assert.IsTrue(response2.ReservedThroughputDetails.LastDecreaseTime >= 0);
                Assert.IsTrue(response2.ReservedThroughputDetails.LastIncreaseTime >= 0);
                Assert.IsTrue(response2.ReservedThroughputDetails.NumberOfDecreasesToday >= 0);
                return;

            case "DeleteTable":
                var request3 = new DeleteTableRequest(tableName);
                OTSClient.DeleteTable(request3);

                var request31  = new ListTableRequest();
                var response31 = OTSClient.ListTable(request31);
                Assert.AreEqual(new List <string>()
                {
                }, response31.TableNames);
                return;

            case "DescribeTable":
                var request4  = new DescribeTableRequest(tableName);
                var response4 = OTSClient.DescribeTable(request4);
                Assert.AreEqual(tableName, response4.TableMeta.TableName);
                AssertPrimaryKeySchema(pkSchema, response4.TableMeta.PrimaryKeySchema);
                AssertCapacityUnit(reservedThroughput, response4.ReservedThroughputDetails.CapacityUnit);
                Assert.IsTrue(response4.ReservedThroughputDetails.LastDecreaseTime >= 0);
                Assert.IsTrue(response4.ReservedThroughputDetails.LastIncreaseTime >= 0);
                Assert.IsTrue(response4.ReservedThroughputDetails.NumberOfDecreasesToday >= 0);
                return;

            case "PutRow":
                var request5  = new PutRowRequest(tableName, condition, primaryKey, attribute);
                var response5 = OTSClient.PutRow(request5);
                AssertCapacityUnit(putRowConsumed, response5.ConsumedCapacityUnit);
                return;

            case "GetRow":
                var request6  = new GetRowRequest(tableName, primaryKey, columnsToGet);
                var response6 = OTSClient.GetRow(request6);
                AssertPrimaryKey(primaryKey, response6.PrimaryKey, columnsToGet);
                AssertAttribute(attribute, response6.Attribute, columnsToGet);
                AssertCapacityUnit(getRowConsumed, response6.ConsumedCapacityUnit);
                return;

            case "DeleteRow":
                var request7  = new DeleteRowRequest(tableName, condition, primaryKey);
                var response7 = OTSClient.DeleteRow(request7);
                AssertCapacityUnit(deleteRowConsumed, response7.ConsumedCapacityUnit);

                var request71  = new GetRowRequest(tableName, primaryKey);
                var response71 = OTSClient.GetRow(request71);
                AssertPrimaryKey(new PrimaryKey(), response71.PrimaryKey);
                AssertAttribute(new AttributeColumns(), response71.Attribute);
                return;

            case "UpdateRow_Put":
                var request8  = new UpdateRowRequest(tableName, condition, primaryKey, updateOfAttributeForPut);
                var response8 = OTSClient.UpdateRow(request8);
                AssertCapacityUnit(updateRowConsumed, response8.ConsumedCapacityUnit);

                var request81  = new GetRowRequest(tableName, primaryKey);
                var response81 = OTSClient.GetRow(request81);
                AssertPrimaryKey(primaryKey, response81.PrimaryKey);
                AssertAttribute(attribute, response81.Attribute);
                AssertCapacityUnit(getRowConsumed, response81.ConsumedCapacityUnit);

                return;

            case "UpdateRow_Delete":
                var request9  = new UpdateRowRequest(tableName, condition, primaryKey, updateOfAttributeForDelete);
                var response9 = OTSClient.UpdateRow(request9);
                AssertCapacityUnit(deleteRowConsumed, response9.ConsumedCapacityUnit);

                var request91  = new GetRowRequest(tableName, primaryKey);
                var response91 = OTSClient.GetRow(request91);
                // Don't assert primary key
                AssertAttribute(new AttributeColumns(), response91.Attribute);
                return;

            case "BatchGetRow":
                var request11 = new BatchGetRowRequest();
                request11.Add(tableName, new List <PrimaryKey>()
                {
                    primaryKey
                }, columnsToGet);
                var response11 = OTSClient.BatchGetRow(request11);
                Assert.AreEqual(1, response11.RowDataGroupByTable.Count);
                Assert.IsTrue(response11.RowDataGroupByTable.ContainsKey(tableName));
                Assert.AreEqual(1, response11.RowDataGroupByTable[tableName].Count);

                if (!response11.RowDataGroupByTable[tableName][0].IsOK)
                {
                    throw new OTSServerException(apiName, HttpStatusCode.OK,
                                                 response11.RowDataGroupByTable[tableName][0].ErrorCode,
                                                 response11.RowDataGroupByTable[tableName][0].ErrorMessage);
                }
                AssertPrimaryKey(primaryKey, response11.RowDataGroupByTable[tableName][0].PrimaryKey);
                AssertAttribute(attribute, response11.RowDataGroupByTable[tableName][0].Attribute);
                AssertCapacityUnit(getRowConsumed, response11.RowDataGroupByTable[tableName][0].Consumed);
                return;

            case "BatchWriteRow_Put":
                var request12  = new BatchWriteRowRequest();
                var rowChanges = new RowChanges();
                rowChanges.AddPut(condition, primaryKey, attribute);
                request12.Add(tableName, rowChanges);
                var response12 = OTSClient.BatchWriteRow(request12);
                Assert.AreEqual(1, response12.TableRespones.Count);
                Assert.IsTrue(response12.TableRespones.ContainsKey(tableName));
                Assert.AreEqual(1, response12.TableRespones[tableName].PutResponses.Count);
                Assert.AreEqual(0, response12.TableRespones[tableName].UpdateResponses.Count);
                Assert.AreEqual(0, response12.TableRespones[tableName].DeleteResponses.Count);
                if (response12.TableRespones[tableName].PutResponses[0].IsOK)
                {
                    AssertCapacityUnit(putRowConsumed,
                                       response12.TableRespones[tableName].PutResponses[0].Consumed);
                }
                else
                {
                    throw new OTSServerException("/BatchWriteRow", HttpStatusCode.OK,
                                                 response12.TableRespones[tableName].PutResponses[0].ErrorCode,
                                                 response12.TableRespones[tableName].PutResponses[0].ErrorMessage);
                }


                var request121  = new GetRowRequest(tableName, primaryKey);
                var response121 = OTSClient.GetRow(request121);
                AssertPrimaryKey(primaryKey, response121.PrimaryKey);
                AssertAttribute(attribute, response121.Attribute);
                AssertCapacityUnit(getRowConsumed, response121.ConsumedCapacityUnit);
                return;

            case "BatchWriteRow_Update":
                var request13   = new BatchWriteRowRequest();
                var rowChanges2 = new RowChanges();
                rowChanges2.AddUpdate(condition, primaryKey, updateOfAttributeForPut);
                request13.Add(tableName, rowChanges2);
                var response13 = OTSClient.BatchWriteRow(request13);
                Assert.AreEqual(1, response13.TableRespones.Count);
                Assert.IsTrue(response13.TableRespones.ContainsKey(tableName));
                Assert.AreEqual(0, response13.TableRespones[tableName].PutResponses.Count);
                Assert.AreEqual(1, response13.TableRespones[tableName].UpdateResponses.Count);
                Assert.AreEqual(0, response13.TableRespones[tableName].DeleteResponses.Count);
                if (response13.TableRespones[tableName].UpdateResponses[0].IsOK)
                {
                    AssertCapacityUnit(updateRowConsumed,
                                       response13.TableRespones[tableName].UpdateResponses[0].Consumed);
                }
                else
                {
                    throw new OTSServerException("/BatchWriteRow", HttpStatusCode.OK,
                                                 response13.TableRespones[tableName].UpdateResponses[0].ErrorCode,
                                                 response13.TableRespones[tableName].UpdateResponses[0].ErrorMessage);
                }

                var request131  = new GetRowRequest(tableName, primaryKey);
                var response131 = OTSClient.GetRow(request131);
                AssertPrimaryKey(primaryKey, response131.PrimaryKey);
                AssertAttribute(attribute, response131.Attribute);
                AssertCapacityUnit(getRowConsumed, response131.ConsumedCapacityUnit);
                return;

            case "BatchWriteRow_Delete":
                var request14   = new BatchWriteRowRequest();
                var rowChanges3 = new RowChanges();
                rowChanges3.AddDelete(condition, primaryKey);
                request14.Add(tableName, rowChanges3);
                var response14 = OTSClient.BatchWriteRow(request14);
                Assert.AreEqual(1, response14.TableRespones.Count);
                Assert.IsTrue(response14.TableRespones.ContainsKey(tableName));
                Assert.AreEqual(0, response14.TableRespones[tableName].PutResponses.Count);
                Assert.AreEqual(0, response14.TableRespones[tableName].UpdateResponses.Count);
                Assert.AreEqual(1, response14.TableRespones[tableName].DeleteResponses.Count);

                if (response14.TableRespones[tableName].DeleteResponses[0].IsOK)
                {
                    AssertCapacityUnit(deleteRowConsumed,
                                       response14.TableRespones[tableName].DeleteResponses[0].Consumed);
                }
                else
                {
                    throw new OTSServerException("/BatchWriteRow", HttpStatusCode.OK,
                                                 response14.TableRespones[tableName].DeleteResponses[0].ErrorCode,
                                                 response14.TableRespones[tableName].DeleteResponses[0].ErrorMessage);
                }
                var request141  = new GetRowRequest(tableName, primaryKey);
                var response141 = OTSClient.GetRow(request141);
                AssertPrimaryKey(new PrimaryKey(), response141.PrimaryKey);
                AssertAttribute(new AttributeColumns(), response141.Attribute);
                return;

            case "GetRange":
                var request15 = new GetRangeRequest(tableName, direction,
                                                    startPrimaryKey, endPrimaryKey,
                                                    columnsToGet, limit);
                var response15 = OTSClient.GetRange(request15);
                Assert.AreEqual(1, response15.RowDataList.Count);
                Assert.AreEqual(null, response15.NextPrimaryKey);
                AssertCapacityUnit(getRangeConsumed, response15.ConsumedCapacityUnit);
                AssertPrimaryKey(primaryKey, response15.RowDataList[0].PrimaryKey, columnsToGet);
                AssertAttribute(attribute, response15.RowDataList[0].Attribute, columnsToGet);
                return;

            default:
                throw new Exception(String.Format("invalid api name: {0}", apiName));
            }
        }
Exemplo n.º 24
0
 public void SmokeTest1()
 {
     var request  = new ListTableRequest();
     var response = OTSClient.ListTable(request);
 }
Exemplo n.º 25
0
 // ListTable
 /// <summary>
 /// 获取当前实例下已创建的所有表的表名。
 /// </summary>
 /// <param name="request">请求参数</param>
 /// <returns>ListTable的返回,用来获取表名列表。</returns>
 /// <example>
 /// 获取一个实例下所有表名并循环读取
 /// <code lang="C#">
 /// var request = new ListTableRequest();
 /// var response = otsClient.ListTable(request);
 /// foreach (var tableName in response.TableNames) {
 ///      // Do something
 /// }
 /// </code>
 /// </example>
 public ListTableResponse ListTable(ListTableRequest request)
 {
     return(GetResponseFromAsyncTask(ListTableAsync(request)));
 }
Exemplo n.º 26
0
 /// <summary>
 /// ListTable的异步形式。
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public Task <ListTableResponse> ListTableAsync(ListTableRequest request)
 {
     return(CallAsync <ListTableRequest, ListTableResponse>("/ListTable", request));
 }