Search in sources :

Example 1 with BeforeClassOnce

use of org.hibernate.testing.BeforeClassOnce in project hibernate-orm by hibernate.

the class CorrectnessTestCase method beforeClass.

@BeforeClassOnce
public void beforeClass() {
    TestResourceTracker.testStarted(getClass().getSimpleName());
    Arrays.asList(new File(System.getProperty("java.io.tmpdir")).listFiles((dir, name) -> name.startsWith("family_") || name.startsWith("invalidations-"))).stream().forEach(f -> f.delete());
    StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().enableAutoClose().applySetting(Environment.USE_SECOND_LEVEL_CACHE, "true").applySetting(Environment.USE_QUERY_CACHE, "true").applySetting(Environment.DRIVER, "org.h2.Driver").applySetting(Environment.URL, "jdbc:h2:mem:" + getDbName() + ";TRACE_LEVEL_FILE=4").applySetting(Environment.DIALECT, H2Dialect.class.getName()).applySetting(Environment.HBM2DDL_AUTO, "create-drop").applySetting(Environment.CACHE_REGION_FACTORY, FailingInfinispanRegionFactory.class.getName()).applySetting(TestInfinispanRegionFactory.CACHE_MODE, cacheMode).applySetting(Environment.USE_MINIMAL_PUTS, "false").applySetting(Environment.GENERATE_STATISTICS, "false");
    applySettings(ssrb);
    sessionFactories = new SessionFactory[NUM_NODES];
    for (int i = 0; i < NUM_NODES; ++i) {
        StandardServiceRegistry registry = ssrb.build();
        Metadata metadata = buildMetadata(registry);
        sessionFactories[i] = metadata.buildSessionFactory();
    }
}
Also used : Arrays(java.util.Arrays) ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) Transaction(org.hibernate.Transaction) Future(java.util.concurrent.Future) PessimisticLockException(org.hibernate.PessimisticLockException) PersistentClass(org.hibernate.mapping.PersistentClass) Map(java.util.Map) StaleStateException(org.hibernate.StaleStateException) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) SessionFactory(org.hibernate.SessionFactory) Set(java.util.Set) Category(org.junit.experimental.categories.Category) Executors(java.util.concurrent.Executors) InvocationTargetException(java.lang.reflect.InvocationTargetException) InterceptorConfiguration(org.infinispan.configuration.cache.InterceptorConfiguration) Stream(java.util.stream.Stream) AfterClassOnce(org.hibernate.testing.AfterClassOnce) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) TestingJtaPlatformImpl(org.hibernate.testing.jta.TestingJtaPlatformImpl) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) H2Dialect(org.hibernate.dialect.H2Dialect) LockAcquisitionException(org.hibernate.exception.LockAcquisitionException) TestResourceTracker(org.infinispan.test.fwk.TestResourceTracker) RunWith(org.junit.runner.RunWith) SimpleDateFormat(java.text.SimpleDateFormat) Session(org.hibernate.Session) Metadata(org.hibernate.boot.Metadata) ArrayList(java.util.ArrayList) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) BiConsumer(java.util.function.BiConsumer) JtaTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl) Environment(org.hibernate.cfg.Environment) Family(org.hibernate.test.cache.infinispan.stress.entities.Family) Properties(java.util.Properties) Files(java.nio.file.Files) BlockingDeque(java.util.concurrent.BlockingDeque) BufferedWriter(java.io.BufferedWriter) OptimisticLockException(javax.persistence.OptimisticLockException) RollbackCommand(org.infinispan.commands.tx.RollbackCommand) IOException(java.io.IOException) Test(org.junit.Test) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) Field(java.lang.reflect.Field) File(java.io.File) TreeMap(java.util.TreeMap) JdbcResourceLocalTransactionCoordinatorBuilderImpl(org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl) ForkJoinPool(java.util.concurrent.ForkJoinPool) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) InfinispanMessageLogger(org.hibernate.cache.infinispan.util.InfinispanMessageLogger) Date(java.util.Date) TransactionStatus(org.hibernate.resource.transaction.spi.TransactionStatus) Person(org.hibernate.test.cache.infinispan.stress.entities.Person) JtaAwareConnectionProviderImpl(org.hibernate.testing.jta.JtaAwareConnectionProviderImpl) InvocationContext(org.infinispan.context.InvocationContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AccessType(org.hibernate.cache.spi.access.AccessType) Method(java.lang.reflect.Method) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Parameterized(org.junit.runners.Parameterized) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) StaleObjectStateException(org.hibernate.StaleObjectStateException) Collection(org.hibernate.mapping.Collection) NavigableMap(java.util.NavigableMap) Collectors(java.util.stream.Collectors) TransactionException(org.hibernate.TransactionException) MetadataSources(org.hibernate.boot.MetadataSources) List(java.util.List) PersistenceException(javax.persistence.PersistenceException) Address(org.hibernate.test.cache.infinispan.stress.entities.Address) PutFromLoadValidator(org.hibernate.cache.infinispan.access.PutFromLoadValidator) TimeoutException(org.infinispan.util.concurrent.TimeoutException) Restrictions(org.hibernate.criterion.Restrictions) RootClass(org.hibernate.mapping.RootClass) HashMap(java.util.HashMap) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ConcurrentMap(java.util.concurrent.ConcurrentMap) RegionAccessStrategy(org.hibernate.cache.spi.access.RegionAccessStrategy) HashSet(java.util.HashSet) RollbackException(javax.transaction.RollbackException) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) ForkJoinTask(java.util.concurrent.ForkJoinTask) LockMode(org.hibernate.LockMode) Iterator(java.util.Iterator) CustomParameterized(org.hibernate.testing.junit4.CustomParameterized) NoJtaPlatform(org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform) CommitCommand(org.infinispan.commands.tx.CommitCommand) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) CacheMode(org.infinispan.configuration.cache.CacheMode) BaseCustomInterceptor(org.infinispan.interceptors.base.BaseCustomInterceptor) Ignore(org.junit.Ignore) BeforeClassOnce(org.hibernate.testing.BeforeClassOnce) VisitableCommand(org.infinispan.commands.VisitableCommand) Comparator(java.util.Comparator) TransactionManager(javax.transaction.TransactionManager) InvalidationCacheAccessDelegate(org.hibernate.cache.infinispan.access.InvalidationCacheAccessDelegate) RemoteException(org.infinispan.remoting.RemoteException) Collections(java.util.Collections) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Metadata(org.hibernate.boot.Metadata) File(java.io.File) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) BeforeClassOnce(org.hibernate.testing.BeforeClassOnce)

Example 2 with BeforeClassOnce

use of org.hibernate.testing.BeforeClassOnce in project hibernate-orm by hibernate.

the class NewCustomEntityMappingAnnotationsTest method setUp.

@BeforeClassOnce
public void setUp() {
    ssr = new StandardServiceRegistryBuilder().build();
    metadata = new MetadataSources(ssr).addAnnotatedClass(Forest.class).addAnnotatedClass(Forest2.class).addPackage(Forest.class.getPackage().getName()).buildMetadata();
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) BeforeClassOnce(org.hibernate.testing.BeforeClassOnce)

Example 3 with BeforeClassOnce

use of org.hibernate.testing.BeforeClassOnce in project hibernate-orm by hibernate.

the class AbstractRegionAccessStrategyTest method prepareResources.

@BeforeClassOnce
public void prepareResources() throws Exception {
    TestResourceTracker.testStarted(getClass().getSimpleName());
    // to mimic exactly the old code results, both environments here are exactly the same...
    StandardServiceRegistryBuilder ssrb = createStandardServiceRegistryBuilder();
    localEnvironment = new NodeEnvironment(ssrb);
    localEnvironment.prepare();
    localRegion = getRegion(localEnvironment);
    localAccessStrategy = getAccessStrategy(localRegion);
    transactional = Caches.isTransactionalCache(localRegion.getCache());
    invalidation = Caches.isInvalidationCache(localRegion.getCache());
    synchronous = Caches.isSynchronousCache(localRegion.getCache());
    remoteEnvironment = new NodeEnvironment(ssrb);
    remoteEnvironment.prepare();
    remoteRegion = getRegion(remoteEnvironment);
    remoteAccessStrategy = getAccessStrategy(remoteRegion);
    waitForClusterToForm(localRegion.getCache(), remoteRegion.getCache());
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) BeforeClassOnce(org.hibernate.testing.BeforeClassOnce)

Example 4 with BeforeClassOnce

use of org.hibernate.testing.BeforeClassOnce in project hibernate-orm by hibernate.

the class AbstractOneSessionTest method init.

@BeforeClassOnce
public void init() throws URISyntaxException {
    config = new Configuration();
    URL url = Thread.currentThread().getContextClassLoader().getResource(getHibernateConfigurationFileName());
    config.configure(new File(url.toURI()));
    String auditStrategy = getAuditStrategy();
    if (auditStrategy != null && !"".equals(auditStrategy)) {
        config.setProperty(EnversSettings.AUDIT_STRATEGY, auditStrategy);
    }
    config.setProperty(Environment.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
    config.setProperty(EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false");
    addProperties(config);
    this.initMappings();
    serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry(config.getProperties());
    sessionFactory = config.buildSessionFactory(serviceRegistry);
}
Also used : Configuration(org.hibernate.cfg.Configuration) File(java.io.File) URL(java.net.URL) BeforeClassOnce(org.hibernate.testing.BeforeClassOnce)

Aggregations

BeforeClassOnce (org.hibernate.testing.BeforeClassOnce)4 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)3 File (java.io.File)2 MetadataSources (org.hibernate.boot.MetadataSources)2 BufferedWriter (java.io.BufferedWriter)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 Files (java.nio.file.Files)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1