Skip to content

Commit

Permalink
Verify object detachment.
Browse files Browse the repository at this point in the history
  • Loading branch information
broneill committed Oct 5, 2024
1 parent 575ed2c commit 3ce1780
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/test/java/org/cojen/dirmi/AutoDisposeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -120,6 +122,8 @@ public void noReply() throws Exception {

int sleep = 100;

assertEquals(0, R2Server.mDetached);

while (true) {
System.gc();

Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand All @@ -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++;
}
}
}

0 comments on commit 3ce1780

Please sign in to comment.