Java SDK 1.1 - Synchronous Add and Views
Hi All,
I trying to create a junit test. Scenario:
- setUp: I'm adding two json documents to database
- Test: I'm getting those documents using view
- tearDown: I'm removing both objects
My view:
function (doc, meta) { if (doc.type && doc.type == "UserConnection") { emit([doc.providerId, doc.providerUserId], doc.userId); } }
This is how I add those documents to database and make sure that "add" is synchronous:
public boolean add(String key, Object element) { String json = gson.toJson(element); OperationFuture<Boolean> result = couchbaseClient.add(key, 0, json); return result.get(); }
JSON Documents that I'm adding are:
{"userId":"1","providerId":"test_pId","providerUserId":"test_pUId","type":"UserConnection"}
{"userId":"2","providerId":"test_pId","providerUserId":"test_pUId","type":"UserConnection"}
This is how I call the view:
View view = couchbaseClient.getView(DESIGN_DOCUMENT_NAME, VIEW_NAME); Query query = new Query(); query.setKey(ComplexKey.of("test_pId", "test_pUId")); ViewResponse viewResponse = couchbaseClient.query(view, query);
Problem:
- Test fails due to invalid number of elements fetched from view.
My observations:
- Sometimes it passes
- Number of elements that are fetched from view is not consistent(from 0 to 2)
- When I've added those documents to database instead of calling setUp the test passed every time
My question:
Is there something wrong with how I've approached to fetching data from view just after this data was inserted to DB? Is there any good practise for solving this problem? And can someone explain it to me please?
Thanks,
Dariusz
Hi, I've posted the same question on stackoverflow and suggested solution worked for me. Here is the link to my question: http://stackoverflow.com/questions/15077820/couchbase-2-0-java-sdk-1-1-s... .
Cheers
+1 to the question. I have the exact same issue. Can someone please point us in the right direction as to if our approach is wrong or this works as designed? Is there a way to make synchronous calls rather than async calls to add/set a value?
All help appreciated !