Search in sources :

Example 66 with DistributedSystem

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);
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) Portfolio(org.apache.geode.cache.query.data.Portfolio) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RangeIndex(org.apache.geode.cache.query.internal.index.RangeIndex) CompactMapRangeIndex(org.apache.geode.cache.query.internal.index.CompactMapRangeIndex) Index(org.apache.geode.cache.query.Index) CompactRangeIndex(org.apache.geode.cache.query.internal.index.CompactRangeIndex) Properties(java.util.Properties) File(java.io.File) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 67 with DistributedSystem

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);
    }
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) Portfolio(org.apache.geode.cache.query.data.Portfolio) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Properties(java.util.Properties) File(java.io.File) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 68 with DistributedSystem

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());
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 69 with DistributedSystem

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());
    }
}
Also used : Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) LoaderHelper(org.apache.geode.cache.LoaderHelper) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) CacheLoader(org.apache.geode.cache.CacheLoader) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 70 with DistributedSystem

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());
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) ReflectionSingleObjectSizer(org.apache.geode.internal.size.ReflectionSingleObjectSizer) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

DistributedSystem (org.apache.geode.distributed.DistributedSystem)250 Properties (java.util.Properties)102 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)65 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)61 Test (org.junit.Test)59 Cache (org.apache.geode.cache.Cache)55 AttributesFactory (org.apache.geode.cache.AttributesFactory)34 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)30 Region (org.apache.geode.cache.Region)24 IOException (java.io.IOException)20 CacheServer (org.apache.geode.cache.server.CacheServer)20 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)20 InternalCache (org.apache.geode.internal.cache.InternalCache)16 IgnoredException (org.apache.geode.test.dunit.IgnoredException)16 ArrayList (java.util.ArrayList)15 LogWriter (org.apache.geode.LogWriter)15 DistributedMember (org.apache.geode.distributed.DistributedMember)15 LocalRegion (org.apache.geode.internal.cache.LocalRegion)15 RegionAttributes (org.apache.geode.cache.RegionAttributes)14 Pool (org.apache.geode.cache.client.Pool)14