Skip to content

Commit

Permalink
Fix styles
Browse files Browse the repository at this point in the history
  • Loading branch information
XmasApple committed Oct 10, 2023
1 parent c81eee0 commit f417a8f
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 56 deletions.
21 changes: 17 additions & 4 deletions src/Ydb.Sdk/src/Services/Table/CreateTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -94,6 +95,7 @@ internal Ydb.Table.ColumnFamilyPolicy GetProto() =>
Data = Data.GetProto(),
KeepInMemory = KeepInMemory.GetProto()
};
}
}

public class StoragePolicy
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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
{
Expand All @@ -418,6 +430,7 @@ internal Ydb.Table.ColumnFamily GetProto() =>
Data = Data.GetProto(),
KeepInMemory = KeepInMemory.GetProto()
};
}
}

public class CreateTableSettings : OperationRequestSettings
Expand Down
6 changes: 3 additions & 3 deletions src/Ydb.Sdk/src/Services/Table/Shared/TableIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ public TableIndex(string name, IEnumerable<string> 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<string> { column };
IndexType = IndexType;
IndexType = indexType;
}

public Ydb.Table.TableIndex GetProto()
{
var proto = new Ydb.Table.TableIndex
{
Name = Name,
IndexColumns = { Columns },
IndexColumns = { Columns }
};
switch (IndexType)
{
Expand Down
14 changes: 5 additions & 9 deletions src/Ydb.Sdk/src/Services/Table/Transaction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Ydb.Sdk.Client;
using Ydb.Sdk.Client;
using Ydb.Table;
using Ydb.Table.V1;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -219,7 +214,8 @@ public async Task<BeginTransactionResponse> BeginTransaction(BeginTransactionSet
}
}

public async Task<CommitTransactionResponse> CommitTransaction(Transaction tx, CommitTransactionSettings? settings = null)
public async Task<CommitTransactionResponse> CommitTransaction(Transaction tx,
CommitTransactionSettings? settings = null)
{
CheckSession();
settings ??= new CommitTransactionSettings();
Expand Down Expand Up @@ -253,7 +249,8 @@ public async Task<CommitTransactionResponse> CommitTransaction(Transaction tx, C
}
}

public async Task<RollbackTransactionResponse> RollbackTransaction(Transaction tx, RollbackTransactionSettings? settings = null)
public async Task<RollbackTransactionResponse> RollbackTransaction(Transaction tx,
RollbackTransactionSettings? settings = null)
{
CheckSession();
settings ??= new RollbackTransactionSettings();
Expand All @@ -276,7 +273,6 @@ public async Task<RollbackTransactionResponse> RollbackTransaction(Transaction t
OnResponseStatus(status);

return new RollbackTransactionResponse(status);

}
catch (Driver.TransportException e)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Ydb.Sdk/src/Value/YdbValueParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}.")
{
}
Expand Down
8 changes: 8 additions & 0 deletions src/Ydb.Sdk/tests/TableService/TestCopyTable.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;
using Xunit.Abstractions;
using Ydb.Sdk.Services.Table;
Expand All @@ -12,10 +14,14 @@ public class TestCopyTable : IDisposable

private readonly Driver _driver;
private readonly TableClient _tableClient;
private readonly ILogger<TestCopyTable> _logger;

public TestCopyTable(ITestOutputHelper output)
{
_output = output;
var loggerFactory = Utils.GetLoggerFactory() ?? NullLoggerFactory.Instance;
_logger = loggerFactory.CreateLogger<TestCopyTable>();

var driverConfig = new DriverConfig(
endpoint: "grpc://localhost:2136",
database: "/local"
Expand All @@ -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);
Expand All @@ -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++)
{
Expand Down
9 changes: 9 additions & 0 deletions src/Ydb.Sdk/tests/TableService/TestCreateTable.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;
using Xunit.Abstractions;
using Ydb.Sdk.Services.Table;
Expand All @@ -13,10 +15,13 @@ public class TestCreateTable : IDisposable

private readonly Driver _driver;
private readonly TableClient _tableClient;
private readonly ILogger<TestCreateTable> _logger;

public TestCreateTable(ITestOutputHelper output)
{
_output = output;
var loggerFactory = Utils.GetLoggerFactory() ?? NullLoggerFactory.Instance;
_logger = loggerFactory.CreateLogger<TestCreateTable>();
var driverConfig = new DriverConfig(
endpoint: "grpc://localhost:2136",
database: "/local"
Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -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))
Expand All @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions src/Ydb.Sdk/tests/TableService/TestDescribeTable.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;
using Xunit.Abstractions;
using Ydb.Sdk.Services.Table;
Expand All @@ -12,10 +14,13 @@ public class TestDescribeTable : IDisposable

private readonly Driver _driver;
private readonly TableClient _tableClient;
private readonly ILogger<TestDescribeTable> _logger;

public TestDescribeTable(ITestOutputHelper output)
{
_output = output;
var loggerFactory = Utils.GetLoggerFactory() ?? NullLoggerFactory.Instance;
_logger = loggerFactory.CreateLogger<TestDescribeTable>();
var driverConfig = new DriverConfig(
endpoint: "grpc://localhost:2136",
database: "/local"
Expand All @@ -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);
}
Expand All @@ -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";

Expand Down
6 changes: 6 additions & 0 deletions src/Ydb.Sdk/tests/TableService/TestDescribeTableOptions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;
using Xunit.Abstractions;
using Ydb.Sdk.Services.Table;
Expand All @@ -12,10 +14,13 @@ public class TestDescribeTableOptions : IDisposable

private readonly Driver _driver;
private readonly TableClient _tableClient;
private readonly ILogger<TestDescribeTableOptions> _logger;

public TestDescribeTableOptions(ITestOutputHelper output)
{
_output = output;
var loggerFactory = Utils.GetLoggerFactory() ?? NullLoggerFactory.Instance;
_logger = loggerFactory.CreateLogger<TestDescribeTableOptions>();
var driverConfig = new DriverConfig(
endpoint: "grpc://localhost:2136",
database: "/local"
Expand All @@ -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();
}
Expand Down
7 changes: 7 additions & 0 deletions src/Ydb.Sdk/tests/TableService/TestDropTable.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;
using Xunit.Abstractions;
using Ydb.Sdk.Services.Table;
Expand All @@ -12,10 +14,13 @@ public class TestDropTable : IDisposable

private readonly Driver _driver;
private readonly TableClient _tableClient;
private readonly ILogger<TestDropTable> _logger;

public TestDropTable(ITestOutputHelper output)
{
_output = output;
var loggerFactory = Utils.GetLoggerFactory() ?? NullLoggerFactory.Instance;
_logger = loggerFactory.CreateLogger<TestDropTable>();
var driverConfig = new DriverConfig(
endpoint: "grpc://localhost:2136",
database: "/local"
Expand All @@ -37,13 +42,15 @@ 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);
}

[Fact]
public async Task CreateAndDrop()
{
_logger.LogInformation($"TestStarted: {nameof(CreateAndDrop)}");
var tablePath = Guid.NewGuid().ToString("n");

await Shared.CreateSimpleTable(_tableClient, tablePath);
Expand Down
8 changes: 8 additions & 0 deletions src/Ydb.Sdk/tests/TableService/TestRenameTable.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Xunit;
using Xunit.Abstractions;
using Ydb.Sdk.Services.Table;
Expand All @@ -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<TestRenameTable>();

var driverConfig = new DriverConfig(
endpoint: "grpc://localhost:2136",
database: "/local"
Expand All @@ -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);
Expand All @@ -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");

Expand Down
Loading

0 comments on commit f417a8f

Please sign in to comment.