Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | SDKs | SDKs

Java SDK 1.1 - Synchronous Add and Views

2 replies [Last post]
  • Login or register to post comments
Thu, 01/10/2013 - 01:55
darek.urlik
Offline
Joined: 01/10/2013
Groups: None

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:

  1. function (doc, meta) {
  2. if (doc.type && doc.type == "UserConnection") {
  3. emit([doc.providerId, doc.providerUserId], doc.userId);
  4. }
  5. }

This is how I add those documents to database and make sure that "add" is synchronous:

  1. public boolean add(String key, Object element) {
  2. String json = gson.toJson(element);
  3. OperationFuture<Boolean> result = couchbaseClient.add(key, 0, json);
  4. return result.get();
  5. }

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:

  1. View view = couchbaseClient.getView(DESIGN_DOCUMENT_NAME, VIEW_NAME);
  2. Query query = new Query();
  3. query.setKey(ComplexKey.of("test_pId", "test_pUId"));
  4. 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

Top
  • Login or register to post comments
Mon, 02/11/2013 - 20:55
shahshi15
Offline
Joined: 02/11/2013
Groups: None

+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 !

Top
  • Login or register to post comments
Sun, 03/03/2013 - 15:33
darek.urlik
Offline
Joined: 01/10/2013
Groups: None

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

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker