Search in sources :

Example 46 with Statistics

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());
}
Also used : Statistics(org.hibernate.stat.Statistics) Session(org.hibernate.Session) Test(org.junit.Test)

Example 47 with Statistics

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());
}
Also used : Statistics(org.hibernate.stat.Statistics) Session(org.hibernate.Session) Test(org.junit.Test)

Example 48 with Statistics

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());
}
Also used : Statistics(org.hibernate.stat.Statistics) Session(org.hibernate.Session) Test(org.junit.Test)

Example 49 with Statistics

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());
}
Also used : Statistics(org.hibernate.stat.Statistics) Session(org.hibernate.Session) Test(org.junit.Test)

Example 50 with Statistics

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";
}
Also used : EntityManager(javax.persistence.EntityManager) QueryStatistics(org.hibernate.stat.QueryStatistics) CacheRegionStatistics(org.hibernate.stat.CacheRegionStatistics) Statistics(org.hibernate.stat.Statistics) CacheRegionStatistics(org.hibernate.stat.CacheRegionStatistics)

Aggregations

Statistics (org.hibernate.stat.Statistics)97 Test (org.junit.Test)59 Session (org.hibernate.Session)27 SecondLevelCacheStatistics (org.hibernate.stat.SecondLevelCacheStatistics)26 EntityManager (javax.persistence.EntityManager)21 QueryStatistics (org.hibernate.stat.QueryStatistics)19 Item (org.hibernate.test.cache.infinispan.functional.entities.Item)14 Transaction (org.hibernate.Transaction)12 ArrayList (java.util.ArrayList)11 VersionedItem (org.hibernate.test.cache.infinispan.functional.entities.VersionedItem)11 List (java.util.List)10 OtherItem (org.hibernate.test.cache.infinispan.functional.entities.OtherItem)10 SessionFactory (org.hibernate.SessionFactory)9 CacheRegionStatistics (org.hibernate.stat.CacheRegionStatistics)9 ByRef (org.infinispan.commons.util.ByRef)8 TestForIssue (org.hibernate.testing.TestForIssue)6 Date (java.util.Date)5 UserTransaction (javax.transaction.UserTransaction)5 NaturalIdCacheStatistics (org.hibernate.stat.NaturalIdCacheStatistics)5 Test (org.testng.annotations.Test)5