use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.
the class CustomRunner method doComputation.
protected List<FrameworkMethod> doComputation() {
// Next, get all the test methods as understood by JUnit
final List<FrameworkMethod> methods = super.computeTestMethods();
// Now process that full list of test methods and build our custom result
final List<FrameworkMethod> result = new ArrayList<FrameworkMethod>();
final boolean doValidation = Boolean.getBoolean(Helper.VALIDATE_FAILURE_EXPECTED);
int testCount = 0;
Ignore virtualIgnore;
for (FrameworkMethod frameworkMethod : methods) {
// potentially ignore based on expected failure
final FailureExpected failureExpected = Helper.locateAnnotation(FailureExpected.class, frameworkMethod, getTestClass());
if (failureExpected != null && !doValidation) {
virtualIgnore = new IgnoreImpl(Helper.extractIgnoreMessage(failureExpected, frameworkMethod));
} else {
virtualIgnore = convertSkipToIgnore(frameworkMethod);
}
testCount++;
log.trace("adding test " + Helper.extractTestName(frameworkMethod) + " [#" + testCount + "]");
result.add(new ExtendedFrameworkMethod(frameworkMethod, virtualIgnore, failureExpected));
}
return result;
}
use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.
the class ReadOnlyProxyTest method testModifyToReadOnlyToModifiableIsUpdated.
@Test
@FailureExpected(jiraKey = "HHH-4642")
public void testModifyToReadOnlyToModifiableIsUpdated() {
DataPoint dpOrig = createDataPoint(CacheMode.IGNORE);
Session s = openSession();
s.setCacheMode(CacheMode.IGNORE);
s.beginTransaction();
DataPoint dp = (DataPoint) s.load(DataPoint.class, new Long(dpOrig.getId()));
assertTrue(dp instanceof HibernateProxy);
assertFalse(Hibernate.isInitialized(dp));
checkReadOnly(s, dp, false);
dp.setDescription("changed");
assertTrue(Hibernate.isInitialized(dp));
assertEquals("changed", dp.getDescription());
s.setReadOnly(dp, true);
checkReadOnly(s, dp, true);
s.setReadOnly(dp, false);
checkReadOnly(s, dp, false);
assertEquals("changed", dp.getDescription());
s.flush();
s.getTransaction().commit();
s.close();
s = openSession();
s.beginTransaction();
dp = (DataPoint) s.get(DataPoint.class, dpOrig.getId());
assertEquals(dpOrig.getId(), dp.getId());
assertEquals(dpOrig.getDescription(), dp.getDescription());
assertEquals(dpOrig.getX(), dp.getX());
assertEquals(dpOrig.getY(), dp.getY());
try {
assertEquals("changed", dp.getDescription());
// should fail due to HHH-4642
} finally {
s.getTransaction().rollback();
s.close();
s = openSession();
s.beginTransaction();
s.delete(dp);
s.getTransaction().commit();
s.close();
}
}
use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.
the class ReadOnlyVersionedNodesTest method testUpdateSetReadOnlySetModifiable.
@Test
@FailureExpected(jiraKey = "unknown")
public void testUpdateSetReadOnlySetModifiable() throws Exception {
Session s = openSession();
s.beginTransaction();
VersionedNode node = new VersionedNode("node", "node");
s.persist(node);
s.getTransaction().commit();
s.close();
clearCounts();
s = openSession();
s.beginTransaction();
node = (VersionedNode) s.get(VersionedNode.class, node.getId());
node.setName("node-name");
s.setReadOnly(node, true);
s.setReadOnly(node, false);
s.getTransaction().commit();
s.close();
assertUpdateCount(1);
assertInsertCount(0);
s = openSession();
s.beginTransaction();
node = (VersionedNode) s.get(VersionedNode.class, node.getId());
assertEquals("node-name", node.getName());
assertEquals(1, node.getVersion());
s.delete(node);
s.getTransaction().commit();
s.close();
}
use of org.hibernate.testing.FailureExpected in project hibernate-orm by hibernate.
the class LockTest method testQueryTimeout.
@Test
@RequiresDialect(Oracle10gDialect.class)
@RequiresDialectFeature(DialectChecks.SupportsLockTimeouts.class)
@FailureExpected(jiraKey = "HHH-8001")
public void testQueryTimeout() throws Exception {
EntityManager em = getOrCreateEntityManager();
final EntityManager em2 = createIsolatedEntityManager();
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);
// 1 sec timeout
query.setHint(QueryHints.SPEC_HINT_TIMEOUT, 500);
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 MappedSuperclassWithOverriddenAttributeTest method testStaticMetamodelOverridden.
@Test
@FailureExpected(jiraKey = "HHH-11078")
public void testStaticMetamodelOverridden() {
EntityManagerFactory emf = TestingEntityManagerFactoryGenerator.generateEntityManagerFactory(AvailableSettings.LOADED_CLASSES, Arrays.asList(Product2.class));
try {
assertNotNull("'Product1_.overridenName' should not be null)", Product1_.overridenName);
assertNotNull("'Product2_.overridenName' should not be null)", Product2_.overridenName);
// is null
} finally {
emf.close();
}
}
Aggregations