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
Bugfix/GEODE-10228 DurableClientTestCase.testDurableHAFailover is failing #7608
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ec21465
GEODE-10228: Fixing a DurableClientTestCase.testDurableHAFailover
mhansonp 9d3ddac
GEODE-10228: Fixing a DurableClientTestCase.testDurableHAFailover
mhansonp cdd126e
GEODE-10228: Fixing a DurableClientTestCase.testDurableHAFailover
mhansonp 96cd36f
GEODE-10228: Cleanup
mhansonp 3149cca
GEODE-10228: Removing unnecessary statement
mhansonp c72002f
GEODE-10228: Cleanup per reviewer comments
mhansonp c5b50d8
GEODE-10228: Cleanup per comments plus one other change
mhansonp 4ecdc3b
GEODE-10228: Cleanup per comments + junit 5 supporting changes
mhansonp 13a5fe7
GEODE-10228: Removing junit5 changes
mhansonp 9b46fa4
GEODE-10228: more cleanup
mhansonp 9d8f193
GEODE-10228: fixing a port conflict by using random ports
mhansonp ab022e8
GEODE-10228: removing diagnostic changes to track down
mhansonp File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,20 +19,16 @@ | |
import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE; | ||
import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL; | ||
import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.net.UnknownHostException; | ||
import java.util.Stack; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.apache.geode.cache.Cache; | ||
import org.apache.geode.cache.CacheFactory; | ||
|
@@ -45,21 +41,17 @@ | |
import org.apache.geode.cache.server.ClientSubscriptionConfig; | ||
import org.apache.geode.cache.util.CacheListenerAdapter; | ||
import org.apache.geode.internal.AvailablePortHelper; | ||
import org.apache.geode.test.dunit.Host; | ||
import org.apache.geode.test.dunit.IgnoredException; | ||
import org.apache.geode.test.dunit.SerializableCallable; | ||
import org.apache.geode.test.dunit.SerializableRunnable; | ||
import org.apache.geode.test.dunit.VM; | ||
import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase; | ||
import org.apache.geode.test.junit.categories.ClientSubscriptionTest; | ||
|
||
/** | ||
* The ClientServerRegisterInterestsDUnitTest class is a test suite of test cases testing the | ||
* interaction between a client and a server in a Register Interests scenario. | ||
* | ||
* @since GemFire 8.0 | ||
*/ | ||
@Category({ClientSubscriptionTest.class}) | ||
@Tag("ClientSubscriptionTest") | ||
public class ClientServerRegisterInterestsDUnitTest extends JUnit4DistributedTestCase { | ||
|
||
protected static final long WAIT_TIME_MILLISECONDS = TimeUnit.SECONDS.toMillis(5); | ||
|
@@ -68,89 +60,78 @@ public class ClientServerRegisterInterestsDUnitTest extends JUnit4DistributedTes | |
|
||
private final AtomicInteger serverPort = new AtomicInteger(0); | ||
|
||
private final Stack entryEvents = new Stack(); | ||
private final Stack<EntryEvent<String, String>> entryEvents = new Stack<>(); | ||
|
||
private VM gemfireServerVm; | ||
|
||
@Override | ||
public final void postSetUp() throws Exception { | ||
public final void postSetUp() { | ||
disconnectAllFromDS(); | ||
setupGemFireCacheServer(); | ||
IgnoredException.addIgnoredException("java.net.ConnectException"); | ||
} | ||
|
||
@Override | ||
public final void preTearDown() throws Exception { | ||
public final void preTearDown() { | ||
serverPort.set(0); | ||
entryEvents.clear(); | ||
gemfireServerVm.invoke(new SerializableRunnable() { | ||
@Override | ||
public void run() { | ||
CacheFactory.getAnyInstance().close(); | ||
} | ||
}); | ||
gemfireServerVm.invoke(() -> CacheFactory.getAnyInstance().close()); | ||
gemfireServerVm = null; | ||
} | ||
|
||
private void setupGemFireCacheServer() { | ||
Host localhost = Host.getHost(0); | ||
|
||
gemfireServerVm = localhost.getVM(0); | ||
|
||
gemfireServerVm = VM.getVM(0); | ||
serverPort.set(AvailablePortHelper.getRandomAvailableTCPPort()); | ||
|
||
gemfireServerVm.invoke(new SerializableRunnable() { | ||
@Override | ||
public void run() { | ||
try { | ||
Cache cache = new CacheFactory() | ||
.set("name", "ClientServerRegisterInterestsTestGemFireServer").set(MCAST_PORT, "0") | ||
.set(LOG_FILE, "clientServerRegisterInterestsTest.log").set(LOG_LEVEL, "config") | ||
// .set("jmx-manager", "true") | ||
// .set("jmx-manager-http-port", "0") | ||
// .set("jmx-manager-port", "1199") | ||
// .set("jmx-manager-start", "true") | ||
.create(); | ||
gemfireServerVm.invoke(() -> { | ||
try { | ||
Cache cache = new CacheFactory() | ||
.set("name", "ClientServerRegisterInterestsTestGemFireServer").set(MCAST_PORT, "0") | ||
.set(LOG_FILE, "clientServerRegisterInterestsTest.log").set(LOG_LEVEL, "config") | ||
.create(); | ||
|
||
RegionFactory<String, String> regionFactory = cache.createRegionFactory(); | ||
RegionFactory<String, String> regionFactory = cache.createRegionFactory(); | ||
|
||
regionFactory.setDataPolicy(DataPolicy.REPLICATE); | ||
regionFactory.setKeyConstraint(String.class); | ||
regionFactory.setValueConstraint(String.class); | ||
regionFactory.setDataPolicy(DataPolicy.REPLICATE); | ||
regionFactory.setKeyConstraint(String.class); | ||
regionFactory.setValueConstraint(String.class); | ||
|
||
Region<String, String> example = regionFactory.create("Example"); | ||
Region<String, String> example = regionFactory.create("Example"); | ||
|
||
assertNotNull("The 'Example' Region was not properly configured and initialized!", | ||
example); | ||
assertEquals(SEPARATOR + "Example", example.getFullPath()); | ||
assertEquals("Example", example.getName()); | ||
assertTrue(example.isEmpty()); | ||
assertThat(example) | ||
.describedAs("The 'Example' Region was not properly configured and initialized!") | ||
.isNotNull(); | ||
assertThat(example.getFullPath()).isEqualTo(SEPARATOR + "Example"); | ||
assertThat(example.getName()).isEqualTo("Example"); | ||
assertThat(example).isEmpty(); | ||
|
||
example.put("1", "ONE"); | ||
example.put("1", "ONE"); | ||
|
||
assertFalse(example.isEmpty()); | ||
assertEquals(1, example.size()); | ||
assertThat(example).isNotEmpty(); | ||
assertThat(example).hasSize(1); | ||
|
||
CacheServer cacheServer = cache.addCacheServer(); | ||
CacheServer cacheServer = cache.addCacheServer(); | ||
|
||
cacheServer.setPort(serverPort.get()); | ||
cacheServer.setMaxConnections(10); | ||
cacheServer.setPort(serverPort.get()); | ||
cacheServer.setMaxConnections(10); | ||
|
||
ClientSubscriptionConfig clientSubscriptionConfig = | ||
cacheServer.getClientSubscriptionConfig(); | ||
ClientSubscriptionConfig clientSubscriptionConfig = | ||
cacheServer.getClientSubscriptionConfig(); | ||
|
||
clientSubscriptionConfig.setCapacity(100); | ||
clientSubscriptionConfig.setEvictionPolicy("entry"); | ||
clientSubscriptionConfig.setCapacity(100); | ||
clientSubscriptionConfig.setEvictionPolicy("entry"); | ||
|
||
cacheServer.start(); | ||
cacheServer.start(); | ||
|
||
assertTrue("Cache Server is not running!", cacheServer.isRunning()); | ||
} catch (UnknownHostException e) { | ||
throw new RuntimeException(e); | ||
} catch (IOException e) { | ||
throw new RuntimeException(String.format( | ||
"Failed to start the GemFire Cache Server listening on port (%1$d) due to IO error!", | ||
serverPort.get()), e); | ||
} | ||
assertThat(cacheServer.isRunning()).describedAs("Cache Server is not running!").isTrue(); | ||
} catch (UnknownHostException e) { | ||
throw new RuntimeException(e); | ||
} catch (IOException e) { | ||
throw new RuntimeException(String.format( | ||
"Failed to start the GemFire Cache Server listening on port (%1$d) due to IO error!", | ||
serverPort.get()), e); | ||
} | ||
}); | ||
} | ||
|
@@ -169,7 +150,9 @@ private ClientCache setupGemFireClientCache() { | |
|
||
Pool pool = poolFactory.create("serverConnectionPool"); | ||
|
||
assertNotNull("The 'serverConnectionPool' was not properly configured and initialized!", pool); | ||
assertThat(pool) | ||
.describedAs("The 'serverConnectionPool' was not properly configured and initialized!") | ||
.isNotNull(); | ||
|
||
ClientRegionFactory<String, String> regionFactory = | ||
clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY); | ||
|
@@ -181,8 +164,9 @@ private ClientCache setupGemFireClientCache() { | |
|
||
Region<String, String> exampleCachingProxy = regionFactory.create("Example"); | ||
|
||
assertNotNull("The 'Example' Client Region was not properly configured and initialized", | ||
exampleCachingProxy); | ||
assertThat(exampleCachingProxy) | ||
.describedAs("The 'Example' Client Region was not properly configured and initialized") | ||
.isNotNull(); | ||
|
||
clientCache.readyForEvents(); | ||
|
||
|
@@ -191,25 +175,23 @@ private ClientCache setupGemFireClientCache() { | |
return clientCache; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
protected <K, V> V put(final String regionName, final K key, final V value) { | ||
return (V) gemfireServerVm.invoke(new SerializableCallable() { | ||
@Override | ||
public Object call() throws Exception { | ||
Cache cache = CacheFactory.getAnyInstance(); | ||
cache.getRegion(regionName).put(key, value); | ||
return cache.getRegion(regionName).get(key); | ||
} | ||
protected <V> V put() { | ||
return (V) gemfireServerVm.invoke(() -> { | ||
Cache cache = CacheFactory.getAnyInstance(); | ||
cache.getRegion("/Example").put("2", "TWO"); | ||
return cache.getRegion("/Example").get("2"); | ||
}); | ||
} | ||
|
||
protected void waitOnEvent(final long waitTimeMilliseconds) { | ||
final long timeout = (System.currentTimeMillis() + waitTimeMilliseconds); | ||
protected void waitOnEvent() { | ||
final long timeout = (System.currentTimeMillis() | ||
+ ClientServerRegisterInterestsDUnitTest.WAIT_TIME_MILLISECONDS); | ||
|
||
while (entryEvents.empty() && (System.currentTimeMillis() < timeout)) { | ||
synchronized (this) { | ||
try { | ||
TimeUnit.MILLISECONDS.timedWait(this, Math.min(500, waitTimeMilliseconds)); | ||
TimeUnit.MILLISECONDS.timedWait(this, Math.min(500, | ||
ClientServerRegisterInterestsDUnitTest.WAIT_TIME_MILLISECONDS)); | ||
} catch (InterruptedException ignore) { | ||
} | ||
Comment on lines
+189
to
198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole method should probably just be replaced with:
|
||
} | ||
|
@@ -218,35 +200,33 @@ protected void waitOnEvent(final long waitTimeMilliseconds) { | |
|
||
@Test | ||
public void testClientRegisterInterests() { | ||
ClientCache clientCache = setupGemFireClientCache(); | ||
|
||
try { | ||
try (ClientCache clientCache = setupGemFireClientCache()) { | ||
Region<String, String> example = clientCache.getRegion(SEPARATOR + "Example"); | ||
|
||
assertNotNull("'Example' Region in Client Cache was not found!", example); | ||
assertEquals(1, example.size()); | ||
assertTrue(example.containsKey("1")); | ||
assertEquals("ONE", example.get("1")); | ||
assertTrue(entryEvents.empty()); | ||
assertThat(example).describedAs("'Example' Region in Client Cache was not found!") | ||
.isNotNull(); | ||
assertThat(example).hasSize(1); | ||
assertThat(example).containsKey("1"); | ||
assertThat(example.get("1")).isEqualTo("ONE"); | ||
jake-at-work marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assertThat(entryEvents).isEmpty(); | ||
|
||
String value = put(SEPARATOR + "Example", "2", "TWO"); | ||
String value = put(); | ||
|
||
assertEquals("TWO", value); | ||
assertThat(value).isEqualTo("TWO"); | ||
|
||
waitOnEvent(WAIT_TIME_MILLISECONDS); | ||
waitOnEvent(); | ||
|
||
assertFalse(entryEvents.empty()); | ||
assertThat(entryEvents).isNotEmpty(); | ||
|
||
EntryEvent entryEvent = (EntryEvent) entryEvents.pop(); | ||
EntryEvent<String, String> entryEvent = entryEvents.pop(); | ||
|
||
assertEquals("2", entryEvent.getKey()); | ||
assertEquals("TWO", entryEvent.getNewValue()); | ||
assertNull(entryEvent.getOldValue()); | ||
assertEquals(2, example.size()); | ||
assertTrue(example.containsKey("2")); | ||
assertEquals("TWO", example.get("2")); | ||
} finally { | ||
clientCache.close(); | ||
assertThat(entryEvent.getKey()).isEqualTo("2"); | ||
assertThat(entryEvent.getNewValue()).isEqualTo("TWO"); | ||
assertThat(entryEvent.getOldValue()).isNull(); | ||
assertThat(example).hasSize(2); | ||
assertThat(example).containsKey("2"); | ||
assertThat(example.get("2")).isEqualTo("TWO"); | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Warnings here can be fixed by using:
Since we explicitly create the Region as
<String, String>
, there's no need to use generics here.