Source:
public void index_UpdateCrudMultiThreaded() throws IndexExistsException, SQLException, ConflictException, InterruptedException { int n_threads = 3; final int n_docs = 100; final Map<String,String> matching = ImmutableMap.of("search", "success"); final Map<String,String> nonmatching = ImmutableMap.of("search", "failure"); indexManager.ensureIndexed("search", "search", IndexType.STRING); final List<String> matching_ids = Collections.synchronizedList(new ArrayList<String>()); class PopulateThread extends Thread { @Override public void run() { String docId; final String thread_id; DocumentBody body; thread_id = Thread.currentThread().getName(); for (int i = 0; i < n_docs; i++) { docId = String.format("%s-%s", thread_id, i); if ((i % 2) == 0) { body = DocumentBodyFactory.create(matching); matching_ids.add(docId); } else { body = DocumentBodyFactory.create(nonmatching); } MutableDocumentRevision rev = new MutableDocumentRevision(); rev.docId = docId; rev.body = body; try { datastore.createDocumentFromRevision(rev); } catch (Exception ioe) { System.out.println("Exception "+ioe); } } } } List<Thread> threads = new ArrayList<Thread>(); for (int i = 0; i < n_threads; i++) { threads.add(new PopulateThread()); } for (Thread t : threads) { t.start(); } for (Thread t : threads) { t.join(); } QueryBuilder q = new QueryBuilder(); q.index("search").equalTo("success"); QueryResult result = indexManager.query(q.build()); List<BasicDocumentRevision> docRevisions = Lists.newArrayList(result); List<String> docIds = new ArrayList<String>(); for (BasicDocumentRevision r : docRevisions) { docIds.add(r.getId()); } Assert.assertEquals(matching_ids.size(), docIds.size()); for (String id : matching_ids) { Assert.assertTrue(docIds.contains(id)); } }

Target:
public void index_UpdateCrudMultiThreaded() throws IndexExistsException, SQLException, ConflictException, InterruptedException { int n_threads = 3; final int n_docs = 100; final Map<String,String> matching = ImmutableMap.of("search", "success"); final Map<String,String> nonmatching = ImmutableMap.of("search", "failure"); indexManager.ensureIndexed("search", "search", IndexType.STRING); final List<String> matching_ids = Collections.synchronizedList(new ArrayList<String>()); class PopulateThread extends Thread { @Override public void run() { String docId; final String thread_id; DocumentBody body; thread_id = Thread.currentThread().getName(); for (int i = 0; i < n_docs; i++) { docId = String.format("%s-%s", thread_id, i); if ((i % 2) == 0) { body = DocumentBodyFactory.create(matching); matching_ids.add(docId); } else { body = DocumentBodyFactory.create(nonmatching); } MutableDocumentRevision rev = new MutableDocumentRevision(); rev.docId = docId; rev.body = body; try { datastore.createDocumentFromRevision(rev); } catch (Exception e) { System.out.println("Exception "+e); } } } } List<Thread> threads = new ArrayList<Thread>(); for (int i = 0; i < n_threads; i++) { threads.add(new PopulateThread()); } for (Thread t : threads) { t.start(); } for (Thread t : threads) { t.join(); } QueryBuilder q = new QueryBuilder(); q.index("search").equalTo("success"); QueryResult result = indexManager.query(q.build()); List<BasicDocumentRevision> docRevisions = Lists.newArrayList(result); List<String> docIds = new ArrayList<String>(); for (BasicDocumentRevision r : docRevisions) { docIds.add(r.getId()); } Assert.assertEquals(matching_ids.size(), docIds.size()); for (String id : matching_ids) { Assert.assertTrue(docIds.contains(id)); } }