Skip to content

Commit

Permalink
watcher: Expose isClosed method
Browse files Browse the repository at this point in the history
Signed-off-by: Giri Ramasamy <46867712+giri-vsr@users.noreply.github.com>
  • Loading branch information
giri-vsr authored and lburgazzoli committed May 14, 2024
1 parent cdd5cd9 commit 6d375c8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions jetcd-core/src/main/java/io/etcd/jetcd/Watch.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ interface Watcher extends Closeable {
@Override
void close();

/**
* Returns if watcher is already closed
*/
boolean isClosed();

/**
* Requests the latest revision processed and propagates it to listeners
*/
Expand Down
3 changes: 2 additions & 1 deletion jetcd-core/src/main/java/io/etcd/jetcd/impl/WatchImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ final class WatcherImpl implements Watcher {
//
// ************************

boolean isClosed() {
@Override
public boolean isClosed() {
return this.closed.get() || WatchImpl.this.closed.get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,7 @@ public void testWatcherWithRequireLeaderErrsOutOnNoLeader() throws InterruptedEx
assertThat(ref.get()).isNotNull();
assertThat(ref.get()).isInstanceOf(EtcdException.class)
.hasMessageContaining(Errors.NO_LEADER_ERROR_MESSAGE);
final WatchImpl.WatcherImpl wimpl = (WatchImpl.WatcherImpl) watcher;
assertThat(wimpl.isClosed()).isTrue();
assertThat(watcher.isClosed()).isTrue();
}
}
}

0 comments on commit 6d375c8

Please sign in to comment.