Skip to content

Apache Lucene open-source search software

SOLR-9983: fixing TestManagedSchemaThreadSafety NPE failure.

Mikhail Khludnevd9741205b5a3
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 25d8cc95bd0..ddff48fc066 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -140,6 +140,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.
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 00000000000..ac64f50042e
--- /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();
+ }
+}
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 e4a5c482eef..a00129a17c5 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;