public void TestDisableErrorLog() { var clientConfig = new OTSClientConfig( TestEndPoint, TestAccessKeyID, TestAccessKeySecret, TestInstanceName) { OTSErrorLogHandler = null }; var otsClient = new OTSClient(clientConfig); var request = new DeleteTableRequest("blahblah"); try { otsClient.DeleteTable(request); Assert.Fail(); } catch (OTSServerException exception) { AssertOTSServerException(new OTSServerException( "/DeleteTable", HttpStatusCode.NotFound, "OTSObjectNotExist", "Requested table does not exist."), exception); } }
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); } }
public static OTSClient GetClient() { if (OtsClient != null) { return(OtsClient); } OTSClientConfig config = new OTSClientConfig(Endpoint, AccessKeyId, AccessKeySecret, InstanceName); config.OTSDebugLogHandler = null; config.OTSErrorLogHandler = null; OtsClient = new OTSClient(config); return(OtsClient); }
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); }
/// <summary> /// /// </summary> protected static void OnConfiguring(String instanceName, String accessKeyID, String accessKeySecret, String regionId) { var watch = Stopwatch.StartNew(); OtsConfig = new OTSClientConfig("https://" + instanceName + "." + regionId + ".ots.aliyuncs.com", accessKeyID, accessKeySecret, instanceName); try { var client = new OTSClient(OtsConfig); var resListTable = client.ListTable(new ListTableRequest()); foreach (var table in resListTable.TableNames) { var resDescribeTable = client.DescribeTable(new DescribeTableRequest(table)); if (resDescribeTable != null && resDescribeTable.TableMeta != null && resDescribeTable.TableMeta.PrimaryKeySchema != null) { tableKey.Add(table, resDescribeTable.TableMeta.PrimaryKeySchema); } } OtsConfig.OTSDebugLogHandler = null; OtsConfig.OTSErrorLogHandler = null; watch.Stop(); Console.WriteLine("Ots Init: " + watch.Elapsed); #region 尝试使用内网链接地址 try { #if !DEBUG System.Threading.Tasks.Task.Run(() => { var tmp = new OTSClientConfig("https://" + instanceName + "." + regionId + ".ots-internal.aliyuncs.com", accessKeyID, accessKeySecret, instanceName); var tmpListTable = new OTSClient(tmp).ListTable(new ListTableRequest()); foreach (var table in tmpListTable.TableNames) { OtsConfig = tmp; OtsConfig.OTSDebugLogHandler = null; OtsConfig.OTSErrorLogHandler = null; return; } }); #endif } catch { } #endregion } catch (Exception ex) { watch.Stop(); Console.WriteLine("Ots Init: " + ex.Message); } }
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); }
/// <summary> /// /// </summary> protected static void OnConfiguring(OTSClientConfig config) { var watch = Stopwatch.StartNew(); OtsConfig = config; OtsConfig.OTSDebugLogHandler = null; OtsConfig.OTSErrorLogHandler = null; var client = new OTSClient(config); var resListTable = client.ListTable(new ListTableRequest()); foreach (var table in resListTable.TableNames) { var resDescribeTable = client.DescribeTable(new DescribeTableRequest(table)); if (resDescribeTable != null && resDescribeTable.TableMeta != null && resDescribeTable.TableMeta.PrimaryKeySchema != null) { tableKey.Add(table, resDescribeTable.TableMeta.PrimaryKeySchema); } } watch.Stop(); Console.WriteLine("Ots Init: " + watch.Elapsed); }
public void Setup() { Thread.Sleep(1000); TestTableName = "SampleTestName"; var clientConfig = new OTSClientConfig( TestEndPoint, TestAccessKeyID, TestAccessKeySecret, TestInstanceName ); Console.WriteLine("Endpoint: {0}", TestEndPoint); Console.WriteLine("TestAccessKeyID: {0}", TestAccessKeyID); Console.WriteLine("TestAccessKeySecret: {0}", TestAccessKeySecret); Console.WriteLine("TestInstanceName: {0}", TestInstanceName); clientConfig.OTSDebugLogHandler = LogToFileHandler.DefaultDebugLogHandler; clientConfig.OTSErrorLogHandler = LogToFileHandler.DefaultErrorLogHandler; OTSClient = new OTSClient(clientConfig); OTSClientTestHelper.Reset(); foreach (var tableName in OTSClient.ListTable(new ListTableRequest()).TableNames) { OTSClient.DeleteTable(new DeleteTableRequest(tableName)); } PrimaryKeyWith4Columns = new PrimaryKey(); PrimaryKeyWith4Columns.Add("PK0", new ColumnValue("ABC")); PrimaryKeyWith4Columns.Add("PK1", new ColumnValue("DEF")); PrimaryKeyWith4Columns.Add("PK2", new ColumnValue(123)); PrimaryKeyWith4Columns.Add("PK3", new ColumnValue(456)); MinPrimaryKeyWith4Columns = new PrimaryKey(); MinPrimaryKeyWith4Columns.Add("PK0", ColumnValue.INF_MIN); MinPrimaryKeyWith4Columns.Add("PK1", new ColumnValue("DEF")); MinPrimaryKeyWith4Columns.Add("PK2", new ColumnValue(123)); MinPrimaryKeyWith4Columns.Add("PK3", new ColumnValue(456)); MaxPrimaryKeyWith4Columns = new PrimaryKey(); MaxPrimaryKeyWith4Columns.Add("PK0", ColumnValue.INF_MAX); MaxPrimaryKeyWith4Columns.Add("PK1", new ColumnValue("DEF")); MaxPrimaryKeyWith4Columns.Add("PK2", new ColumnValue(123)); MaxPrimaryKeyWith4Columns.Add("PK3", new ColumnValue(456)); AttributeWith5Columns = new AttributeColumns(); AttributeWith5Columns.Add("Col0", new ColumnValue("ABC")); AttributeWith5Columns.Add("Col1", new ColumnValue(123)); AttributeWith5Columns.Add("Col2", new ColumnValue(3.14)); AttributeWith5Columns.Add("Col3", new ColumnValue(true)); AttributeWith5Columns.Add("Col4", new ColumnValue(new byte[] { 0x20, 0x20 })); PrimaryKeyList = new List <PrimaryKey>(); AttributeColumnsList = new List <AttributeColumns>(); for (int i = 0; i < 1000; i++) { PrimaryKeyList.Add(GetPredefinedPrimaryKeyWith4PK(i)); AttributeColumnsList.Add(GetPredefinedAttributeWith5PK(i)); } }