forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQL: Add test for handling of partial results
Makes sure that partial results are rejected in the SQL mode. Closes elastic#32284
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...-security/src/test/java/org/elasticsearch/xpack/qa/sql/nosecurity/JdbcShardFailureIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.qa.sql.nosecurity; | ||
|
||
import org.elasticsearch.xpack.qa.sql.jdbc.JdbcShardFailureTestCase; | ||
|
||
public class JdbcShardFailureIT extends JdbcShardFailureTestCase { | ||
} |
54 changes: 54 additions & 0 deletions
54
...ck/qa/sql/src/main/java/org/elasticsearch/xpack/qa/sql/jdbc/JdbcShardFailureTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.qa.sql.jdbc; | ||
|
||
import org.elasticsearch.client.Request; | ||
import org.junit.Before; | ||
|
||
import java.io.IOException; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
|
||
/** | ||
* Tests for handling of partial results in SQL layer | ||
*/ | ||
public class JdbcShardFailureTestCase extends JdbcIntegrationTestCase { | ||
@Before | ||
public void createTestIndex() throws IOException { | ||
Request createTest1 = new Request("PUT", "/test1"); | ||
String body1 = "{\"aliases\":{\"test\":{}}, \"mappings\": {\"doc\": {\"properties\": {\"test_field\":{\"type\":\"integer\"}}}}}"; | ||
createTest1.setJsonEntity(body1); | ||
client().performRequest(createTest1); | ||
|
||
Request createTest2 = new Request("PUT", "/test2"); | ||
String body2 = "{\"aliases\":{\"test\":{}}, \"mappings\": {\"doc\": {\"properties\": {\"test_field\":{\"type\":\"integer\"}}}}," + | ||
"\"settings\": {\"index.routing.allocation.include.node\": \"nowhere\"}}"; | ||
createTest2.setJsonEntity(body2); | ||
createTest2.addParameter("timeout", "100ms"); | ||
client().performRequest(createTest2); | ||
|
||
Request request = new Request("PUT", "/test1/doc/_bulk"); | ||
request.addParameter("refresh", "true"); | ||
StringBuilder bulk = new StringBuilder(); | ||
for (int i = 0; i < 20; i++) { | ||
bulk.append("{\"index\":{}}\n"); | ||
bulk.append("{\"test_field\":" + i + "}\n"); | ||
} | ||
request.setJsonEntity(bulk.toString()); | ||
client().performRequest(request); | ||
} | ||
|
||
|
||
public void testPartialResponseHandling() throws SQLException { | ||
try (Connection c = esJdbc(); Statement s = c.createStatement()) { | ||
SQLException exception = expectThrows(SQLException.class, () -> s.executeQuery("SELECT * FROM test ORDER BY test_field ASC")); | ||
assertThat(exception.getMessage(), containsString("Search rejected due to missing shards")); | ||
} | ||
} | ||
} |