From 3ce17806005a7c86ff502e6b6cb0e22a0ad60946 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sat, 5 Oct 2024 09:43:56 -0700 Subject: [PATCH] Verify object detachment. --- .../java/org/cojen/dirmi/AutoDisposeTest.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/cojen/dirmi/AutoDisposeTest.java b/src/test/java/org/cojen/dirmi/AutoDisposeTest.java index 3717c5d..be3abec 100644 --- a/src/test/java/org/cojen/dirmi/AutoDisposeTest.java +++ b/src/test/java/org/cojen/dirmi/AutoDisposeTest.java @@ -99,6 +99,8 @@ public void basic() throws Exception { @Test public void noReply() throws Exception { + R2Server.mDetached = 0; + R1 root = mSession.root(); R2 r2 = root.r2(); @@ -120,6 +122,8 @@ public void noReply() throws Exception { int sleep = 100; + assertEquals(0, R2Server.mDetached); + while (true) { System.gc(); @@ -130,6 +134,7 @@ public void noReply() throws Exception { if (newId != id) { // Original remote object was disposed and a new one was created. + assertEquals(1, R2Server.mDetached); break; } @@ -207,7 +212,9 @@ public R2 r2() { } } - private static class R2Server implements R2 { + private static class R2Server implements R2, SessionAware { + static volatile int mDetached; + private volatile String mMessage; @Override @@ -219,5 +226,14 @@ public void update(String msg) { public String getMessage() { return mMessage; } + + @Override + public void attached(Session s) { + } + + @Override + public void detached(Session s) { + mDetached++; + } } }