unlocks the document
It hangs on line 22, which is the unlock.
Do I do something wrong, or is it a bug?
I use java sdk 3.4.6 and couchbase server 7.1.0 on a Mac.
package dr.couchbase;
import java.time.Duration;
import java.util.concurrent.CountDownLatch;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.ReactiveCollection;
public class Test {
public static void main(final String[] args) throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final Cluster cluster = Cluster.connect(
"couchbase://127.0.0.1", "Administrator", "cbadmin"
);
final Bucket bucket = cluster.bucket("Aggregation");
final ReactiveCollection reactiveColl = bucket.reactive().defaultCollection();
reactiveColl.upsert("k", "hello").subscribe(r1 -> {
System.out.println("add");
reactiveColl.getAndLock("k", Duration.ofSeconds(10)).subscribe(r2 -> {
System.out.println("lock");
reactiveColl.unlock("k", r2.cas()).subscribe(v -> {
System.out.println("unlocked");
latch.countDown();
});
});
});
latch.await();
}
}
No there’s no bug here, you just need to chain reactive operations together using concatMap rather than calling them inside the subscribe in this way.
unlock returns Mono<Void> - there is no (next) object. So the consumer for objects is never called. Use the subscribe() method that takes a completeConsumer (the last argument).