HHH-12769 - Rework LockTest#testContendedPessimisticLock so that it can work on Oracle without throwing exceptions

This commit is contained in:
Vlad Mihalcea 2018-07-04 21:00:11 +03:00
parent 6b3e4e6f56
commit 8fff54d6ee
1 changed files with 4 additions and 10 deletions

View File

@ -425,9 +425,10 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
final CountDownLatch latch = new CountDownLatch( 1 );
final Lock lock = new Lock();
final AtomicBoolean backgroundThreadHasReadNewValue = new AtomicBoolean();
FutureTask<Boolean> bgTask = new FutureTask<>(
() -> {
AtomicBoolean backgroundThreadHasReadNewValue = new AtomicBoolean();
try {
doInJPA( this::entityManagerFactory, _entityManager -> {
@ -490,29 +491,22 @@ public class LockTest extends BaseEntityManagerFunctionalTestCase {
if ( backGroundThreadCompleted ) {
// the background thread read a value. At the very least we need to assert that he did not see the
// changed value
boolean backgroundThreadHasReadNewValue = bgTask.get();
assertFalse(
"The background thread is not allowed to see the updated value while the first transaction has not committed yet",
backgroundThreadHasReadNewValue
backgroundThreadHasReadNewValue.get()
);
}
else {
log.debug( "The background thread was blocked" );
boolean backgroundThreadHasReadNewValue = bgTask.get();
assertTrue(
"Background thread should read the new value after being unblocked",
backgroundThreadHasReadNewValue
backgroundThreadHasReadNewValue.get()
);
}
}
catch (InterruptedException e) {
Thread.interrupted();
}
catch (ExecutionException e) {
if ( !Oracle8iDialect.class.isAssignableFrom( Dialect.getDialect().getClass() ) ) {
fail(e.getMessage());
}
}
} );
}
finally {