public void TestFourColumnInAttribute()
        {
            var attribute = new AttributeColumns
            {
                { "Col0", new ColumnValue(3.14) },
                { "Col1", new ColumnValue(3.14) },
                { "Col2", new ColumnValue(3.14) },
                { "Col3", new ColumnValue(3.14) }
            };

            SetTestConext(attribute: attribute);
            TestAllDataAPI();
        }
Esempio n. 2
0
        public AttributeColumns GetPredefinedAttributeWith5PK(int index)
        {
            var attribute = new AttributeColumns
            {
                { "Col0", new ColumnValue("ABC" + index) },
                { "Col1", new ColumnValue(123 + index) },
                { "Col2", new ColumnValue(3.14 + index) },
                { "Col3", new ColumnValue(index % 2 == 0) },
                { "Col4", new ColumnValue(new byte[] { 0x20, 0x20 }) }
            };

            return(attribute);
        }
        public void TestNormalDoubleValue()
        {
            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(3.1415926));
            SetTestConext(attribute: attribute);
            TestAllDataAPI();

            attribute = new AttributeColumns();
            attribute.Add("Col0", new ColumnValue(3.1415926));
            SetTestConext(attribute: attribute);
            TestAllDataAPI();
        }
Esempio n. 4
0
        public void TestDoubleValueInBoundary()
        {
            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(double.MaxValue));
            SetTestConext(attribute: attribute);
            TestAllDataAPI();

            attribute = new AttributeColumns();
            attribute.Add("Col0", new ColumnValue(double.MinValue));
            SetTestConext(attribute: attribute);
            TestAllDataAPI();
        }
        public void CheckSingleRow(string tableName, PrimaryKey primaryKey,
                                   AttributeColumns attribute,
                                   CapacityUnit expectCapacityUnitConsumed = null,
                                   HashSet <string> columnsToGet           = null,
                                   bool isEmpty = false,
                                   ColumnCondition condition = null)
        {
            var request = new GetRowRequest(tableName, primaryKey, columnsToGet, condition);

            var response = OTSClient.GetRow(request);

            PrimaryKey       primaryKeyToExpect;
            AttributeColumns attributeToExpect;

            if (isEmpty)
            {
                primaryKeyToExpect = new PrimaryKey();
                attributeToExpect  = new AttributeColumns();
            }
            else if (columnsToGet == null || columnsToGet.Count == 0)
            {
                primaryKeyToExpect = primaryKey;
                attributeToExpect  = attribute;
            }
            else
            {
                primaryKeyToExpect = new PrimaryKey();
                attributeToExpect  = new AttributeColumns();
                foreach (var columnName in columnsToGet)
                {
                    if (primaryKey.ContainsKey(columnName))
                    {
                        primaryKeyToExpect.Add(columnName, primaryKey[columnName]);
                    }

                    if (attribute.ContainsKey(columnName))
                    {
                        attributeToExpect.Add(columnName, attribute[columnName]);
                    }
                }
            }

            AssertColumns(primaryKeyToExpect, response.PrimaryKey);
            AssertColumns(attributeToExpect, response.Attribute);

            if (expectCapacityUnitConsumed != null)
            {
                AssertCapacityUnit(expectCapacityUnitConsumed, response.ConsumedCapacityUnit);
            }
        }
        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);
        }
        public void TestDoubleValueOutOfBoundary()
        {
            CreateTestTableWith4PK();
            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(double.MaxValue * 1.1));
            SetTestConext(attribute: attribute, allFailedMessage: "The input parameter is invalid.");
            TestAllDataAPIWithColumnValue(createTable: false);

            attribute = new AttributeColumns();
            attribute.Add("Col0", new ColumnValue(double.MinValue * 1.1));
            SetTestConext(attribute: attribute, allFailedMessage: "The input parameter is invalid.");
            TestAllDataAPIWithColumnValue(createTable: false);
        }
Esempio n. 8
0
        public void TestDoubleValueOutOfBoundary()
        {
            CreateTestTableWith4PK();
            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(double.MaxValue * 1.1));
            SetTestConext(attribute: attribute, allFailedMessage: "Infinity can't be set to double value.");
            TestAllDataAPIWithColumnValue(createTable: false);

            attribute = new AttributeColumns();
            attribute.Add("Col0", new ColumnValue(double.MinValue * 1.1));
            SetTestConext(attribute: attribute, allFailedMessage: "Infinity can't be set to double value.");
            TestAllDataAPIWithColumnValue(createTable: false);
        }
Esempio n. 9
0
        public void TestGetRowWithDefaultColumnsToGet()
        {
            CreateTestTableWith4PK();

            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(1));
            attribute.Add("Col1", new ColumnValue(2));
            attribute.Add("Col2", new ColumnValue(3));
            attribute.Add("Col3", new ColumnValue(4));

            PutSingleRow(TestTableName, PrimaryKeyWith4Columns, attribute);
            CheckSingleRow(TestTableName, PrimaryKeyWith4Columns, attribute, new CapacityUnit(1, 0));
        }
        public void TestInvalidValueType()
        {
            CreateTestTableWith4PK();
            var attribute = new AttributeColumns();

            attribute.Add("Col0", ColumnValue.INF_MAX);
            SetTestConext(attribute: attribute, allFailedMessage: "INF_MAX is an invalid type for the attribute column.");
            TestAllDataAPIWithColumnValue(createTable: false);

            attribute = new AttributeColumns();
            attribute.Add("Col0", ColumnValue.INF_MIN);
            SetTestConext(attribute: attribute, allFailedMessage: "INF_MIN is an invalid type for the attribute column.");
            TestAllDataAPIWithColumnValue(createTable: false);
        }
        public void TestBadColumnName(string badColumnName)
        {
            var badPrimaryKeySchema = new PrimaryKeySchema
            {
                { badColumnName, ColumnValueType.String }
            };

            var badPrimaryKey = new PrimaryKey
            {
                { badColumnName, new ColumnValue(3.14) }
            };

            var badColumnsToGet = new HashSet <string>
            {
                badColumnName
            };

            var expectFailureInfo = "Invalid column name: '" + badColumnName + "'.";

            var expectedFailure = new Dictionary <string, string>
            {
                { "CreateTable", expectFailureInfo }
            };

            var errorMessage = String.Format("Bug: unsupported primary key type: Double");
            var badAttribute = new AttributeColumns
            {
                { badColumnName, new ColumnValue(3.14) }
            };

            SetTestConext(
                pkSchema: badPrimaryKeySchema,
                primaryKey: badPrimaryKey,
                startPrimaryKey: badPrimaryKey,
                expectedFailure: expectedFailure,
                allFailedMessage: errorMessage);
            TestAllDataAPI(deleteTable: false);

            SetTestConext(
                attribute: badAttribute,
                allFailedMessage: expectFailureInfo);
            TestAllDataAPIWithAttribute(false);

            SetTestConext(
                columnsToGet: badColumnsToGet,
                expectedFailure: expectedFailure,
                allFailedMessage: expectFailureInfo);
            TestAllDataAPIWithColumnsToGet();
        }
Esempio n. 12
0
        public void TestColumnsToGet()
        {
            CreateTestTable();

            var primaryKey = new PrimaryKey();

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

            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(123));
            attribute.Add("Col1", new ColumnValue("ABC"));
            attribute.Add("Col2", new ColumnValue(new byte[] { 0x20, 0x21, 0x23, 0x24 }));
            var request1 = new PutRowRequest(
                "SampleTableName",
                new Condition(RowExistenceExpectation.IGNORE),
                primaryKey,
                attribute
                );

            var response1 = OTSClient.PutRow(request1);

            Assert.AreEqual(0, response1.ConsumedCapacityUnit.Read);
            Assert.AreEqual(1, response1.ConsumedCapacityUnit.Write);

            var request2 = new GetRowRequest(
                "SampleTableName",
                primaryKey,
                new HashSet <string>()
            {
                "Col0", "Col2"
            }
                );
            var response2 = OTSClient.GetRow(request2);

            Assert.AreEqual(1, response2.ConsumedCapacityUnit.Read);
            Assert.AreEqual(0, response2.ConsumedCapacityUnit.Write);
            AssertColumns(new PrimaryKey(), response2.PrimaryKey);


            var attributeToExpect = new AttributeColumns();

            attributeToExpect.Add("Col0", new ColumnValue(123));
            attributeToExpect.Add("Col2", new ColumnValue(new byte[] { 0x20, 0x21, 0x23, 0x24 }));

            AssertColumns(attributeToExpect, response2.Attribute);
        }
Esempio n. 13
0
        public void TestEmptyPrimaryKey()
        {
            var primaryKey = new PrimaryKey();

            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(true));
            var request1 = new PutRowRequest(
                "SampleTableName",
                new Condition(RowExistenceExpectation.IGNORE),
                primaryKey,
                attribute
                );

            try
            {
                OTSClient.PutRow(request1);
                Assert.Fail();
            }
            catch (OTSServerException e)
            {
                Assert.AreEqual("/PutRow", e.APIName);
                Assert.AreEqual(400, (int)e.HttpStatusCode);
                Assert.AreEqual("OTSParameterInvalid", e.ErrorCode);
                Assert.AreEqual("The number of primary key columns must be in range: [1, 4].", e.ErrorMessage);
                Assert.NotNull(e.RequestID);
            }

            var request2 = new GetRowRequest(
                "SampleTableName",
                primaryKey
                );

            try
            {
                OTSClient.GetRow(request2);
                Assert.Fail();
            }
            catch (OTSServerException e)
            {
                Assert.AreEqual("/GetRow", e.APIName);
                Assert.AreEqual(400, (int)e.HttpStatusCode);
                Assert.AreEqual("OTSParameterInvalid", e.ErrorCode);
                Assert.AreEqual("The number of primary key columns must be in range: [1, 4].", e.ErrorMessage);
                Assert.NotNull(e.RequestID);
            }
        }
        public void Test3WriteCUConsumed()
        {
            var attribute = new AttributeColumns
            {
                { "Col0", new ColumnValue(new String('X', 9 * 1024)) }
            };

            SetTestConext(attribute: attribute,
                          getRowConsumed: new CapacityUnit(3, 0),
                          getRangeConsumed: new CapacityUnit(3, 0),
                          putRowConsumed: new CapacityUnit(0, 3),
                          updateRowConsumed: new CapacityUnit(0, 3),
                          deleteRowConsumed: new CapacityUnit(0, 1));

            TestSingleAPI("CreateTable");
            WaitForTableReady();
            TestSingleAPI("DescribeTable");

            TestSingleAPI("PutRow");
            TestSingleAPI("GetRow");
            TestSingleAPI("GetRange");
            TestSingleAPI("BatchGetRow");
            TestSingleAPI("DeleteRow");

            SetTestConext(primaryKey: GetPredefinedPrimaryKeyWith4PK(1),
                          attribute: attribute,
                          getRowConsumed: new CapacityUnit(3, 0),
                          getRangeConsumed: new CapacityUnit(3, 0),
                          putRowConsumed: new CapacityUnit(0, 3),
                          updateRowConsumed: new CapacityUnit(0, 3),
                          deleteRowConsumed: new CapacityUnit(0, 1));

            TestSingleAPI("UpdateRow_Put");
            TestSingleAPI("UpdateRow_Delete");

            SetTestConext(primaryKey: GetPredefinedPrimaryKeyWith4PK(2),
                          attribute: attribute,
                          getRowConsumed: new CapacityUnit(3, 0),
                          getRangeConsumed: new CapacityUnit(3, 0),
                          putRowConsumed: new CapacityUnit(0, 3),
                          updateRowConsumed: new CapacityUnit(0, 3),
                          deleteRowConsumed: new CapacityUnit(0, 1));

            TestSingleAPI("BatchWriteRow_Put");
            TestSingleAPI("BatchWriteRow_Delete");
            TestSingleAPI("BatchWriteRow_Update");
        }
Esempio n. 15
0
        public static void PutRowAsync()
        {
            Console.WriteLine("Start put row async...");
            PrepareTable();
            OTSClient TabeStoreClient = Config.GetClient();

            try
            {
                var putRowTaskList = new List <Task <PutRowResponse> >();
                for (int i = 0; i < 100; i++)
                {
                    // 定义行的主键,必须与创建表时的TableMeta中定义的一致
                    var primaryKey = new PrimaryKey
                    {
                        { "pk0", new ColumnValue(i) },
                        { "pk1", new ColumnValue("abc") }
                    };

                    // 定义要写入改行的属性列
                    var attribute = new AttributeColumns
                    {
                        { "col0", new ColumnValue(i) },
                        { "col1", new ColumnValue("a") },
                        { "col2", new ColumnValue(true) }
                    };

                    var request = new PutRowRequest(TableName, new Condition(RowExistenceExpectation.IGNORE),
                                                    primaryKey, attribute);

                    putRowTaskList.Add(TabeStoreClient.PutRowAsync(request));
                }

                foreach (var task in putRowTaskList)
                {
                    task.Wait();
                    Console.WriteLine("consumed read:{0}, write:{1}", task.Result.ConsumedCapacityUnit.Read,
                                      task.Result.ConsumedCapacityUnit.Write);
                }

                Console.WriteLine("Put row async succeeded.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Put row async failed. exception:{0}", ex.Message);
            }
        }
        public void TestNormalIntegerValue()
        {
            var primaryKey = new PrimaryKey();

            primaryKey.Add("PK0", new ColumnValue("ABC"));
            primaryKey.Add("PK1", new ColumnValue("DEF"));
            primaryKey.Add("PK2", new ColumnValue(10));
            primaryKey.Add("PK3", new ColumnValue(456));
            SetTestConext(primaryKey: primaryKey);
            TestAllDataAPI();

            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(10));
            SetTestConext(attribute: attribute);
            TestAllDataAPI();
        }
Esempio n. 17
0
        private static void PrintRow(Row row)
        {
            PrimaryKey       primaryKeyRead = row.PrimaryKey;
            AttributeColumns attributesRead = row.AttributeColumns;

            Console.WriteLine("Primary key: ");
            foreach (KeyValuePair <string, ColumnValue> entry in primaryKeyRead)
            {
                Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value));
            }

            Console.WriteLine("Attributes: ");
            foreach (KeyValuePair <string, ColumnValue> entry in attributesRead)
            {
                Console.WriteLine(entry.Key + ":" + PrintColumnValue(entry.Value));
            }
        }
Esempio n. 18
0
        public void Test3ReadCUConsumed()
        {
            CreateTestTableWith4PK();
            WaitForTableReady();

            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(new String('X', 9 * 1024)));
            PutSingleRow(TestTableName, PrimaryKeyWith4Columns, attribute);

            SetTestConext(attribute: attribute,
                          getRowConsumed: new CapacityUnit(3, 0),
                          getRangeConsumed: new CapacityUnit(3, 0));

            TestSingleAPI("GetRow");
            TestSingleAPI("BatchGetRow");
            TestSingleAPI("GetRange");
        }
        public BatchGetRowResponseItem(string tableName, IRow row, CapacityUnit consumed, int index)
        {
            TableName = tableName;
            Row       = row;
            Consumed  = consumed;
            Index     = index;

            if (row != null)
            {
                PrimaryKey = row.GetPrimaryKey();
                Attribute  = (row as Row).AttributeColumns;
            }
            else
            {
                PrimaryKey = new PrimaryKey();
                Attribute  = new AttributeColumns();
            }
        }
        public void TestEmptyStringValue()
        {
            string targetString = "";

            var primaryKey = new PrimaryKey();

            primaryKey.Add("PK0", new ColumnValue(targetString));
            primaryKey.Add("PK1", new ColumnValue("ABC"));
            primaryKey.Add("PK2", new ColumnValue(123));
            primaryKey.Add("PK3", new ColumnValue(456));

            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(targetString));

            SetTestConext(primaryKey: primaryKey, attribute: attribute);
            TestAllDataAPI();
        }
        public void TestGetRowWith0ColumsToGet()
        {
            CreateTestTableWith4PK();

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

            PutSingleRow(TestTableName, PrimaryKeyWith4Columns, attribute);

            var columnsToGet = new HashSet <string>();

            CheckSingleRow(TestTableName, PrimaryKeyWith4Columns, attribute, new CapacityUnit(1, 0), columnsToGet);
        }
Esempio n. 22
0
        private void BatchWriteRow()
        {
            var otsClient = OTSClient;

            var primaryKey1 = new PrimaryKey
            {
                { "PK0", new ColumnValue("TestData") },
                { "PK1", new ColumnValue(0) }
            };

            var attribute1 = new AttributeColumns
            {
                { "Col0", new ColumnValue("Hangzhou") }
            };

            var primaryKey2 = new PrimaryKey
            {
                { "PK0", new ColumnValue("TestData") },
                { "PK1", new ColumnValue(1) }
            };

            var attribute2 = new AttributeColumns
            {
                { "Col0", new ColumnValue("Shanghai") }
            };

            var rowChanges = new RowChanges(TestTableName);

            rowChanges.AddPut(new Condition(RowExistenceExpectation.IGNORE), primaryKey1, attribute1);
            rowChanges.AddPut(new Condition(RowExistenceExpectation.IGNORE), primaryKey2, attribute2);
            var batchWriteRowRequest = new BatchWriteRowRequest();

            batchWriteRowRequest.Add(TestTableName, rowChanges);

            var batchWriteRowResponse = otsClient.BatchWriteRow(batchWriteRowRequest);

            foreach (var responseForOneTable in batchWriteRowResponse.TableRespones)
            {
                foreach (var row in responseForOneTable.Value.Responses)
                {
                    Console.WriteLine(row);
                }
            }
        }
        public void TestEmptyStringValue()
        {
            string targetString = "";

            var primaryKey = new PrimaryKey
            {
                { "PK0", new ColumnValue(targetString) },
                { "PK1", new ColumnValue("ABC") },
                { "PK2", new ColumnValue(123) },
                { "PK3", new ColumnValue(456) }
            };

            var attribute = new AttributeColumns
            {
                { "Col0", new ColumnValue(targetString) }
            };

            SetTestConext(primaryKey: primaryKey, attribute: attribute);
            TestAllDataAPI();
        }
Esempio n. 24
0
        public void TestTooMuchColumnInAttribute()
        {
            var attribute = new AttributeColumns();

            for (int i = 0; i < 1025; i++)
            {
                attribute.Add("Col" + i, new ColumnValue(3.14));
            }

            var expectedFailure = new Dictionary <string, string>();

            expectedFailure.Add("PutRow", "The number of columns from the request exceeded the limit.");
            expectedFailure.Add("UpdateRow_Put", "The number of columns from the request exceeded the limit.");
            expectedFailure.Add("UpdateRow_Delete", "The number of columns from the request exceeded the limit.");
            expectedFailure.Add("BatchWriteRow_Put", "The number of columns from the request exceeded the limit of putting row #0 in table: 'SampleTestName'.");
            expectedFailure.Add("BatchWriteRow_Update", "The number of columns from the request exceeded the limit of updating row #0 in table: 'SampleTestName'.");

            SetTestConext(attribute: attribute, expectedFailure: expectedFailure);
            TestAllDataAPIWithAttribute(true);
        }
Esempio n. 25
0
        public void TestGetRowWith4ColumnsToGet()
        {
            CreateTestTableWith4PK();

            var attribute = new AttributeColumns();

            attribute.Add("Col0", new ColumnValue(1));
            attribute.Add("Col1", new ColumnValue(2));
            attribute.Add("Col2", new ColumnValue(3));
            attribute.Add("Col3", new ColumnValue(4));

            PutSingleRow(TestTableName, PrimaryKeyWith4Columns, attribute);

            var columnsToGet = new HashSet <string>()
            {
                "PK0", "PK1", "Col0", "Col1"
            };

            CheckSingleRow(TestTableName, PrimaryKeyWith4Columns, attribute, new CapacityUnit(1, 0), columnsToGet);
        }
        public void TestBinary()
        {
            CreateTable();

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

            var attribute = new AttributeColumns
            {
                { "Col0", new ColumnValue(new byte[] { 0x20, 0x21, 0x23, 0x24 }) }
            };

            var request1 = new PutRowRequest(
                TestTableName,
                new Condition(RowExistenceExpectation.IGNORE),
                primaryKey,
                attribute
                );

            var response1 = OTSClient.PutRow(request1);

            Assert.AreEqual(0, response1.ConsumedCapacityUnit.Read);
            Assert.AreEqual(1, response1.ConsumedCapacityUnit.Write);

            var request2 = new GetRowRequest(
                TestTableName,
                primaryKey
                );

            var response2 = OTSClient.GetRow(request2);

            Assert.AreEqual(1, response2.ConsumedCapacityUnit.Read);
            Assert.AreEqual(0, response2.ConsumedCapacityUnit.Write);
            AssertColumns(primaryKey, response2.PrimaryKey);
            AssertColumns(attribute, response2.Attribute);

            DeleteTable();
        }
        private static void PrepareData()
        {
            OTSClient otsClient = Config.GetClient();

            // 插入100条数据
            for (int i = 0; i < 100; i++)
            {
                PrimaryKey primaryKey = new PrimaryKey();
                primaryKey.Add("pk0", new ColumnValue(i));
                primaryKey.Add("pk1", new ColumnValue("abc"));

                // 定义要写入改行的属性列
                AttributeColumns attribute = new AttributeColumns();
                attribute.Add("col0", new ColumnValue(0));
                attribute.Add("col1", new ColumnValue("a"));
                attribute.Add("col2", new ColumnValue(i % 3 != 0));
                PutRowRequest request = new PutRowRequest(TableName, new Condition(RowExistenceExpectation.IGNORE), primaryKey, attribute);

                otsClient.PutRow(request);
            }
        }
Esempio n. 28
0
        /// <summary>
        /// 向主表中写入数据(自动同步到索引表)
        /// </summary>
        public static void PutRow()
        {
            Console.WriteLine("Start put row...");
            OTSClient  otsClient  = Config.GetClient();
            PrimaryKey primaryKey = new PrimaryKey
            {
                { Pk1, new ColumnValue("abc") },
                { Pk2, new ColumnValue("edf") }
            };

            // 定义要写入改行的属性列
            AttributeColumns attribute = new AttributeColumns
            {
                { Col1, new ColumnValue("Col1Value") },
                { Col2, new ColumnValue("Col2Value") }
            };
            PutRowRequest request = new PutRowRequest(TableName, new Condition(RowExistenceExpectation.IGNORE), primaryKey, attribute);

            otsClient.PutRow(request);
            Console.WriteLine("Put row succeed.");
        }
        public void TestTooMuchColumnInAttribute()
        {
            var attribute = new AttributeColumns();

            for (int i = 0; i < 1025; i++)
            {
                attribute.Add("Col" + i, new ColumnValue(3.14));
            }

            var expectedFailure = new Dictionary <string, string>
            {
                { "PutRow", "The number of attribute columns exceeds the limit, limit count: 1024, column count: 1025." },
                { "UpdateRow_Put", "The number of attribute columns exceeds the limit, limit count: 1024, column count: 1025." },
                { "UpdateRow_Delete", "The number of attribute columns exceeds the limit, limit count: 1024, column count: 1025." },
                { "BatchWriteRow_Put", "The number of attribute columns exceeds the limit, limit count: 1024, column count: 1025." },
                { "BatchWriteRow_Update", "The number of attribute columns exceeds the limit, limit count: 1024, column count: 1025." }
            };

            SetTestConext(attribute: attribute, expectedFailure: expectedFailure);
            TestAllDataAPIWithAttribute(true);
        }
Esempio n. 30
0
        public void BatchWriteRowTest()
        {
            var otsClient = OTSClient;

            var primaryKey1 = new PrimaryKey();

            primaryKey1.Add("PK0", new ColumnValue("TestData"));
            primaryKey1.Add("PK1", new ColumnValue(0));

            var attribute1 = new AttributeColumns();

            attribute1.Add("Col0", new ColumnValue("Hangzhou"));

            var primaryKey2 = new PrimaryKey();

            primaryKey2.Add("PK0", new ColumnValue("TestData"));
            primaryKey2.Add("PK1", new ColumnValue(1));

            var attribute2 = new AttributeColumns();

            attribute2.Add("Col0", new ColumnValue("Shanghai"));

            var rowChanges = new RowChanges();

            rowChanges.AddPut(new Condition(RowExistenceExpectation.IGNORE), primaryKey1, attribute1);
            rowChanges.AddPut(new Condition(RowExistenceExpectation.IGNORE), primaryKey2, attribute2);
            var batchWriteRowRequest = new BatchWriteRowRequest();

            batchWriteRowRequest.Add("SampleTableName", rowChanges);

            var batchWriteRowResponse = otsClient.BatchWriteRow(batchWriteRowRequest);

            foreach (var responseForOneTable in batchWriteRowResponse.TableRespones)
            {
                foreach (var row in responseForOneTable.Value.PutResponses)
                {
                    // 处理每一行的返回
                }
            }
        }