List of usage examples for org.hibernate.stat SecondLevelCacheStatistics getEntries
default Map getEntries()
From source file:com.francetelecom.clara.cloud.scalability.helper.StatisticsHelper.java
License:Apache License
private static void secondLevelStats(Statistics stats, String name) { logger.info("Second level statistics for " + name); SecondLevelCacheStatistics slStats = stats.getSecondLevelCacheStatistics(name); logger.info(" Elements in memory : " + slStats.getElementCountInMemory()); logger.info(" Element on disk : " + slStats.getElementCountOnDisk()); logger.info(" Entries : " + slStats.getEntries()); logger.info(" Hit count : " + slStats.getHitCount()); logger.info(" Miss count : " + slStats.getMissCount()); logger.info(" Put count : " + slStats.getPutCount()); logger.info(" Memory size : " + slStats.getSizeInMemory()); }
From source file:com.hazelcast.hibernate.CacheHitMissNonStrictTest.java
License:Open Source License
@Test public void testUpdateEventuallyInvalidatesObject() { insertDummyEntities(10, 4);/*from ww w . ja va 2 s. c om*/ //all 10 entities and 40 properties are cached final SecondLevelCacheStatistics dummyEntityCacheStats = sf.getStatistics() .getSecondLevelCacheStatistics(CACHE_ENTITY); SecondLevelCacheStatistics dummyPropertyCacheStats = sf.getStatistics() .getSecondLevelCacheStatistics(CACHE_PROPERTY); sf.getCache().evictEntityRegions(); sf.getCache().evictCollectionRegions(); //miss 10 entities getDummyEntities(sf, 10); //hit 1 entity and 4 properties updateDummyEntityName(sf, 2, "updated"); assertSizeEventually(9, dummyEntityCacheStats.getEntries()); }
From source file:com.hibernateinstrumentator.jboss.StatisticsService.java
License:Apache License
@Override public Map<String, Object> getSecondLevelCacheStatisticsMap(String regionName) { Map<String, Object> m = null; SecondLevelCacheStatistics slcs = super.getSecondLevelCacheStatistics(regionName); if (slcs != null) { m = new HashMap<String, Object>(); m.put("elementCountInMemory", slcs.getElementCountInMemory()); m.put("elementCountOnDisk", slcs.getElementCountOnDisk()); m.put("entries", slcs.getEntries()); m.put("hitCount", slcs.getHitCount()); m.put("missCount", slcs.getMissCount()); m.put("putCount", slcs.getPutCount()); m.put("sizeInMemory", slcs.getSizeInMemory()); }/*from www . j a va 2 s . c om*/ return m; }
From source file:com.thoughtworks.go.server.dao.UserSqlMapDaoCachingTest.java
License:Apache License
@Test public void shouldCacheUserOnFind() { User first = new User("first"); first.addNotificationFilter(new NotificationFilter("pipline", "stage1", StageEvent.Fails, true)); first.addNotificationFilter(new NotificationFilter("pipline", "stage2", StageEvent.Fails, true)); int originalUserCacheSize = sessionFactory.getStatistics() .getSecondLevelCacheStatistics(User.class.getCanonicalName()).getEntries().size(); int originalNotificationsCacheSize = sessionFactory.getStatistics() .getSecondLevelCacheStatistics(User.class.getCanonicalName() + ".notificationFilters").getEntries() .size();/*from w w w. j a v a2 s . c o m*/ userDao.saveOrUpdate(first); long userId = userDao.findUser("first").getId(); assertThat(sessionFactory.getStatistics().getSecondLevelCacheStatistics(User.class.getCanonicalName()) .getEntries().size(), is(originalUserCacheSize + 1)); SecondLevelCacheStatistics notificationFilterCollectionCache = sessionFactory.getStatistics() .getSecondLevelCacheStatistics(User.class.getCanonicalName() + ".notificationFilters"); assertThat(notificationFilterCollectionCache.getEntries().size(), is(originalNotificationsCacheSize + 1)); assertThat(notificationFilterCollectionCache.getEntries().get(userId), is(Matchers.notNullValue())); }
From source file:org.apache.ignite.examples.datagrid.hibernate.HibernateL2CacheExample.java
License:Apache License
/** * Prints Hibernate L2 cache statistics to standard output. * * @param sesFactory Hibernate {@link SessionFactory}, for which to print * statistics.//from ww w . j ava2 s. c o m */ private static void printStats(SessionFactory sesFactory) { System.out.println("=== Hibernate L2 cache statistics ==="); for (String entityName : ENTITY_NAMES) { System.out.println("\tEntity: " + entityName); SecondLevelCacheStatistics stats = sesFactory.getStatistics().getSecondLevelCacheStatistics(entityName); System.out.println("\t\tL2 cache entries: " + stats.getEntries()); System.out.println("\t\tHits: " + stats.getHitCount()); System.out.println("\t\tMisses: " + stats.getMissCount()); } System.out.println("====================================="); }
From source file:org.infinispan.test.hibernate.cache.functional.ConcurrentWriteTest.java
License:LGPL
@Test public void testSingleUser() throws Exception { // setup//from w ww . j ava2 s. c o m sessionFactory().getStatistics().clear(); // wait a while to make sure that timestamp comparison works after invalidateRegion TIME_SERVICE.advance(1); Customer customer = createCustomer(0); final Integer customerId = customer.getId(); getCustomerIDs().add(customerId); // wait a while to make sure that timestamp comparison works after collection remove (during insert) TIME_SERVICE.advance(1); assertNull("contact exists despite not being added", getFirstContact(customerId)); // check that cache was hit SecondLevelCacheStatistics customerSlcs = sessionFactory().getStatistics() .getSecondLevelCacheStatistics(Customer.class.getName()); assertEquals(1, customerSlcs.getPutCount()); assertEquals(1, customerSlcs.getElementCountInMemory()); assertEquals(1, customerSlcs.getEntries().size()); log.infof("Add contact to customer {0}", customerId); SecondLevelCacheStatistics contactsCollectionSlcs = sessionFactory().getStatistics() .getSecondLevelCacheStatistics(Customer.class.getName() + ".contacts"); assertEquals(1, contactsCollectionSlcs.getPutCount()); assertEquals(1, contactsCollectionSlcs.getElementCountInMemory()); assertEquals(1, contactsCollectionSlcs.getEntries().size()); final Contact contact = addContact(customerId); assertNotNull("contact returned by addContact is null", contact); assertEquals("Customer.contacts cache was not invalidated after addContact", 0, contactsCollectionSlcs.getElementCountInMemory()); assertNotNull("Contact missing after successful add call", getFirstContact(customerId)); // read everyone's contacts readEveryonesFirstContact(); removeContact(customerId); assertNull("contact still exists after successful remove call", getFirstContact(customerId)); }
From source file:org.infinispan.test.hibernate.cache.functional.ReadOnlyTest.java
License:LGPL
@Test public void testEmptySecondLevelCacheEntry() throws Exception { sessionFactory().getCache().evictCollectionRegion(Item.class.getName() + ".items"); Statistics stats = sessionFactory().getStatistics(); stats.clear();/*from w w w .j a v a 2 s . c o m*/ SecondLevelCacheStatistics statistics = stats .getSecondLevelCacheStatistics(Item.class.getName() + ".items"); Map cacheEntries = statistics.getEntries(); assertEquals(0, cacheEntries.size()); }
From source file:org.infinispan.test.hibernate.cache.functional.ReadWriteTest.java
License:LGPL
@Test public void testCollectionCache() throws Exception { final Statistics stats = sessionFactory().getStatistics(); stats.clear();//from www . j a v a 2 s .c om final Item item = new Item("chris", "Chris's Item"); final Item another = new Item("another", "Owned Item"); item.addItem(another); withTxSession(s -> { s.persist(item); s.persist(another); }); // The collection has been removed, but we can't add it again immediately using putFromLoad TIME_SERVICE.advance(1); withTxSession(s -> { Item loaded = s.load(Item.class, item.getId()); assertEquals(1, loaded.getItems().size()); }); SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics(Item.class.getName() + ".items"); assertEquals(1, cStats.getElementCountInMemory()); withTxSession(s -> { Item loadedWithCachedCollection = (Item) s.load(Item.class, item.getId()); stats.logSummary(); assertEquals(item.getName(), loadedWithCachedCollection.getName()); assertEquals(item.getItems().size(), loadedWithCachedCollection.getItems().size()); assertEquals(1, cStats.getHitCount()); Map cacheEntries = cStats.getEntries(); assertEquals(1, cacheEntries.size()); Item itemElement = loadedWithCachedCollection.getItems().iterator().next(); itemElement.setOwner(null); loadedWithCachedCollection.getItems().clear(); s.delete(itemElement); s.delete(loadedWithCachedCollection); }); }
From source file:org.infinispan.test.hibernate.cache.functional.ReadWriteTest.java
License:LGPL
@Test public void testStaleWritesLeaveCacheConsistent() throws Exception { Statistics stats = sessionFactory().getStatistics(); stats.clear();/*from w w w. j ava2s .c o m*/ ByRef<VersionedItem> itemRef = new ByRef<>(null); withTxSession(s -> { VersionedItem item = new VersionedItem(); item.setName("steve"); item.setDescription("steve's item"); s.save(item); itemRef.set(item); }); final VersionedItem item = itemRef.get(); Long initialVersion = item.getVersion(); // manually revert the version property item.setVersion(new Long(item.getVersion().longValue() - 1)); try { withTxSession(s -> s.update(item)); fail("expected stale write to fail"); } catch (Exception e) { log.debug("Rollback was expected", e); } // check the version value in the cache... SecondLevelCacheStatistics slcs = stats.getSecondLevelCacheStatistics(VersionedItem.class.getName()); Object entry = slcs.getEntries().get(item.getId()); Long cachedVersionValue; cachedVersionValue = (Long) ((CacheEntry) entry).getVersion(); assertEquals(initialVersion.longValue(), cachedVersionValue.longValue()); withTxSession(s -> { VersionedItem item2 = s.load(VersionedItem.class, item.getId()); s.delete(item2); }); }
From source file:org.infinispan.test.hibernate.cache.functional.ReadWriteTest.java
License:LGPL
@Test @TestForIssue(jiraKey = "HHH-5690") public void testPersistEntityFlushRollbackNotInEntityCache() throws Exception { Statistics stats = sessionFactory().getStatistics(); stats.clear();/*from w ww. ja va 2 s. c om*/ SecondLevelCacheStatistics slcs = stats.getSecondLevelCacheStatistics(Item.class.getName()); ByRef<Long> itemId = new ByRef<>(null); withTxSession(s -> { Item item = new Item(); item.setName("steve"); item.setDescription("steve's item"); s.persist(item); s.flush(); itemId.set(item.getId()); // assertNotNull( slcs.getEntries().get( item.getId() ) ); markRollbackOnly(s); }); // item should not be in entity cache. assertEquals(Collections.EMPTY_MAP, slcs.getEntries()); withTxSession(s -> { Item item = s.get(Item.class, itemId.get()); assertNull(item); }); }