@@ -47,6 +47,7 @@ public void SetupDefaultBehavior()
47
47
48
48
this . fixture . Parameters = new Dictionary < string , IConvertible > ( )
49
49
{
50
+ { nameof ( SysbenchConfiguration . Benchmark ) , "OLTP" } ,
50
51
{ nameof ( SysbenchConfiguration . DatabaseName ) , "sbtest" } ,
51
52
{ nameof ( SysbenchConfiguration . PackageName ) , "sysbench" } ,
52
53
{ nameof ( SysbenchConfiguration . Scenario ) , "populate_database" }
@@ -74,7 +75,7 @@ public async Task SysbenchConfigurationSkipsSysbenchInitialization()
74
75
75
76
string [ ] expectedCommands =
76
77
{
77
- $ "python3 { this . mockPackagePath } /populate-database.py --dbName sbtest --tableCount 10 --recordCount 1000 --threadCount 8",
78
+ $ "python3 { this . mockPackagePath } /populate-database.py --dbName sbtest --benchmark OLTP -- tableCount 10 --recordCount 1000 --threadCount 8",
78
79
} ;
79
80
80
81
int commandNumber = 0 ;
@@ -119,7 +120,7 @@ public async Task SysbenchConfigurationPreparesDatabase()
119
120
string [ ] expectedCommands =
120
121
{
121
122
$ "python3 { this . mockPackagePath } /configure-workload-generator.py --distro Ubuntu --packagePath { this . mockPackagePath } ",
122
- $ "python3 { this . mockPackagePath } /populate-database.py --dbName sbtest --tableCount 10 --recordCount 1000 --threadCount 8",
123
+ $ "python3 { this . mockPackagePath } /populate-database.py --dbName sbtest --benchmark OLTP -- tableCount 10 --recordCount 1000 --threadCount 8",
123
124
} ;
124
125
125
126
int commandNumber = 0 ;
@@ -165,12 +166,12 @@ public async Task SysbenchConfigurationUsesDefinedParametersWhenRunningTheWorklo
165
166
this . fixture . Parameters [ nameof ( SysbenchConfiguration . Threads ) ] = "16" ;
166
167
this . fixture . Parameters [ nameof ( SysbenchConfiguration . RecordCount ) ] = "1000" ;
167
168
this . fixture . Parameters [ nameof ( SysbenchConfiguration . TableCount ) ] = "40" ;
168
- this . fixture . Parameters [ nameof ( SysbenchClientExecutor . Scenario ) ] = "Configure" ;
169
+ this . fixture . Parameters [ nameof ( SysbenchClientExecutor . DatabaseScenario ) ] = "Configure" ;
169
170
170
171
string [ ] expectedCommands =
171
172
{
172
173
$ "python3 { this . mockPackagePath } /configure-workload-generator.py --distro Ubuntu --packagePath { this . mockPackagePath } ",
173
- $ "python3 { this . mockPackagePath } /populate-database.py --dbName sbtest --tableCount 40 --recordCount 1000 --threadCount 16",
174
+ $ "python3 { this . mockPackagePath } /populate-database.py --dbName sbtest --benchmark OLTP -- tableCount 40 --recordCount 1000 --threadCount 16",
174
175
} ;
175
176
176
177
int commandNumber = 0 ;
@@ -259,6 +260,114 @@ public async Task SysbenchConfigurationSkipsDatabasePopulationWhenInitialized()
259
260
}
260
261
}
261
262
263
+ [ Test ]
264
+ public async Task SysbenchConfigurationProperlyExecutesTPCCPreparation ( )
265
+ {
266
+ this . fixture . Parameters [ nameof ( SysbenchConfiguration . Benchmark ) ] = "TPCC" ;
267
+
268
+ this . fixture . StateManager . OnGetState ( ) . ReturnsAsync ( JObject . FromObject ( new SysbenchExecutor . SysbenchState ( )
269
+ {
270
+ SysbenchInitialized = true
271
+ } ) ) ;
272
+
273
+ string [ ] expectedCommands =
274
+ {
275
+ $ "python3 { this . mockPackagePath } /populate-database.py --dbName sbtest --benchmark TPCC --tableCount 10 --warehouses 100 --threadCount 8"
276
+ } ;
277
+
278
+ int commandNumber = 0 ;
279
+ bool commandExecuted = false ;
280
+
281
+ this . fixture . ProcessManager . OnCreateProcess = ( exe , arguments , workingDir ) =>
282
+ {
283
+ string expectedCommand = expectedCommands [ commandNumber ] ;
284
+
285
+ if ( expectedCommand == $ "{ exe } { arguments } ")
286
+ {
287
+ commandExecuted = true ;
288
+ }
289
+
290
+ Assert . IsTrue ( commandExecuted ) ;
291
+ commandExecuted = false ;
292
+ commandNumber += 1 ;
293
+
294
+ InMemoryProcess process = new InMemoryProcess
295
+ {
296
+ StartInfo = new ProcessStartInfo
297
+ {
298
+ FileName = exe ,
299
+ Arguments = arguments
300
+ } ,
301
+ ExitCode = 0 ,
302
+ OnStart = ( ) => true ,
303
+ OnHasExited = ( ) => true
304
+ } ;
305
+
306
+ return process ;
307
+ } ;
308
+
309
+ using ( TestSysbenchConfiguration SysbenchExecutor = new TestSysbenchConfiguration ( this . fixture . Dependencies , this . fixture . Parameters ) )
310
+ {
311
+ await SysbenchExecutor . ExecuteAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
312
+ }
313
+ }
314
+
315
+ [ Test ]
316
+ public async Task SysbenchConfigurationProperlyExecutesTPCCConfigurablePreparation ( )
317
+ {
318
+ this . fixture . Parameters [ nameof ( SysbenchConfiguration . Benchmark ) ] = "TPCC" ;
319
+ this . fixture . Parameters [ nameof ( SysbenchConfiguration . Threads ) ] = "16" ;
320
+ this . fixture . Parameters [ nameof ( SysbenchConfiguration . WarehouseCount ) ] = "1000" ;
321
+ this . fixture . Parameters [ nameof ( SysbenchConfiguration . TableCount ) ] = "40" ;
322
+ this . fixture . Parameters [ nameof ( SysbenchClientExecutor . DatabaseScenario ) ] = "Configure" ;
323
+
324
+ this . fixture . StateManager . OnGetState ( ) . ReturnsAsync ( JObject . FromObject ( new SysbenchExecutor . SysbenchState ( )
325
+ {
326
+ SysbenchInitialized = true
327
+ } ) ) ;
328
+
329
+ string [ ] expectedCommands =
330
+ {
331
+ $ "python3 { this . mockPackagePath } /populate-database.py --dbName sbtest --benchmark TPCC --tableCount 40 --warehouses 1000 --threadCount 16"
332
+ } ;
333
+
334
+ int commandNumber = 0 ;
335
+ bool commandExecuted = false ;
336
+
337
+ this . fixture . ProcessManager . OnCreateProcess = ( exe , arguments , workingDir ) =>
338
+ {
339
+ string expectedCommand = expectedCommands [ commandNumber ] ;
340
+
341
+ if ( expectedCommand == $ "{ exe } { arguments } ")
342
+ {
343
+ commandExecuted = true ;
344
+ }
345
+
346
+ Assert . IsTrue ( commandExecuted ) ;
347
+ commandExecuted = false ;
348
+ commandNumber += 1 ;
349
+
350
+ InMemoryProcess process = new InMemoryProcess
351
+ {
352
+ StartInfo = new ProcessStartInfo
353
+ {
354
+ FileName = exe ,
355
+ Arguments = arguments
356
+ } ,
357
+ ExitCode = 0 ,
358
+ OnStart = ( ) => true ,
359
+ OnHasExited = ( ) => true
360
+ } ;
361
+
362
+ return process ;
363
+ } ;
364
+
365
+ using ( TestSysbenchConfiguration SysbenchExecutor = new TestSysbenchConfiguration ( this . fixture . Dependencies , this . fixture . Parameters ) )
366
+ {
367
+ await SysbenchExecutor . ExecuteAsync ( CancellationToken . None ) . ConfigureAwait ( false ) ;
368
+ }
369
+ }
370
+
262
371
private class TestSysbenchConfiguration : SysbenchConfiguration
263
372
{
264
373
public TestSysbenchConfiguration ( IServiceCollection services , IDictionary < string , IConvertible > parameters = null )
0 commit comments