mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
No effective change - change Line endings to CR (from CRLF)
This commit is contained in:
+147
-147
@@ -1,147 +1,147 @@
|
||||
package com.avaje.tests.cache;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.cache.ServerCache;
|
||||
import com.avaje.ebean.cache.ServerCacheStatistics;
|
||||
import com.avaje.tests.model.basic.Country;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestCacheBasic extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Ebean.getServerCacheManager().clear(Country.class);
|
||||
ServerCache countryCache = Ebean.getServerCacheManager().getBeanCache(Country.class);
|
||||
|
||||
loadCountryCache();
|
||||
Assert.assertTrue(countryCache.size() > 0);
|
||||
|
||||
// reset the statistics
|
||||
countryCache.getStatistics(true);
|
||||
|
||||
Country c0 = Ebean.getReference(Country.class, "NZ");
|
||||
ServerCacheStatistics statistics = countryCache.getStatistics(false);
|
||||
long hc = statistics.getHitCount();
|
||||
Assert.assertEquals(1, hc);
|
||||
Assert.assertNotNull(c0);
|
||||
|
||||
// Country c1 = Ebean.getReference(Country.class, "NZ");
|
||||
// Assert.assertEquals(2, countryCache.getStatistics(false).getHitCount());
|
||||
// //Assert.assertEquals(100,
|
||||
// countryCache.getStatistics(false).getHitRatio());
|
||||
//
|
||||
// // same instance as caching with readOnly=true
|
||||
// Assert.assertTrue(c0 != c1);
|
||||
//
|
||||
// c0.getName();
|
||||
// c1.getName();
|
||||
//
|
||||
// // reset the statistics
|
||||
// Assert.assertEquals(2,countryCache.getStatistics(true).getHitCount());
|
||||
// // now the count should be 0 again
|
||||
// Assert.assertEquals(0, countryCache.getStatistics(false).getHitCount());
|
||||
// // and hitRatio is 0 as well
|
||||
// Assert.assertEquals(0, countryCache.getStatistics(false).getHitRatio());
|
||||
//
|
||||
// // hit the country cache automatically via join
|
||||
//
|
||||
// Customer custTest = ResetBasicData.createCustAndOrder("cacheBasic");
|
||||
// Integer id = custTest.getId();
|
||||
// Customer customer = Ebean.find(Customer.class, id);
|
||||
//
|
||||
// Address billingAddress = customer.getBillingAddress();
|
||||
// Country c2 = billingAddress.getCountry();
|
||||
// c2.getName();
|
||||
//
|
||||
// Assert.assertTrue(countryCache.getStatistics(false).getHitCount() > 0);
|
||||
//
|
||||
// //Country c3 = Ebean.getReference(Country.class, "NZ");
|
||||
// //Country c4 = Ebean.find(Country.class, "NZ");
|
||||
//
|
||||
//
|
||||
// // clear the cache
|
||||
// Ebean.getServerCacheManager().clear(Country.class);
|
||||
// // reset statistics
|
||||
// countryCache.getStatistics(true);
|
||||
//
|
||||
// // try to hit the country cache automatically via join
|
||||
// customer = Ebean.find(Customer.class, id);
|
||||
// billingAddress = customer.getBillingAddress();
|
||||
// Country c5 = billingAddress.getCountry();
|
||||
// // but cache is empty so c5 is reference that will load cache
|
||||
// // if it is lazy loaded
|
||||
// Assert.assertEquals("empty cache",0,countryCache.getStatistics(false).getSize());
|
||||
// //Assert.assertEquals("missCount 1",1,countryCache.getStatistics(false).getMissCount());
|
||||
//
|
||||
// // lazy load on c5 populates the cache
|
||||
// c5.getName();
|
||||
// Assert.assertEquals("cache populated via lazy load",1,countryCache.getStatistics(false).getSize());
|
||||
//
|
||||
// // now these get hits in the cache
|
||||
// Country c6 = Ebean.find(Country.class, "NZ");
|
||||
//
|
||||
// Assert.assertTrue("different instance as cache cleared",c2 != c5);
|
||||
// Assert.assertTrue("these 2 are different",c5 != c6);
|
||||
//
|
||||
// // by default readOnly based on deployment annotation
|
||||
// Assert.assertTrue("read only",Ebean.getBeanState(c6).isReadOnly());
|
||||
//
|
||||
// try {
|
||||
// // can't modify a readOnly bean
|
||||
// c6.setName("Nu Zilund");
|
||||
// Assert.assertFalse("Never get here",true);
|
||||
// } catch (IllegalStateException e){
|
||||
// Assert.assertTrue("This is readOnly",true);
|
||||
// }
|
||||
//
|
||||
// Country c8 = Ebean.find(Country.class)
|
||||
// .setId("NZ")
|
||||
// .setReadOnly(false)
|
||||
// .findUnique();
|
||||
//
|
||||
// // Explicitly NOT readOnly
|
||||
// Assert.assertFalse("NOT read only",Ebean.getBeanState(c8).isReadOnly());
|
||||
//
|
||||
// Assert.assertEquals("1 countries in cache", 1, countryCache.size());
|
||||
// c8.setName("Nu Zilund");
|
||||
// // the update will remove the entry from the cache
|
||||
// Ebean.save(c8);
|
||||
//
|
||||
// Assert.assertEquals("1 country in cache", 1, countryCache.size());
|
||||
//
|
||||
// Country c9 = Ebean.find(Country.class)
|
||||
// .setReadOnly(false)
|
||||
// .setId("NZ")
|
||||
// .findUnique();
|
||||
//
|
||||
// // Find loads cache ...
|
||||
// Assert.assertFalse(Ebean.getBeanState(c9).isReadOnly());
|
||||
// Assert.assertTrue(countryCache.size() > 0);
|
||||
//
|
||||
// Country c10 = Ebean.find(Country.class,"NZ");
|
||||
//
|
||||
// Assert.assertTrue(Ebean.getBeanState(c10).isReadOnly());
|
||||
// Assert.assertTrue(countryCache.size() > 0);
|
||||
//
|
||||
// Ebean.getServerCacheManager().clear(Country.class);
|
||||
// Assert.assertEquals("0 country in cache", 0, countryCache.size());
|
||||
//
|
||||
// // reference doesn't load cache yet
|
||||
// Country c11 = Ebean.getReference(Country.class, "NZ");
|
||||
//
|
||||
// // still 0 in cache
|
||||
// Assert.assertEquals("0 country in cache", 0, countryCache.size());
|
||||
//
|
||||
// // will invoke lazy loading..
|
||||
// c11.getName();
|
||||
// Assert.assertTrue(countryCache.size() > 0);
|
||||
|
||||
}
|
||||
}
|
||||
package com.avaje.tests.cache;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.cache.ServerCache;
|
||||
import com.avaje.ebean.cache.ServerCacheStatistics;
|
||||
import com.avaje.tests.model.basic.Country;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestCacheBasic extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Ebean.getServerCacheManager().clear(Country.class);
|
||||
ServerCache countryCache = Ebean.getServerCacheManager().getBeanCache(Country.class);
|
||||
|
||||
loadCountryCache();
|
||||
Assert.assertTrue(countryCache.size() > 0);
|
||||
|
||||
// reset the statistics
|
||||
countryCache.getStatistics(true);
|
||||
|
||||
Country c0 = Ebean.getReference(Country.class, "NZ");
|
||||
ServerCacheStatistics statistics = countryCache.getStatistics(false);
|
||||
long hc = statistics.getHitCount();
|
||||
Assert.assertEquals(1, hc);
|
||||
Assert.assertNotNull(c0);
|
||||
|
||||
// Country c1 = Ebean.getReference(Country.class, "NZ");
|
||||
// Assert.assertEquals(2, countryCache.getStatistics(false).getHitCount());
|
||||
// //Assert.assertEquals(100,
|
||||
// countryCache.getStatistics(false).getHitRatio());
|
||||
//
|
||||
// // same instance as caching with readOnly=true
|
||||
// Assert.assertTrue(c0 != c1);
|
||||
//
|
||||
// c0.getName();
|
||||
// c1.getName();
|
||||
//
|
||||
// // reset the statistics
|
||||
// Assert.assertEquals(2,countryCache.getStatistics(true).getHitCount());
|
||||
// // now the count should be 0 again
|
||||
// Assert.assertEquals(0, countryCache.getStatistics(false).getHitCount());
|
||||
// // and hitRatio is 0 as well
|
||||
// Assert.assertEquals(0, countryCache.getStatistics(false).getHitRatio());
|
||||
//
|
||||
// // hit the country cache automatically via join
|
||||
//
|
||||
// Customer custTest = ResetBasicData.createCustAndOrder("cacheBasic");
|
||||
// Integer id = custTest.getId();
|
||||
// Customer customer = Ebean.find(Customer.class, id);
|
||||
//
|
||||
// Address billingAddress = customer.getBillingAddress();
|
||||
// Country c2 = billingAddress.getCountry();
|
||||
// c2.getName();
|
||||
//
|
||||
// Assert.assertTrue(countryCache.getStatistics(false).getHitCount() > 0);
|
||||
//
|
||||
// //Country c3 = Ebean.getReference(Country.class, "NZ");
|
||||
// //Country c4 = Ebean.find(Country.class, "NZ");
|
||||
//
|
||||
//
|
||||
// // clear the cache
|
||||
// Ebean.getServerCacheManager().clear(Country.class);
|
||||
// // reset statistics
|
||||
// countryCache.getStatistics(true);
|
||||
//
|
||||
// // try to hit the country cache automatically via join
|
||||
// customer = Ebean.find(Customer.class, id);
|
||||
// billingAddress = customer.getBillingAddress();
|
||||
// Country c5 = billingAddress.getCountry();
|
||||
// // but cache is empty so c5 is reference that will load cache
|
||||
// // if it is lazy loaded
|
||||
// Assert.assertEquals("empty cache",0,countryCache.getStatistics(false).getSize());
|
||||
// //Assert.assertEquals("missCount 1",1,countryCache.getStatistics(false).getMissCount());
|
||||
//
|
||||
// // lazy load on c5 populates the cache
|
||||
// c5.getName();
|
||||
// Assert.assertEquals("cache populated via lazy load",1,countryCache.getStatistics(false).getSize());
|
||||
//
|
||||
// // now these get hits in the cache
|
||||
// Country c6 = Ebean.find(Country.class, "NZ");
|
||||
//
|
||||
// Assert.assertTrue("different instance as cache cleared",c2 != c5);
|
||||
// Assert.assertTrue("these 2 are different",c5 != c6);
|
||||
//
|
||||
// // by default readOnly based on deployment annotation
|
||||
// Assert.assertTrue("read only",Ebean.getBeanState(c6).isReadOnly());
|
||||
//
|
||||
// try {
|
||||
// // can't modify a readOnly bean
|
||||
// c6.setName("Nu Zilund");
|
||||
// Assert.assertFalse("Never get here",true);
|
||||
// } catch (IllegalStateException e){
|
||||
// Assert.assertTrue("This is readOnly",true);
|
||||
// }
|
||||
//
|
||||
// Country c8 = Ebean.find(Country.class)
|
||||
// .setId("NZ")
|
||||
// .setReadOnly(false)
|
||||
// .findUnique();
|
||||
//
|
||||
// // Explicitly NOT readOnly
|
||||
// Assert.assertFalse("NOT read only",Ebean.getBeanState(c8).isReadOnly());
|
||||
//
|
||||
// Assert.assertEquals("1 countries in cache", 1, countryCache.size());
|
||||
// c8.setName("Nu Zilund");
|
||||
// // the update will remove the entry from the cache
|
||||
// Ebean.save(c8);
|
||||
//
|
||||
// Assert.assertEquals("1 country in cache", 1, countryCache.size());
|
||||
//
|
||||
// Country c9 = Ebean.find(Country.class)
|
||||
// .setReadOnly(false)
|
||||
// .setId("NZ")
|
||||
// .findUnique();
|
||||
//
|
||||
// // Find loads cache ...
|
||||
// Assert.assertFalse(Ebean.getBeanState(c9).isReadOnly());
|
||||
// Assert.assertTrue(countryCache.size() > 0);
|
||||
//
|
||||
// Country c10 = Ebean.find(Country.class,"NZ");
|
||||
//
|
||||
// Assert.assertTrue(Ebean.getBeanState(c10).isReadOnly());
|
||||
// Assert.assertTrue(countryCache.size() > 0);
|
||||
//
|
||||
// Ebean.getServerCacheManager().clear(Country.class);
|
||||
// Assert.assertEquals("0 country in cache", 0, countryCache.size());
|
||||
//
|
||||
// // reference doesn't load cache yet
|
||||
// Country c11 = Ebean.getReference(Country.class, "NZ");
|
||||
//
|
||||
// // still 0 in cache
|
||||
// Assert.assertEquals("0 country in cache", 0, countryCache.size());
|
||||
//
|
||||
// // will invoke lazy loading..
|
||||
// c11.getName();
|
||||
// Assert.assertTrue(countryCache.size() > 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+63
-63
@@ -1,63 +1,63 @@
|
||||
package com.avaje.tests.cache;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.bean.BeanCollection;
|
||||
import com.avaje.ebean.cache.ServerCache;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryCache extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
ServerCache customerCache = Ebean.getServerCacheManager().getQueryCache(Customer.class);
|
||||
customerCache.clear();
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class).setUseQueryCache(true).setReadOnly(true).where()
|
||||
.ilike("name", "Rob").findList();
|
||||
|
||||
BeanCollection<Customer> bc = (BeanCollection<Customer>) list;
|
||||
Assert.assertFalse(bc.isReadOnly());
|
||||
Assert.assertFalse(bc.isEmpty());
|
||||
Assert.assertTrue(!list.isEmpty());
|
||||
Assert.assertTrue(Ebean.getBeanState(list.get(0)).isReadOnly());
|
||||
|
||||
List<Customer> list2 = Ebean.find(Customer.class).setUseQueryCache(true).setReadOnly(true).where()
|
||||
.ilike("name", "Rob").findList();
|
||||
|
||||
List<Customer> list2B = Ebean.find(Customer.class).setUseQueryCache(true)
|
||||
// .setReadOnly(true)
|
||||
.where().ilike("name", "Rob").findList();
|
||||
|
||||
Assert.assertSame(list, list2);
|
||||
|
||||
// readOnly defaults to true for query cache
|
||||
Assert.assertSame(list, list2B);
|
||||
|
||||
|
||||
// TODO: At this stage setReadOnly(false) does not
|
||||
// create a shallow copy of the List/Set/Map
|
||||
|
||||
// List<Customer> list3 = Ebean.find(Customer.class).setUseQueryCache(true).setReadOnly(false).where()
|
||||
// .ilike("name", "Rob").findList();
|
||||
//
|
||||
// Assert.assertNotSame(list, list3);
|
||||
// BeanCollection<Customer> bc3 = (BeanCollection<Customer>) list3;
|
||||
// Assert.assertFalse(bc3.isReadOnly());
|
||||
// Assert.assertFalse(bc3.isEmpty());
|
||||
// Assert.assertTrue(list3.size() > 0);
|
||||
// Assert.assertFalse(Ebean.getBeanState(list3.get(0)).isReadOnly());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package com.avaje.tests.cache;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.bean.BeanCollection;
|
||||
import com.avaje.ebean.cache.ServerCache;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
|
||||
public class TestQueryCache extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
ServerCache customerCache = Ebean.getServerCacheManager().getQueryCache(Customer.class);
|
||||
customerCache.clear();
|
||||
|
||||
List<Customer> list = Ebean.find(Customer.class).setUseQueryCache(true).setReadOnly(true).where()
|
||||
.ilike("name", "Rob").findList();
|
||||
|
||||
BeanCollection<Customer> bc = (BeanCollection<Customer>) list;
|
||||
Assert.assertFalse(bc.isReadOnly());
|
||||
Assert.assertFalse(bc.isEmpty());
|
||||
Assert.assertTrue(!list.isEmpty());
|
||||
Assert.assertTrue(Ebean.getBeanState(list.get(0)).isReadOnly());
|
||||
|
||||
List<Customer> list2 = Ebean.find(Customer.class).setUseQueryCache(true).setReadOnly(true).where()
|
||||
.ilike("name", "Rob").findList();
|
||||
|
||||
List<Customer> list2B = Ebean.find(Customer.class).setUseQueryCache(true)
|
||||
// .setReadOnly(true)
|
||||
.where().ilike("name", "Rob").findList();
|
||||
|
||||
Assert.assertSame(list, list2);
|
||||
|
||||
// readOnly defaults to true for query cache
|
||||
Assert.assertSame(list, list2B);
|
||||
|
||||
|
||||
// TODO: At this stage setReadOnly(false) does not
|
||||
// create a shallow copy of the List/Set/Map
|
||||
|
||||
// List<Customer> list3 = Ebean.find(Customer.class).setUseQueryCache(true).setReadOnly(false).where()
|
||||
// .ilike("name", "Rob").findList();
|
||||
//
|
||||
// Assert.assertNotSame(list, list3);
|
||||
// BeanCollection<Customer> bc3 = (BeanCollection<Customer>) list3;
|
||||
// Assert.assertFalse(bc3.isReadOnly());
|
||||
// Assert.assertFalse(bc3.isEmpty());
|
||||
// Assert.assertTrue(list3.size() > 0);
|
||||
// Assert.assertFalse(Ebean.getBeanState(list3.get(0)).isReadOnly());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user