use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class IndexCreationJUnitTest method testIndexCreationFromXMLForDiskLocalScope.
@Test
public void testIndexCreationFromXMLForDiskLocalScope() throws Exception {
InternalDistributedSystem.getAnyInstance().disconnect();
// TODO: use TemporaryFolder
File file = new File("persistData0");
file.mkdir();
Properties props = new Properties();
props.setProperty(NAME, "test");
props.setProperty(MCAST_PORT, "0");
props.setProperty(CACHE_XML_FILE, getClass().getResource("index-creation-without-eviction.xml").toURI().getPath());
DistributedSystem ds = DistributedSystem.connect(props);
Cache cache = CacheFactory.create(ds);
Region localDiskRegion = cache.getRegion("localDiskRegion");
for (int i = 0; i < 100; i++) {
Portfolio pf = new Portfolio(i);
localDiskRegion.put("" + i, pf);
}
QueryService qs = cache.getQueryService();
Index ind = qs.getIndex(localDiskRegion, "localDiskIndex");
assertNotNull("Index localIndex should have been created ", ind);
// verify that a query on the creation time works as expected
SelectResults results = (SelectResults) qs.newQuery("<trace>SELECT * FROM " + localDiskRegion.getFullPath() + " Where status = 'active'").execute();
assertEquals("OQL index results did not match", 50, results.size());
ds.disconnect();
FileUtils.deleteDirectory(file);
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class IndexCreationJUnitTest method testIndexCreationFromXML.
/**
* Test for bug 46872, make sure we recover the index correctly if the cache.xml changes for a
* persistent region.
*/
@Test
public void testIndexCreationFromXML() throws Exception {
InternalDistributedSystem.getAnyInstance().disconnect();
File file = new File("persistData0");
file.mkdir();
{
Properties props = new Properties();
props.setProperty(NAME, "test");
props.setProperty(MCAST_PORT, "0");
props.setProperty(CACHE_XML_FILE, getClass().getResource("index-creation-with-eviction.xml").toURI().getPath());
DistributedSystem ds = DistributedSystem.connect(props);
// Create the cache which causes the cache-xml-file to be parsed
Cache cache = CacheFactory.create(ds);
QueryService qs = cache.getQueryService();
Region region = cache.getRegion("mainReportRegion");
for (int i = 0; i < 100; i++) {
Portfolio pf = new Portfolio(i);
pf.setCreateTime(i);
region.put("" + i, pf);
}
// verify that a query on the creation time works as expected
SelectResults results = (SelectResults) qs.newQuery("<trace>SELECT * FROM /mainReportRegion.entrySet mr Where mr.value.createTime > 1L and mr.value.createTime < 3L").execute();
assertEquals("OQL index results did not match", 1, results.size());
cache.close();
ds.disconnect();
}
{
Properties props = new Properties();
props.setProperty(NAME, "test");
props.setProperty(MCAST_PORT, "0");
// Using a different cache.xml that changes some region properties
// That will force the disk code to copy the region entries.
props.setProperty(CACHE_XML_FILE, getClass().getResource("index-creation-without-eviction.xml").toURI().getPath());
DistributedSystem ds = DistributedSystem.connect(props);
Cache cache = CacheFactory.create(ds);
QueryService qs = cache.getQueryService();
Region region = cache.getRegion("mainReportRegion");
// verify that a query on the creation time works as expected
SelectResults results = (SelectResults) qs.newQuery("<trace>SELECT * FROM /mainReportRegion.entrySet mr Where mr.value.createTime > 1L and mr.value.createTime < 3L").execute();
assertEquals("OQL index results did not match", 1, results.size());
ds.disconnect();
FileUtils.deleteDirectory(file);
}
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class LRUEvictionControllerDUnitTest method testRegionOperations.
//////// Test Methods
/**
* Carefully verifies that region operations effect the {@link LRUStatistics} as expected.
*/
@Test
public void testRegionOperations() throws CacheException {
int threshold = 10;
final String name = this.getUniqueName();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(threshold));
Region region;
if (usingMain) {
DistributedSystem system = DistributedSystem.connect(new Properties());
Cache cache = CacheFactory.create(system);
region = cache.createRegion("Test", factory.create());
} else {
region = createRegion(name, factory.create());
}
LRUStatistics lruStats = getLRUStats(region);
assertNotNull(lruStats);
for (int i = 1; i <= 10; i++) {
Object key = new Integer(i);
Object value = String.valueOf(i);
region.put(key, value);
assertEquals(i, lruStats.getCounter());
assertEquals(0, lruStats.getEvictions());
}
for (int i = 11; i <= 20; i++) {
Object key = new Integer(i);
Object value = String.valueOf(i);
region.put(key, value);
assertEquals(10, lruStats.getCounter());
assertEquals(i - 10, lruStats.getEvictions());
}
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class LRUEvictionControllerDUnitTest method testSizeOne.
/**
* Tests an <code>LRUCapacityController</code> of size 1.
*/
@Test
public void testSizeOne() throws CacheException {
int threshold = 1;
final String name = this.getUniqueName();
AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeapEnabled());
factory.setScope(Scope.LOCAL);
factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(threshold));
factory.setCacheLoader(new CacheLoader() {
public Object load(LoaderHelper helper) throws CacheLoaderException {
return "LOADED VALUE";
}
public void close() {
}
});
Region region;
if (usingMain) {
DistributedSystem system = DistributedSystem.connect(new Properties());
Cache cache = CacheFactory.create(system);
region = cache.createRegion("Test", factory.create());
} else {
region = createRegion(name, factory.create());
}
LRUStatistics lruStats = getLRUStats(region);
assertNotNull(lruStats);
for (int i = 1; i <= 1; i++) {
Object key = new Integer(i);
Object value = String.valueOf(i);
region.put(key, value);
assertEquals(1, lruStats.getCounter());
assertEquals(0, lruStats.getEvictions());
}
for (int i = 2; i <= 10; i++) {
Object key = new Integer(i);
Object value = String.valueOf(i);
region.put(key, value);
assertEquals(1, lruStats.getCounter());
assertEquals(i - 1, lruStats.getEvictions());
}
for (int i = 11; i <= 20; i++) {
Object key = new Integer(i);
// Object value = String.valueOf(i);
// Invoke loader
region.get(key);
assertEquals(1, lruStats.getCounter());
assertEquals(i - 1, lruStats.getEvictions());
}
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class MemLRUEvictionControllerDUnitTest method testRegionOperations.
// ////// Test Methods
/**
* Carefully verifies that region operations effect the {@link LRUStatistics} as expected.
*/
@Test
public void testRegionOperations() throws CacheException {
int threshold = 4;
final String name = this.getUniqueName();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(threshold));
Region region;
if (usingMain) {
DistributedSystem system = DistributedSystem.connect(new Properties());
Cache cache = CacheFactory.create(system);
region = cache.createRegion("Test", factory.create());
} else {
region = createRegion(name, factory.create());
}
LRUStatistics lruStats = getLRUStats(region);
assertNotNull(lruStats);
String sampleKey = new String("10000");
int stringSize = // String object
SharedLibrary.getObjectHeaderSize() + (2 * 4) + // 2 ints and a reference on a string
SharedLibrary.getReferenceSize();
stringSize = (int) ReflectionSingleObjectSizer.roundUpSize(stringSize);
int charArraySize = // char array
sampleKey.length() * 2 + SharedLibrary.getObjectHeaderSize() + // object
4;
// length of char array
charArraySize = (int) ReflectionSingleObjectSizer.roundUpSize(charArraySize);
assertEquals(stringSize, ReflectionSingleObjectSizer.sizeof(String.class));
assertEquals(ReflectionSingleObjectSizer.roundUpSize(SharedLibrary.getObjectHeaderSize() + 4), (new ReflectionSingleObjectSizer()).sizeof(new char[0]));
assertEquals(charArraySize, (new ReflectionSingleObjectSizer()).sizeof(new char[5]));
int keySize = stringSize + charArraySize;
assertEquals(keySize, WellKnownClassSizer.sizeof(sampleKey));
assertEquals(keySize, ObjectSizer.DEFAULT.sizeof(sampleKey));
// now that keys are inlined the keySize is 0
keySize = 0;
byte[] sampleValue = new byte[1000];
int valueSize = // byte array object;
sampleValue.length + SharedLibrary.getObjectHeaderSize() + // length of byte array
4;
valueSize = (int) ReflectionSingleObjectSizer.roundUpSize(valueSize);
int entrySize = keySize + valueSize + getEntryOverhead(region);
assertEquals(valueSize, ObjectSizer.DEFAULT.sizeof(sampleValue));
for (int i = 1; i <= 100; i++) {
Object key = String.valueOf(10000 + i);
Object value = new byte[1000];
region.put(key, value);
assertEquals(i * entrySize, lruStats.getCounter());
assertEquals(0, lruStats.getEvictions());
}
for (int i = 100; i >= 1; i--) {
Object key = String.valueOf(10000 + i);
region.destroy(key);
assertEquals((i - 1) * entrySize, lruStats.getCounter());
assertEquals(0, lruStats.getEvictions());
}
}
Aggregations