use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.
the class MultiCircleJpaCascadeTest method testPersistThenUpdate.
@Test
@FailureExpected(jiraKey = "HHH-6999")
public // fails on d.e; should pass
void testPersistThenUpdate() {
EntityManager em = getOrCreateEntityManager();
em.getTransaction().begin();
em.persist(b);
// remove old e from associations
e.getDCollection().remove(d);
d.setE(null);
f.getECollection().remove(e);
e.setF(null);
// add new e to associations
e = new E();
e.getDCollection().add(d);
f.getECollection().add(e);
d.setE(e);
e.setF(f);
em.getTransaction().commit();
em.close();
check();
}
use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.
the class LockTest method testQueryTimeoutEMProps.
@Test
@RequiresDialect(Oracle10gDialect.class)
@RequiresDialectFeature(DialectChecks.SupportsLockTimeouts.class)
@FailureExpected(jiraKey = "HHH-8001")
public void testQueryTimeoutEMProps() throws Exception {
EntityManager em = getOrCreateEntityManager();
Map<String, Object> queryTimeoutProps = new HashMap<String, Object>();
// 1 sec timeout (should round up)
queryTimeoutProps.put(QueryHints.SPEC_HINT_TIMEOUT, 500);
final EntityManager em2 = createIsolatedEntityManager(queryTimeoutProps);
Lock lock = new Lock();
Thread t = null;
FutureTask<Boolean> bgTask;
final CountDownLatch latch = new CountDownLatch(1);
try {
lock.setName("testQueryTimeout");
em.getTransaction().begin();
em.persist(lock);
em.getTransaction().commit();
em.clear();
em.getTransaction().begin();
lock = em.getReference(Lock.class, lock.getId());
em.lock(lock, LockModeType.PESSIMISTIC_WRITE);
final Integer id = lock.getId();
// force entity to be read
lock.getName();
log.info("testQueryTimeout: got write lock");
bgTask = new FutureTask<Boolean>(new Callable<Boolean>() {
public Boolean call() {
try {
// true (success) if LockTimeoutException occurred
boolean timedOut = false;
em2.getTransaction().begin();
log.info("testQueryTimeout: (BG) about to read write-locked entity");
// we should block on the following read
Lock lock2 = em2.getReference(Lock.class, id);
// force entity to be read
lock2.getName();
log.info("testQueryTimeout: (BG) read write-locked entity");
try {
// we should block on the following read
Query query = em2.createQuery("select L from Lock_ L where L.id < 10000 ");
query.setLockMode(LockModeType.PESSIMISTIC_READ);
List<Lock> resultList = query.getResultList();
// force entity to be read
String name = resultList.get(0).getName();
log.info("testQueryTimeout: name read =" + name);
} catch (QueryTimeoutException e) {
// success
log.info("testQueryTimeout: (BG) got expected timeout exception");
timedOut = true;
} catch (Throwable e) {
log.info("testQueryTimeout: Expected LockTimeoutException but got unexpected exception", e);
}
em2.getTransaction().commit();
return timedOut;
} finally {
// signal that we finished
latch.countDown();
}
}
});
t = new Thread(bgTask);
t.setDaemon(true);
t.setName("testQueryTimeout (bg)");
t.start();
// should return quickly on success
boolean latchSet = latch.await(10, TimeUnit.SECONDS);
assertTrue("background test thread finished (lock timeout is broken)", latchSet);
assertTrue("background test thread timed out on lock attempt", bgTask.get());
em.getTransaction().commit();
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
if (t != null) {
// wait for background thread to finish beforeQuery deleting entity
t.join();
}
em.getTransaction().begin();
lock = em.getReference(Lock.class, lock.getId());
em.remove(lock);
em.getTransaction().commit();
em.close();
em2.close();
}
}
use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.
the class DeleteOneToManyOrphansTest method testOrphanedWhileManagedMergeOwner.
@Test
@TestForIssue(jiraKey = "HHH-9568")
@FailureExpected(jiraKey = "HHH-9568")
public void testOrphanedWhileManagedMergeOwner() {
createData();
EntityManager entityManager = getOrCreateEntityManager();
entityManager.getTransaction().begin();
List results = entityManager.createQuery("from Feature").getResultList();
assertEquals(1, results.size());
results = entityManager.createQuery("from Product").getResultList();
assertEquals(1, results.size());
Product product = (Product) results.get(0);
assertEquals(1, product.getFeatures().size());
product.getFeatures().clear();
entityManager.merge(product);
entityManager.getTransaction().commit();
entityManager.close();
entityManager = getOrCreateEntityManager();
entityManager.getTransaction().begin();
product = entityManager.find(Product.class, product.getId());
assertEquals(0, product.getFeatures().size());
results = entityManager.createQuery("from Feature").getResultList();
assertEquals(0, results.size());
results = entityManager.createQuery("from Product").getResultList();
assertEquals(1, results.size());
entityManager.getTransaction().commit();
entityManager.close();
cleanupData();
}
use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.
the class JpaTckUsageTest method testExecuteUpdate.
@Test
@FailureExpected(jiraKey = "HHH-8395", message = "Out of the frying pan into the fire: https://issues.apache.org/jira/browse/DERBY-211")
public void testExecuteUpdate() {
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
try {
StoredProcedureQuery query = em.createStoredProcedureQuery("deleteAllUsers");
int count = query.executeUpdate();
// this fails because the Derby EmbeddedDriver is returning zero here rather than the actual updateCount :(
// https://issues.apache.org/jira/browse/DERBY-211
assertEquals(1, count);
} finally {
em.getTransaction().commit();
em.close();
}
}
use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.
the class EmbeddedTest method testQueryWithEmbeddedParameterAllNull.
@Test
@TestForIssue(jiraKey = "HHH-8172")
@FailureExpected(jiraKey = "HHH-8172")
public void testQueryWithEmbeddedParameterAllNull() throws Exception {
Session s;
Transaction tx;
Person person = new Person();
Address a = new Address();
Country c = new Country();
Country bornCountry = new Country();
assertNull(bornCountry.getIso2());
assertNull(bornCountry.getName());
a.address1 = "colorado street";
a.city = "Springfield";
a.country = c;
person.address = a;
person.bornIn = bornCountry;
person.name = "Homer";
TransactionUtil.doInHibernate(this::sessionFactory, session -> {
session.persist(person);
});
TransactionUtil.doInHibernate(this::sessionFactory, session -> {
Person p = (Person) session.createQuery("from Person p where p.bornIn = :b").setParameter("b", person.bornIn).uniqueResult();
assertNotNull(p);
assertNotNull(p.address);
assertEquals("Springfield", p.address.city);
assertNotNull(p.address.country);
assertEquals("DM", p.address.country.getIso2());
assertNull(p.bornIn);
});
}
Aggregations