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();
}
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();
}
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);
}
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);
}
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");
}
Aggregations