@@ -223,49 +223,94 @@ private void transactionReplayPreparedStatementBatch(
223223 + useBulk 
224224 + "&transactionReplay=" 
225225 + transactionReplay )) {
226-  stmt  = con .createStatement ();
227226 con .setNetworkTimeout (Runnable ::run , 200 );
228227 long  threadId  = con .getContext ().getThreadId ();
228+  execute (con , transactionReplay , threadId );
229+  threadId  = con .getContext ().getThreadId ();
230+  execute (con , transactionReplay , threadId );
231+  }
232+  }
229233
230-  stmt .executeUpdate ("INSERT INTO transaction_failover_2 (test) VALUES ('test0')" );
231-  con .setAutoCommit (false );
232-  stmt .executeUpdate ("INSERT INTO transaction_failover_2 (test) VALUES ('test1')" );
233-  try  (PreparedStatement  p  =
234-  con .prepareStatement ("INSERT INTO transaction_failover_2 (test) VALUES (?)" )) {
235-  p .setString (1 , "test2" );
236-  p .execute ();
237-  p .setString (1 , "test3" );
238-  p .addBatch ();
239-  p .setString (1 , "test4" );
240-  p .addBatch ();
234+  private  void  execute (Connection  con , boolean  transactionReplay , long  threadId ) throws  SQLException  {
235+  Statement  stmt  = con .createStatement ();
236+ 
237+  stmt .executeUpdate ("INSERT INTO transaction_failover_2 (test) VALUES ('test0')" );
238+  con .setAutoCommit (false );
239+  stmt .executeUpdate ("INSERT INTO transaction_failover_2 (test) VALUES ('test1')" );
240+  try  (PreparedStatement  p  =
241+  con .prepareStatement ("INSERT INTO transaction_failover_2 (test) VALUES (?)" )) {
242+  p .setString (1 , "test2" );
243+  p .execute ();
244+  p .setString (1 , "test3" );
245+  p .addBatch ();
246+  p .setString (1 , "test4" );
247+  p .addBatch ();
248+  p .executeBatch ();
249+ 
250+  proxy .restart (300 );
251+  p .setString (1 , "test5" );
252+  p .addBatch ();
253+  p .setString (1 , "test6" );
254+  p .addBatch ();
255+ 
256+  if  (transactionReplay ) {
241257 p .executeBatch ();
258+  con .commit ();
242259
243-  proxy .restart (300 );
244-  p .setString (1 , "test5" );
245-  p .addBatch ();
246-  p .setString (1 , "test6" );
247-  p .addBatch ();
260+  ResultSet  rs  = stmt .executeQuery ("SELECT * FROM transaction_failover_2" );
261+  for  (int  i  = 0 ; i  < 6 ; i ++) {
262+  assertTrue (rs .next ());
263+  assertEquals ("test"  + i , rs .getString ("test" ));
264+  }
265+  con .commit ();
266+  Assertions .assertTrue (con .getContext ().getThreadId () != threadId );
267+  assertFalse (con .getAutoCommit ());
268+  } else  {
269+  try  {
270+  p .executeBatch ();
271+  Assertions .fail ();
272+  } catch  (SQLException  e ) {
273+  Throwable  ee  = (e  instanceof  BatchUpdateException ) ? e .getCause () : e ;
274+  assertTrue (ee .getMessage ().contains ("In progress transaction was lost" ));
275+  }
276+  }
277+  }
278+  stmt .execute ("TRUNCATE transaction_failover_2" );
279+  stmt .executeUpdate ("INSERT INTO transaction_failover_2 (test) VALUES ('test0')" );
280+  con .setAutoCommit (false );
281+  stmt .executeUpdate ("INSERT INTO transaction_failover_2 (test) VALUES ('test1')" );
282+  try  (PreparedStatement  p  =
283+  con .prepareStatement ("INSERT INTO transaction_failover_2 (test) VALUES (?)" )) {
248284
249-  if  (transactionReplay ) {
285+  proxy .restart (300 );
286+  p .setString (1 , "test2" );
287+  p .addBatch ();
288+  p .setString (1 , "test3" );
289+  p .addBatch ();
290+  p .setString (1 , "test4" );
291+  p .addBatch ();
292+  p .setString (1 , "test5" );
293+  p .addBatch ();
294+ 
295+  if  (transactionReplay ) {
296+  p .executeBatch ();
297+  con .commit ();
298+ 
299+  ResultSet  rs  = stmt .executeQuery ("SELECT * FROM transaction_failover_2" );
300+  for  (int  i  = 0 ; i  < 5 ; i ++) {
301+  assertTrue (rs .next ());
302+  assertEquals ("test"  + i , rs .getString ("test" ));
303+  }
304+  con .commit ();
305+  Assertions .assertTrue (con .getContext ().getThreadId () != threadId );
306+  assertFalse (con .getAutoCommit ());
307+  } else  {
308+  try  {
250309 p .executeBatch ();
251-  con .commit ();
252- 
253-  ResultSet  rs  = stmt .executeQuery ("SELECT * FROM transaction_failover_2" );
254-  for  (int  i  = 0 ; i  < 6 ; i ++) {
255-  assertTrue (rs .next ());
256-  assertEquals ("test"  + i , rs .getString ("test" ));
257-  }
258-  con .commit ();
259-  Assertions .assertTrue (con .getContext ().getThreadId () != threadId );
260-  assertFalse (con .getAutoCommit ());
261-  } else  {
262-  try  {
263-  p .executeBatch ();
264-  Assertions .fail ();
265-  } catch  (SQLException  e ) {
266-  Throwable  ee  = (e  instanceof  BatchUpdateException ) ? e .getCause () : e ;
267-  assertTrue (ee .getMessage ().contains ("In progress transaction was lost" ));
268-  }
310+  Assertions .fail ();
311+  } catch  (SQLException  e ) {
312+  Throwable  ee  = (e  instanceof  BatchUpdateException ) ? e .getCause () : e ;
313+  assertTrue (ee .getMessage ().contains ("In progress transaction was lost" ));
269314 }
270315 }
271316 }
0 commit comments