コード例 #1
0
        public void TestDuplicateDeleteInUpdateRow()
        {
            var pk = new PrimaryKey();

            pk.Add("PK0", new ColumnValue("123"));
            pk.Add("PK1", new ColumnValue(123));


            var updateOfAttribute = new UpdateOfAttribute();

            updateOfAttribute.AddAttributeColumnToDelete("Col0");
            updateOfAttribute.AddAttributeColumnToDelete("Col0");

            var request = new UpdateRowRequest(
                TestTableName, new Condition(RowExistenceExpectation.IGNORE), pk, updateOfAttribute);

            try {
                var response = OTSClient.UpdateRow(request);
                Assert.Fail();
            } catch (OTSServerException e) {
                AssertOTSServerException(e, new OTSServerException(
                                             "/UpdateRow",
                                             HttpStatusCode.BadRequest,
                                             "OTSParameterInvalid",
                                             "Duplicated attribute column name: 'Col0' while updating row."
                                             ));
            }
        }
コード例 #2
0
        public void Test4PutAnd4DeleteInUpdateRow()
        {
            CreateTestTableWith2PK();

            var pk = new PrimaryKey
            {
                { "PK0", new ColumnValue("123") },
                { "PK1", new ColumnValue(123) }
            };

            var attribute = new AttributeColumns
            {
                { "Col0", new ColumnValue("0") },
                { "Col1", new ColumnValue("1") },
                { "Col2", new ColumnValue("2") },
                { "Col3", new ColumnValue("3") },
                { "Col4", new ColumnValue("4") }
            };

            PutSingleRow(TestTableName, pk, attribute);

            var updateOfAttribute = new UpdateOfAttribute();

            updateOfAttribute.AddAttributeColumnToPut("Col3", new ColumnValue("5"));
            updateOfAttribute.AddAttributeColumnToPut("Col4", new ColumnValue("6"));
            updateOfAttribute.AddAttributeColumnToPut("Col5", new ColumnValue("7"));
            updateOfAttribute.AddAttributeColumnToPut("Col6", new ColumnValue("8"));

            updateOfAttribute.AddAttributeColumnToDelete("Col1");
            updateOfAttribute.AddAttributeColumnToDelete("Col2");
            updateOfAttribute.AddAttributeColumnToDelete("Col7");
            updateOfAttribute.AddAttributeColumnToDelete("Col8");

            var request = new UpdateRowRequest(
                TestTableName, new Condition(RowExistenceExpectation.IGNORE), pk, updateOfAttribute);
            var response = OTSClient.UpdateRow(request);

            AssertCapacityUnit(new CapacityUnit(0, 1), response.ConsumedCapacityUnit);

            var expectAttribute = new AttributeColumns
            {
                { "Col0", new ColumnValue("0") },
                { "Col3", new ColumnValue("5") },
                { "Col4", new ColumnValue("6") },
                { "Col5", new ColumnValue("7") },
                { "Col6", new ColumnValue("8") }
            };

            CheckSingleRow(TestTableName, pk, expectAttribute);
        }
コード例 #3
0
        public void UpdateRowTest()
        {
            CreateTable();
            var otsClient  = OTSClient;
            var primaryKey = new PrimaryKey();

            primaryKey.Add("PK0", new ColumnValue("ABC"));
            primaryKey.Add("PK1", new ColumnValue(123));
            var updateOfAttribute = new UpdateOfAttribute();

            updateOfAttribute.AddAttributeColumnToPut("NewColumn", new ColumnValue(123));
            updateOfAttribute.AddAttributeColumnToDelete("IntAttr0");

            var updateRowRequest = new UpdateRowRequest(
                "SampleTable",
                new Condition(RowExistenceExpectation.IGNORE),
                primaryKey,
                updateOfAttribute);
            var updateRowResponse = otsClient.UpdateRow(updateRowRequest);

            System.Console.WriteLine("UpdateRow CU Consumed: Read {0} Write {0}",
                                     updateRowResponse.ConsumedCapacityUnit.Read,
                                     updateRowResponse.ConsumedCapacityUnit.Write);
            DeleteTable();
        }
コード例 #4
0
        public void Test1000PutAnd1000DeleteInUpdateRow()
        {
            var pk = new PrimaryKey
            {
                { "PK0", new ColumnValue("123") },
                { "PK1", new ColumnValue(123) }
            };


            var updateOfAttribute = new UpdateOfAttribute();

            for (int i = 0; i < 1000; i++)
            {
                updateOfAttribute.AddAttributeColumnToPut("Put" + i, new ColumnValue("blah"));
                updateOfAttribute.AddAttributeColumnToDelete("Delete" + i);
            }

            var request = new UpdateRowRequest(
                TestTableName, new Condition(RowExistenceExpectation.IGNORE), pk, updateOfAttribute);

            try {
                var response = OTSClient.UpdateRow(request);
            } catch (OTSServerException e) {
                AssertOTSServerException(e, new OTSServerException(
                                             "/UpdateRow",
                                             HttpStatusCode.BadRequest,
                                             "OTSParameterInvalid",
                                             "The number of attribute columns exceeds the limit, limit count: 1024, column count: 2000."
                                             ));
            }
        }
コード例 #5
0
        private void UpdateRow(OTSClient client, String tableName, IColumnCondition cond)
        {
            var primaryKey = new PrimaryKey
            {
                { COLUMN_GID_NAME, new ColumnValue(1) },
                { COLUMN_UID_NAME, new ColumnValue(101) }
            };

            UpdateOfAttribute updateOfAttributeForPut = new UpdateOfAttribute();

            updateOfAttributeForPut.AddAttributeColumnToPut(COLUMN_NAME_NAME, new ColumnValue("张三"));
            updateOfAttributeForPut.AddAttributeColumnToPut(COLUMN_ADDRESS_NAME, new ColumnValue("中国B地"));
            updateOfAttributeForPut.AddAttributeColumnToDelete(COLUMN_MOBILE_NAME);
            updateOfAttributeForPut.AddAttributeColumnToDelete(COLUMN_AGE_NAME);

            Condition condition = new Condition(RowExistenceExpectation.IGNORE)
            {
                ColumnCondition = cond
            };

            var request = new UpdateRowRequest(tableName, condition, primaryKey, updateOfAttributeForPut);

            try
            {
                client.UpdateRow(request);
                Console.WriteLine("UpdateRow success");
            }
            catch (OTSServerException e)
            {
                //服务端异常
                Console.WriteLine("操作失败:{0}", e.ErrorMessage);
                Console.WriteLine("请求ID:{0}", e.RequestID);
            }
            catch (OTSClientException e)
            {
                //可能是网络不好或者返回结果有问题
                Console.WriteLine("请求失败:{0}", e.ErrorMessage);
            }
        }
コード例 #6
0
        public void SetTestConext(string tableName                             = null,
                                  PrimaryKeySchema pkSchema                    = null,
                                  CapacityUnit reservedThroughput              = null,
                                  PrimaryKey primaryKey                        = null,
                                  AttributeColumns attribute                   = null,
                                  UpdateOfAttribute updateOfAttributeForPut    = null,
                                  UpdateOfAttribute updateOfAttributeForDelete = null,
                                  Condition condition                          = null,
                                  GetRangeDirection direction                  = GetRangeDirection.Forward,
                                  PrimaryKey startPrimaryKey                   = null,
                                  PrimaryKey endPrimaryKey                     = null,
                                  HashSet <string> columnsToGet                = null,
                                  int?limit = null,
                                  CapacityUnit putRowConsumed    = null,
                                  CapacityUnit getRowConsumed    = null,
                                  CapacityUnit updateRowConsumed = null,
                                  CapacityUnit deleteRowConsumed = null,
                                  CapacityUnit getRangeConsumed  = null,
                                  Dictionary <string, string> expectedFailure = null,
                                  string allFailedMessage = null)
        {
            var DefaultPrimaryKeySchema = new PrimaryKeySchema();

            DefaultPrimaryKeySchema.Add("PK0", ColumnValueType.String);
            DefaultPrimaryKeySchema.Add("PK1", ColumnValueType.String);
            DefaultPrimaryKeySchema.Add("PK2", ColumnValueType.Integer);
            DefaultPrimaryKeySchema.Add("PK3", ColumnValueType.Integer);

            var DefaultReservedThroughput = new CapacityUnit(0, 0);

            TestContext = new APITestContext();
            TestContext.expectedFailure    = expectedFailure;
            TestContext.allFailedMessage   = allFailedMessage;
            TestContext.tableName          = tableName ?? OTSUnitTestBase.TestTableName;
            TestContext.pkSchema           = pkSchema ?? DefaultPrimaryKeySchema;
            TestContext.reservedThroughput = reservedThroughput ?? DefaultReservedThroughput;
            TestContext.primaryKey         = primaryKey ?? PrimaryKeyWith4Columns;
            TestContext.attribute          = attribute ?? AttributeWith5Columns;
            TestContext.condition          = condition ?? new Condition(RowExistenceExpectation.IGNORE);
            TestContext.startPrimaryKey    = startPrimaryKey ?? MinPrimaryKeyWith4Columns;
            TestContext.endPrimaryKey      = endPrimaryKey ?? MaxPrimaryKeyWith4Columns;
            TestContext.putRowConsumed     = putRowConsumed ?? new CapacityUnit(0, 1);
            TestContext.getRowConsumed     = getRowConsumed ?? new CapacityUnit(1, 0);
            TestContext.updateRowConsumed  = updateRowConsumed ?? new CapacityUnit(0, 1);
            TestContext.deleteRowConsumed  = deleteRowConsumed ?? new CapacityUnit(0, 1);
            TestContext.getRangeConsumed   = getRangeConsumed ?? new CapacityUnit(1, 0);
            TestContext.columnsToGet       = columnsToGet;
            TestContext.limit     = limit;
            TestContext.direction = direction;

            if (updateOfAttributeForPut == null)
            {
                updateOfAttributeForPut = new UpdateOfAttribute();
                foreach (var item in TestContext.attribute)
                {
                    updateOfAttributeForPut.AddAttributeColumnToPut(item.Key, item.Value);
                }
            }

            if (updateOfAttributeForDelete == null)
            {
                updateOfAttributeForDelete = new UpdateOfAttribute();
                foreach (var item in TestContext.attribute)
                {
                    updateOfAttributeForDelete.AddAttributeColumnToDelete(item.Key);
                }
            }

            TestContext.updateOfAttributeForPut    = updateOfAttributeForPut;
            TestContext.updateOfAttributeForDelete = updateOfAttributeForDelete;
        }