Skip to content

Commit

Permalink
Start refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vplauzon committed Oct 24, 2023
1 parent 869ca36 commit eaca923
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 15 deletions.
14 changes: 2 additions & 12 deletions code/DeltaKustoAdxIntegrationTest/AdxDbTestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@ public async Task<IImmutableList<string>> GetDbsAsync(int dbCount)
}
}

public void ReleaseDbs(IEnumerable<string> dbNames)
{
_availableDbNames.AddRange(dbNames);
}

public async Task CleanDbAsync(string dbName)
{
var kustoGateway = _kustoManagementGatewayFactory(dbName);
Expand All @@ -140,20 +135,15 @@ public async Task CleanDbAsync(string dbName)
await kustoGateway.ExecuteCommandsAsync(cleanCommands);
}

public Task<DbNameHolder> GetCleanDbAsync()
public void ReleaseDbs(IEnumerable<string> dbNames)
{
throw new NotImplementedException();
_availableDbNames.AddRange(dbNames);
}

void IDisposable.Dispose()
{
}

private void ReleaseDb(string dbName)
{
throw new NotImplementedException();
}

private string DbNumberToDbName(int c)
{
return $"{_dbPrefix}{c:D8}";
Expand Down
56 changes: 53 additions & 3 deletions code/DeltaKustoAdxIntegrationTest/AdxIntegrationTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ namespace DeltaKustoAdxIntegrationTest
{
public abstract class AdxIntegrationTestBase : IntegrationTestBase
{
#region Inner Types
private record TestCase(string FromFile, string ToFile, bool UsePluralForms);
#endregion

private readonly bool _overrideLoginTokenProvider;

protected AdxIntegrationTestBase(bool overrideLoginTokenProvider = true)
Expand Down Expand Up @@ -73,11 +77,24 @@ protected AdxIntegrationTestBase(bool overrideLoginTokenProvider = true)

protected IKustoManagementGatewayFactory KustoGatewayFactory { get; }

protected static async Task<DbNameHolder> InitializeDbAsync()
protected static Task<DbNameHolder> InitializeDbAsync()
{
throw new NotImplementedException();
}

protected async Task<IImmutableList<string>> GetDbsAsync(int dbCount)
{
return await AdxDbTestHelper.Instance.GetDbsAsync(dbCount);
}

protected async Task CleanDbAsync(string dbName)
{
var dbNameHolder = await AdxDbTestHelper.Instance.GetCleanDbAsync();
await AdxDbTestHelper.Instance.CleanDbAsync(dbName);
}

return dbNameHolder;
public void ReleaseDbs(IEnumerable<string> dbNames)
{
AdxDbTestHelper.Instance.ReleaseDbs(dbNames);
}

protected async Task TestAdxToFile(string statesFolderPath)
Expand Down Expand Up @@ -180,6 +197,24 @@ await ApplyCommandsAsync(

protected async Task TestAdxToAdx(string statesFolderPath)
{
var testCases = CreateTestCases(Path.Combine(statesFolderPath, "States"));
var dbNames = await GetDbsAsync(2 * testCases.Count);
var currentDbNames = dbNames.Take(testCases.Count).ToImmutableArray();
var targetDbNames = dbNames.Take(testCases.Count).ToImmutableArray();
Func<int, Task> prepareDbs = async i =>
{
await Task.WhenAll(
CleanDbAsync(currentDbNames[i]),
CleanDbAsync(targetDbNames[i]));
await Task.WhenAll(
PrepareDbAsync(testCases[i].FromFile, currentDbNames[i]),
PrepareDbAsync(testCases[i].ToFile, targetDbNames[i]));
};
var prepareDbTasks = Enumerable.Range(0, testCases.Count)
.Select(i => prepareDbs(i))
.ToImmutableArray();

await Task.WhenAll(prepareDbTasks);
await LoopThroughStateFilesAsync(
Path.Combine(statesFolderPath, "States"),
async (fromFile, toFile, usePluralForms) =>
Expand Down Expand Up @@ -243,6 +278,21 @@ await loopFunction(
}
}

private static IImmutableList<TestCase> CreateTestCases(string folderPath)
{
var stateFiles = Directory.GetFiles(folderPath);
var usePluralFormsSet = ImmutableArray<bool>.Empty.Add(true).Add(false);
var testCases = stateFiles
.SelectMany(fromFile => stateFiles.Select(toFile => (fromFile, toFile)))
.SelectMany(pair => usePluralFormsSet.Select(b => new TestCase(
pair.fromFile,
pair.toFile,
b)))
.ToImmutableArray();

return testCases;
}

private async Task ApplyCommandsAsync(IEnumerable<CommandBase> commands, string dbName)
{
var gateway = KustoGatewayFactory.CreateGateway(ClusterUri, dbName);
Expand Down

0 comments on commit eaca923

Please sign in to comment.