summaryrefslogtreecommitdiffstats
path: root/container-disc/src/test
diff options
context:
space:
mode:
authorgjoranv <gv@verizonmedia.com>2020-12-15 13:39:32 +0100
committergjoranv <gv@verizonmedia.com>2020-12-15 14:37:14 +0100
commit08d1933bd7a34d0fae3c4cf0dcd8ba28084d83d1 (patch)
tree4982fe89a8b60f409a98127b4ed06298c663ea2f /container-disc/src/test
parentad4a9a58f97d7558eff48c6cd857cae3b570d55d (diff)
Wait for component deconstruction to finish when shutting down.
- Wait up to 10 minuts. - Add separate modes for reconfig and shutdown. - Add test ctor for setting the delay before deconstruction starts in RECONFIG mode. (Tests are TBD.)
Diffstat (limited to 'container-disc/src/test')
-rw-r--r--container-disc/src/test/java/com/yahoo/container/jdisc/component/DeconstructorTest.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/container-disc/src/test/java/com/yahoo/container/jdisc/component/DeconstructorTest.java b/container-disc/src/test/java/com/yahoo/container/jdisc/component/DeconstructorTest.java
index 9ae05f5c193..dfc1d32938f 100644
--- a/container-disc/src/test/java/com/yahoo/container/jdisc/component/DeconstructorTest.java
+++ b/container-disc/src/test/java/com/yahoo/container/jdisc/component/DeconstructorTest.java
@@ -24,12 +24,13 @@ public class DeconstructorTest {
@Before
public void init() {
- deconstructor = new Deconstructor(false);
+ deconstructor = new Deconstructor(Deconstructor.Mode.SHUTDOWN);
}
@Test
public void require_abstract_component_destructed() throws InterruptedException {
TestAbstractComponent abstractComponent = new TestAbstractComponent();
+
// Done by executor, so it takes some time even with a 0 delay.
deconstructor.deconstruct(List.of(abstractComponent), emptyList());
deconstructor.executor.shutdown();
@@ -47,6 +48,13 @@ public class DeconstructorTest {
}
@Test
+ public void deconstruct_is_synchronous_in_shutdown_mode() {
+ var slowDeconstructComponent = new SlowDeconstructComponent();
+ deconstructor.deconstruct(List.of(slowDeconstructComponent), emptyList());
+ assertTrue(slowDeconstructComponent.destructed);
+ }
+
+ @Test
public void require_shared_resource_released() {
TestSharedResource sharedResource = new TestSharedResource();
deconstructor.deconstruct(List.of(sharedResource), emptyList());
@@ -68,6 +76,20 @@ public class DeconstructorTest {
@Override public void deconstruct() { destructed = true; }
}
+ private static class SlowDeconstructComponent extends AbstractComponent {
+ boolean destructed = false;
+ @Override
+ public void deconstruct() {
+ // Add delay to verify that the Deconstructor waits until this is complete before returning.
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ throw new RuntimeException("The delayed deconstruct was interrupted.");
+ }
+ destructed = true;
+ }
+ }
+
private static class TestProvider implements Provider<Void> {
volatile boolean destructed = false;