@Test
public void test() {
ResetBasicData.reset();
ServerCache custCache = cacheManager.getBeanCache(Customer.class);
ServerCache contactCache = cacheManager.getBeanCache(Contact.class);
ServerCache custManyIdsCache = cacheManager.getCollectionIdsCache(Customer.class, "contacts");
// cacheManager.setCaching(Customer.class, true);
// cacheManager.setCaching(Contact.class, true);
custCache.clear();
custManyIdsCache.clear();
List<Customer> list = Ebean.find(Customer.class).setAutofetch(false).setLoadBeanCache(true)
.order().asc("id").findList();
Assert.assertTrue(list.size() > 1);
// Assert.assertEquals(list.size(),
// custCache.getStatistics(false).getSize());
Customer customer = list.get(0);
List<Contact> contacts = customer.getContacts();
// Assert.assertEquals(0, custManyIdsCache.getStatistics(false).getSize());
contacts.size();
Assert.assertTrue(contacts.size() > 1);
// Assert.assertEquals(1, custManyIdsCache.getStatistics(false).getSize());
// Assert.assertEquals(0,
// custManyIdsCache.getStatistics(false).getHitCount());
fetchCustomer(customer.getId());
// Assert.assertEquals(1,
// custManyIdsCache.getStatistics(false).getHitCount());
fetchCustomer(customer.getId());
// Assert.assertEquals(2,
// custManyIdsCache.getStatistics(false).getHitCount());
int currentNumContacts = fetchCustomer(customer.getId());
// Assert.assertEquals(3,
// custManyIdsCache.getStatistics(false).getHitCount());
Contact newContact = ResetBasicData.createContact("Check", "CollIds");
newContact.setCustomer(customer);
Ebean.save(newContact);
int currentNumContacts2 = fetchCustomer(customer.getId());
Assert.assertEquals(currentNumContacts + 1, currentNumContacts2);
System.out.println("custCache:" + custCache.getStatistics(false));
System.out.println("contactCache:" + contactCache.getStatistics(false));
System.out.println("custManyIdsCache:" + custManyIdsCache.getStatistics(false));
}