Search in sources :

Example 1 with TestForIssue

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

the class CursorFromCallableTest method testStatementClosing.

@Test
@TestForIssue(jiraKey = "HHH-7984")
public void testStatementClosing() {
    Session session = openSession();
    session.getTransaction().begin();
    // Reading maximum number of opened cursors requires SYS privileges.
    // Verify statement closing with JdbcCoordinator#hasRegisteredResources() instead.
    // BigDecimal maxCursors = (BigDecimal) session.createSQLQuery( "SELECT value FROM v$parameter WHERE name = 'open_cursors'" ).uniqueResult();
    // for ( int i = 0; i < maxCursors + 10; ++i ) { named_query_execution }
    Assert.assertEquals(Arrays.asList(new NumValue(1, "Line 1"), new NumValue(2, "Line 2")), session.getNamedQuery("NumValue.getSomeValues").list());
    JdbcCoordinator jdbcCoordinator = ((SessionImplementor) session).getJdbcCoordinator();
    Assert.assertFalse("Prepared statement and result set should be released afterQuery query execution.", jdbcCoordinator.getResourceRegistry().hasRegisteredResources());
    session.getTransaction().commit();
    session.close();
}
Also used : JdbcCoordinator(org.hibernate.engine.jdbc.spi.JdbcCoordinator) SessionImplementor(org.hibernate.engine.spi.SessionImplementor) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 2 with TestForIssue

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

the class ByteTest method testByteDataPersistenceAndRetrieval.

@Test
@TestForIssue(jiraKey = "HHH-6533")
public void testByteDataPersistenceAndRetrieval() {
    Session session = openSession();
    Transaction transaction = session.beginTransaction();
    VariousTypesEntity entity = new VariousTypesEntity();
    entity.setId(1);
    entity.setByteData(TEST_VALUE);
    session.persist(entity);
    transaction.commit();
    session.close();
    // Testing sample value.
    session = openSession();
    transaction = session.beginTransaction();
    entity = (VariousTypesEntity) session.createQuery(" from VariousTypesEntity " + " where byteData = org.hibernate.test.typedescriptor.ByteTest.TEST_VALUE ").uniqueResult();
    Assert.assertNotNull(entity);
    Assert.assertEquals(TEST_VALUE, entity.getByteData());
    entity.setByteData(Byte.MIN_VALUE);
    session.update(entity);
    transaction.commit();
    session.close();
    // Testing minimal value.
    session = openSession();
    transaction = session.beginTransaction();
    entity = (VariousTypesEntity) session.createQuery(" from VariousTypesEntity " + " where byteData = java.lang.Byte.MIN_VALUE ").uniqueResult();
    Assert.assertNotNull(entity);
    Assert.assertEquals(Byte.MIN_VALUE, entity.getByteData());
    entity.setByteData(Byte.MAX_VALUE);
    session.update(entity);
    transaction.commit();
    session.close();
    // Testing maximal value.
    session = openSession();
    transaction = session.beginTransaction();
    entity = (VariousTypesEntity) session.createQuery(" from VariousTypesEntity " + " where byteData = java.lang.Byte.MAX_VALUE ").uniqueResult();
    Assert.assertNotNull(entity);
    Assert.assertEquals(Byte.MAX_VALUE, entity.getByteData());
    transaction.commit();
    session.close();
}
Also used : Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 3 with TestForIssue

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

the class PutFromLoadValidatorUnitTest method testGetForNullReleasePuts.

@Test
@TestForIssue(jiraKey = "HHH-9928")
public void testGetForNullReleasePuts() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.simpleCache(true).expiration().maxIdle(500);
    Configuration ppCfg = cb.build();
    InfinispanRegionFactory regionFactory = mock(InfinispanRegionFactory.class);
    doReturn(ppCfg).when(regionFactory).getPendingPutsCacheConfiguration();
    doAnswer(invocation -> TIME_SERVICE.wallClockTime()).when(regionFactory).nextTimestamp();
    PutFromLoadValidator testee = new PutFromLoadValidator(cache, regionFactory, cm);
    for (int i = 0; i < 100; ++i) {
        try {
            withTx(tm, () -> {
                SharedSessionContractImplementor session = mock(SharedSessionContractImplementor.class);
                testee.registerPendingPut(session, KEY1, 0);
                return null;
            });
            TIME_SERVICE.advance(10);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    String ppName = cm.getCache().getName() + "-" + InfinispanRegionFactory.DEF_PENDING_PUTS_RESOURCE;
    Map ppCache = cm.getCache(ppName, false);
    assertNotNull(ppCache);
    Object pendingPutMap = ppCache.get(KEY1);
    assertNotNull(pendingPutMap);
    int size;
    try {
        Method sizeMethod = pendingPutMap.getClass().getMethod("size");
        sizeMethod.setAccessible(true);
        size = (Integer) sizeMethod.invoke(pendingPutMap);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // some of the pending puts need to be expired by now
    assertTrue(size < 100);
    // but some are still registered
    assertTrue(size > 0);
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) InfinispanRegionFactory(org.hibernate.cache.infinispan.InfinispanRegionFactory) TestInfinispanRegionFactory(org.hibernate.test.cache.infinispan.util.TestInfinispanRegionFactory) Configuration(org.infinispan.configuration.cache.Configuration) PutFromLoadValidator(org.hibernate.cache.infinispan.access.PutFromLoadValidator) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) Method(java.lang.reflect.Method) Map(java.util.Map) TimeoutException(java.util.concurrent.TimeoutException) Exceptions.expectException(org.infinispan.test.Exceptions.expectException) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 4 with TestForIssue

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

the class InvalidationTest method testFailedUpdate.

@TestForIssue(jiraKey = "HHH-11304")
@Test
public void testFailedUpdate() throws Exception {
    AdvancedCache pendingPutsCache = getPendingPutsCache(Item.class);
    assertNoInvalidators(pendingPutsCache);
    final Item item = new Item("before-update", "bar");
    withTxSession(s -> s.persist(item));
    withTxSession(s -> {
        Item item2 = s.load(Item.class, item.getId());
        assertEquals("before-update", item2.getName());
        item2.setName("after-update");
        s.persist(item2);
        s.flush();
        s.flush();
        s.getTransaction().setRollbackOnly();
    });
    assertNoInvalidators(pendingPutsCache);
    withTxSession(s -> {
        Item item3 = s.load(Item.class, item.getId());
        assertEquals("before-update", item3.getName());
        s.remove(item3);
    });
    assertNoInvalidators(pendingPutsCache);
}
Also used : Item(org.hibernate.test.cache.infinispan.functional.entities.Item) AdvancedCache(org.infinispan.AdvancedCache) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 5 with TestForIssue

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

the class TombstoneTest method testEvictPutFromLoadDuringUpdate.

@TestForIssue(jiraKey = "HHH-11323")
@Test
public void testEvictPutFromLoadDuringUpdate() throws Exception {
    CountDownLatch flushLatch = new CountDownLatch(1);
    CountDownLatch commitLatch = new CountDownLatch(1);
    CyclicBarrier putFromLoadBarrier = new CyclicBarrier(2);
    Future<?> putFromLoad = blockedPutFromLoad(putFromLoadBarrier);
    Future<Boolean> update = updateFlushWait(itemId, null, null, flushLatch, commitLatch);
    // Flush stores FutureUpdate(timestamp, null)
    awaitOrThrow(flushLatch);
    sessionFactory().getCache().evictEntity(Item.class, itemId);
    commitLatch.countDown();
    update.get(WAIT_TIMEOUT, TimeUnit.SECONDS);
    unblockPutFromLoad(putFromLoadBarrier, putFromLoad);
    assertItemDescription("Updated item");
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

TestForIssue (org.hibernate.testing.TestForIssue)649 Test (org.junit.Test)647 Session (org.hibernate.Session)357 EntityManager (javax.persistence.EntityManager)97 List (java.util.List)91 Transaction (org.hibernate.Transaction)88 MetadataSources (org.hibernate.boot.MetadataSources)47 ArrayList (java.util.ArrayList)38 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)38 Query (org.hibernate.Query)28 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)25 Metadata (org.hibernate.boot.Metadata)24 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)24 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)23 Map (java.util.Map)22 CollectionEntry (org.hibernate.engine.spi.CollectionEntry)19 HashMap (java.util.HashMap)18 SessionImplementor (org.hibernate.engine.spi.SessionImplementor)18 PersistentClass (org.hibernate.mapping.PersistentClass)18 HibernateException (org.hibernate.HibernateException)16