mirror of https://github.com/apache/lucene.git
SOLR-9983: fixing TestManagedSchemaThreadSafety NPE failure.
Also testing session expiration and set sensible Zookeeper connection timeout.
This commit is contained in:
parent
0187838022
commit
d9741205b5
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue