|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | +package org.elasticsearch.xpack.qa.sql.nosecurity; |
| 7 | + |
| 8 | +import org.elasticsearch.client.Request; |
| 9 | +import org.elasticsearch.xpack.qa.sql.jdbc.JdbcIntegrationTestCase; |
| 10 | +import org.junit.Before; |
| 11 | + |
| 12 | +import java.io.IOException; |
| 13 | +import java.sql.Connection; |
| 14 | +import java.sql.SQLException; |
| 15 | +import java.sql.Statement; |
| 16 | + |
| 17 | +import static org.hamcrest.Matchers.containsString; |
| 18 | + |
| 19 | +public class JdbcShardFailureIT extends JdbcIntegrationTestCase { |
| 20 | + @Before |
| 21 | + public void createTestIndex() throws IOException { |
| 22 | + Request createTest1 = new Request("PUT", "/test1"); |
| 23 | + String body1 = "{\"aliases\":{\"test\":{}}, \"mappings\": {\"doc\": {\"properties\": {\"test_field\":{\"type\":\"integer\"}}}}}"; |
| 24 | + createTest1.setJsonEntity(body1); |
| 25 | + client().performRequest(createTest1); |
| 26 | + |
| 27 | + Request createTest2 = new Request("PUT", "/test2"); |
| 28 | + String body2 = "{\"aliases\":{\"test\":{}}, \"mappings\": {\"doc\": {\"properties\": {\"test_field\":{\"type\":\"integer\"}}}}," + |
| 29 | + "\"settings\": {\"index.routing.allocation.include.node\": \"nowhere\"}}"; |
| 30 | + createTest2.setJsonEntity(body2); |
| 31 | + createTest2.addParameter("timeout", "100ms"); |
| 32 | + client().performRequest(createTest2); |
| 33 | + |
| 34 | + Request request = new Request("PUT", "/test1/doc/_bulk"); |
| 35 | + request.addParameter("refresh", "true"); |
| 36 | + StringBuilder bulk = new StringBuilder(); |
| 37 | + for (int i = 0; i < 20; i++) { |
| 38 | + bulk.append("{\"index\":{}}\n"); |
| 39 | + bulk.append("{\"test_field\":" + i + "}\n"); |
| 40 | + } |
| 41 | + request.setJsonEntity(bulk.toString()); |
| 42 | + client().performRequest(request); |
| 43 | + } |
| 44 | + |
| 45 | + public void testPartialResponseHandling() throws SQLException { |
| 46 | + try (Connection c = esJdbc(); Statement s = c.createStatement()) { |
| 47 | + SQLException exception = expectThrows(SQLException.class, () -> s.executeQuery("SELECT * FROM test ORDER BY test_field ASC")); |
| 48 | + assertThat(exception.getMessage(), containsString("Search rejected due to missing shards")); |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments