You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by da...@apache.org on 2018/11/21 11:44:59 UTC

lucene-solr:jira/http2: Add more tests for ConcurrentUpdateHttp2SolrClient

Repository: lucene-solr
Updated Branches:
  refs/heads/jira/http2 7c9eac91a -> cc4ae97b1


Add more tests for ConcurrentUpdateHttp2SolrClient


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/cc4ae97b
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/cc4ae97b
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/cc4ae97b

Branch: refs/heads/jira/http2
Commit: cc4ae97b1889bc9d7848bc5318390954e2a48d34
Parents: 7c9eac9
Author: Cao Manh Dat <da...@apache.org>
Authored: Wed Nov 21 11:44:46 2018 +0000
Committer: Cao Manh Dat <da...@apache.org>
Committed: Wed Nov 21 11:44:46 2018 +0000

----------------------------------------------------------------------
 .../solr/update/StreamingSolrClients.java       |   7 +-
 .../impl/ConcurrentUpdateHttp2SolrClient.java   |  37 +--
 .../solr/client/solrj/impl/Http2SolrClient.java |   5 +-
 .../embedded/SolrExampleStreamingHttp2Test.java | 146 +++++++++++
 ...urrentUpdateHttp2SolrClientBadInputTest.java | 100 ++++++++
 ...pdateHttp2SolrClientMultiCollectionTest.java |  95 ++++++++
 .../ConcurrentUpdateHttp2SolrClientTest.java    | 244 +++++++++++++++++++
 .../impl/ConcurrentUpdateSolrClientTest.java    |   7 +-
 8 files changed, 604 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cc4ae97b/solr/core/src/java/org/apache/solr/update/StreamingSolrClients.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/update/StreamingSolrClients.java b/solr/core/src/java/org/apache/solr/update/StreamingSolrClients.java
index f46c744..39d8f03 100644
--- a/solr/core/src/java/org/apache/solr/update/StreamingSolrClients.java
+++ b/solr/core/src/java/org/apache/solr/update/StreamingSolrClients.java
@@ -72,8 +72,7 @@ public class StreamingSolrClients {
       // NOTE: increasing to more than 1 threadCount for the client could cause updates to be reordered
       // on a greater scale since the current behavior is to only increase the number of connections/Runners when
       // the queue is more than half full.
-      client = new ErrorReportingConcurrentUpdateSolrClient.Builder(url, req, errors)
-          .withHttp2SolrClient(httpClient)
+      client = new ErrorReportingConcurrentUpdateSolrClient.Builder(url, httpClient, req, errors)
           .withQueueSize(100)
           .withThreadCount(runnerCount)
           .withExecutorService(updateExecutor)
@@ -152,8 +151,8 @@ class ErrorReportingConcurrentUpdateSolrClient extends ConcurrentUpdateHttp2Solr
     protected SolrCmdDistributor.Req req;
     protected List<Error> errors;
 
-    public Builder(String baseSolrUrl, SolrCmdDistributor.Req req, List<Error> errors) {
-      super(baseSolrUrl);
+    public Builder(String baseSolrUrl, Http2SolrClient client, SolrCmdDistributor.Req req, List<Error> errors) {
+      super(baseSolrUrl, client);
       this.req = req;
       this.errors = errors;
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cc4ae97b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java
index 58abd0a..eeb4c90 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClient.java
@@ -259,6 +259,7 @@ public class ConcurrentUpdateHttp2SolrClient extends SolrClient {
   public NamedList<Object> request(final SolrRequest request, String collection)
       throws SolrServerException, IOException {
     if (!(request instanceof UpdateRequest)) {
+      request.setBasePath(basePath);
       return client.request(request, collection);
     }
     UpdateRequest req = (UpdateRequest) request;
@@ -480,7 +481,12 @@ public class ConcurrentUpdateHttp2SolrClient extends SolrClient {
   private void interruptRunnerThreadsPolling() {
     synchronized (runners) {
       for (Runner ignored : runners) {
-        queue.add(END_UPDATE);
+        try {
+          queue.put(END_UPDATE);
+        } catch (InterruptedException e) {
+          Thread.currentThread().interrupt();
+          return;
+        }
       }
     }
   }
@@ -526,34 +532,9 @@ public class ConcurrentUpdateHttp2SolrClient extends SolrClient {
     protected ExecutorService executorService;
     protected boolean streamDeletes;
 
-    /**
-     * Create a Builder object, based on the provided Solr URL.
-     *
-     * Two different paths can be specified as a part of this URL:
-     *
-     * 1) A path pointing directly at a particular core
-     * <pre>
-     *   SolrClient client = new ConcurrentUpdateHttp2SolrClient.Builder("http://my-solr-server:8983/solr/core1").build();
-     *   QueryResponse resp = client.query(new SolrQuery("*:*"));
-     * </pre>
-     * Note that when a core is provided in the base URL, queries and other requests can be made without mentioning the
-     * core explicitly.  However, the client can only send requests to that core.
-     *
-     * 2) The path of the root Solr path ("/solr")
-     * <pre>
-     *   SolrClient client = new ConcurrentUpdateHttp2SolrClient.Builder("http://my-solr-server:8983/solr").build();
-     *   QueryResponse resp = client.query("core1", new SolrQuery("*:*"));
-     * </pre>
-     * In this case the client is more flexible and can be used to send requests to any cores.  This flexibility though
-     * requires that the core be specified on all requests.
-     */
-    public Builder(String baseSolrUrl) {
+    public Builder(String baseSolrUrl, Http2SolrClient client) {
       this.baseSolrUrl = baseSolrUrl;
-    }
-
-    public Builder withHttp2SolrClient(Http2SolrClient solrClient) {
-      this.client = solrClient;
-      return this;
+      this.client = client;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cc4ae97b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
index 58091c7..a85555c 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
@@ -244,8 +244,9 @@ public class Http2SolrClient extends SolrClient {
       this.isXml = isXml;
     }
 
-    public boolean belongToThisStream(SolrRequest solrRequest, String collection) {
-      if (!origParams.toNamedList().equals(solrRequest.getParams().toNamedList()) || !StringUtils.equals(origCollection, collection)) {
+    boolean belongToThisStream(SolrRequest solrRequest, String collection) {
+      ModifiableSolrParams solrParams = new ModifiableSolrParams(solrRequest.getParams());
+      if (!origParams.toNamedList().equals(solrParams.toNamedList()) || !StringUtils.equals(origCollection, collection)) {
         return false;
       }
       return true;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cc4ae97b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingHttp2Test.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingHttp2Test.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingHttp2Test.java
new file mode 100644
index 0000000..473716d
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/SolrExampleStreamingHttp2Test.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.client.solrj.embedded;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrExampleTests;
+import org.apache.solr.client.solrj.impl.ConcurrentUpdateHttp2SolrClient;
+import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient;
+import org.apache.solr.client.solrj.impl.Http2SolrClient;
+import org.apache.solr.client.solrj.impl.XMLResponseParser;
+import org.apache.solr.client.solrj.request.RequestWriter;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.common.SolrInputDocument;
+import org.junit.BeforeClass;
+
+public class SolrExampleStreamingHttp2Test extends SolrExampleTests {
+
+  @BeforeClass
+  public static void beforeTest() throws Exception {
+    createJetty(legacyExampleCollection1SolrHome());
+  }
+
+  @Override
+  public SolrClient createNewSolrClient()
+  {
+    try {
+      // setup the server...
+      String url = jetty.getBaseUrl().toString() + "/collection1";
+      // smaller queue size hits locks more often
+      Http2SolrClient solrClient = new Http2SolrClient.Builder()
+          .build();
+      solrClient.setParser(new XMLResponseParser());
+      solrClient.setRequestWriter(new RequestWriter());
+      ConcurrentUpdateHttp2SolrClient concurrentClient = new ErrorTrackingConcurrentUpdateSolrClient.Builder(url, solrClient)
+          .withQueueSize(2)
+          .withThreadCount(5)
+          .build();
+      return concurrentClient;
+    }
+
+    catch( Exception ex ) {
+      throw new RuntimeException( ex );
+    }
+  }
+
+  public void testWaitOptions() throws Exception {
+    // SOLR-3903
+    final List<Throwable> failures = new ArrayList<>();
+    final String serverUrl = jetty.getBaseUrl().toString() + "/collection1";
+    try (Http2SolrClient http2Client = new Http2SolrClient.Builder().build();
+         ConcurrentUpdateHttp2SolrClient concurrentClient = new FailureRecordingConcurrentUpdateSolrClient.Builder(serverUrl, http2Client)
+             .withQueueSize(2)
+             .withThreadCount(2)
+             .build()) {
+      int docId = 42;
+      for (UpdateRequest.ACTION action : EnumSet.allOf(UpdateRequest.ACTION.class)) {
+        for (boolean waitSearch : Arrays.asList(true, false)) {
+          for (boolean waitFlush : Arrays.asList(true, false)) {
+            UpdateRequest updateRequest = new UpdateRequest();
+            SolrInputDocument document = new SolrInputDocument();
+            document.addField("id", docId++);
+            updateRequest.add(document);
+            updateRequest.setAction(action, waitSearch, waitFlush);
+            concurrentClient.request(updateRequest);
+          }
+        }
+      }
+      concurrentClient.commit();
+      concurrentClient.blockUntilFinished();
+    }
+
+    if (0 != failures.size()) {
+      assertEquals(failures.size() + " Unexpected Exception, starting with...",
+          null, failures.get(0));
+    }
+  }
+
+  static class FailureRecordingConcurrentUpdateSolrClient extends ConcurrentUpdateHttp2SolrClient {
+    private final List<Throwable> failures = new ArrayList<>();
+
+    public FailureRecordingConcurrentUpdateSolrClient(Builder builder) {
+      super(builder);
+    }
+
+    @Override
+    public void handleError(Throwable ex) {
+      failures.add(ex);
+    }
+
+    static class Builder extends ConcurrentUpdateHttp2SolrClient.Builder {
+      public Builder(String baseSolrUrl, Http2SolrClient http2Client) {
+        super(baseSolrUrl, http2Client);
+      }
+
+      @Override
+      public FailureRecordingConcurrentUpdateSolrClient build() {
+        return new FailureRecordingConcurrentUpdateSolrClient(this);
+      }
+    }
+  }
+
+  public static class ErrorTrackingConcurrentUpdateSolrClient extends ConcurrentUpdateHttp2SolrClient {
+    public Throwable lastError = null;
+
+    public ErrorTrackingConcurrentUpdateSolrClient(Builder builder) {
+      super(builder);
+    }
+
+    @Override
+    public void handleError(Throwable ex) {
+      lastError = ex;
+    }
+
+    public static class Builder extends ConcurrentUpdateHttp2SolrClient.Builder {
+
+      public Builder(String baseSolrUrl, Http2SolrClient http2Client) {
+        super(baseSolrUrl, http2Client);
+      }
+
+      @Override
+      public ErrorTrackingConcurrentUpdateSolrClient build() {
+        return new ErrorTrackingConcurrentUpdateSolrClient(this);
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cc4ae97b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClientBadInputTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClientBadInputTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClientBadInputTest.java
new file mode 100644
index 0000000..7aea0a3
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClientBadInputTest.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.client.solrj.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.common.collect.Lists;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.embedded.JettyConfig;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.internal.matchers.StringContains.containsString;
+
+public class ConcurrentUpdateHttp2SolrClientBadInputTest extends SolrJettyTestBase {
+  private static final List<String> NULL_STR_LIST = null;
+  private static final List<String> EMPTY_STR_LIST = new ArrayList<>();
+  private static final String ANY_COLLECTION = "ANY_COLLECTION";
+  private static final int ANY_COMMIT_WITHIN_TIME = -1;
+  private static final int ANY_QUEUE_SIZE = 1;
+  private static final int ANY_MAX_NUM_THREADS = 1;
+
+  @BeforeClass
+  public static void beforeTest() throws Exception {
+    JettyConfig jettyConfig = JettyConfig.builder()
+        .withSSLConfig(sslConfig.buildServerSSLConfig())
+        .build();
+    createJetty(legacyExampleCollection1SolrHome(), jettyConfig);
+  }
+
+  @Test
+  public void testDeleteByIdReportsInvalidIdLists() throws Exception {
+
+    try (Http2SolrClient http2Client = new Http2SolrClient.Builder().build();
+         SolrClient client = new ConcurrentUpdateHttp2SolrClient.Builder(jetty.getBaseUrl().toString() + "/" + ANY_COLLECTION, http2Client)
+             .withQueueSize(ANY_QUEUE_SIZE)
+             .withThreadCount(ANY_MAX_NUM_THREADS)
+             .build()) {
+      assertExceptionThrownWithMessageContaining(IllegalArgumentException.class, Lists.newArrayList("ids", "null"), () -> {
+        client.deleteById(NULL_STR_LIST);
+      });
+      assertExceptionThrownWithMessageContaining(IllegalArgumentException.class, Lists.newArrayList("ids", "empty"), () -> {
+        client.deleteById(EMPTY_STR_LIST);
+      });
+      assertExceptionThrownWithMessageContaining(IllegalArgumentException.class, Lists.newArrayList("ids", "null"), () -> {
+        client.deleteById(NULL_STR_LIST, ANY_COMMIT_WITHIN_TIME);
+      });
+      assertExceptionThrownWithMessageContaining(IllegalArgumentException.class, Lists.newArrayList("ids", "empty"), () -> {
+        client.deleteById(EMPTY_STR_LIST, ANY_COMMIT_WITHIN_TIME);
+      });
+    }
+
+    try (Http2SolrClient http2Client = new Http2SolrClient.Builder().build();
+         SolrClient client = new ConcurrentUpdateHttp2SolrClient.Builder(jetty.getBaseUrl().toString() + "/" + ANY_COLLECTION, http2Client)
+             .withQueueSize(ANY_QUEUE_SIZE)
+             .withThreadCount(ANY_MAX_NUM_THREADS)
+             .build()) {
+      assertExceptionThrownWithMessageContaining(IllegalArgumentException.class, Lists.newArrayList("ids", "null"), () -> {
+        client.deleteById(ANY_COLLECTION, NULL_STR_LIST);
+      });
+      assertExceptionThrownWithMessageContaining(IllegalArgumentException.class, Lists.newArrayList("ids", "empty"), () -> {
+        client.deleteById(ANY_COLLECTION, EMPTY_STR_LIST);
+      });
+      assertExceptionThrownWithMessageContaining(IllegalArgumentException.class, Lists.newArrayList("ids", "null"), () -> {
+        client.deleteById(ANY_COLLECTION, NULL_STR_LIST, ANY_COMMIT_WITHIN_TIME);
+      });
+      assertExceptionThrownWithMessageContaining(IllegalArgumentException.class, Lists.newArrayList("ids", "empty"), () -> {
+        client.deleteById(ANY_COLLECTION, EMPTY_STR_LIST, ANY_COMMIT_WITHIN_TIME);
+      });
+    }
+  }
+
+  private void assertExceptionThrownWithMessageContaining(Class expectedType, List<String> expectedStrings, LuceneTestCase.ThrowingRunnable runnable) {
+    Throwable thrown = expectThrows(expectedType, runnable);
+
+    if (expectedStrings != null) {
+      for (String expectedString : expectedStrings) {
+        assertThat(thrown.getMessage(), containsString(expectedString));
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cc4ae97b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClientMultiCollectionTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClientMultiCollectionTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClientMultiCollectionTest.java
new file mode 100644
index 0000000..b8456bb
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClientMultiCollectionTest.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.client.solrj.impl;
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.util.ExternalPaths;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * {@link ConcurrentUpdateSolrClient} reuses the same HTTP connection to send multiple requests.  These tests ensure
+ * that this connection-reuse never results in documents being sent to the wrong collection.  See SOLR-12803
+ */
+public class ConcurrentUpdateHttp2SolrClientMultiCollectionTest extends SolrCloudTestCase {
+
+  private static final String COLLECTION_ONE_NAME = "collection1";
+  private static final String COLLECTION_TWO_NAME = "collection2";
+
+  private String solrUrl;
+
+  @BeforeClass
+  public static void setupCluster() throws Exception {
+    configureCluster(1)
+        .addConfig("conf", new File(ExternalPaths.TECHPRODUCTS_CONFIGSET).toPath())
+        .configure();
+  }
+
+  @Before
+  public void createCollections() throws Exception {
+    solrUrl = cluster.getJettySolrRunner(0).getBaseUrl().toString();
+
+    CollectionAdminRequest.createCollection(COLLECTION_ONE_NAME, "conf", 1, 1).process(cluster.getSolrClient());
+    CollectionAdminRequest.createCollection(COLLECTION_TWO_NAME, "conf", 1, 1).process(cluster.getSolrClient());
+  }
+
+  @After
+  public void deleteCollections() throws Exception {
+    cluster.deleteAllCollections();
+  }
+
+  @Test
+  public void testEnsureDocumentsSentToCorrectCollection() throws Exception {
+    int numTotalDocs = 1000;
+    int numExpectedPerCollection = numTotalDocs / 2;
+    try (Http2SolrClient http2Client = new Http2SolrClient.Builder().build();
+         SolrClient client = new ConcurrentUpdateHttp2SolrClient.Builder(solrUrl, http2Client)
+        .withQueueSize(numTotalDocs).build()) {
+      splitDocumentsAcrossCollections(client, numTotalDocs);
+
+      assertEquals(numExpectedPerCollection, client.query(COLLECTION_ONE_NAME, new SolrQuery("*:*")).getResults().getNumFound());
+      assertEquals(numExpectedPerCollection, client.query(COLLECTION_TWO_NAME, new SolrQuery("*:*")).getResults().getNumFound());
+    }
+
+  }
+
+  private void splitDocumentsAcrossCollections(SolrClient client, int numTotalDocs) throws IOException, SolrServerException {
+    for (int docNum = 0; docNum < numTotalDocs; docNum++) {
+      final SolrInputDocument doc = new SolrInputDocument();
+      doc.setField("id", "value" + docNum);
+
+      if (docNum %2 == 0) {
+        client.add(COLLECTION_ONE_NAME, doc);
+      } else {
+        client.add(COLLECTION_TWO_NAME, doc);
+      }
+    }
+
+    client.commit(COLLECTION_ONE_NAME);
+    client.commit(COLLECTION_TWO_NAME);
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cc4ae97b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClientTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClientTest.java
new file mode 100644
index 0000000..06016b4
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateHttp2SolrClientTest.java
@@ -0,0 +1,244 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.client.solrj.impl;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.http.HttpResponse;
+import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.embedded.JettyConfig;
+import org.apache.solr.client.solrj.request.JavaBinUpdateRequestCodec;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.util.ExecutorUtil;
+import org.apache.solr.common.util.SolrjNamedThreadFactory;
+import org.eclipse.jetty.client.api.Response;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ConcurrentUpdateHttp2SolrClientTest extends SolrJettyTestBase {
+
+
+  @BeforeClass
+  public static void beforeTest() throws Exception {
+    JettyConfig jettyConfig = JettyConfig.builder()
+        .withServlet(new ServletHolder(ConcurrentUpdateSolrClientTest.TestServlet.class), "/cuss/*")
+        .withSSLConfig(sslConfig.buildServerSSLConfig())
+        .build();
+    createJetty(legacyExampleCollection1SolrHome(), jettyConfig);
+  }
+
+  @Test
+  public void testConcurrentUpdate() throws Exception {
+    ConcurrentUpdateSolrClientTest.TestServlet.clear();
+
+    String serverUrl = jetty.getBaseUrl().toString() + "/cuss/foo";
+
+    int cussThreadCount = 2;
+    int cussQueueSize = 100;
+
+    // for tracking callbacks from CUSS
+    final AtomicInteger successCounter = new AtomicInteger(0);
+    final AtomicInteger errorCounter = new AtomicInteger(0);
+    final StringBuilder errors = new StringBuilder();
+
+    try (Http2SolrClient http2Client = new Http2SolrClient.Builder().build();
+         ConcurrentUpdateHttp2SolrClient concurrentClient = new OutcomeCountingConcurrentUpdateSolrClient.Builder(serverUrl, http2Client, successCounter, errorCounter, errors)
+             .withQueueSize(cussQueueSize)
+             .withThreadCount(cussThreadCount)
+             .build()) {
+      concurrentClient.setPollQueueTime(0);
+
+      // ensure it doesn't block where there's nothing to do yet
+      concurrentClient.blockUntilFinished();
+
+      int poolSize = 5;
+      ExecutorService threadPool = ExecutorUtil.newMDCAwareFixedThreadPool(poolSize, new SolrjNamedThreadFactory("testCUSS"));
+
+      int numDocs = 100;
+      int numRunnables = 5;
+      for (int r=0; r < numRunnables; r++)
+        threadPool.execute(new ConcurrentUpdateSolrClientTest.SendDocsRunnable(String.valueOf(r), numDocs, concurrentClient));
+
+      // ensure all docs are sent
+      threadPool.awaitTermination(5, TimeUnit.SECONDS);
+      threadPool.shutdown();
+
+      // wait until all requests are processed by CUSS
+      concurrentClient.blockUntilFinished();
+      concurrentClient.shutdownNow();
+
+      assertEquals("post", ConcurrentUpdateSolrClientTest.TestServlet.lastMethod);
+
+      // expect all requests to be successful
+      int expectedSuccesses = ConcurrentUpdateSolrClientTest.TestServlet.numReqsRcvd.get();
+      assertTrue(expectedSuccesses > 0); // at least one request must have been sent
+
+      assertTrue("Expected no errors but got "+errorCounter.get()+
+          ", due to: "+errors.toString(), errorCounter.get() == 0);
+      assertTrue("Expected "+expectedSuccesses+" successes, but got "+successCounter.get(),
+          successCounter.get() == expectedSuccesses);
+
+      int expectedDocs = numDocs * numRunnables;
+      assertTrue("Expected CUSS to send "+expectedDocs+" but got "+ ConcurrentUpdateSolrClientTest.TestServlet.numDocsRcvd.get(),
+          ConcurrentUpdateSolrClientTest.TestServlet.numDocsRcvd.get() == expectedDocs);
+    }
+
+
+
+  }
+
+  @Test
+  public void testCollectionParameters() throws IOException, SolrServerException {
+
+    int cussThreadCount = 2;
+    int cussQueueSize = 10;
+
+    try (Http2SolrClient http2Client = new Http2SolrClient.Builder().build();
+        ConcurrentUpdateHttp2SolrClient concurrentClient
+             = (new ConcurrentUpdateHttp2SolrClient.Builder(jetty.getBaseUrl().toString(), http2Client))
+        .withQueueSize(cussQueueSize)
+        .withThreadCount(cussThreadCount).build()) {
+
+      SolrInputDocument doc = new SolrInputDocument();
+      doc.addField("id", "collection");
+      concurrentClient.add("collection1", doc);
+      concurrentClient.commit("collection1");
+
+      assertEquals(1, concurrentClient.query("collection1", new SolrQuery("id:collection")).getResults().getNumFound());
+    }
+
+    try (Http2SolrClient http2Client = new Http2SolrClient.Builder().build();
+         ConcurrentUpdateHttp2SolrClient concurrentClient
+             = new ConcurrentUpdateHttp2SolrClient.Builder(jetty.getBaseUrl().toString() + "/collection1", http2Client)
+             .withQueueSize(cussQueueSize)
+             .withThreadCount(cussThreadCount).build()) {
+
+      assertEquals(1, concurrentClient.query(new SolrQuery("id:collection")).getResults().getNumFound());
+    }
+
+  }
+
+  @Test
+  public void testConcurrentCollectionUpdate() throws Exception {
+
+    int cussThreadCount = 2;
+    int cussQueueSize = 100;
+    int numDocs = 100;
+    int numRunnables = 5;
+    int expected = numDocs * numRunnables;
+
+    try (Http2SolrClient http2Client = new Http2SolrClient.Builder().build();
+         ConcurrentUpdateHttp2SolrClient concurrentClient
+             = new ConcurrentUpdateHttp2SolrClient.Builder(jetty.getBaseUrl().toString(), http2Client)
+             .withQueueSize(cussQueueSize)
+             .withThreadCount(cussThreadCount).build()) {
+      concurrentClient.setPollQueueTime(0);
+
+      // ensure it doesn't block where there's nothing to do yet
+      concurrentClient.blockUntilFinished();
+
+      // Delete all existing documents.
+      concurrentClient.deleteByQuery("collection1", "*:*");
+
+      int poolSize = 5;
+      ExecutorService threadPool = ExecutorUtil.newMDCAwareFixedThreadPool(poolSize, new SolrjNamedThreadFactory("testCUSS"));
+
+      for (int r=0; r < numRunnables; r++)
+        threadPool.execute(new ConcurrentUpdateSolrClientTest.SendDocsRunnable(String.valueOf(r), numDocs, concurrentClient, "collection1"));
+
+      // ensure all docs are sent
+      threadPool.awaitTermination(5, TimeUnit.SECONDS);
+      threadPool.shutdown();
+
+      concurrentClient.commit("collection1");
+
+      assertEquals(expected, concurrentClient.query("collection1", new SolrQuery("*:*")).getResults().getNumFound());
+
+      // wait until all requests are processed by CUSS
+      concurrentClient.blockUntilFinished();
+      concurrentClient.shutdownNow();
+    }
+
+    try (Http2SolrClient http2Client = new Http2SolrClient.Builder().build();
+         ConcurrentUpdateHttp2SolrClient concurrentClient
+             = new ConcurrentUpdateHttp2SolrClient.Builder(jetty.getBaseUrl().toString() + "/collection1", http2Client)
+             .withQueueSize(cussQueueSize)
+             .withThreadCount(cussThreadCount).build()) {
+
+      assertEquals(expected, concurrentClient.query(new SolrQuery("*:*")).getResults().getNumFound());
+    }
+
+  }
+
+  static class OutcomeCountingConcurrentUpdateSolrClient extends ConcurrentUpdateHttp2SolrClient {
+    private final AtomicInteger successCounter;
+    private final AtomicInteger failureCounter;
+    private final StringBuilder errors;
+
+    public OutcomeCountingConcurrentUpdateSolrClient(OutcomeCountingConcurrentUpdateSolrClient.Builder builder) {
+      super(builder);
+      this.successCounter = builder.successCounter;
+      this.failureCounter = builder.failureCounter;
+      this.errors = builder.errors;
+    }
+
+    @Override
+    public void handleError(Throwable ex) {
+      failureCounter.incrementAndGet();
+      errors.append(" "+ex);
+    }
+
+    @Override
+    public void onSuccess(Response resp, InputStream respBody) {
+      successCounter.incrementAndGet();
+    }
+
+    static class Builder extends ConcurrentUpdateHttp2SolrClient.Builder {
+      protected final AtomicInteger successCounter;
+      protected final AtomicInteger failureCounter;
+      protected final StringBuilder errors;
+
+      public Builder(String baseSolrUrl, Http2SolrClient http2Client, AtomicInteger successCounter, AtomicInteger failureCounter, StringBuilder errors) {
+        super(baseSolrUrl, http2Client);
+        this.successCounter = successCounter;
+        this.failureCounter = failureCounter;
+        this.errors = errors;
+      }
+
+      public OutcomeCountingConcurrentUpdateSolrClient build() {
+        return new OutcomeCountingConcurrentUpdateSolrClient(this);
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cc4ae97b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientTest.java
index c2c5722..2deaa27 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/ConcurrentUpdateSolrClientTest.java
@@ -18,6 +18,7 @@ package org.apache.solr.client.solrj.impl;
 
 import org.apache.http.HttpResponse;
 import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.embedded.JettyConfig;
@@ -273,14 +274,14 @@ public class ConcurrentUpdateSolrClientTest extends SolrJettyTestBase {
     
     private String id;
     private int numDocs;
-    private ConcurrentUpdateSolrClient cuss;
+    private SolrClient cuss;
     private String collection;
     
-    SendDocsRunnable(String id, int numDocs, ConcurrentUpdateSolrClient cuss) {
+    SendDocsRunnable(String id, int numDocs, SolrClient cuss) {
       this(id, numDocs, cuss, null);
     }
     
-    SendDocsRunnable(String id, int numDocs, ConcurrentUpdateSolrClient cuss, String collection) {
+    SendDocsRunnable(String id, int numDocs, SolrClient cuss, String collection) {
       this.id = id;
       this.numDocs = numDocs;
       this.cuss = cuss;