use of org.hibernate.stat.Statistics in project redisson by redisson.
the class TransactionalTest method testCollection.
@Test
public void testCollection() {
Long id = null;
Statistics stats = sessionFactory().getStatistics();
Session s = openSession();
s.beginTransaction();
ItemTransactional item = new ItemTransactional("data");
item.getEntries().addAll(Arrays.asList("a", "b", "c"));
id = (Long) s.save(item);
s.flush();
s.getTransaction().commit();
s = openSession();
s.beginTransaction();
item = (ItemTransactional) s.get(ItemTransactional.class, id);
assertThat(item.getEntries()).containsExactly("a", "b", "c");
s.getTransaction().commit();
s.close();
Assert.assertEquals(1, stats.getDomainDataRegionStatistics("item_entries").getPutCount());
s = openSession();
s.beginTransaction();
item = (ItemTransactional) s.get(ItemTransactional.class, id);
assertThat(item.getEntries()).containsExactly("a", "b", "c");
s.delete(item);
s.getTransaction().commit();
s.close();
Assert.assertEquals(1, stats.getDomainDataRegionStatistics("item_entries").getHitCount());
}
use of org.hibernate.stat.Statistics in project redisson by redisson.
the class TransactionalTest method testUpdateWithRefreshThenRollback.
@Test
public void testUpdateWithRefreshThenRollback() {
Statistics stats = sessionFactory().getStatistics();
Long id = null;
Session s = openSession();
s.beginTransaction();
ItemTransactional item = new ItemTransactional("data");
id = (Long) s.save(item);
s.flush();
s.getTransaction().commit();
Assert.assertEquals(1, stats.getDomainDataRegionStatistics("item").getPutCount());
s = openSession();
s.beginTransaction();
item = (ItemTransactional) s.get(ItemTransactional.class, id);
item.setName("newdata");
s.update(item);
s.flush();
s.refresh(item);
s.getTransaction().rollback();
s.clear();
s.close();
Assert.assertEquals(1, stats.getDomainDataRegionStatistics("item").getHitCount());
}
use of org.hibernate.stat.Statistics in project redisson by redisson.
the class ReadWriteTest method testTimeToLive.
@Test
public void testTimeToLive() throws InterruptedException {
Statistics stats = sessionFactory().getStatistics();
Long id;
Session s = openSession();
s.beginTransaction();
ItemReadWrite item = new ItemReadWrite("data");
id = (Long) s.save(item);
s.flush();
s.getTransaction().commit();
s.close();
Thread.sleep(900);
s = openSession();
s.beginTransaction();
item = s.get(ItemReadWrite.class, id);
Assert.assertEquals("data", item.getName());
s.getTransaction().commit();
s.close();
Assert.assertEquals(1, stats.getDomainDataRegionStatistics("item").getHitCount());
Assert.assertEquals(0, stats.getDomainDataRegionStatistics("item").getMissCount());
Thread.sleep(600);
s = openSession();
s.beginTransaction();
item = s.get(ItemReadWrite.class, id);
Assert.assertEquals("data", item.getName());
s.delete(item);
s.getTransaction().commit();
s.close();
Assert.assertEquals(1, stats.getDomainDataRegionStatistics("item").getHitCount());
Assert.assertEquals(1, stats.getDomainDataRegionStatistics("item").getMissCount());
}
use of org.hibernate.stat.Statistics in project redisson by redisson.
the class ReadWriteTest method testCollection.
@Test
public void testCollection() {
Long id = null;
Statistics stats = sessionFactory().getStatistics();
Session s = openSession();
s.beginTransaction();
ItemReadWrite item = new ItemReadWrite("data");
item.getEntries().addAll(Arrays.asList("a", "b", "c"));
id = (Long) s.save(item);
s.flush();
s.getTransaction().commit();
s = openSession();
s.beginTransaction();
item = s.get(ItemReadWrite.class, id);
assertThat(item.getEntries()).containsExactly("a", "b", "c");
s.getTransaction().commit();
s.close();
Assert.assertEquals(1, stats.getDomainDataRegionStatistics("item_entries").getPutCount());
s = openSession();
s.beginTransaction();
item = s.get(ItemReadWrite.class, id);
assertThat(item.getEntries()).containsExactly("a", "b", "c");
s.delete(item);
s.getTransaction().commit();
s.close();
Assert.assertEquals(1, stats.getDomainDataRegionStatistics("item_entries").getHitCount());
}
use of org.hibernate.stat.Statistics in project wildfly by wildfly.
the class SFSB2LC method addEntitiesAndEvictAll.
/**
* Insert 2 entities and put them into the 2LC and then evicts entity cache.
*/
public String addEntitiesAndEvictAll(String CACHE_REGION_NAME) {
EntityManager em = emf.createEntityManager();
Statistics stats = em.unwrap(Session.class).getSessionFactory().getStatistics();
stats.clear();
CacheRegionStatistics emp2LCStats = stats.getDomainDataRegionStatistics(CACHE_REGION_NAME + "Employee");
try {
createEmployee(em, "Jan", "Ostrava", 20);
createEmployee(em, "Martin", "Brno", 30);
assertEquals("There are 2 puts in the 2LC" + generateEntityCacheStats(emp2LCStats), 2, emp2LCStats.getPutCount());
assertTrue("Expected entities stored in the cache" + generateEntityCacheStats(emp2LCStats), emp2LCStats.getElementCountInMemory() > 0);
// evict entity 2lc
emf.getCache().evictAll();
} catch (AssertionError e) {
return e.getMessage();
} finally {
em.close();
}
return "OK";
}
Aggregations