use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.
the class JUnit4CacheTestCase method createRegion.
public final Region createRegion(final String name, final String rootName, final RegionAttributes attributes) throws CacheException {
Region root = getRootRegion(rootName);
if (root == null) {
// don't put listeners on root region
RegionAttributes rootAttrs = attributes;
AttributesFactory fac = new AttributesFactory(attributes);
ExpirationAttributes expiration = ExpirationAttributes.DEFAULT;
// fac.setCacheListener(null);
fac.setCacheLoader(null);
fac.setCacheWriter(null);
fac.setPoolName(null);
fac.setPartitionAttributes(null);
fac.setRegionTimeToLive(expiration);
fac.setEntryTimeToLive(expiration);
fac.setRegionIdleTimeout(expiration);
fac.setEntryIdleTimeout(expiration);
rootAttrs = fac.create();
root = createRootRegion(rootName, rootAttrs);
}
InternalRegionArguments internalArgs = getInternalRegionArguments();
if (internalArgs == null) {
return root.createSubregion(name, attributes);
} else {
try {
LocalRegion lr = (LocalRegion) root;
return lr.createSubregion(name, attributes, internalArgs);
} catch (IOException ioe) {
AssertionError assErr = new AssertionError("unexpected exception");
assErr.initCause(ioe);
throw assErr;
} catch (ClassNotFoundException cnfe) {
AssertionError assErr = new AssertionError("unexpected exception");
assErr.initCause(cnfe);
throw assErr;
}
}
}
use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.
the class CqServiceImpl method processRegionEvent.
private void processRegionEvent(CacheEvent event, Profile localProfile, Profile[] profiles, FilterRoutingInfo frInfo) throws CqException {
final boolean isDebugEnabled = logger.isDebugEnabled();
if (isDebugEnabled) {
logger.debug("CQ service processing region event {}", event);
}
Integer cqRegionEvent = generateCqRegionEvent(event);
for (int i = -1; i < profiles.length; i++) {
CacheProfile cf;
if (i < 0) {
cf = (CacheProfile) localProfile;
if (cf == null)
continue;
} else {
cf = (CacheProfile) profiles[i];
}
FilterProfile pf = cf.filterProfile;
if (pf == null || pf.getCqMap().isEmpty()) {
continue;
}
Map cqs = pf.getCqMap();
HashMap<Long, Integer> cqInfo = new HashMap<>();
Iterator cqIter = cqs.entrySet().iterator();
while (cqIter.hasNext()) {
Map.Entry cqEntry = (Map.Entry) cqIter.next();
ServerCQImpl cQuery = (ServerCQImpl) cqEntry.getValue();
if (!event.isOriginRemote() && event.getOperation().isRegionDestroy() && !((LocalRegion) event.getRegion()).isUsedForPartitionedRegionBucket()) {
try {
if (isDebugEnabled) {
logger.debug("Closing CQ on region destroy event. CqName : {}", cQuery.getName());
}
cQuery.close(false);
} catch (Exception ex) {
if (isDebugEnabled) {
logger.debug("Failed to Close CQ on region destroy. CqName : {}", cQuery.getName(), ex);
}
}
}
cqInfo.put(cQuery.getFilterID(), cqRegionEvent);
cQuery.getVsdStats().updateStats(cqRegionEvent);
}
if (pf.isLocalProfile()) {
frInfo.setLocalCqInfo(cqInfo);
} else {
frInfo.setCqRoutingInfo(cf.getDistributedMember(), cqInfo);
}
}
}
use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.
the class HADispatcherDUnitTest method createClientCache.
private void createClientCache(String hostName, Integer port1, Integer port2, Boolean isListenerPresent) throws CqException, CqExistsException, RegionNotFoundException {
int PORT1 = port1.intValue();
int PORT2 = port2.intValue();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
createCache(props);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
ClientServerTestCase.configureConnectionPool(factory, hostName, new int[] { PORT1, PORT2 }, true, -1, 2, null);
if (isListenerPresent.booleanValue() == true) {
CacheListener clientListener = new HAClientListener();
factory.setCacheListener(clientListener);
}
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
Region region = cache.getRegion(Region.SEPARATOR + REGION_NAME);
assertNotNull(region);
{
LocalRegion lr = (LocalRegion) region;
final PoolImpl pool = (PoolImpl) (lr.getServerProxy().getPool());
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return pool.getPrimary() != null;
}
public String description() {
return null;
}
};
waitForCriterion(ev, 30 * 1000, 200, true);
ev = new WaitCriterion() {
public boolean done() {
return pool.getRedundants().size() >= 1;
}
public String description() {
return null;
}
};
waitForCriterion(ev, 30 * 1000, 200, true);
assertNotNull(pool.getPrimary());
assertTrue("backups=" + pool.getRedundants() + " expected=" + 1, pool.getRedundants().size() >= 1);
assertEquals(PORT1, pool.getPrimaryPort());
}
region.registerInterest(KEY1);
// Register CQ.
createCQ();
}
use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.
the class ClientToServerDeltaDUnitTest method testC2SDeltaPropagationWithOldValueInvalidatedAtServer.
@Test
public void testC2SDeltaPropagationWithOldValueInvalidatedAtServer() throws Exception {
String key = "DELTA_KEY";
Integer port1 = (Integer) server.invoke(() -> ClientToServerDeltaDUnitTest.createServerCache(false, false, false, true));
createClientCache("localhost", port1, false, false, false, null, false, false);
LocalRegion region = (LocalRegion) cache.getRegion(REGION_NAME);
region.put(key, new DeltaTestImpl());
server.invoke(() -> ClientToServerDeltaDUnitTest.doInvalidate(key));
DeltaTestImpl value = new DeltaTestImpl();
value.setStr("UPDATED_VALUE");
region.put(key, value);
assertTrue(region.getCachePerfStats().getDeltasSent() == 1);
assertTrue(region.getCachePerfStats().getDeltaFullValuesSent() == 1);
}
use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.
the class LuceneTestUtilities method verifyInternalRegions.
public static void verifyInternalRegions(LuceneService luceneService, Cache cache, Consumer<LocalRegion> verify) {
// Get index
LuceneIndexForPartitionedRegion index = (LuceneIndexForPartitionedRegion) luceneService.getIndex(INDEX_NAME, REGION_NAME);
LocalRegion fileRegion = (LocalRegion) cache.getRegion(index.createFileRegionName());
verify.accept(fileRegion);
}
Aggregations