Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for durable client startup #7827

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,7 @@ void unregisterClient(ClientProxyMembershipID memberId, boolean normalShutdown)
public void readyForEvents(ClientProxyMembershipID proxyId) {
CacheClientProxy proxy = getClientProxy(proxyId);
if (proxy != null) {
// False signifies that a marker message has not already been processed.
// Generate and send one.
proxy.startOrResumeMessageDispatcher(false);
proxy.startOrResumeMessageDispatcher(true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected void preTearDownDurableClientTestBase() {
@Test
public void testDurableClient() {

startupDurableClientAndServer(VERY_LONG_DURABLE_TIMEOUT_SECONDS);
startupDurableClientAndServer(VERY_LONG_DURABLE_TIMEOUT_SECONDS, true);

verifyDurableClientPresent(VERY_LONG_DURABLE_TIMEOUT_SECONDS, durableClientId, server1VM);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void verifyListenerUpdatesDisconnected(int numberOfEntries) {
@Test
public void testDurableClient() {

startupDurableClientAndServer(VERY_LONG_DURABLE_TIMEOUT_SECONDS);
startupDurableClientAndServer(VERY_LONG_DURABLE_TIMEOUT_SECONDS, true);

verifyDurableClientPresent(VERY_LONG_DURABLE_TIMEOUT_SECONDS, durableClientId, server1VM);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package org.apache.geode.internal.cache.tier.sockets;

import static java.lang.Thread.sleep;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static org.apache.geode.cache.InterestResultPolicy.NONE;
import static org.apache.geode.cache.Region.SEPARATOR;
import static org.apache.geode.internal.cache.tier.sockets.CacheServerTestUtil.TYPE_CREATE;
Expand Down Expand Up @@ -866,19 +864,11 @@ public void testDurableClientReceivedClientSessionInitialValue() {

// Start a durable client with the ControlListener
durableClientId = getName() + "_client";
durableClientVM.invoke(() -> createCacheClient(
getClientPool(getServerHostName(), server1Port, server2Port, true), regionName,
getClientDistributedSystemProperties(durableClientId, VERY_LONG_DURABLE_TIMEOUT_SECONDS),
true));

durableClientVM.invoke(() -> {
await().atMost(HEAVY_TEST_LOAD_DELAY_SUPPORT_MULTIPLIER, MINUTES)
.pollInterval(100, MILLISECONDS)
.untilAsserted(() -> assertThat(getCache()).isNotNull());
});

// Send clientReady message
sendClientReady(durableClientVM);
startupDurableClient(VERY_LONG_DURABLE_TIMEOUT_SECONDS,
getClientPool(getServerHostName(), server1Port, server2Port,
true),
Boolean.TRUE, true);

// Use ClientSession on the server to ` in entry key on behalf of durable client
boolean server1IsPrimary = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static org.hamcrest.Matchers.nullValue;

import java.time.Duration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
Expand All @@ -43,6 +44,7 @@
import org.apache.geode.cache.CacheException;
import org.apache.geode.cache.InterestResultPolicy;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.Pool;
import org.apache.geode.cache.client.PoolFactory;
import org.apache.geode.cache.client.PoolManager;
Expand Down Expand Up @@ -115,48 +117,40 @@ public final void preTearDown() {
protected void preTearDownDurableClientTestBase() {}


void startupDurableClientAndServer(final int durableClientTimeout) {
void startupDurableClientAndServer(final int durableClientTimeout,
final boolean sendReadyForEvents) {

server1Port = server1VM
.invoke(() -> createCacheServer(regionName, Boolean.TRUE));

durableClientId = getName() + "_client";
durableClientVM.invoke(() -> createCacheClient(
getClientPool(NetworkUtils.getServerHostName(), server1Port, true), regionName,
getClientDistributedSystemProperties(durableClientId, durableClientTimeout),
Boolean.TRUE));

durableClientVM.invoke(() -> {
await().atMost(HEAVY_TEST_LOAD_DELAY_SUPPORT_MULTIPLIER, MINUTES)
.pollInterval(100, MILLISECONDS)
.until(CacheServerTestUtil::getCache, notNullValue());
});

// Send clientReady message
sendClientReady(durableClientVM);
startupDurableClient(durableClientTimeout, Boolean.TRUE, sendReadyForEvents);
verifyDurableClientPresent(durableClientTimeout, durableClientId, server1VM);

}

// This exists so child classes can override the behavior and mock out network failures
public void restartDurableClient(int durableClientTimeout, Pool clientPool,
Boolean addControlListener) {
durableClientVM.invoke(() -> createCacheClient(clientPool, regionName,
getClientDistributedSystemProperties(durableClientId, durableClientTimeout),
addControlListener));

durableClientVM.invoke(() -> {
await().atMost(HEAVY_TEST_LOAD_DELAY_SUPPORT_MULTIPLIER, MINUTES)
.pollInterval(100, MILLISECONDS)
.until(CacheServerTestUtil::getCache, notNullValue());
});
startupDurableClient(durableClientTimeout, clientPool, addControlListener, true);
}

// This exists so child classes can override the behavior and mock out network failures
public void restartDurableClient(int durableClientTimeout, Boolean addControlListener) {
durableClientVM.invoke(() -> createCacheClient(
getClientPool(NetworkUtils.getServerHostName(), server1Port, true), regionName,
getClientDistributedSystemProperties(durableClientId, durableClientTimeout),
startupDurableClient(durableClientTimeout, addControlListener, true);
}

public void restartDurableClient(int durableClientTimeout, Boolean addControlListener,
boolean readyForEvents) {
startupDurableClient(durableClientTimeout, addControlListener, readyForEvents);
}


void startupDurableClient(int durableClientTimeout, Pool clientPool,
Boolean addControlListener, final boolean sendReadyForEvents) {
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
clientPool,
regionName, getClientDistributedSystemProperties(durableClientId, durableClientTimeout),
addControlListener));

durableClientVM.invoke(() -> {
Expand All @@ -165,8 +159,17 @@ public void restartDurableClient(int durableClientTimeout, Boolean addControlLis
.until(CacheServerTestUtil::getCache, notNullValue());
});

// Send clientReady message
sendClientReady(durableClientVM);
if (sendReadyForEvents) {
// Send clientReady message
sendClientReady(durableClientVM);
}
}

private void startupDurableClient(int durableClientTimeout, Boolean addControlListener,
boolean sendReadyForEvents) {
startupDurableClient(durableClientTimeout,
getClientPool(NetworkUtils.getServerHostName(), server1Port, true), addControlListener,
sendReadyForEvents);
}

void verifyDurableClientPresent(int durableClientTimeout, String durableClientId,
Expand All @@ -190,6 +193,19 @@ void waitForDurableClientPresence(String durableClientId, VM serverVM) {
});
}

void verifyEntryPresentInCache(Map.Entry<String, String> expectedEntry) {
this.durableClientVM.invoke(() -> {
ClientCache clientCache = CacheServerTestUtil.getClientCache();
Region<String, String> region = clientCache.getRegion(regionName);

Map<String, String> entriesMap = new HashMap<>();
for (Map.Entry entry : region.entrySet()) {
entriesMap.put((String) entry.getKey(), (String) entry.getValue());
}
await().untilAsserted(() -> assertThat(entriesMap).contains(expectedEntry));
});
}

void verifyDurableClientPresence(int durableClientTimeout, String durableClientId,
VM serverVM, final int count) {
serverVM.invoke(() -> {
Expand Down Expand Up @@ -521,6 +537,30 @@ public void run2() throws CacheException {
}
}


protected void registerInterestAll(VM vm, final String regionName, final boolean durable,
final InterestResultPolicy interestResultPolicy) {
vm.invoke(new CacheSerializableRunnable("Register interest on region : " + regionName) {
@Override
public void run2() throws CacheException {

Region<Object, Object> region = CacheServerTestUtil.getCache().getRegion(regionName);
assertThat(region).isNotNull();

// Register interest in all keys
region.registerInterestForAllKeys(interestResultPolicy, durable);
}
});

// This seems to be necessary for the queue to start up. Ideally should be replaced with
// Awaitility if possible.
try {
java.lang.Thread.sleep(5000);
} catch (java.lang.InterruptedException ex) {
fail("interrupted");
}
}

void createCq(VM vm, final String cqName, final String cqQuery, final boolean durable) {
vm.invoke("Register cq " + cqName, new CacheSerializableRunnable() {
@Override
Expand Down Expand Up @@ -555,6 +595,18 @@ public void run2() throws CacheException {
});
}

void publishEntry(Map.Entry<String, String> entry) {
this.publisherClientVM.invoke(new CacheSerializableRunnable("Publish entry") {
@Override
public void run2() throws CacheException {
Region<String, String> region = CacheServerTestUtil.getCache().getRegion(
regionName);
assertThat(region).isNotNull();
region.put(entry.getKey(), entry.getValue());
}
});
}

// Publishes portfolios
void publishEntries(VM publisherClientVM, final String regionName, final int numEntries) {
publisherClientVM.invoke("publish " + numEntries + " entries", new CacheSerializableRunnable() {
Expand Down
Loading