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.º 2
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);
            }
        }