Darrel Schneider created GEODE-9706:
---------------------------------------
Summary: OutOfMemoryDUnitTest can be improved
Key: GEODE-9706
URL: https://issues.apache.org/jira/browse/GEODE-9706
Project: Geode
Issue Type: Test
Components: redis
Reporter: Darrel Schneider
Kirk Lund made the following suggestions for improving OutOfMemoryDUnitTest:
You might want to consider using ExecutorServiceRule or
DistributedExecutorServiceRule with a CompletableFuture instead of directly
using a thread:
{code:java}
@Rule
public ExecutorServiceRule executorServiceRule = new ExecutorServiceRule();
CompletableFuture<Void> memoryPressure = executorServiceRule.runAsync(() ->
{
try {
while (true) {
Thread.sleep(1000);
}
} catch (InterruptedException e) {
// done
}
});
// do something
memoryPressure.cancel(true);
{code}
The cancel(true) will interrupt the thread. If the test throws before that,
ExecutorServiceRule will clean up any threads during tear down by invoking
shutdownNow which will also interrupt any running threads. If the thread
resists interrupt and hangs, the rule should print a stack trace for it as a
test failure which would then make it easy to debug.
ExecutorServiceRule will work well within the controller JVM. If you need a
version of the rule that works within any JVM in a dunit test, then use
DistributedExecutorServiceRule.
Also when the test does a "join()" add a timeout like so:
{code:java}
join(GeodeAwaitility.getTimeout().getSeconds(), TimeUnit.SECONDS);
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)