SHARE
TWEET

Bulk Replace Test

a guest Jul 16th, 2019 65 in 327 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   @Test
  2.   public void testBulkOperation_multiReplaces() {
  3.     String collection = randomCollection();
  4.     insertDocs(mongoClient, collection, 1, onSuccess(v -> {
  5.  
  6.       JsonObject filter1 = new JsonObject().put("num", 123);
  7.       JsonObject replace1 = new JsonObject().put("foo", "replaced");
  8.       BulkOperation bulkReplace1 = BulkOperation.createReplace(filter1, replace1);
  9.  
  10.       JsonObject filter2 = new JsonObject().put("num", 456);
  11.       JsonObject replace2 = new JsonObject().put("foo", "bar");
  12.       BulkOperation bulkReplace2 = BulkOperation.createReplace(filter2, replace2);
  13.  
  14.       mongoClient.bulkWrite(collection, Arrays.asList(bulkReplace1, bulkReplace2), onSuccess(bulkResult -> {
  15.         assertEquals(0, bulkResult.getInsertedCount());
  16.         assertEquals(2, bulkResult.getModifiedCount());
  17.         assertEquals(0, bulkResult.getDeletedCount());
  18.         assertEquals(2, bulkResult.getMatchedCount());
  19.         assertEquals(0, bulkResult.getUpserts().size());
  20.         mongoClient.find(collection, new JsonObject(), onSuccess(docs -> {
  21.           assertEquals(1, docs.size());
  22.           JsonObject foundDoc = docs.get(0);
  23.           assertEquals("replaced", foundDoc.getString("foo"));
  24.           assertNull(foundDoc.getInteger("num"));
  25.           testComplete();
  26.         }));
  27.       }));
  28.     }));
  29.     await();
  30.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top