From f417a8f33804448f2f2484cda747909deda56d61 Mon Sep 17 00:00:00 2001 From: XmasApple Date: Tue, 10 Oct 2023 14:04:59 +0300 Subject: [PATCH] Fix styles --- src/Ydb.Sdk/src/Services/Table/CreateTable.cs | 21 ++++++-- .../src/Services/Table/Shared/TableIndex.cs | 6 +-- src/Ydb.Sdk/src/Services/Table/Transaction.cs | 14 ++--- src/Ydb.Sdk/src/Value/YdbValueParser.cs | 2 +- .../tests/TableService/TestCopyTable.cs | 8 +++ .../tests/TableService/TestCreateTable.cs | 9 ++++ .../tests/TableService/TestDescribeTable.cs | 7 +++ .../TableService/TestDescribeTableOptions.cs | 6 +++ .../tests/TableService/TestDropTable.cs | 7 +++ .../tests/TableService/TestRenameTable.cs | 8 +++ .../tests/TableService/TestTransaction.cs | 53 +++++-------------- 11 files changed, 85 insertions(+), 56 deletions(-) diff --git a/src/Ydb.Sdk/src/Services/Table/CreateTable.cs b/src/Ydb.Sdk/src/Services/Table/CreateTable.cs index fbe4120c..01a7436f 100644 --- a/src/Ydb.Sdk/src/Services/Table/CreateTable.cs +++ b/src/Ydb.Sdk/src/Services/Table/CreateTable.cs @@ -79,8 +79,9 @@ internal ColumnFamilyPolicy(Ydb.Table.ColumnFamilyPolicy proto) }; } - internal Ydb.Table.ColumnFamilyPolicy GetProto() => - new() + internal Ydb.Table.ColumnFamilyPolicy GetProto() + { + return new Ydb.Table.ColumnFamilyPolicy { Compression = Compression switch { @@ -94,6 +95,7 @@ internal Ydb.Table.ColumnFamilyPolicy GetProto() => Data = Data.GetProto(), KeepInMemory = KeepInMemory.GetProto() }; + } } public class StoragePolicy @@ -197,6 +199,15 @@ public enum PartitionsCase ExplicitPartitions } + public PartitioningPolicy() + { + PresetName = ""; + AutoPartitioning = AutoPartitioningPolicy.Unspecified; + PartitionsType = PartitionsCase.None; + UniformPartitions = 0; + ExplicitPartitions = null; + } + public string PresetName { get; set; } public AutoPartitioningPolicy AutoPartitioning { get; set; } public PartitionsCase PartitionsType { get; set; } @@ -404,8 +415,9 @@ internal ColumnFamily(Ydb.Table.ColumnFamily proto) KeepInMemory = proto.KeepInMemory.FromProto(); } - internal Ydb.Table.ColumnFamily GetProto() => - new() + internal Ydb.Table.ColumnFamily GetProto() + { + return new Ydb.Table.ColumnFamily { Compression = Compression switch { @@ -418,6 +430,7 @@ internal Ydb.Table.ColumnFamily GetProto() => Data = Data.GetProto(), KeepInMemory = KeepInMemory.GetProto() }; + } } public class CreateTableSettings : OperationRequestSettings diff --git a/src/Ydb.Sdk/src/Services/Table/Shared/TableIndex.cs b/src/Ydb.Sdk/src/Services/Table/Shared/TableIndex.cs index c4dc3ba4..3e364e4b 100644 --- a/src/Ydb.Sdk/src/Services/Table/Shared/TableIndex.cs +++ b/src/Ydb.Sdk/src/Services/Table/Shared/TableIndex.cs @@ -13,14 +13,14 @@ public TableIndex(string name, IEnumerable columns, IndexType indexType { Name = name; Columns = columns.ToList(); - IndexType = IndexType; + IndexType = indexType; } public TableIndex(string name, string column, IndexType indexType = IndexType.None) { Name = name; Columns = new List { column }; - IndexType = IndexType; + IndexType = indexType; } public Ydb.Table.TableIndex GetProto() @@ -28,7 +28,7 @@ public Ydb.Table.TableIndex GetProto() var proto = new Ydb.Table.TableIndex { Name = Name, - IndexColumns = { Columns }, + IndexColumns = { Columns } }; switch (IndexType) { diff --git a/src/Ydb.Sdk/src/Services/Table/Transaction.cs b/src/Ydb.Sdk/src/Services/Table/Transaction.cs index ed07bd2e..94d7ebc7 100644 --- a/src/Ydb.Sdk/src/Services/Table/Transaction.cs +++ b/src/Ydb.Sdk/src/Services/Table/Transaction.cs @@ -1,5 +1,4 @@ -using System.Diagnostics.CodeAnalysis; -using Ydb.Sdk.Client; +using Ydb.Sdk.Client; using Ydb.Table; using Ydb.Table.V1; @@ -165,10 +164,6 @@ internal CommitTransactionResponse(Status status, ResultData? result = null) : b public class ResultData { - public ResultData() - { - } - internal static ResultData FromProto(CommitTransactionResult resultProto) { return new ResultData(); @@ -219,7 +214,8 @@ public async Task BeginTransaction(BeginTransactionSet } } - public async Task CommitTransaction(Transaction tx, CommitTransactionSettings? settings = null) + public async Task CommitTransaction(Transaction tx, + CommitTransactionSettings? settings = null) { CheckSession(); settings ??= new CommitTransactionSettings(); @@ -253,7 +249,8 @@ public async Task CommitTransaction(Transaction tx, C } } - public async Task RollbackTransaction(Transaction tx, RollbackTransactionSettings? settings = null) + public async Task RollbackTransaction(Transaction tx, + RollbackTransactionSettings? settings = null) { CheckSession(); settings ??= new RollbackTransactionSettings(); @@ -276,7 +273,6 @@ public async Task RollbackTransaction(Transaction t OnResponseStatus(status); return new RollbackTransactionResponse(status); - } catch (Driver.TransportException e) { diff --git a/src/Ydb.Sdk/src/Value/YdbValueParser.cs b/src/Ydb.Sdk/src/Value/YdbValueParser.cs index e55cfcda..3aa71023 100644 --- a/src/Ydb.Sdk/src/Value/YdbValueParser.cs +++ b/src/Ydb.Sdk/src/Value/YdbValueParser.cs @@ -319,7 +319,7 @@ private void EnsureTypeIs(Type type) public class InvalidTypeException : Exception { - internal InvalidTypeException(string expectedType, string actualType) + internal InvalidTypeException(string? expectedType, string? actualType) : base($"Invalid type of YDB value, expected: {expectedType}, actual: {actualType}.") { } diff --git a/src/Ydb.Sdk/tests/TableService/TestCopyTable.cs b/src/Ydb.Sdk/tests/TableService/TestCopyTable.cs index bd2e9ab8..e35b14ab 100644 --- a/src/Ydb.Sdk/tests/TableService/TestCopyTable.cs +++ b/src/Ydb.Sdk/tests/TableService/TestCopyTable.cs @@ -1,3 +1,5 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Xunit; using Xunit.Abstractions; using Ydb.Sdk.Services.Table; @@ -12,10 +14,14 @@ public class TestCopyTable : IDisposable private readonly Driver _driver; private readonly TableClient _tableClient; + private readonly ILogger _logger; public TestCopyTable(ITestOutputHelper output) { _output = output; + var loggerFactory = Utils.GetLoggerFactory() ?? NullLoggerFactory.Instance; + _logger = loggerFactory.CreateLogger(); + var driverConfig = new DriverConfig( endpoint: "grpc://localhost:2136", database: "/local" @@ -37,6 +43,7 @@ public void Dispose() [Fact] public async Task CopyTable() { + _logger.LogInformation($"TestStarted: {nameof(CopyTable)}"); var source = Guid.NewGuid().ToString("n"); var dest = Guid.NewGuid().ToString("n"); await Shared.CreateSimpleTable(_tableClient, source); @@ -51,6 +58,7 @@ public async Task CopyTable() [Fact] public async Task CopyTables() { + _logger.LogInformation($"TestStarted: {nameof(CopyTables)}"); var pairs = new List<(string, string)>(); for (var i = 0; i < 5; i++) { diff --git a/src/Ydb.Sdk/tests/TableService/TestCreateTable.cs b/src/Ydb.Sdk/tests/TableService/TestCreateTable.cs index 9d48a850..5e3ba9aa 100644 --- a/src/Ydb.Sdk/tests/TableService/TestCreateTable.cs +++ b/src/Ydb.Sdk/tests/TableService/TestCreateTable.cs @@ -1,3 +1,5 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Xunit; using Xunit.Abstractions; using Ydb.Sdk.Services.Table; @@ -13,10 +15,13 @@ public class TestCreateTable : IDisposable private readonly Driver _driver; private readonly TableClient _tableClient; + private readonly ILogger _logger; public TestCreateTable(ITestOutputHelper output) { _output = output; + var loggerFactory = Utils.GetLoggerFactory() ?? NullLoggerFactory.Instance; + _logger = loggerFactory.CreateLogger(); var driverConfig = new DriverConfig( endpoint: "grpc://localhost:2136", database: "/local" @@ -38,6 +43,7 @@ public void Dispose() [Fact] public async Task CreateWithoutColumns() { + _logger.LogInformation($"TestStarted: {nameof(CreateWithoutColumns)}"); var tablePath = Guid.NewGuid().ToString("n"); var response = await _tableClient.CreateTable(tablePath); Assert.Equal(StatusCode.BadRequest, response.Status.StatusCode); @@ -46,6 +52,7 @@ public async Task CreateWithoutColumns() [Fact] public async Task CreateWithColumns() { + _logger.LogInformation($"TestStarted: {nameof(CreateWithColumns)}"); var tablePath = Guid.NewGuid().ToString("n"); var settings = new CreateTableSettings() .WithColumn(new ColumnMeta("a", YdbValue.Uint64Type)); @@ -57,6 +64,7 @@ public async Task CreateWithColumns() [Fact] public async Task CreateWithWrongPrimaryKey() { + _logger.LogInformation($"TestStarted: {nameof(CreateWithWrongPrimaryKey)}"); var tablePath = Guid.NewGuid().ToString("n"); var settings = new CreateTableSettings() .WithColumn(new ColumnMeta("a", YdbValue.Uint64Type)) @@ -69,6 +77,7 @@ public async Task CreateWithWrongPrimaryKey() [Fact] public async Task CreateWithPrimaryKey() { + _logger.LogInformation($"TestStarted: {nameof(CreateWithPrimaryKey)}"); var tablePath = Guid.NewGuid().ToString("n"); var settings = new CreateTableSettings() .WithColumn(new ColumnMeta("a", YdbValue.Uint64Type)) diff --git a/src/Ydb.Sdk/tests/TableService/TestDescribeTable.cs b/src/Ydb.Sdk/tests/TableService/TestDescribeTable.cs index 1a121e31..90611386 100644 --- a/src/Ydb.Sdk/tests/TableService/TestDescribeTable.cs +++ b/src/Ydb.Sdk/tests/TableService/TestDescribeTable.cs @@ -1,3 +1,5 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Xunit; using Xunit.Abstractions; using Ydb.Sdk.Services.Table; @@ -12,10 +14,13 @@ public class TestDescribeTable : IDisposable private readonly Driver _driver; private readonly TableClient _tableClient; + private readonly ILogger _logger; public TestDescribeTable(ITestOutputHelper output) { _output = output; + var loggerFactory = Utils.GetLoggerFactory() ?? NullLoggerFactory.Instance; + _logger = loggerFactory.CreateLogger(); var driverConfig = new DriverConfig( endpoint: "grpc://localhost:2136", database: "/local" @@ -38,6 +43,7 @@ public void Dispose() [Fact] public async Task DescribeNotExisting() { + _logger.LogInformation($"TestStarted: {nameof(DescribeNotExisting)}"); var response = await _tableClient.DescribeTable("/local/not_exists"); Assert.Equal(StatusCode.SchemeError, response.Status.StatusCode); } @@ -46,6 +52,7 @@ public async Task DescribeNotExisting() [Fact] public async Task CreateAndDescribe() { + _logger.LogInformation($"TestStarted: {nameof(CreateAndDescribe)}"); var tablePath = Guid.NewGuid().ToString("n"); const string columnName = "columnName"; diff --git a/src/Ydb.Sdk/tests/TableService/TestDescribeTableOptions.cs b/src/Ydb.Sdk/tests/TableService/TestDescribeTableOptions.cs index 2a3d5d3b..1615fc35 100644 --- a/src/Ydb.Sdk/tests/TableService/TestDescribeTableOptions.cs +++ b/src/Ydb.Sdk/tests/TableService/TestDescribeTableOptions.cs @@ -1,3 +1,5 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Xunit; using Xunit.Abstractions; using Ydb.Sdk.Services.Table; @@ -12,10 +14,13 @@ public class TestDescribeTableOptions : IDisposable private readonly Driver _driver; private readonly TableClient _tableClient; + private readonly ILogger _logger; public TestDescribeTableOptions(ITestOutputHelper output) { _output = output; + var loggerFactory = Utils.GetLoggerFactory() ?? NullLoggerFactory.Instance; + _logger = loggerFactory.CreateLogger(); var driverConfig = new DriverConfig( endpoint: "grpc://localhost:2136", database: "/local" @@ -38,6 +43,7 @@ public void Dispose() [Fact] public async Task DescribeTableOptions() { + _logger.LogInformation($"TestStarted: {nameof(DescribeTableOptions)}"); var response = await _tableClient.DescribeTableOptions(); response.Status.EnsureSuccess(); } diff --git a/src/Ydb.Sdk/tests/TableService/TestDropTable.cs b/src/Ydb.Sdk/tests/TableService/TestDropTable.cs index 424f158e..c2191630 100644 --- a/src/Ydb.Sdk/tests/TableService/TestDropTable.cs +++ b/src/Ydb.Sdk/tests/TableService/TestDropTable.cs @@ -1,3 +1,5 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Xunit; using Xunit.Abstractions; using Ydb.Sdk.Services.Table; @@ -12,10 +14,13 @@ public class TestDropTable : IDisposable private readonly Driver _driver; private readonly TableClient _tableClient; + private readonly ILogger _logger; public TestDropTable(ITestOutputHelper output) { _output = output; + var loggerFactory = Utils.GetLoggerFactory() ?? NullLoggerFactory.Instance; + _logger = loggerFactory.CreateLogger(); var driverConfig = new DriverConfig( endpoint: "grpc://localhost:2136", database: "/local" @@ -37,6 +42,7 @@ public void Dispose() [Fact] public async Task DropNotExisting() { + _logger.LogInformation($"TestStarted: {nameof(DropNotExisting)}"); var response = await _tableClient.DropTable("/local/not_exists"); Assert.Equal(StatusCode.SchemeError, response.Status.StatusCode); } @@ -44,6 +50,7 @@ public async Task DropNotExisting() [Fact] public async Task CreateAndDrop() { + _logger.LogInformation($"TestStarted: {nameof(CreateAndDrop)}"); var tablePath = Guid.NewGuid().ToString("n"); await Shared.CreateSimpleTable(_tableClient, tablePath); diff --git a/src/Ydb.Sdk/tests/TableService/TestRenameTable.cs b/src/Ydb.Sdk/tests/TableService/TestRenameTable.cs index 72ae5972..8e46c10f 100644 --- a/src/Ydb.Sdk/tests/TableService/TestRenameTable.cs +++ b/src/Ydb.Sdk/tests/TableService/TestRenameTable.cs @@ -1,3 +1,5 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Xunit; using Xunit.Abstractions; using Ydb.Sdk.Services.Table; @@ -12,10 +14,14 @@ public class TestRenameTable : IDisposable private readonly Driver _driver; private readonly TableClient _tableClient; + private readonly ILogger _logger; public TestRenameTable(ITestOutputHelper output) { _output = output; + var loggerFactory = Utils.GetLoggerFactory() ?? NullLoggerFactory.Instance; + _logger = loggerFactory.CreateLogger(); + var driverConfig = new DriverConfig( endpoint: "grpc://localhost:2136", database: "/local" @@ -37,6 +43,7 @@ public void Dispose() [Fact] public async Task RenameNotExisting() { + _logger.LogInformation($"TestStarted: {nameof(RenameNotExisting)}"); var settings = new RenameTablesSettings().WithItem("notexists", "new", false); var response = await _tableClient.RenameTable(settings); Assert.Equal(StatusCode.SchemeError, response.Status.StatusCode); @@ -45,6 +52,7 @@ public async Task RenameNotExisting() [Fact] public async Task Rename() { + _logger.LogInformation($"TestStarted: {nameof(Rename)}"); var sourcePath = Guid.NewGuid().ToString("n"); var destPath = Guid.NewGuid().ToString("n"); diff --git a/src/Ydb.Sdk/tests/TableService/TestTransaction.cs b/src/Ydb.Sdk/tests/TableService/TestTransaction.cs index 5935e4b2..c071e8a4 100644 --- a/src/Ydb.Sdk/tests/TableService/TestTransaction.cs +++ b/src/Ydb.Sdk/tests/TableService/TestTransaction.cs @@ -1,21 +1,25 @@ +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Xunit; using Xunit.Abstractions; using Ydb.Sdk.Services.Table; -using Ydb.Sdk.Value; namespace Ydb.Sdk.Tests.TableService; -public class TestTransaction +public class TestTransaction : IDisposable { // ReSharper disable once NotAccessedField.Local private readonly ITestOutputHelper _output; private readonly Driver _driver; private readonly TableClient _tableClient; + private readonly ILogger _logger; public TestTransaction(ITestOutputHelper output) { _output = output; + var loggerFactory = Utils.GetLoggerFactory() ?? NullLoggerFactory.Instance; + _logger = loggerFactory.CreateLogger(); var driverConfig = new DriverConfig( endpoint: "grpc://localhost:2136", database: "/local" @@ -27,47 +31,17 @@ public TestTransaction(ITestOutputHelper output) _tableClient = new TableClient(_driver); } - // [Fact] - // public async Task TxCheck() - // { - // var tablePath = $"t{Guid.NewGuid():n}"; - // _output.WriteLine($"table {tablePath}"); - // await Shared.CreateSimpleTable(_tableClient, tablePath); - // - // var resonse = await _tableClient.SessionExec(async session => - // { - // var val = (ulong)new Random().Next(int.MaxValue); - // _output.WriteLine($"val: {val}"); - // for (var i = 0; i < 9; i++) - // { - // var r = await session.ExecuteDataQuery( - // query: $"UPSERT INTO {tablePath} ( a ) VALUES ($val)", - // txControl: TxControl.BeginSerializableRW(), - // parameters: new Dictionary - // { - // { "$val", YdbValue.MakeUint64(val) } - // }); - // r.Status.EnsureSuccess(); - // } - // - // var r2 = await session.ExecuteDataQuery( - // query: $"UPSERT INTO {tablePath} ( a ) VALUES ($val)", - // txControl: TxControl.BeginSerializableRW().Commit(), - // parameters: new Dictionary - // { - // { "$val", YdbValue.MakeUint64(val + 1) } - // } - // ); - // r2.Status.EnsureSuccess(); - // - // return r2; - // } - // ); - // } + public void Dispose() + { + _tableClient.Dispose(); + _driver.Dispose(); + GC.SuppressFinalize(this); + } [Fact] public async Task TestBeginCommit() { + _logger.LogInformation($"TestStarted: {nameof(TestBeginCommit)}"); var tablePath = $"t{Guid.NewGuid():n}"; const string columnName = "columnName"; await Shared.CreateSimpleTable(_tableClient, tablePath, columnName); @@ -117,6 +91,7 @@ await _tableClient.SessionExec(async session => [Fact] public async Task TestBeginRollback() { + _logger.LogInformation($"TestStarted: {nameof(TestBeginCommit)}"); var tablePath = $"t{Guid.NewGuid():n}"; const string columnName = "columnName"; await Shared.CreateSimpleTable(_tableClient, tablePath, columnName);