66import java .io .PrintWriter ;
77import java .io .StringWriter ;
88import java .io .Writer ;
9+ import java .lang .reflect .InvocationTargetException ;
10+ import java .lang .reflect .Method ;
911import java .nio .file .Files ;
1012import java .sql .Connection ;
1113import java .sql .SQLException ;
@@ -252,19 +254,19 @@ private void printState(FileWriter writer, StateToReproduce state) {
252254 public static class QueryManager {
253255
254256 private final Connection con ;
255- private final StateToReproduce state ;
257+ private final StateToReproduce stateToRepro ;
256258
257259 QueryManager (Connection con , StateToReproduce state ) {
258260 if (con == null || state == null ) {
259261 throw new IllegalArgumentException ();
260262 }
261263 this .con = con ;
262- this .state = state ;
264+ this .stateToRepro = state ;
263265
264266 }
265267
266268 public boolean execute (Query q ) throws SQLException {
267- state .statements .add (q );
269+ stateToRepro .statements .add (q );
268270 boolean success = q .execute (con );
269271 Main .nrSuccessfulActions .addAndGet (1 );
270272 return success ;
@@ -311,12 +313,14 @@ public void run() {
311313 long currentNrDbs = nrDatabases .get ();
312314 long nrCurrentDbs = currentNrDbs - lastNrDbs ;
313315 double throughputDbs = nrCurrentDbs / (elapsedTimeMillis / 1000d );
314- long successfulStatementsRatio = (long ) (100.0 * nrSuccessfulActions .get () / (nrSuccessfulActions .get () + nrUnsuccessfulActions .get ()));
316+ long successfulStatementsRatio = (long ) (100.0 * nrSuccessfulActions .get ()
317+ / (nrSuccessfulActions .get () + nrUnsuccessfulActions .get ()));
315318 DateFormat dateFormat = new SimpleDateFormat ("yyyy/MM/dd HH:mm:ss" );
316319 Date date = new Date ();
317320 System .out .println (String .format (
318321 "[%s] Executed %d queries (%d queries/s; %.2f/s dbs, successful statements: %2d%%). Threads shut down: %d." ,
319- dateFormat .format (date ), currentNrQueries , (int ) throughput , throughputDbs , successfulStatementsRatio , threadsShutdown ));
322+ dateFormat .format (date ), currentNrQueries , (int ) throughput , throughputDbs ,
323+ successfulStatementsRatio , threadsShutdown ));
320324 timeMillis = System .currentTimeMillis ();
321325 lastNrQueries = currentNrQueries ;
322326 lastNrDbs = currentNrDbs ;
@@ -330,9 +334,9 @@ public void run() {
330334
331335 executor .execute (new Runnable () {
332336
333- StateToReproduce state ;
337+ StateToReproduce stateToRepro ;
334338 StateLogger logger ;
335- DatabaseProvider provider ;
339+ DatabaseProvider <?> provider ;
336340
337341 @ Override
338342 public void run () {
@@ -365,24 +369,43 @@ public void run() {
365369 private void runThread (final String databaseName ) {
366370 Thread .currentThread ().setName (databaseName );
367371 while (true ) {
368- state = provider .getStateToReproduce (databaseName );
372+ stateToRepro = provider .getStateToReproduce (databaseName );
369373 logger = new StateLogger (databaseName , provider , options );
370- try (Connection con = provider .createDatabase (databaseName , state )) {
371- QueryManager manager = new QueryManager (con , state );
374+ try (Connection con = provider .createDatabase (databaseName , stateToRepro )) {
375+ QueryManager manager = new QueryManager (con , stateToRepro );
372376 java .sql .DatabaseMetaData meta = con .getMetaData ();
373- state .databaseVersion = meta .getDatabaseProductVersion ();
374- provider .generateAndTestDatabase (databaseName , con , logger , state , manager , options );
377+ stateToRepro .databaseVersion = meta .getDatabaseProductVersion ();
378+ GlobalState state = (GlobalState ) provider .generateGlobalState ();
379+ state .setState (stateToRepro );
380+ Randomly r = new Randomly ();
381+ state .setDatabaseName (databaseName );
382+ state .setConnection (con );
383+ state .setRandomly (r );
384+ state .setMainOptions (options );
385+ state .setStateLogger (logger );
386+ state .setManager (manager );
387+ Method method = provider .getClass ().getMethod ("generateAndTestDatabase" , state .getClass ());
388+ method .setAccessible (true );
389+ method .invoke (provider , state );
390+ // provider.generateAndTestDatabase(state);
391+ // provider.generateAndTestDatabase(databaseName, con, logger, state, manager, options);
375392 } catch (IgnoreMeException e ) {
376393 continue ;
394+ } catch (InvocationTargetException e ) {
395+ if (e .getCause () instanceof IgnoreMeException ) {
396+ continue ;
397+ } else {
398+ throw new AssertionError (e );
399+ }
377400 } catch (ReduceMeException reduce ) {
378- logger .logRowNotFound (state );
401+ logger .logRowNotFound (stateToRepro );
379402 threadsShutdown ++;
380403 break ;
381404 } catch (Throwable reduce ) {
382405 reduce .printStackTrace ();
383- state .exception = reduce .getMessage ();
406+ stateToRepro .exception = reduce .getMessage ();
384407 logger .logFileWriter = null ;
385- logger .logException (reduce , state );
408+ logger .logException (reduce , stateToRepro );
386409 threadsShutdown ++;
387410 break ;
388411 } finally {
0 commit comments