Search in sources :

Example 46 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class CompressionStatsDUnitTest method getTotalDecompressionTime.

/**
   * Returns the total decompression time stat for a region.
   * 
   * @param regionName a region.
   */
private long getTotalDecompressionTime(String regionName) {
    LocalRegion region = (LocalRegion) getCache().getRegion(regionName);
    assertNotNull(region);
    return region.getCachePerfStats().getTotalDecompressionTime();
}
Also used : LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Example 47 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class CompressionStatsDUnitTest method getTotalPostCompressedBytes.

/**
   * Returns the number of post-decompressed bytes stat for a region.
   * 
   * @param regionName a region.
   */
private long getTotalPostCompressedBytes(String regionName) {
    LocalRegion region = (LocalRegion) getCache().getRegion(regionName);
    assertNotNull(region);
    return region.getCachePerfStats().getTotalPostCompressedBytes();
}
Also used : LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Example 48 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class MemoryThresholdsOffHeapDUnitTest method testLRLoadRejection.

/**
   * Test that LocalRegion cache Loads are not stored in the Region if the VM is in a critical
   * state, then test that they are allowed once the VM is no longer critical
   */
@Test
public void testLRLoadRejection() throws Exception {
    final Host host = Host.getHost(0);
    final VM vm = host.getVM(2);
    final String rName = getUniqueName();
    vm.invoke(() -> disconnectFromDS());
    vm.invoke(new CacheSerializableRunnable("test LocalRegion load passthrough when critical") {

        @Override
        public void run2() throws CacheException {
            getSystem(getOffHeapProperties());
            InternalResourceManager irm = (InternalResourceManager) getCache().getResourceManager();
            final OffHeapMemoryMonitor ohmm = irm.getOffHeapMonitor();
            irm.setCriticalOffHeapPercentage(90f);
            AttributesFactory<Integer, String> af = new AttributesFactory<Integer, String>();
            af.setScope(Scope.LOCAL);
            af.setOffHeap(true);
            final AtomicInteger numLoaderInvocations = new AtomicInteger(0);
            af.setCacheLoader(new CacheLoader<Integer, String>() {

                public String load(LoaderHelper<Integer, String> helper) throws CacheLoaderException {
                    numLoaderInvocations.incrementAndGet();
                    return helper.getKey().toString();
                }

                public void close() {
                }
            });
            final LocalRegion r = (LocalRegion) getCache().createRegion(rName, af.create());
            assertFalse(ohmm.getState().isCritical());
            int expectedInvocations = 0;
            assertEquals(expectedInvocations++, numLoaderInvocations.get());
            {
                Integer k = new Integer(1);
                assertEquals(k.toString(), r.get(k));
            }
            assertEquals(expectedInvocations++, numLoaderInvocations.get());
            expectedInvocations++;
            expectedInvocations++;
            r.getAll(createRanges(10, 12));
            assertEquals(expectedInvocations++, numLoaderInvocations.get());
            getCache().getLoggerI18n().fine(addExpectedExString);
            r.put("oh1", new byte[838860]);
            r.put("oh3", new byte[157287]);
            getCache().getLoggerI18n().fine(removeExpectedExString);
            WaitCriterion wc = new WaitCriterion() {

                public String description() {
                    return "expected region " + r + " to set memoryThresholdReached";
                }

                public boolean done() {
                    return r.memoryThresholdReached.get();
                }
            };
            Wait.waitForCriterion(wc, 30 * 1000, 10, true);
            {
                Integer k = new Integer(2);
                assertEquals(k.toString(), r.get(k));
            }
            assertEquals(expectedInvocations++, numLoaderInvocations.get());
            expectedInvocations++;
            expectedInvocations++;
            r.getAll(createRanges(13, 15));
            assertEquals(expectedInvocations++, numLoaderInvocations.get());
            getCache().getLoggerI18n().fine(addExpectedBelow);
            r.destroy("oh3");
            getCache().getLoggerI18n().fine(removeExpectedBelow);
            wc = new WaitCriterion() {

                public String description() {
                    return "expected region " + r + " to unset memoryThresholdReached";
                }

                public boolean done() {
                    return !r.memoryThresholdReached.get();
                }
            };
            Wait.waitForCriterion(wc, 30 * 1000, 10, true);
            {
                Integer k = new Integer(3);
                assertEquals(k.toString(), r.get(k));
            }
            assertEquals(expectedInvocations++, numLoaderInvocations.get());
            expectedInvocations++;
            expectedInvocations++;
            r.getAll(createRanges(16, 18));
            assertEquals(expectedInvocations, numLoaderInvocations.get());
            // Do extra validation that the entry doesn't exist in the local region
            for (Integer i : createRanges(2, 2, 13, 15)) {
                if (r.containsKey(i)) {
                    fail("Expected containsKey return false for key" + i);
                }
                if (r.getEntry(i) != null) {
                    fail("Expected getEntry to return null for key" + i);
                }
            }
        }
    });
}
Also used : OffHeapMemoryMonitor(org.apache.geode.internal.cache.control.OffHeapMemoryMonitor) CacheException(org.apache.geode.cache.CacheException) Host(org.apache.geode.test.dunit.Host) LocalRegion(org.apache.geode.internal.cache.LocalRegion) InternalResourceManager(org.apache.geode.internal.cache.control.InternalResourceManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LoaderHelper(org.apache.geode.cache.LoaderHelper) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VM(org.apache.geode.test.dunit.VM) CacheLoader(org.apache.geode.cache.CacheLoader) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 49 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class IndexUseJUnitTest method testMapIndexUsageWithIndexOnMultipleKeys.

@Test
public void testMapIndexUsageWithIndexOnMultipleKeys() throws Exception {
    try {
        IndexManager.TEST_RANGEINDEX_ONLY = true;
        String[] queries = { "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.maap['key2'] >= 3", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.maap['key3'] >= 3" };
        String[] queriesIndexNotUsed = { "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.maap.get('key2') >= 16", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.maap['key4'] >= 16" };
        LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
        int ID = 1;
        // and so on
        for (; ID <= 30; ++ID) {
            MapKeyIndexData mkid = new MapKeyIndexData(ID);
            for (int j = 1; j <= ID; ++j) {
                mkid.addKeyValue("key1", j * 1);
                mkid.addKeyValue("key2", j * 2);
                mkid.addKeyValue("key3", j * 3);
            }
            testRgn.put(ID, mkid);
        }
        evaluateMapTypeIndexUsage("objs.maap['key2','key3']", "/testRgn objs", queries, queriesIndexNotUsed, MapRangeIndex.class);
    } finally {
        IndexManager.TEST_RANGEINDEX_ONLY = false;
    }
}
Also used : LocalRegion(org.apache.geode.internal.cache.LocalRegion) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 50 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class IndexUseJUnitTest method testCompactMapIndexUsageWithIndexOnMultipleKeys.

@Test
public void testCompactMapIndexUsageWithIndexOnMultipleKeys() throws Exception {
    String[] queries = { "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.maap['key2'] >= 3", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.maap['key3'] >= 3" };
    String[] queriesIndexNotUsed = { "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.maap.get('key2') >= 16", "SELECT DISTINCT * FROM /testRgn itr1  WHERE itr1.maap['key4'] >= 16" };
    LocalRegion testRgn = (LocalRegion) CacheUtils.createRegion("testRgn", null);
    int ID = 1;
    // and so on
    for (; ID <= 30; ++ID) {
        MapKeyIndexData mkid = new MapKeyIndexData(ID);
        for (int j = 1; j <= ID; ++j) {
            mkid.addKeyValue("key1", j * 1);
            mkid.addKeyValue("key2", j * 2);
            mkid.addKeyValue("key3", j * 3);
        }
        testRgn.put(ID, mkid);
    }
    evaluateMapTypeIndexUsage("objs.maap['key2','key3']", "/testRgn objs", queries, queriesIndexNotUsed, CompactMapRangeIndex.class);
}
Also used : LocalRegion(org.apache.geode.internal.cache.LocalRegion) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

LocalRegion (org.apache.geode.internal.cache.LocalRegion)243 Test (org.junit.Test)103 Region (org.apache.geode.cache.Region)70 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)54 IOException (java.io.IOException)50 AttributesFactory (org.apache.geode.cache.AttributesFactory)42 VM (org.apache.geode.test.dunit.VM)39 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)38 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)37 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)34 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)34 Cache (org.apache.geode.cache.Cache)31 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)31 Host (org.apache.geode.test.dunit.Host)31 Iterator (java.util.Iterator)29 QueryService (org.apache.geode.cache.query.QueryService)29 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)27 CancelException (org.apache.geode.CancelException)26 CacheException (org.apache.geode.cache.CacheException)26 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)25