You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mk...@apache.org on 2017/01/27 21:55:37 UTC

lucene-solr:branch_6x: SOLR-9983: fixing TestManagedSchemaThreadSafety NPE failure.

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 4cd3d15da -> 55c1e88d9


SOLR-9983: fixing TestManagedSchemaThreadSafety NPE failure.

Also testing session expiration and set sensible Zookeeper connection
timeout.


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

Branch: refs/heads/branch_6x
Commit: 55c1e88d907bf54610f72981f7b569ae477775d0
Parents: 4cd3d15
Author: Mikhail Khludnev <mk...@apache.org>
Authored: Fri Jan 20 23:07:42 2017 +0300
Committer: Mikhail Khludnev <mk...@apache.org>
Committed: Sat Jan 28 00:48:52 2017 +0300

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  3 ++
 .../org/apache/solr/cloud/MockZkController.java | 36 ++++++++++++++++++++
 .../schema/TestManagedSchemaThreadSafety.java   | 32 ++++++++++++++---
 3 files changed, 67 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/55c1e88d/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index df83eed..aebdf08 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -72,6 +72,9 @@ Other Changes
 * SOLR-9972: SpellCheckComponent collations and suggestions returned as a JSON object rather than a list
   (Christine Poerschke in response to bug report from Ricky Oktavianus Lazuardy)
 
+* SOLR-9996: Fixing NullPointerException failure by TestManagedSchemaThreadSafety 
+  adding check for Zookeeper session expiration (Steve Rowe, Mikhail Khludnev)
+
 ==================  6.4.1 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/55c1e88d/solr/core/src/test/org/apache/solr/cloud/MockZkController.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/MockZkController.java b/solr/core/src/test/org/apache/solr/cloud/MockZkController.java
new file mode 100644
index 0000000..ac64f50
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/cloud/MockZkController.java
@@ -0,0 +1,36 @@
+/*
+ * 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.cloud;
+
+import java.io.IOException;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.solr.core.CloudConfig;
+import org.apache.solr.core.CoreContainer;
+
+public class MockZkController extends ZkController {
+
+  public MockZkController(CoreContainer cc, String zkServerAddress, int zkClientConnectTimeout, CloudConfig cloudConfig,
+      CurrentCoreDescriptorProvider registerOnReconnect) throws InterruptedException, TimeoutException, IOException {
+    super(cc, zkServerAddress, zkClientConnectTimeout, cloudConfig, registerOnReconnect);
+  }
+
+  @Override
+  public CoreContainer getCoreContainer() {
+    return super.getCoreContainer();
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/55c1e88d/solr/core/src/test/org/apache/solr/schema/TestManagedSchemaThreadSafety.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/schema/TestManagedSchemaThreadSafety.java b/solr/core/src/test/org/apache/solr/schema/TestManagedSchemaThreadSafety.java
index e4a5c48..a00129a 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestManagedSchemaThreadSafety.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestManagedSchemaThreadSafety.java
@@ -28,17 +28,20 @@ import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.cloud.MockZkController;
 import org.apache.solr.cloud.ZkController;
 import org.apache.solr.cloud.ZkSolrResourceLoader;
 import org.apache.solr.cloud.ZkTestServer;
 import org.apache.solr.common.cloud.SolrZkClient;
 import org.apache.solr.common.util.ExecutorUtil;
 import org.apache.solr.common.util.NamedList;
+import org.apache.solr.core.CoreContainer;
 import org.apache.solr.core.SolrConfig;
 import org.apache.solr.core.SolrResourceLoader;
 import org.apache.solr.util.LogLevel;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.KeeperException.NoNodeException;
+import org.apache.zookeeper.KeeperException.SessionExpiredException;
 import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.data.Stat;
 import org.junit.AfterClass;
@@ -106,14 +109,14 @@ public class TestManagedSchemaThreadSafety extends SolrTestCaseJ4 {
 
     final String configsetName = "managed-config";//
 
-    try (SolrZkClient client = new SuspendingZkClient(zkServer.getZkHost(), 30)) {
+    try (SolrZkClient client = new SuspendingZkClient(zkServer.getZkHost(), 30000)) {
       // we can pick any to load configs, I suppose, but here we check
       client.upConfig(configset("cloud-managed-upgrade"), configsetName);
     }
 
     ExecutorService executor = ExecutorUtil.newMDCAwareCachedThreadPool("threadpool");
     
-    try (SolrZkClient raceJudge = new SuspendingZkClient(zkServer.getZkHost(), 30)) {
+    try (SolrZkClient raceJudge = new SuspendingZkClient(zkServer.getZkHost(), 30000)) {
 
       ZkController zkController = createZkController(raceJudge);
 
@@ -132,14 +135,35 @@ public class TestManagedSchemaThreadSafety extends SolrTestCaseJ4 {
   }
 
   private ZkController createZkController(SolrZkClient client) throws KeeperException, InterruptedException {
-    ZkController zkController = mock(ZkController.class,
+    
+    CoreContainer mockAlwaysUpCoreContainer = mock(CoreContainer.class, 
+        Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
+    when(mockAlwaysUpCoreContainer.isShutDown()).thenReturn(Boolean.FALSE);  // Allow retry on session expiry
+    
+    
+    MockZkController zkController = mock(MockZkController.class,
         Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
 
+    when(zkController.getCoreContainer()).thenReturn(mockAlwaysUpCoreContainer);
+
     when(zkController.getZkClient()).thenReturn(client);
     Mockito.doAnswer(new Answer<Boolean>() {
+      volatile boolean sessionExpired=false;
+      
       @Override
       public Boolean answer(InvocationOnMock invocation) throws Throwable {
-        return client.exists((String) invocation.getArguments()[0], true);
+        String path = (String) invocation.getArguments()[0];
+        perhapsExpired();
+        Boolean exists = client.exists(path, true);
+        perhapsExpired();
+        return exists;
+      }
+
+      private void perhapsExpired() throws SessionExpiredException {
+        if (!sessionExpired && rarely()) {
+          sessionExpired = true;
+          throw new KeeperException.SessionExpiredException();
+        }
       }
     }).when(zkController).pathExists(Mockito.anyString());
     return zkController;