@@ -114,38 +114,39 @@ public void testConcurrentForUpdate() throws InterruptedException {
114114 db .markAsDirty (first );
115115 db .save (first , transaction );
116116
117- log .info ("Thread: after find - size:{}" , list .size ());
118117 try {
119- // hold onto the locks for 3 seconds, and then end the transaction
118+ log . info ( "Thread: after find - rows locked:{}, hold for 3 seconds" , list . size ());
120119 Thread .sleep (3000 );
121120 } catch (InterruptedException e ) {
122121 throw new RuntimeException (e );
123122 }
124123 log .info ("Thread: done" );
125- }
124+ } // transaction ended here via try-with-resources
126125 });
127126
128127 t1 .start ();
129128
130129 Thread .sleep (300 );
131130
132131 long start = System .currentTimeMillis ();
133- try (final Transaction transaction = db .beginTransaction ()) {
132+ try (final Transaction transaction = db .beginTransaction ()) { // second transaction
134133 if (isH2 ()) {
135134 DB .sqlUpdate ("SET LOCK_TIMEOUT 5000" ).execute ();
136135 }
137- log .info ("Main: before find, should wait ..." );
136+ log .info ("Main: before find, should wait (blocked by other thread) ..." );
138137 DB .find (Customer .class )
139138 .usingTransaction (transaction )
140139 .forUpdate ()
141140 //.orderBy().desc("1") // this would help by the locks in DB2
142141 .findList ();
143142
144143 log .info ("Main: complete" );
145- }
144+ } // end second transaction
146145
147146 long exeMillis = System .currentTimeMillis () - start ;
148- assertThat (exeMillis ).isGreaterThan (2500 );
147+ assertThat (exeMillis )
148+ .describedAs ("select for update expected to wait" )
149+ .isGreaterThan (2500 );
149150 }
150151
151152 @ Test
0 commit comments