Added check for explicit empty line response from Zookeeper

This commit is contained in:
Jan Høydahl 2019-08-06 15:33:08 +02:00
parent 8d0506e962
commit 79c13d62d3
2 changed files with 20 additions and 1 deletions

View File

@ -255,7 +255,7 @@ public class ZookeeperStatusHandler extends RequestHandlerBase {
* @throws SolrException if validation fails
*/
protected boolean validateZkRawResponse(List<String> response, String zkHostPort, String fourLetterWordCommand) {
if (response == null || response.isEmpty()) {
if (response == null || response.isEmpty() || (response.size() == 1 && response.get(0).isBlank())) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Empty response from Zookeeper " + zkHostPort);
}
if (response.size() == 1 && response.get(0).contains("not in the whitelist")) {

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
@ -33,6 +34,7 @@ import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.response.DelegationTokenResponse;
import org.apache.solr.cloud.SolrCloudTestCase;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.junit.After;
@ -41,6 +43,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Answers;
import org.mockito.ArgumentMatchers;
import org.mockito.invocation.InvocationOnMock;
import org.noggit.JSONUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -49,6 +52,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;
public class ZookeeperStatusHandlerTest extends SolrCloudTestCase {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@ -148,4 +152,19 @@ public class ZookeeperStatusHandlerTest extends SolrCloudTestCase {
" \"status\":\"yellow\"}";
assertEquals(expected, JSONUtil.toJSON(mockStatus));
}
@Test(expected = SolrException.class)
public void validateNotWhitelisted() {
assumeWorkingMockito();
ZookeeperStatusHandler zkStatusHandler = mock(ZookeeperStatusHandler.class, withSettings().defaultAnswer(InvocationOnMock::callRealMethod));
zkStatusHandler.validateZkRawResponse(Collections.singletonList("mntr is not executed because it is not in the whitelist."),
"zoo1:2181", "mntr");
}
@Test(expected = SolrException.class)
public void validateEmptyResponse() {
assumeWorkingMockito();
ZookeeperStatusHandler zkStatusHandler = mock(ZookeeperStatusHandler.class, withSettings().defaultAnswer(InvocationOnMock::callRealMethod));
zkStatusHandler.validateZkRawResponse(Collections.emptyList(), "zoo1:2181", "mntr");
}
}