DATACOUCH-462 - ReactiveCouchbaseRepository count() will raise exception when bucket is empty.

Small cleanup in the deleteAll test (which actually tests this as well), while
we are there.

Also, removed an unused import
This commit is contained in:
David Kelly
2019-06-28 10:21:41 -06:00
committed by GitHub
parent 64a91f1eb6
commit 4341edf941
2 changed files with 9 additions and 13 deletions

View File

@@ -21,7 +21,6 @@ import java.io.Serializable;
import com.couchbase.client.java.document.json.JsonArray;
import com.couchbase.client.java.error.DocumentDoesNotExistException;
import com.couchbase.client.java.view.AsyncViewResult;
import com.couchbase.client.java.view.AsyncViewRow;
import com.couchbase.client.java.view.ViewQuery;
import org.reactivestreams.Publisher;
@@ -238,7 +237,8 @@ public class SimpleReactiveCouchbaseRepository<T, ID extends Serializable> imple
.queryView(query)
.flatMap(AsyncViewResult::rows)
.map(asyncViewRow ->
Long.valueOf(asyncViewRow.value().toString())).toSingle());
Long.valueOf(asyncViewRow.value().toString()))
.switchIfEmpty(Observable.just(0L)).toSingle());
}
@SuppressWarnings("unchecked")

View File

@@ -30,11 +30,7 @@ import org.springframework.data.couchbase.repository.support.ReactiveCouchbaseRe
import org.springframework.data.repository.core.support.ReactiveRepositoryFactorySupport;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import reactor.core.publisher.Mono;
import java.util.NoSuchElementException;
import static junit.framework.TestCase.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.springframework.data.couchbase.CouchbaseTestHelper.getRepositoryWithRetry;
@@ -76,19 +72,19 @@ public class SimpleReactiveCouchbaseRepositoryDeleteAllIntegrationTests {
@Test
public void simpleDeleteAll() {
String key = "my_unique_user_key";
// in case there are other tests later, lets insure there is at least one
// User in the repository
ReactiveUser instance = new ReactiveUser(key, "foobar", 22);
repository.save(instance).block();
// we put a doc in, lets be sure the count reflects that there is
// at least one doc in there...
// we put a user in, lets be sure the count reflects that.
assertTrue(getCount() > 0L);
repository.deleteAll().block();
try {
getCount();
fail("count returned documents!");
} catch (NoSuchElementException e) {
}
// after deleteAll, we should have a count of 0
assertEquals(0L, getCount());
}
}