Package org.hibernate.stat

Examples of org.hibernate.stat.SecondLevelCacheStatistics


        i.setDescription("A really top-quality, full-featured widget.");
        s.persist(i);
        t.commit();
        s.close();

        SecondLevelCacheStatistics slcs = s.getSessionFactory().getStatistics().getSecondLevelCacheStatistics(
              getPrefixedRegionName(Item.class.getName()));

        assertEquals(slcs.getPutCount(), 1);
        assertEquals(slcs.getElementCountInMemory(), 1);
        assertEquals(slcs.getEntries().size(), 1);

        s = openSession();
        t = s.beginTransaction();
        i = (Item) s.get(Item.class, i.getId());

        assertEquals(slcs.getHitCount(), 1);
        assertEquals(slcs.getMissCount(), 0);

        i.setDescription("A bog standard item");

        t.commit();
        s.close();

        assertEquals(slcs.getPutCount(), 2);

        Object entry = slcs.getEntries().get(i.getId());
        Map map;
        if (entry instanceof ReadWriteCache.Item) {
            map = (Map) ((ReadWriteCache.Item) entry).getValue();
        } else {
            map = (Map) entry;
View Full Code Here


        getCustomerIDs().add(customerId);

        assertNull("contact exists despite not being added", getFirstContact(customerId));

        //check that cache was hit
        SecondLevelCacheStatistics customerSlcs = getEnvironment().getSessionFactory().getStatistics().getSecondLevelCacheStatistics(
                getPrefixedRegionName(Customer.class.getName()));
        assertEquals(customerSlcs.getPutCount(), 1);
        assertEquals(customerSlcs.getElementCountInMemory(), 1);
        assertEquals(customerSlcs.getEntries().size(), 1);

        SecondLevelCacheStatistics contactsCollectionSlcs = getEnvironment().getSessionFactory().getStatistics().getSecondLevelCacheStatistics(
                getPrefixedRegionName(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
View Full Code Here

    public void testEmptySecondLevelCacheEntry() throws Exception {
        getSessions().evictEntity(Item.class.getName());
        Statistics stats = getSessions().getStatistics();
        stats.clear();
        SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics(getPrefixedRegionName(Item.class.getName()));
        Map cacheEntries = statistics.getEntries();
        assertEquals(0, cacheEntries.size());
    }
View Full Code Here

                }
            }
        }

        // check the version value in the cache...
        SecondLevelCacheStatistics slcs = sfi().getStatistics().getSecondLevelCacheStatistics(
              getPrefixedRegionName(VersionedItem.class.getName()));

        Object entry = slcs.getEntries().get(item.getId());
        Long cachedVersionValue;
        if (entry instanceof ReadWriteCache.Lock) {
            // FIXME don't know what to test here
            cachedVersionValue = new Long(((ReadWriteCache.Lock) entry).getUnlockTimestamp());
        } else {
View Full Code Here

      getCustomerIDs().add(customerId);

      assertNull("contact exists despite not being added", getFirstContact(customerId));

      // check that cache was hit
      SecondLevelCacheStatistics customerSlcs = getEnvironment().getSessionFactory()
               .getStatistics().getSecondLevelCacheStatistics(Customer.class.getName());
      assertEquals(customerSlcs.getPutCount(), 1);
      assertEquals(customerSlcs.getElementCountInMemory(), 1);
      assertEquals(customerSlcs.getEntries().size(), 1);

      SecondLevelCacheStatistics contactsCollectionSlcs = getEnvironment().getSessionFactory()
               .getStatistics().getSecondLevelCacheStatistics(Customer.class.getName() + ".contacts");
      assertEquals(1, contactsCollectionSlcs.getPutCount());
      assertEquals(1, contactsCollectionSlcs.getElementCountInMemory());
      assertEquals(1, contactsCollectionSlcs.getEntries().size());

      log.info("Add contact to customer {0}", customerId);
      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();
View Full Code Here

         List<Integer> rhContacts = getContactsByCustomer("Red Hat");
         assertNotNull("Red Hat contacts exist", rhContacts);
         assertEquals("Created expected number of Red Hat contacts", 10, rhContacts.size());

         SecondLevelCacheStatistics contactSlcs = getEnvironment().getSessionFactory()
                  .getStatistics().getSecondLevelCacheStatistics(Contact.class.getName());
         assertEquals(20, contactSlcs.getElementCountInMemory());

         assertEquals("Deleted all Red Hat contacts", 10, deleteContacts());
         assertEquals(0, contactSlcs.getElementCountInMemory());

         List<Integer> jbContacts = getContactsByCustomer("JBoss");
         assertNotNull("JBoss contacts exist", jbContacts);
         assertEquals("JBoss contacts remain", 10, jbContacts.size());

         for (Integer id : rhContacts) {
            assertNull("Red Hat contact " + id + " cannot be retrieved", getContact(id));
         }
         rhContacts = getContactsByCustomer("Red Hat");
         if (rhContacts != null) {
            assertEquals("No Red Hat contacts remain", 0, rhContacts.size());
         }

         updateContacts("Kabir", "Updated");
         assertEquals(0, contactSlcs.getElementCountInMemory());
         for (Integer id : jbContacts) {
            Contact contact = getContact(id);
            assertNotNull("JBoss contact " + id + " exists", contact);
            String expected = ("Kabir".equals(contact.getName())) ? "Updated" : "2222";
            assertEquals("JBoss contact " + id + " has correct TLF", expected, contact.getTlf());
         }

         List<Integer> updated = getContactsByTLF("Updated");
         assertNotNull("Got updated contacts", updated);
         assertEquals("Updated contacts", 5, updated.size());

         updateContactsWithOneManual("Kabir", "UpdatedAgain");
         assertEquals(contactSlcs.getElementCountInMemory(), 0);
         for (Integer id : jbContacts) {
            Contact contact = getContact(id);
            assertNotNull("JBoss contact " + id + " exists", contact);
            String expected = ("Kabir".equals(contact.getName())) ? "UpdatedAgain" : "2222";
            assertEquals("JBoss contact " + id + " has correct TLF", expected, contact.getTlf());
View Full Code Here

      beginTx();
      try {
         Session s = openSession();
         Statistics stats = s.getSessionFactory().getStatistics();
         SecondLevelCacheStatistics cStats = stats.getSecondLevelCacheStatistics(Item.class.getName() + ".items");
         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());
         s.close();
      } catch (Exception e) {
         setRollbackOnlyTx(e);
      } finally {
View Full Code Here

            }
         }
      }

      // check the version value in the cache...
      SecondLevelCacheStatistics slcs = sfi().getStatistics().getSecondLevelCacheStatistics(VersionedItem.class.getName());

      Object entry = slcs.getEntries().get(item.getId());
      Long cachedVersionValue;
      cachedVersionValue = (Long) ((CacheEntry) entry).getVersion();
      assertEquals(initialVersion.longValue(), cachedVersionValue.longValue());

      beginTx();
View Full Code Here

         setRollbackOnlyTx(e);
      } finally {
         commitOrRollbackTx();
      }

      SecondLevelCacheStatistics slcs = s.getSessionFactory().getStatistics().getSecondLevelCacheStatistics(Item.class.getName());

      assertEquals(slcs.getPutCount(), 1);
      assertEquals(slcs.getElementCountInMemory(), 1);
      assertEquals(slcs.getEntries().size(), 1);

      beginTx();
      try {
         s = openSession();
         t = s.beginTransaction();
         i = (Item) s.get(Item.class, i.getId());
         assertEquals(slcs.getHitCount(), 1);
         assertEquals(slcs.getMissCount(), 0);
         i.setDescription("A bog standard item");
         t.commit();
         s.close();
      } catch (Exception e) {
         setRollbackOnlyTx(e);
      } finally {
         commitOrRollbackTx();
      }

      assertEquals(slcs.getPutCount(), 2);

      CacheEntry entry = (CacheEntry) slcs.getEntries().get(i.getId());
      Serializable[] ser = entry.getDisassembledState();
      assertTrue(ser[0].equals("widget"));
      assertTrue(ser[1].equals("A bog standard item"));
     
      beginTx();
View Full Code Here

   public void testEmptySecondLevelCacheEntry() throws Exception {
      getSessions().getCache().evictEntityRegion(Item.class.getName());
      Statistics stats = getSessions().getStatistics();
      stats.clear();
      SecondLevelCacheStatistics statistics = stats.getSecondLevelCacheStatistics(Item.class.getName() + ".items");
      Map cacheEntries = statistics.getEntries();
      assertEquals(0, cacheEntries.size());
   }
View Full Code Here

TOP

Related Classes of org.hibernate.stat.SecondLevelCacheStatistics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.