Hello,
I am using Java SDK 2.4.1 and what i have noticed that when the key is not present the onNext call does not happen when using AsyncBucket, the expected behaviour should be to have an exception “DocumentDoesNotExistException” or “NoSuchElementException”. I have tried with previous versions of SDKs(2.3.x, 2.2.x,2.1.x) as well, the same behaviour occurs.
The reason i am posting this is because the behaviour of normal Observable and BlockingObservable is not in sync. when i tried same call with toBlocking.single() it gave me an exception DocumentDoesNotExistsException
- Below is the source code which doesnt throw an exception -
- We are using AsyncBucket by using .async() over bucket to have immediate access to Observable and run custom flatmaps over it. But below code calls onCompleted of that Observable.
couchbaseServiceDelegator.getCouchbaseBucket(requestType).get(key, StringDocument.class);
- Below code provides an exception when Key does not exists.
couchbaseServiceDelegator.getCouchbaseBucket(requestType).get(key, StringDocument.class).toBlocking().single();
To help you guys out more when i checked the code below are my findings
In class CouchbaseAsyncBucket in method get(final String id, final Class target) there a switch case which when document does not exists returns false
switch(response.status()) {
case NOT_EXISTS:
** return false;**
case TEMPORARY_FAILURE:
case SERVER_BUSY:
throw new TemporaryFailureException();
case OUT_OF_MEMORY:
throw new CouchbaseOutOfMemoryException();
default:
throw new CouchbaseException(response.status().toString());
}
and once we return false this wont call onNext - below is the code(FilterSubscriber class) which doesnt calls the actual onNext of the Observable.
– Below is the code that gets called when we apply filter on an Observable.
@Override
public void onNext(T t) {
boolean result;
try {
result = predicate.call(t); // We return false here from filter when document does not exists.
} catch (Throwable ex) {
Exceptions.throwIfFatal(ex);
unsubscribe();
onError(OnErrorThrowable.addValueAsLastCause(ex, t));
return;
}
if (result) {
actual.onNext(t); // This never gets called as we are returning false. So we cant control error flow.
} else {
request(1);
}
}
Please let me know if any more inputs required
Thanks,
Dhawal Patel