Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task SysbenchClientExecutorRunsTheExpectedWorkloadCommand()
{
SetupDefaultBehavior();

string expectedCommand = @$"python3 {this.mockPackagePath}/run-workload.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --tableCount 10 --recordCount 1000 --threadCount 8 --workload oltp_read_write --hostIpAddress 1.2.3.5 --durationSecs 10 --password [A-Za-z0-9+/=]+";
string expectedCommand = @$"python3 {this.mockPackagePath}/run-workload.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --threadCount 8 --tableCount 10 --recordCount 1000 --workload oltp_read_write --hostIpAddress 1.2.3.5 --durationSecs 10 --password [A-Za-z0-9+/=]+";
bool commandExecuted = false;

this.fixture.ProcessManager.OnCreateProcess = (exe, arguments, workingDir) =>
Expand Down Expand Up @@ -136,7 +136,7 @@ public async Task SysbenchClientExecutorUsesDefinedParametersWhenRunningTheWorkl
this.fixture.Parameters[nameof(SysbenchClientExecutor.TableCount)] = "40";
this.fixture.Parameters[nameof(SysbenchClientExecutor.DatabaseScenario)] = "Configure";

string expectedCommand = @$"python3 {this.mockPackagePath}/run-workload.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --tableCount 40 --recordCount 1000 --threadCount 64 --workload oltp_read_write --hostIpAddress 1.2.3.5 --durationSecs 10 --password [A-Za-z0-9+/=]+";
string expectedCommand = @$"python3 {this.mockPackagePath}/run-workload.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --threadCount 64 --tableCount 40 --recordCount 1000 --workload oltp_read_write --hostIpAddress 1.2.3.5 --durationSecs 10 --password [A-Za-z0-9+/=]+";
bool commandExecuted = false;

this.fixture.ProcessManager.OnCreateProcess = (exe, arguments, workingDir) =>
Expand Down Expand Up @@ -179,7 +179,7 @@ public async Task SysbenchClientExecutorRunsTheExpectedBalancedScenario()

this.fixture.Parameters[nameof(SysbenchClientExecutor.DatabaseScenario)] = "Balanced";

string expectedCommand = $"python3 {this.mockPackagePath}/run-workload.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --tableCount 10 --recordCount 1000 --threadCount 8 --workload oltp_read_write --hostIpAddress 1.2.3.5 --durationSecs 10 --password [A-Za-z0-9+/=]+";
string expectedCommand = $"python3 {this.mockPackagePath}/run-workload.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --threadCount 8 --tableCount 10 --recordCount 1000 --workload oltp_read_write --hostIpAddress 1.2.3.5 --durationSecs 10 --password [A-Za-z0-9+/=]+";
bool commandExecuted = false;

this.fixture.ProcessManager.OnCreateProcess = (exe, arguments, workingDir) =>
Expand Down Expand Up @@ -222,7 +222,7 @@ public async Task SysbenchClientExecutorRunsInMemoryScenario()

this.fixture.Parameters[nameof(SysbenchClientExecutor.DatabaseScenario)] = "InMemory";

string expectedCommand = $"python3 {this.mockPackagePath}/run-workload.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --tableCount 10 --recordCount 100000 --threadCount 8 --workload oltp_read_write --hostIpAddress 1.2.3.5 --durationSecs 10 --password [A-Za-z0-9+/=]+";
string expectedCommand = $"python3 {this.mockPackagePath}/run-workload.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --threadCount 8 --tableCount 10 --recordCount 100000 --workload oltp_read_write --hostIpAddress 1.2.3.5 --durationSecs 10 --password [A-Za-z0-9+/=]+";
bool commandExecuted = false;

this.fixture.ProcessManager.OnCreateProcess = (exe, arguments, workingDir) =>
Expand Down Expand Up @@ -264,8 +264,9 @@ public async Task SysbenchClientExecutorRunsTheExpectedTPCCWorkloadCommand()
SetupDefaultBehavior();

this.fixture.Parameters[nameof(SysbenchClientExecutor.Benchmark)] = "TPCC";
this.fixture.Parameters[nameof(SysbenchClientExecutor.Workload)] = "tpcc";

string expectedCommand = $"python3 {this.mockPackagePath}/run-workload.py --dbName sbtest --databaseSystem MySQL --benchmark TPCC --tableCount 10 --warehouses 100 --threadCount 8 --workload tpcc --hostIpAddress 1.2.3.5 --durationSecs 10 --password [A-Za-z0-9+/=]+";
string expectedCommand = $"python3 {this.mockPackagePath}/run-workload.py --dbName sbtest --databaseSystem MySQL --benchmark TPCC --threadCount 8 --tableCount 10 --warehouses 100 --workload tpcc --hostIpAddress 1.2.3.5 --durationSecs 10 --password [A-Za-z0-9+/=]+";
bool commandExecuted = false;

this.fixture.ProcessManager.OnCreateProcess = (exe, arguments, workingDir) =>
Expand Down Expand Up @@ -308,7 +309,7 @@ public async Task SysbenchClientExecutorRunsTheExpectedPostgreSQLOLTPWorkloadCom

this.fixture.Parameters[nameof(SysbenchClientExecutor.DatabaseSystem)] = "PostgreSQL";

string expectedCommand = $"python3 {this.mockPackagePath}/run-workload.py --dbName sbtest --databaseSystem PostgreSQL --benchmark OLTP --tableCount 10 --recordCount 1000 --threadCount 8 --workload oltp_read_write --hostIpAddress 1.2.3.5 --durationSecs 10 --password [A-Za-z0-9+/=]+";
string expectedCommand = $"python3 {this.mockPackagePath}/run-workload.py --dbName sbtest --databaseSystem PostgreSQL --benchmark OLTP --threadCount 8 --tableCount 10 --recordCount 1000 --workload oltp_read_write --hostIpAddress 1.2.3.5 --durationSecs 10 --password [A-Za-z0-9+/=]+";
bool commandExecuted = false;

this.fixture.ProcessManager.OnCreateProcess = (exe, arguments, workingDir) =>
Expand Down Expand Up @@ -351,8 +352,9 @@ public async Task SysbenchClientExecutorRunsTheExpectedPostgreSQLTPCCWorkloadCom

this.fixture.Parameters[nameof(SysbenchClientExecutor.DatabaseSystem)] = "PostgreSQL";
this.fixture.Parameters[nameof(SysbenchClientExecutor.Benchmark)] = "TPCC";
this.fixture.Parameters[nameof(SysbenchClientExecutor.Workload)] = "tpcc";

string expectedCommand = $"python3 {this.mockPackagePath}/run-workload.py --dbName sbtest --databaseSystem PostgreSQL --benchmark TPCC --tableCount 10 --warehouses 100 --threadCount 8 --workload tpcc --hostIpAddress 1.2.3.5 --durationSecs 10 --password [A-Za-z0-9+/=]+";
string expectedCommand = $"python3 {this.mockPackagePath}/run-workload.py --dbName sbtest --databaseSystem PostgreSQL --benchmark TPCC --threadCount 8 --tableCount 10 --warehouses 100 --workload tpcc --hostIpAddress 1.2.3.5 --durationSecs 10 --password [A-Za-z0-9+/=]+";
bool commandExecuted = false;

this.fixture.ProcessManager.OnCreateProcess = (exe, arguments, workingDir) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void SetupDefaultBehavior()
this.fixture.Parameters = new Dictionary<string, IConvertible>()
{
{ nameof(SysbenchConfiguration.DatabaseSystem), "MySQL" },
{ nameof(SysbenchConfiguration.Action), "PopulateTables" },
{ nameof(SysbenchConfiguration.Benchmark), "OLTP" },
{ nameof(SysbenchConfiguration.DatabaseName), "sbtest" },
{ nameof(SysbenchConfiguration.PackageName), "sysbench" },
Expand Down Expand Up @@ -77,7 +78,7 @@ public async Task SysbenchConfigurationSkipsSysbenchInitialization()

string[] expectedCommands =
{
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --tableCount 10 --recordCount 1000 --threadCount 8 --password [A-Za-z0-9+/=]+",
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --threadCount 8 --tableCount 10 --recordCount 1000 --password [A-Za-z0-9+/=]+ --host \"1.2.3.5\"",
};

int commandNumber = 0;
Expand Down Expand Up @@ -122,7 +123,7 @@ public async Task SysbenchConfigurationPreparesDatabase()
string[] expectedCommands =
{
$"python3 {this.mockPackagePath}/configure-workload-generator.py --distro Ubuntu --databaseSystem MySQL --packagePath {this.mockPackagePath}",
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --tableCount 10 --recordCount 1000 --threadCount 8 --password [A-Za-z0-9+/=]+",
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --threadCount 8 --tableCount 10 --recordCount 1000 --password [A-Za-z0-9+/=]+",
};

int commandNumber = 0;
Expand Down Expand Up @@ -173,7 +174,7 @@ public async Task SysbenchConfigurationUsesDefinedParametersWhenRunningTheWorklo
string[] expectedCommands =
{
$"python3 {this.mockPackagePath}/configure-workload-generator.py --distro Ubuntu --databaseSystem MySQL --packagePath {this.mockPackagePath}",
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --tableCount 40 --recordCount 1000 --threadCount 16 --password [A-Za-z0-9+/=]+",
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark OLTP --threadCount 16 --tableCount 40 --recordCount 1000 --password [A-Za-z0-9+/=]+",
};

int commandNumber = 0;
Expand Down Expand Up @@ -213,7 +214,7 @@ public async Task SysbenchConfigurationUsesDefinedParametersWhenRunningTheWorklo
}

[Test]
public async Task SysbenchConfigurationSkipsDatabasePopulationWhenInitialized()
public void SysbenchConfigurationThrowsErrorWhenDatabasePopulated()
{
this.fixture.StateManager.OnGetState().ReturnsAsync(JObject.FromObject(new SysbenchExecutor.SysbenchState()
{
Expand Down Expand Up @@ -258,7 +259,8 @@ public async Task SysbenchConfigurationSkipsDatabasePopulationWhenInitialized()

using (TestSysbenchConfiguration SysbenchExecutor = new TestSysbenchConfiguration(this.fixture.Dependencies, this.fixture.Parameters))
{
await SysbenchExecutor.ExecuteAsync(CancellationToken.None).ConfigureAwait(false);
DependencyException error = Assert.ThrowsAsync<DependencyException>(() => SysbenchExecutor.ExecuteAsync(CancellationToken.None));
Assert.IsTrue(error.Reason == ErrorReason.NotSupported);
}
}

Expand All @@ -274,7 +276,7 @@ public async Task SysbenchConfigurationProperlyExecutesTPCCPreparation()

string[] expectedCommands =
{
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark TPCC --tableCount 10 --warehouses 100 --threadCount 8 --password [A-Za-z0-9+/=]+"
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark TPCC --threadCount 8 --tableCount 10 --warehouses 100 --password [A-Za-z0-9+/=]+ --host \"1.2.3.5\""
};

int commandNumber = 0;
Expand Down Expand Up @@ -330,7 +332,7 @@ public async Task SysbenchConfigurationProperlyExecutesTPCCConfigurablePreparati

string[] expectedCommands =
{
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark TPCC --tableCount 40 --warehouses 1000 --threadCount 16 --password [A-Za-z0-9+/=]+"
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem MySQL --benchmark TPCC --threadCount 16 --tableCount 40 --warehouses 1000 --password [A-Za-z0-9+/=]+ --host \"1.2.3.5\""
};

int commandNumber = 0;
Expand Down Expand Up @@ -386,7 +388,7 @@ public async Task SysbenchConfigurationProperlyExecutesPostgreSQLOLTPConfigurabl

string[] expectedCommands =
{
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem PostgreSQL --benchmark OLTP --tableCount 40 --recordCount 1000 --threadCount 16 --password [A-Za-z0-9+/=]+"
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem PostgreSQL --benchmark OLTP --threadCount 16 --tableCount 40 --recordCount 1000 --password [A-Za-z0-9+/=]+"
};

int commandNumber = 0;
Expand Down Expand Up @@ -444,7 +446,7 @@ public async Task SysbenchConfigurationProperlyExecutesPostgreSQLTPCCConfigurabl

string[] expectedCommands =
{
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem PostgreSQL --benchmark TPCC --tableCount 40 --warehouses 1000 --threadCount 16 --password [A-Za-z0-9+/=]+"
$"python3 {this.mockPackagePath}/populate-database.py --dbName sbtest --databaseSystem PostgreSQL --benchmark TPCC --threadCount 16 --tableCount 40 --warehouses 1000 --password [A-Za-z0-9+/=]+ --host \"1.2.3.5\""
};

int commandNumber = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace VirtualClient.Actions
using VirtualClient;
using VirtualClient.Common;
using VirtualClient.Common.Extensions;
using VirtualClient.Common.Platform;
using VirtualClient.Common.Telemetry;
using VirtualClient.Contracts;

Expand Down Expand Up @@ -44,6 +43,18 @@ public HammerDBExecutor(IServiceCollection dependencies, IDictionary<string, ICo
this.stateManager = this.SystemManager.StateManager;
}

/// <summary>
/// The specifed action that controls the execution of the dependency.
/// </summary>
public string Action
{
get
{
this.Parameters.TryGetValue(nameof(this.Action), out IConvertible action);
return action?.ToString();
}
}

/// <summary>
/// Defines the name of the createDB TCL file.
/// </summary>
Expand Down Expand Up @@ -196,7 +207,7 @@ protected override async Task ExecuteAsync(EventContext telemetryContext, Cancel
HammerDBState state = await this.stateManager.GetStateAsync<HammerDBState>(nameof(HammerDBState), cancellationToken)
?? new HammerDBState();

if (state.DatabaseCreated != 2)
if (!state.DatabasePopulated)
{
await this.Logger.LogMessageAsync($"{this.TypeName}.{this.Scenario}", telemetryContext.Clone(), async () =>
{
Expand All @@ -205,8 +216,12 @@ await this.Logger.LogMessageAsync($"{this.TypeName}.{this.Scenario}", telemetryC
await this.PrepareSQLDatabase(telemetryContext, cancellationToken);
}
});
state.DatabaseCreated++;
await this.stateManager.SaveStateAsync<HammerDBState>(nameof(HammerDBState), state, cancellationToken);

if (this.Action == ConfigurationAction.PopulateTables)
{
state.DatabasePopulated = true;
await this.stateManager.SaveStateAsync<HammerDBState>(nameof(HammerDBState), state, cancellationToken);
}
}
}

Expand Down Expand Up @@ -318,9 +333,20 @@ private async Task PrepareSQLDatabase(EventContext telemetryContext, Cancellatio

private async Task ConfigureCreateHammerDBFile(EventContext telemetryContext, CancellationToken cancellationToken)
{
string warehouseCount = this.WarehouseCount;
string virtualUsers = this.VirtualUsers;

// For CreateTables action, we set warehouse count and virtual users to 1
// Then will run populate again to fill up the tables in entirety.
if (this.Action == ConfigurationAction.CreateTables)
{
warehouseCount = "1";
virtualUsers = "1";
}

string command = $"python3";
string arguments = $"{this.HammerDBPackagePath}/configure-workload-generator.py --workload {this.Workload} --sqlServer {this.SQLServer} --port {this.Port}" +
$" --virtualUsers {this.VirtualUsers} --warehouseCount {this.WarehouseCount} --password {this.SuperUserPassword} --dbName {this.DatabaseName} --hostIPAddress {this.ServerIpAddress}";
$" --virtualUsers {virtualUsers} --warehouseCount {warehouseCount} --password {this.SuperUserPassword} --dbName {this.DatabaseName} --hostIPAddress {this.ServerIpAddress}";

using (IProcessProxy process = await this.ExecuteCommandAsync(
command,
Expand Down Expand Up @@ -406,18 +432,34 @@ public bool HammerDBInitialized
}
}

public int DatabaseCreated
public bool DatabasePopulated
{
get
{
return this.Properties.GetValue<int>(nameof(HammerDBState.DatabaseCreated), 0);
return this.Properties.GetValue<bool>(nameof(HammerDBState.DatabasePopulated), false);
}

set
{
this.Properties[nameof(HammerDBState.DatabaseCreated)] = value;
this.Properties[nameof(HammerDBState.DatabasePopulated)] = value;
}
}
}

/// <summary>
/// Supported HammerDB Configuration actions.
/// </summary>
internal class ConfigurationAction
{
/// <summary>
/// Initializes the tables on the database.
/// </summary>
public const string CreateTables = nameof(CreateTables);

/// <summary>
/// Populates Database on server.
/// </summary>
public const string PopulateTables = nameof(PopulateTables);
}
}
}
Loading
Loading