Skip to content

Commit a6f582a

Browse files
committed
Use transactions in tests to fix timeout with DB2
Because of a bug in the Db2 Vert.x SQL client (see eclipse-vertx/vertx-sql-client#920) The error seems to disappear when we use transactions but we need to investigate further.
1 parent d3d46c4 commit a6f582a

File tree

2 files changed

+59
-77
lines changed

2 files changed

+59
-77
lines changed

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerElementCollectionForBasicTypeSetTest.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,14 @@ public void setNewElementCollectionWithStageAPI(TestContext context){
234234

235235
@Test
236236
public void setNewElementCollectionWithMutinyAPI(TestContext context) {
237-
test( context, openMutinySession()
238-
.chain( session -> session
237+
test( context, getMutinySessionFactory()
238+
.withTransaction( (session, tx) -> session
239239
.find( Person.class, thePerson.getId() )
240240
.invoke( foundPerson -> {
241241
context.assertNotNull( foundPerson );
242242
context.assertFalse( foundPerson.getPhones().isEmpty() );
243243
foundPerson.setPhones( new HashSet<>( Arrays.asList( "555" ) ) );
244-
} )
245-
.call( session::flush ) )
244+
} ) )
246245
.chain( this::openMutinySession )
247246
.chain( session -> session.find( Person.class, thePerson.getId() ) )
248247
.invoke( changedPerson -> assertPhones( context, changedPerson, "555" ) )
@@ -251,12 +250,11 @@ public void setNewElementCollectionWithMutinyAPI(TestContext context) {
251250

252251
@Test
253252
public void removePersonWithStageAPI(TestContext context) {
254-
test( context, openSession()
255-
.thenCompose( session -> session
253+
test( context, getSessionFactory()
254+
.withTransaction( (session, tx) -> session
256255
.find( Person.class, thePerson.getId() )
257256
// remove thePerson entity and flush
258-
.thenCompose( foundPerson -> session.remove( foundPerson ) )
259-
.thenCompose( v -> session.flush() ) )
257+
.thenCompose( foundPerson -> session.remove( foundPerson ) ) )
260258
.thenCompose( v -> openSession() )
261259
.thenCompose( session -> session.find( Person.class, thePerson.getId() ) )
262260
.thenAccept( nullPerson -> context.assertNull( nullPerson ) )

hibernate-reactive-core/src/test/java/org/hibernate/reactive/EagerOrderedElementCollectionForEmbeddableTypeListTest.java

Lines changed: 53 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,9 @@ public void updateCollectionWithDuplicatesWithStageAPI(TestContext context) {
166166

167167
Person thomas = new Person( 47, "Thomas Reaper", phones );
168168

169-
test( context, openSession()
170-
.thenCompose( session -> session
171-
.persist( thomas )
172-
.thenCompose( v -> session.flush() ) )
169+
test( context, getSessionFactory()
170+
.withTransaction( (session, tx) -> session
171+
.persist( thomas ) )
173172
.thenCompose( v -> openSession() )
174173
.thenCompose( session -> session
175174
.find( Person.class, thomas.getId() )
@@ -196,12 +195,12 @@ public void updateCollectionWithDuplicatesWithMutinyAPI(TestContext context) {
196195

197196
Person thomas = new Person( 47, "Thomas Reaper", phones );
198197

199-
test( context, openMutinySession()
200-
.chain( session -> session
201-
.persist( thomas )
202-
.call( session::flush ) )
198+
test( context, getMutinySessionFactory()
199+
.withTransaction( (session, tx) -> session
200+
.persist( thomas ) )
203201
.chain( () -> openMutinySession() )
204-
.chain( newSession -> newSession.find( Person.class, thomas.getId() )
202+
.chain( newSession -> newSession
203+
.find( Person.class, thomas.getId() )
205204
// Change a couple of the elements in the collection
206205
.invoke( found -> {
207206
found.getPhones().set( 1, new Phone( "47" ) );
@@ -224,10 +223,9 @@ public void deleteElementsFromCollectionWithDuplicatesWithStageAPI(TestContext c
224223

225224
Person thomas = new Person( 47, "Thomas Reaper", phones );
226225

227-
test( context, openSession()
228-
.thenCompose( session -> session
229-
.persist( thomas )
230-
.thenCompose( v -> session.flush() ) )
226+
test( context, getSessionFactory()
227+
.withTransaction( (session, tx) -> session
228+
.persist( thomas ) )
231229
.thenCompose( v -> openSession() )
232230
.thenCompose( newSession -> newSession
233231
.find( Person.class, thomas.getId() )
@@ -254,10 +252,9 @@ public void deleteElementsFromCollectionWithDuplicatesWithMutinyAPI(TestContext
254252

255253
Person thomas = new Person( 47, "Thomas Reaper", phones );
256254

257-
test( context, openMutinySession()
258-
.chain( session -> session
259-
.persist( thomas )
260-
.call( session::flush ) )
255+
test( context, getMutinySessionFactory()
256+
.withTransaction( (session, tx) -> session
257+
.persist( thomas ) )
261258
.chain( this::openMutinySession )
262259
.chain( newSession -> newSession
263260
.find( Person.class, thomas.getId() )
@@ -276,12 +273,11 @@ public void deleteElementsFromCollectionWithDuplicatesWithMutinyAPI(TestContext
276273

277274
@Test
278275
public void addOneElementWithMutinyAPI(TestContext context) {
279-
test( context, openMutinySession()
280-
.chain( session -> session
276+
test( context, getMutinySessionFactory()
277+
.withTransaction( (session, tx) -> session
281278
.find( Person.class, thePerson.getId() )
282279
// add one element to the collection
283-
.invoke( foundPerson -> foundPerson.getPhones().add( new Phone( "000" ) ) )
284-
.call( session::flush ) )
280+
.invoke( foundPerson -> foundPerson.getPhones().add( new Phone( "000" ) ) ) )
285281
// Check new person collection
286282
.chain( this::openMutinySession )
287283
.chain( session -> session.find( Person.class, thePerson.getId() ) )
@@ -291,12 +287,11 @@ public void addOneElementWithMutinyAPI(TestContext context) {
291287

292288
@Test
293289
public void removeOneElementWithStageAPI(TestContext context) {
294-
test( context, openSession()
295-
.thenCompose( session -> session
290+
test( context, getSessionFactory()
291+
.withTransaction( (session, tx) -> session
296292
.find( Person.class, thePerson.getId() )
297293
// Remove one element from the collection
298-
.thenAccept( foundPerson -> foundPerson.getPhones().remove( new Phone( "999-999-9999" ) ) )
299-
.thenCompose( v -> session.flush() ) )
294+
.thenAccept( foundPerson -> foundPerson.getPhones().remove( new Phone( "999-999-9999" ) ) ) )
300295
.thenCompose( v -> openSession() )
301296
.thenCompose( session -> session.find( Person.class, thePerson.getId() ) )
302297
.thenAccept( foundPerson -> assertPhones( context, foundPerson, "111-111-1111" ) )
@@ -305,12 +300,11 @@ public void removeOneElementWithStageAPI(TestContext context) {
305300

306301
@Test
307302
public void removeOneElementWithMutinyAPI(TestContext context) {
308-
test( context, openMutinySession()
309-
.chain( session -> session
303+
test( context, getMutinySessionFactory()
304+
.withTransaction( (session, tx) -> session
310305
.find( Person.class, thePerson.getId() )
311306
// Remove one element from the collection
312-
.invoke( foundPerson -> foundPerson.getPhones().remove( new Phone( "999-999-9999" ) ) )
313-
.call( session::flush ) )
307+
.invoke( foundPerson -> foundPerson.getPhones().remove( new Phone( "999-999-9999" ) ) ) )
314308
.chain( this::openMutinySession )
315309
.chain( session -> session.find( Person.class, thePerson.getId() ) )
316310
.invoke( foundPerson -> assertPhones( context, foundPerson, "111-111-1111" ) )
@@ -319,12 +313,11 @@ public void removeOneElementWithMutinyAPI(TestContext context) {
319313

320314
@Test
321315
public void clearCollectionElementsStageAPI(TestContext context) {
322-
test( context, openSession()
323-
.thenCompose( session -> session
316+
test( context, getSessionFactory()
317+
.withTransaction( (session, tx) -> session
324318
.find( Person.class, thePerson.getId() )
325319
// clear collection
326-
.thenAccept( foundPerson -> foundPerson.getPhones().clear() )
327-
.thenCompose( v -> session.flush() ) )
320+
.thenAccept( foundPerson -> foundPerson.getPhones().clear() ) )
328321
.thenCompose( s -> openSession() )
329322
.thenCompose( session -> session.find( Person.class, thePerson.getId() ) )
330323
.thenAccept( changedPerson -> assertPhones( context, changedPerson ) )
@@ -333,12 +326,11 @@ public void clearCollectionElementsStageAPI(TestContext context) {
333326

334327
@Test
335328
public void clearCollectionElementsMutinyAPI(TestContext context) {
336-
test( context, openMutinySession()
337-
.chain( session -> session
329+
test( context, getMutinySessionFactory()
330+
.withTransaction( (session, tx) -> session
338331
.find( Person.class, thePerson.getId() )
339332
// clear collection
340-
.invoke( foundPerson -> foundPerson.getPhones().clear() )
341-
.call( session::flush ) )
333+
.invoke( foundPerson -> foundPerson.getPhones().clear() ) )
342334
.chain( this::openMutinySession )
343335
.chain( session -> session.find( Person.class, thePerson.getId() )
344336
.invoke( changedPerson -> context.assertTrue( changedPerson.getPhones().isEmpty() ) ) )
@@ -347,15 +339,14 @@ public void clearCollectionElementsMutinyAPI(TestContext context) {
347339

348340
@Test
349341
public void removeAndAddElementWithStageAPI(TestContext context){
350-
test( context, openSession()
351-
.thenCompose( session -> session
342+
test( context, getSessionFactory()
343+
.withTransaction( (session, tx) -> session
352344
.find( Person.class, thePerson.getId() )
353345
.thenAccept( foundPerson -> {
354346
context.assertNotNull( foundPerson );
355347
foundPerson.getPhones().remove( new Phone( "111-111-1111" ) );
356348
foundPerson.getPhones().add( new Phone( "000" ) );
357-
} )
358-
.thenCompose( v -> session.flush() ) )
349+
} ) )
359350
.thenCompose( v -> openSession() )
360351
.thenCompose( session -> session.find( Person.class, thePerson.getId() ) )
361352
.thenAccept( changedPerson -> assertPhones( context, changedPerson, "000", "999-999-9999" ) )
@@ -364,15 +355,14 @@ public void removeAndAddElementWithStageAPI(TestContext context){
364355

365356
@Test
366357
public void removeAndAddElementWithMutinyAPI(TestContext context){
367-
test( context, openMutinySession()
368-
.chain( session -> session
358+
test( context, getMutinySessionFactory()
359+
.withTransaction( (session, tx) -> session
369360
.find( Person.class, thePerson.getId() )
370361
.invoke( foundPerson -> {
371362
context.assertNotNull( foundPerson );
372363
foundPerson.getPhones().remove( new Phone( "111-111-1111" ) );
373364
foundPerson.getPhones().add( new Phone( "000" ) );
374-
} )
375-
.call( session::flush ) )
365+
} ) )
376366
.chain( () -> openMutinySession() )
377367
.chain( session -> session.find( Person.class, thePerson.getId() ) )
378368
.invoke( person -> assertPhones( context, person, "000", "999-999-9999" ) )
@@ -381,15 +371,14 @@ public void removeAndAddElementWithMutinyAPI(TestContext context){
381371

382372
@Test
383373
public void replaceSecondCollectionElementStageAPI(TestContext context){
384-
test( context, openSession()
385-
.thenCompose( session -> session
374+
test( context, getSessionFactory()
375+
.withTransaction( (session, tx) -> session
386376
.find( Person.class, thePerson.getId() )
387377
.thenAccept( foundPerson -> {
388378
// remove existing phone and add new phone
389379
foundPerson.getPhones().remove( new Phone( "999-999-9999" ) );
390380
foundPerson.getPhones().add( new Phone( "000-000-0000" ) );
391-
} )
392-
.thenCompose( v -> session.flush() ) )
381+
} ) )
393382
.thenCompose( s -> openSession() )
394383
.thenCompose( session -> session.find( Person.class, thePerson.getId() ) )
395384
.thenAccept( changedPerson -> assertPhones( context, changedPerson, "000-000-0000", "111-111-1111" ) )
@@ -398,15 +387,14 @@ public void replaceSecondCollectionElementStageAPI(TestContext context){
398387

399388
@Test
400389
public void replaceSecondCollectionElementMutinyAPI(TestContext context){
401-
test( context, openMutinySession()
402-
.chain( session -> session
390+
test( context, getMutinySessionFactory()
391+
.withTransaction( (session, tx) -> session
403392
.find( Person.class, thePerson.getId() )
404393
.invoke( foundPerson -> {
405394
// remove existing phone and add new phone
406395
foundPerson.getPhones().remove( new Phone( "999-999-9999" ) );
407396
foundPerson.getPhones().add( new Phone( "000-000-0000" ) );
408-
} )
409-
.call( session::flush ) )
397+
} ) )
410398
.chain( () -> openMutinySession() )
411399
.chain( session -> session.find( Person.class, thePerson.getId() ) )
412400
.invoke( changedPerson -> assertPhones( context, changedPerson, "000-000-0000", "111-111-1111" ) )
@@ -415,12 +403,11 @@ public void replaceSecondCollectionElementMutinyAPI(TestContext context){
415403

416404
@Test
417405
public void setNewElementCollectionStageAPI(TestContext context) {
418-
test( context, openSession()
419-
.thenCompose( session -> session
406+
test( context, getSessionFactory()
407+
.withTransaction( (session, tx) -> session
420408
.find( Person.class, thePerson.getId() )
421409
// replace phones with list of 1 phone
422-
.thenAccept( foundPerson -> foundPerson.setPhones( Arrays.asList( new Phone( "000-000-0000" ) ) ) )
423-
.thenCompose( v -> session.flush() ) )
410+
.thenAccept( foundPerson -> foundPerson.setPhones( Arrays.asList( new Phone( "000-000-0000" ) ) ) ) )
424411
.thenCompose( s -> openSession() )
425412
.thenCompose( session -> session.find( Person.class, thePerson.getId() ) )
426413
.thenAccept( changedPerson -> assertPhones( context, changedPerson, "000-000-0000" ) )
@@ -429,12 +416,11 @@ public void setNewElementCollectionStageAPI(TestContext context) {
429416

430417
@Test
431418
public void setNewElementCollectionMutinyAPI(TestContext context) {
432-
test( context, openMutinySession()
433-
.chain( session -> session
419+
test( context, getMutinySessionFactory()
420+
.withTransaction( (session, tx) -> session
434421
.find( Person.class, thePerson.getId() )
435422
// replace phones with list of 1 phone
436-
.invoke( foundPerson -> foundPerson.setPhones( Arrays.asList( new Phone( "000-000-0000" ) ) ) )
437-
.call( session::flush ) )
423+
.invoke( foundPerson -> foundPerson.setPhones( Arrays.asList( new Phone( "000-000-0000" ) ) ) ) )
438424
.chain( this::openMutinySession )
439425
.chain( session -> session.find( Person.class, thePerson.getId() ) )
440426
.invoke( changedPerson -> assertPhones( context, changedPerson, "000-000-0000" ) )
@@ -443,12 +429,11 @@ public void setNewElementCollectionMutinyAPI(TestContext context) {
443429

444430
@Test
445431
public void removePersonStageAPI(TestContext context){
446-
test( context, openSession()
447-
.thenCompose( session -> session
432+
test( context, getSessionFactory()
433+
.withTransaction( (session, tx) -> session
448434
.find( Person.class, thePerson.getId() )
449435
// remove thePerson entity and flush
450-
.thenCompose( foundPerson -> session.remove( foundPerson ) )
451-
.thenCompose( v -> session.flush() ) )
436+
.thenCompose( foundPerson -> session.remove( foundPerson ) ) )
452437
.thenCompose( v -> openSession() )
453438
.thenCompose( session -> session.find( Person.class, thePerson.getId() ) )
454439
.thenAccept( context::assertNull )
@@ -460,12 +445,11 @@ public void removePersonStageAPI(TestContext context){
460445

461446
@Test
462447
public void removePersonMutinyAPI(TestContext context) {
463-
test( context, openMutinySession()
464-
.chain( session -> session
448+
test( context, getMutinySessionFactory()
449+
.withTransaction( (session, tx) -> session
465450
.find( Person.class, thePerson.getId() )
466451
// remove thePerson entity and flush
467-
.call( session::remove )
468-
.call( session::flush ) )
452+
.call( session::remove ) )
469453
.chain( this::openMutinySession )
470454
.chain( session -> session.find( Person.class, thePerson.getId() ) )
471455
.invoke( context::assertNull )

0 commit comments

Comments
 (0)