aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_core/src/test
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@oath.com>2018-02-06 11:59:55 +0100
committerBjørn Christian Seime <bjorncs@oath.com>2018-02-06 16:50:32 +0100
commitbfe2dbe8f5b5e9278c59c9c34aa32a5cf776283b (patch)
tree60ba3c820e00fabfc8210d8244951b6d13cc47ad /jdisc_core/src/test
parent6e6e9c71e11268a7badd2297341a0937cbad2d1f (diff)
Only run gc when number of stale containers above threshold
Changes the deactivated container watchdog to only trigger gc when the number of deactivated containers passed grace period is above a threshold.
Diffstat (limited to 'jdisc_core/src/test')
-rw-r--r--jdisc_core/src/test/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdogTest.java12
1 files changed, 8 insertions, 4 deletions
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdogTest.java b/jdisc_core/src/test/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdogTest.java
index a8bf7bd1d62..280ecd51624 100644
--- a/jdisc_core/src/test/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdogTest.java
+++ b/jdisc_core/src/test/java/com/yahoo/jdisc/core/ActiveContainerDeactivationWatchdogTest.java
@@ -33,7 +33,9 @@ public class ActiveContainerDeactivationWatchdogTest {
TestDriver driver = TestDriver.newSimpleApplicationInstanceWithoutOsgi();
ManualClock clock = new ManualClock(Instant.now());
ActiveContainerDeactivationWatchdog watchdog =
- new ActiveContainerDeactivationWatchdog(clock, Executors.newScheduledThreadPool(1));
+ new ActiveContainerDeactivationWatchdog(clock,
+ Executors.newScheduledThreadPool(1),
+ ActiveContainerDeactivationWatchdog.DEFAULT_DEACTIVATED_CONTAINERS_BEFORE_GC_THRESHOLD);
MockMetric metric = new MockMetric();
ActiveContainer containerWithoutRetainedResources = new ActiveContainer(driver.newContainerBuilder());
@@ -73,20 +75,22 @@ public class ActiveContainerDeactivationWatchdogTest {
"This is the case on most JVMs.")
public void deactivated_container_destructed_if_its_reference_counter_is_nonzero() {
ExecutorMock executor = new ExecutorMock();
+ ManualClock clock = new ManualClock(Instant.now());
ActiveContainerDeactivationWatchdog watchdog =
- new ActiveContainerDeactivationWatchdog(new ManualClock(), executor);
+ new ActiveContainerDeactivationWatchdog(clock, executor, /*deactivatedContainersBeforeGcThreshold*/0);
ActiveContainer container =
new ActiveContainer(TestDriver.newSimpleApplicationInstanceWithoutOsgi().newContainerBuilder());
AtomicBoolean destructed = new AtomicBoolean(false);
container.shutdown().notifyTermination(() -> destructed.set(true));
- container.refer(); // increase reference counter to simluate a leaking resource
+ container.refer(); // increase reference counter to simulate a leaking resource
watchdog.onContainerActivation(container);
container.release(); // release resource
- watchdog.onContainerActivation(null); // deactive container
+ watchdog.onContainerActivation(null); // deactivate container
WeakReference<ActiveContainer> containerWeakReference = new WeakReference<>(container);
container = null; // make container instance collectable by GC
+ clock.advance(ActiveContainerDeactivationWatchdog.ACTIVE_CONTAINER_GRACE_PERIOD.plusSeconds(1));
executor.triggerGcCommand.run();