use of org.apache.geode.internal.cache.FilterProfile in project geode by apache.
the class FilterProfileJUnitTest method setUp.
@Before
public void setUp() {
mockRegion = mock(LocalRegion.class);
GemFireCacheImpl mockCache = mock(GemFireCacheImpl.class);
when(mockCache.getCacheServers()).thenReturn(Collections.emptyList());
when(mockRegion.getGemFireCache()).thenReturn(mockCache);
fprofile = new FilterProfile(mockRegion);
}
use of org.apache.geode.internal.cache.FilterProfile in project geode by apache.
the class DurableRegistrationDUnitTest method testDurableClientDisConnectWithRegistrationHA.
@Test
public void testDurableClientDisConnectWithRegistrationHA() {
// Step 1: Start server1
PORT2 = new Integer(AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET));
PORT1 = ((Integer) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true)))).intValue();
// Step 2: Bring Up the Client
final String durableClientId = getName() + "_client";
// keep the client alive for 600 seconds
final int durableClientTimeout = 600;
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), PORT1, PORT2, true, 1), regionName, getClientDistributedSystemProperties(durableClientId, durableClientTimeout)));
// Send clientReady message
this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
public void run2() throws CacheException {
CacheServerTestUtil.getCache().readyForEvents();
}
});
// Step 3: Client registers Interests
this.durableClientVM.invoke(() -> DurableRegistrationDUnitTest.registerKey(K1, new Boolean(false)));
this.durableClientVM.invoke(() -> DurableRegistrationDUnitTest.registerKey(K2, new Boolean(false)));
this.durableClientVM.invoke(() -> DurableRegistrationDUnitTest.registerKey(K3, new Boolean(true)));
this.durableClientVM.invoke(() -> DurableRegistrationDUnitTest.registerKey(K4, new Boolean(true)));
// Close Cache of the DurableClient
this.durableClientVM.invoke(() -> DurableRegistrationDUnitTest.closeCache());
Wait.pause(2000);
// Re-start the Client
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), PORT1, PORT2, true, 1), regionName, getClientDistributedSystemProperties(durableClientId), Boolean.TRUE));
// Send clientReady message
this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
public void run2() throws CacheException {
CacheServerTestUtil.getCache().readyForEvents();
}
});
// Step 4: Bring up the server2
this.server2VM.invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true), PORT2));
Wait.pause(3000);
// Check server2 got all the interests registered by the durable client.
server2VM.invoke(new CacheSerializableRunnable("Verify Interests.") {
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("### Verifying interests registered by DurableClient. ###");
CacheClientNotifier ccn = CacheClientNotifier.getInstance();
CacheClientProxy p = null;
// Get proxy for the client.
for (int i = 0; i < 60; i++) {
Iterator ps = ccn.getClientProxies().iterator();
if (!ps.hasNext()) {
Wait.pause(1000);
continue;
} else {
p = (CacheClientProxy) ps.next();
break;
}
}
if (p == null) {
fail("Proxy initialization taking long time. Increase the wait time.");
}
Iterator rs = p.getInterestRegisteredRegions().iterator();
String rName = (String) rs.next();
assertNotNull("Null region Name found.", rs);
LocalRegion r = (LocalRegion) GemFireCacheImpl.getInstance().getRegion(rName);
assertNotNull("Null region found.", r);
FilterProfile pf = r.getFilterProfile();
Set intrests = Collections.EMPTY_SET;
Set interestKeys = pf.getKeysOfInterest(p.getProxyID().getDurableId());
assertNotNull("durable Interests not found for the proxy", interestKeys);
assertEquals("The number of durable keys registered during HARegion GII doesn't match.", interestKeys.size(), 2);
interestKeys = pf.getKeysOfInterest(p.getProxyID());
assertNull("non-durable Interests found for the proxy", interestKeys);
}
});
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop server 2
this.server2VM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop server 1
this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
}
use of org.apache.geode.internal.cache.FilterProfile in project geode by apache.
the class DurableRegistrationDUnitTest method testDurableClientWithRegistrationHA.
// GEODE-1537
@Category(FlakyTest.class)
@Test
public void testDurableClientWithRegistrationHA() {
// Step 1: Start server1
PORT2 = new Integer(AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET));
PORT1 = ((Integer) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true)))).intValue();
// Step 2: Bring Up the Client
final String durableClientId = getName() + "_client";
// keep the client alive for 600 seconds
final int durableClientTimeout = 600;
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), PORT1, PORT2, true, 1), regionName, getClientDistributedSystemProperties(durableClientId, durableClientTimeout)));
// Send clientReady message
this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
public void run2() throws CacheException {
CacheServerTestUtil.getCache().readyForEvents();
}
});
// Step 3: Client registers Interests
this.durableClientVM.invoke(() -> DurableRegistrationDUnitTest.registerKey(K1, new Boolean(false)));
this.durableClientVM.invoke(() -> DurableRegistrationDUnitTest.registerKey(K2, new Boolean(false)));
this.durableClientVM.invoke(() -> DurableRegistrationDUnitTest.registerKey(K3, new Boolean(true)));
this.durableClientVM.invoke(() -> DurableRegistrationDUnitTest.registerKey(K4, new Boolean(true)));
// Step 4: Bring up the server2
this.server2VM.invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true), PORT2));
Wait.pause(3000);
// Check server2 got all the interests registered by the durable client.
server2VM.invoke(new CacheSerializableRunnable("Verify Interests.") {
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("### Verifying interests registered by DurableClient. ###");
CacheClientNotifier ccn = CacheClientNotifier.getInstance();
CacheClientProxy p = null;
// Get proxy for the client.
for (int i = 0; i < 60; i++) {
Iterator ps = ccn.getClientProxies().iterator();
if (!ps.hasNext()) {
Wait.pause(1000);
continue;
} else {
p = (CacheClientProxy) ps.next();
break;
}
}
if (p == null) {
fail("Proxy initialization taking long time. Increase the wait time.");
}
Iterator rs = p.getInterestRegisteredRegions().iterator();
String rName = (String) rs.next();
assertNotNull("Null region Name found.", rs);
LocalRegion r = (LocalRegion) GemFireCacheImpl.getInstance().getRegion(rName);
assertNotNull("Null region found.", r);
FilterProfile pf = r.getFilterProfile();
Set intrests = Collections.EMPTY_SET;
Set interestKeys = pf.getKeysOfInterest(p.getProxyID().getDurableId());
assertNotNull("durable Interests not found for the proxy", interestKeys);
assertEquals("The number of durable keys registered during HARegion GII doesn't match.", interestKeys.size(), 2);
interestKeys = pf.getKeysOfInterest(p.getProxyID());
assertNotNull("non-durable Interests not found for the proxy", interestKeys);
assertEquals("The number of non-durable keys registered during HARegion GII doesn't match.", interestKeys.size(), 2);
}
});
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop server 2
this.server2VM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop server 1
this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
}
use of org.apache.geode.internal.cache.FilterProfile in project geode by apache.
the class CqServiceImpl method processEntryEvent.
private void processEntryEvent(CacheEvent event, Profile localProfile, Profile[] profiles, FilterRoutingInfo frInfo) throws CqException {
final boolean isDebugEnabled = logger.isDebugEnabled();
HashSet<Object> cqUnfilteredEventsSet_newValue = new HashSet<>();
HashSet<Object> cqUnfilteredEventsSet_oldValue = new HashSet<>();
boolean b_cqResults_newValue;
boolean b_cqResults_oldValue;
boolean queryOldValue;
EntryEvent entryEvent = (EntryEvent) event;
Object eventKey = entryEvent.getKey();
boolean isDupEvent = ((EntryEventImpl) event).isPossibleDuplicate();
// The CQ query needs to be applied when the op is update, destroy
// invalidate and in case when op is create and its an duplicate
// event, the reason for this is when peer sends a duplicate event
// it marks it as create and sends it, so that the receiving node
// applies it (see DR.virtualPut()).
boolean opRequiringQueryOnOldValue = (event.getOperation().isUpdate() || event.getOperation().isDestroy() || event.getOperation().isInvalidate() || (event.getOperation().isCreate() && isDupEvent));
HashMap<String, Integer> matchedCqs = new HashMap<>();
long executionStartTime;
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();
if (isDebugEnabled) {
logger.debug("Profile for {} processing {} CQs", cf.peerMemberId, cqs.size());
}
if (cqs.isEmpty()) {
continue;
}
// Get new value. If its not retrieved.
if (cqUnfilteredEventsSet_newValue.isEmpty() && (event.getOperation().isCreate() || event.getOperation().isUpdate())) {
Object newValue = entryEvent.getNewValue();
if (newValue != null) {
// We have a new value to run the query on
cqUnfilteredEventsSet_newValue.add(newValue);
}
}
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();
b_cqResults_newValue = false;
b_cqResults_oldValue = false;
queryOldValue = false;
if (cQuery == null) {
continue;
}
String cqName = cQuery.getServerCqName();
Long filterID = cQuery.getFilterID();
if (isDebugEnabled) {
logger.debug("Processing CQ : {} Key: {}", cqName, eventKey);
}
Integer cqEvent = null;
if (matchedCqs.containsKey(cqName)) {
cqEvent = matchedCqs.get(cqName);
if (isDebugEnabled) {
logger.debug("query {} has already been processed and returned {}", cqName, cqEvent);
}
if (cqEvent == null) {
continue;
}
// Update the Cache Results for this CQ.
if (cqEvent.intValue() == MessageType.LOCAL_CREATE || cqEvent.intValue() == MessageType.LOCAL_UPDATE) {
cQuery.addToCqResultKeys(eventKey);
} else if (cqEvent.intValue() == MessageType.LOCAL_DESTROY) {
cQuery.markAsDestroyedInCqResultKeys(eventKey);
}
} else {
boolean error = false;
{
try {
synchronized (cQuery) {
// Apply query on new value.
if (!cqUnfilteredEventsSet_newValue.isEmpty()) {
executionStartTime = this.stats.startCqQueryExecution();
b_cqResults_newValue = evaluateQuery(cQuery, new Object[] { cqUnfilteredEventsSet_newValue });
this.stats.endCqQueryExecution(executionStartTime);
}
}
// Apply query on oldValue.
if (opRequiringQueryOnOldValue) {
// with PR region.
if (cQuery.cqResultKeysInitialized) {
b_cqResults_oldValue = cQuery.isPartOfCqResult(eventKey);
// Also apply if the query was not executed during cq execute
if ((cQuery.isPR || !CqServiceImpl.EXECUTE_QUERY_DURING_INIT) && b_cqResults_oldValue == false) {
queryOldValue = true;
}
if (isDebugEnabled && !cQuery.isPR && !b_cqResults_oldValue) {
logger.debug("Event Key not found in the CQ Result Queue. EventKey : {} CQ Name : {}", eventKey, cqName);
}
} else {
queryOldValue = true;
}
if (queryOldValue) {
if (cqUnfilteredEventsSet_oldValue.isEmpty()) {
Object oldValue = entryEvent.getOldValue();
if (oldValue != null) {
cqUnfilteredEventsSet_oldValue.add(oldValue);
}
}
synchronized (cQuery) {
// Apply query on old value.
if (!cqUnfilteredEventsSet_oldValue.isEmpty()) {
executionStartTime = this.stats.startCqQueryExecution();
b_cqResults_oldValue = evaluateQuery(cQuery, new Object[] { cqUnfilteredEventsSet_oldValue });
this.stats.endCqQueryExecution(executionStartTime);
} else {
if (isDebugEnabled) {
logger.debug("old value for event with key {} is null - query execution not performed", eventKey);
}
}
}
}
// Query oldValue
}
} catch (Exception ex) {
// Any exception in running the query should be caught here and
// buried because this code is running in-line with the message
// processing code and we don't want to kill that thread
error = true;
// CHANGE LOG MESSAGE:
logger.info(LocalizedMessage.create(LocalizedStrings.CqService_ERROR_WHILE_PROCESSING_CQ_ON_THE_EVENT_KEY_0_CQNAME_1_ERROR_2, new Object[] { ((EntryEvent) event).getKey(), cQuery.getName(), ex.getLocalizedMessage() }));
}
if (error) {
cqEvent = MESSAGE_TYPE_EXCEPTION;
} else {
if (b_cqResults_newValue) {
if (b_cqResults_oldValue) {
cqEvent = MESSAGE_TYPE_LOCAL_UPDATE;
} else {
cqEvent = MESSAGE_TYPE_LOCAL_CREATE;
}
// If its create and caching is enabled, cache the key
// for this CQ.
cQuery.addToCqResultKeys(eventKey);
} else if (b_cqResults_oldValue) {
// Base invalidate operation is treated as destroy.
// When the invalidate comes through, the entry will no longer
// satisfy the query and will need to be deleted.
cqEvent = MESSAGE_TYPE_LOCAL_DESTROY;
// If caching is enabled, mark this event's key as removed
// from the CQ cache.
cQuery.markAsDestroyedInCqResultKeys(eventKey);
}
}
}
// Get the matching CQs if any.
// synchronized (this.matchingCqMap){
String query = cQuery.getQueryString();
Set matchingCqs = (Set) matchingCqMap.get(query);
if (matchingCqs != null) {
Iterator iter = matchingCqs.iterator();
while (iter.hasNext()) {
String matchingCqName = (String) iter.next();
if (!matchingCqName.equals(cqName)) {
matchedCqs.put(matchingCqName, cqEvent);
if (isDebugEnabled) {
logger.debug("Adding CQ into Matching CQ Map: {} Event is: {}", matchingCqName, cqEvent);
}
}
}
}
}
if (cqEvent != null && cQuery.isRunning()) {
if (isDebugEnabled) {
logger.debug("Added event to CQ with client-side name: {} key: {} operation : {}", cQuery.cqName, eventKey, cqEvent);
}
cqInfo.put(filterID, cqEvent);
CqQueryVsdStats stats = cQuery.getVsdStats();
if (stats != null) {
stats.updateStats(cqEvent);
}
}
}
if (cqInfo.size() > 0) {
if (pf.isLocalProfile()) {
if (isDebugEnabled) {
logger.debug("Setting local CQ matches to {}", cqInfo);
}
frInfo.setLocalCqInfo(cqInfo);
} else {
if (isDebugEnabled) {
logger.debug("Setting CQ matches for {} to {}", cf.getDistributedMember(), cqInfo);
}
frInfo.setCqRoutingInfo(cf.getDistributedMember(), cqInfo);
}
}
}
// iteration over Profiles.
}
Aggregations