HHH-11381 : Run CorrectnessTestCase in nonstrict mode

* the test was not running in nonstrict-read-write mode but in read-write mode instead
* for collections, we have to fallback to read-write mode
* there are expected failures in nonstrict mode, as the test does not allow stale reads
  (adding a switch to handle these is TODO)

(cherry picked from commit f574325c04)
This commit is contained in:
Radim Vansa 2017-01-11 14:07:25 +01:00 committed by Gail Badner
parent 46898c928a
commit f87a66e32d
3 changed files with 13 additions and 6 deletions

View File

@ -272,9 +272,7 @@ public abstract class CorrectnessTestCase {
return new Class[] {Family.class, Person.class, Address.class}; return new Class[] {Family.class, Person.class, Address.class};
} }
private static Metadata buildMetadata(StandardServiceRegistry registry) { private Metadata buildMetadata(StandardServiceRegistry registry) {
final String cacheStrategy = "transactional";
MetadataSources metadataSources = new MetadataSources( registry ); MetadataSources metadataSources = new MetadataSources( registry );
for ( Class entityClass : getAnnotatedClasses() ) { for ( Class entityClass : getAnnotatedClasses() ) {
metadataSources.addAnnotatedClass( entityClass ); metadataSources.addAnnotatedClass( entityClass );
@ -284,12 +282,15 @@ public abstract class CorrectnessTestCase {
for ( PersistentClass entityBinding : metadata.getEntityBindings() ) { for ( PersistentClass entityBinding : metadata.getEntityBindings() ) {
if (!entityBinding.isInherited()) { if (!entityBinding.isInherited()) {
( (RootClass) entityBinding ).setCacheConcurrencyStrategy( cacheStrategy); ( (RootClass) entityBinding ).setCacheConcurrencyStrategy( accessType.getExternalName() );
} }
} }
// Collections don't have integrated version, these piggyback on parent's owner version (for DB).
// However, this version number isn't extractable and is not passed to cache methods.
AccessType collectionAccessType = accessType == AccessType.NONSTRICT_READ_WRITE ? AccessType.READ_WRITE : accessType;
for ( Collection collectionBinding : metadata.getCollectionBindings() ) { for ( Collection collectionBinding : metadata.getCollectionBindings() ) {
collectionBinding.setCacheConcurrencyStrategy( cacheStrategy ); collectionBinding.setCacheConcurrencyStrategy( collectionAccessType.getExternalName() );
} }
return metadata; return metadata;
@ -409,7 +410,7 @@ public abstract class CorrectnessTestCase {
})); }));
} }
} }
Exception failure = exceptions.poll(EXECUTION_TIME, TimeUnit.SECONDS); Exception failure = exceptions.poll(EXECUTION_TIME, TimeUnit.MILLISECONDS);
if (failure != null) exceptions.addFirst(failure); if (failure != null) exceptions.addFirst(failure);
running = false; running = false;
exec.shutdown(); exec.shutdown();

View File

@ -11,6 +11,8 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Version;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
@ -28,6 +30,7 @@ public final class Address {
private String zipCode; private String zipCode;
@OneToMany @OneToMany
private Set<Person> inhabitants; private Set<Person> inhabitants;
@Version
private int version; private int version;
public Address(int streetNumber, String streetName, String cityName, String countryName) { public Address(int streetNumber, String streetName, String cityName, String countryName) {

View File

@ -11,6 +11,8 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Version;
import java.util.Date; import java.util.Date;
@Entity @Entity
@ -26,6 +28,7 @@ public class Person {
@ManyToOne @ManyToOne
private Address address; private Address address;
private boolean checked; private boolean checked;
@Version
private int version; private int version;
public Person(String firstName, Family family) { public Person(String firstName, Family family) {