Search in sources :

Example 76 with LocalRegion

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

the class HAInterestTestCase method stopSecondaryAndUNregisterK1.

/**
   * returns the secondary that was stopped
   */
public static VM stopSecondaryAndUNregisterK1() {
    LocalRegion r = (LocalRegion) cache.getRegion(Region.SEPARATOR + REGION_NAME);
    assertNotNull(r);
    ServerRegionProxy srp = new ServerRegionProxy(r);
    WaitCriterion wc = new WaitCriterion() {

        @Override
        public boolean done() {
            return pool.getConnectedServerCount() == 3;
        }

        @Override
        public String description() {
            return "connected server count never became 3";
        }
    };
    Wait.waitForCriterion(wc, TIMEOUT_MILLIS, INTERVAL_MILLIS, true);
    // close secondary EP
    VM result = getBackupVM();
    result.invoke(() -> HAInterestTestCase.stopServer());
    List list = new ArrayList();
    list.add(k1);
    srp.unregisterInterest(list, InterestType.KEY, false, false);
    return result;
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) VM(org.apache.geode.test.dunit.VM) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Example 77 with LocalRegion

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

the class ForceInvalidateEvictionDUnitTest method checkValue.

private void checkValue(VM vm, final Serializable key, final Object expected) {
    final String name = getUniqueName();
    vm.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            final LocalRegion region = (LocalRegion) cache.getRegion(name);
            Wait.waitForCriterion(new WaitCriterion() {

                public boolean done() {
                    Object value = null;
                    try {
                        value = region.getValueInVM(key);
                        if (value instanceof CachedDeserializable) {
                            value = ((CachedDeserializable) value).getDeserializedForReading();
                        }
                    } catch (EntryNotFoundException e) {
                    // ok
                    }
                    return expected == null ? value == null : expected.equals(value);
                }

                public String description() {
                    return "Value did not become " + expected + " after 30s: " + region.getValueInVM(key);
                }
            }, 30000, 100, true);
        }
    });
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Cache(org.apache.geode.cache.Cache)

Example 78 with LocalRegion

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

the class RegionJUnitTest method testRegionEntryAccess.

@Test
public void testRegionEntryAccess() throws Exception {
    Iterator entriesIter = region.entrySet(false).iterator();
    while (entriesIter.hasNext()) {
        Region.Entry entry = (Region.Entry) entriesIter.next();
        RegionEntry regionEntry = null;
        if (entry instanceof LocalRegion.NonTXEntry) {
            regionEntry = ((LocalRegion.NonTXEntry) entry).getRegionEntry();
        } else {
            regionEntry = ((EntrySnapshot) entry).getRegionEntry();
        }
        assertNotNull(regionEntry);
    }
    LocalRegion lRegion = (LocalRegion) region;
    Iterator keysIterator = lRegion.keys().iterator();
    while (keysIterator.hasNext()) {
        Object key = keysIterator.next();
        Region.Entry rEntry = lRegion.getEntry(key);
        RegionEntry regionEntry = null;
        if (rEntry instanceof LocalRegion.NonTXEntry) {
            regionEntry = ((LocalRegion.NonTXEntry) rEntry).getRegionEntry();
        } else {
            regionEntry = ((EntrySnapshot) rEntry).getRegionEntry();
        }
        assertNotNull(regionEntry);
    }
}
Also used : RegionEntry(org.apache.geode.internal.cache.RegionEntry) Iterator(java.util.Iterator) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) RegionEntry(org.apache.geode.internal.cache.RegionEntry) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 79 with LocalRegion

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

the class QueryIndexUsingXMLDUnitTest method indexCreationCheck.

private CacheSerializableRunnable indexCreationCheck(final String regionName, final String indexName) {
    return new CacheSerializableRunnable("IndexCreationCheck region: " + regionName + " indexName:" + indexName) {

        @Override
        public void run2() {
            Cache cache = getCache();
            LocalRegion region = (LocalRegion) cache.getRegion(regionName);
            Index index = region.getIndexManager().getIndex(indexName);
            assertThat(index).isNotNull();
        }
    };
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Index(org.apache.geode.cache.query.Index) PartitionedIndex(org.apache.geode.cache.query.internal.index.PartitionedIndex) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Cache(org.apache.geode.cache.Cache)

Example 80 with LocalRegion

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

the class QueryObserverCallbackJUnitTest method tearDown.

@After
public void tearDown() throws Exception {
    CacheUtils.closeCache();
    IndexManager indexManager = ((LocalRegion) region).getIndexManager();
    if (indexManager != null)
        indexManager.destroy();
}
Also used : IndexManager(org.apache.geode.cache.query.internal.index.IndexManager) LocalRegion(org.apache.geode.internal.cache.LocalRegion) After(org.junit.After)

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