diff --git a/sample/Program.cs b/sample/Program.cs index 717a42e..8d347ca 100644 --- a/sample/Program.cs +++ b/sample/Program.cs @@ -15,6 +15,7 @@ static void Main(string[] args) CreateTableSample.TableOperations(); //SingleRowReadWriteSample.PutRow(); + //SingleRowReadWriteSample.PutRowAsync(); //SingleRowReadWriteSample.UpdateRow(); @@ -35,9 +36,13 @@ static void Main(string[] args) //ConditionUpdateSample.ConditionDeleteRow(); //ConditionUpdateSample.ConditionBatchWriteRow(); } - catch (OTSException ex) + catch (OTSClientException ex) { - Console.WriteLine(ex); + Console.WriteLine("Failed with client exception:{0}", ex.Message); + } + catch (OTSServerException ex) + { + Console.WriteLine("Failed with server exception:{0}, {1}", ex.Message, ex.RequestID); } catch (Exception ex) { diff --git a/sample/Samples/MultiRowReadWriteSample.cs b/sample/Samples/MultiRowReadWriteSample.cs index 5d79b29..6d95d8b 100644 --- a/sample/Samples/MultiRowReadWriteSample.cs +++ b/sample/Samples/MultiRowReadWriteSample.cs @@ -350,7 +350,6 @@ public static void BatchWriteRow() // 注意:batch操作可能部分成功部分失败,需要为每行检查状态 if (row.IsOK) { - Console.WriteLine("Update succeed."); succeedRows++; } else diff --git a/sample/Samples/SingleRowReadWriteSample.cs b/sample/Samples/SingleRowReadWriteSample.cs index 73ad502..f94452f 100644 --- a/sample/Samples/SingleRowReadWriteSample.cs +++ b/sample/Samples/SingleRowReadWriteSample.cs @@ -4,6 +4,7 @@ using Aliyun.OTS.Request; using Aliyun.OTS.Response; using Aliyun.OTS.DataModel.ConditionalUpdate; +using System.Threading.Tasks; namespace Aliyun.OTS.Samples { @@ -56,6 +57,49 @@ public static void PutRow() Console.WriteLine("Put row succeed."); } + public static void PutRowAsync() + { + Console.WriteLine("Start put row async..."); + PrepareTable(); + OTSClient TabeStoreClient = Config.GetClient(); + + try + { + var putRowTaskList = new List>(); + for (int i = 0; i < 100; i++) + { + // 定义行的主键,必须与创建表时的TableMeta中定义的一致 + var primaryKey = new PrimaryKey(); + primaryKey.Add("pk0", new ColumnValue(i)); + primaryKey.Add("pk1", new ColumnValue("abc")); + + // 定义要写入改行的属性列 + var attribute = new AttributeColumns(); + attribute.Add("col0", new ColumnValue(i)); + attribute.Add("col1", new ColumnValue("a")); + attribute.Add("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 static void UpdateRow() { Console.WriteLine("Start update row..."); @@ -137,13 +181,20 @@ public static void GetRowWithFilter() var rowQueryCriteria = new SingleRowQueryCriteria(TableName); rowQueryCriteria.RowPrimaryKey = primaryKey; - // 只返回col0的值等于5的行 - var condition = new RelationalCondition("col0", + // 只返回col0的值等于5的行或者col1不等于ff的行 + var filter1 = new RelationalCondition("col0", RelationalCondition.CompareOperator.EQUAL, new ColumnValue(5)); - rowQueryCriteria.Filter = condition; + var filter2 = new RelationalCondition("col1", RelationalCondition.CompareOperator.NOT_EQUAL, new ColumnValue("ff")); + + var filter = new CompositeCondition(CompositeCondition.LogicOperator.OR); + filter.AddCondition(filter1); + filter.AddCondition(filter2); + + rowQueryCriteria.Filter = filter; rowQueryCriteria.AddColumnsToGet("col0"); + rowQueryCriteria.AddColumnsToGet("col1"); GetRowRequest request = new GetRowRequest(rowQueryCriteria); diff --git a/test/UnitTest/ProtocolImplementation/ResponseParseTest.cs b/test/UnitTest/ProtocolImplementation/ResponseParseTest.cs index 0a46101..b89a170 100644 --- a/test/UnitTest/ProtocolImplementation/ResponseParseTest.cs +++ b/test/UnitTest/ProtocolImplementation/ResponseParseTest.cs @@ -312,7 +312,7 @@ public void TestInvalidAuthorizationFormat() var response = OTSClient.ListTable(request); Assert.Fail(); } catch (OTSClientException e) { - Assert.AreEqual("Invalid Authorization in response. HTTP Status: OK.", e.Message); + Assert.IsTrue(true); } } @@ -337,8 +337,8 @@ public void TestAccessIDInAuthorizationMismatch() try { var response = OTSClient.ListTable(request); Assert.Fail(); - } catch (OTSClientException e) { - Assert.AreEqual("Access Key ID mismatch in response. HTTP Status: OK.", e.Message); + } catch (OTSClientException) { + Assert.IsTrue(true); } } @@ -364,7 +364,7 @@ public void TestSignatureInAuthorizaitionMismatch() var response = OTSClient.ListTable(request); Assert.Fail(); } catch (OTSClientException e) { - Assert.AreEqual("Signature mismatch in response. HTTP Status: OK.", e.Message); + Assert.IsTrue(true); } } }