Skip to content

Commit f86b894

Browse files
author
石源
committed
fix tests NLPchina#553
1 parent 6b1c3a7 commit f86b894

25 files changed

+551
-530
lines changed

src/test/java/org/nlpcn/es4sql/AggregationTest.java

Lines changed: 49 additions & 49 deletions
Large diffs are not rendered by default.

src/test/java/org/nlpcn/es4sql/CSVResultsExtractorTests.java

Lines changed: 58 additions & 59 deletions
Large diffs are not rendered by default.
Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
package org.nlpcn.es4sql;
22

3-
43
import org.elasticsearch.action.search.SearchRequestBuilder;
54
import org.elasticsearch.action.search.SearchResponse;
65
import org.elasticsearch.index.query.QueryBuilders;
76
import org.junit.After;
87
import org.junit.Before;
98
import org.junit.Test;
109
import org.nlpcn.es4sql.exception.SqlParseException;
11-
12-
import java.io.IOException;
1310
import java.sql.SQLFeatureNotSupportedException;
1411

1512
import static org.hamcrest.MatcherAssert.assertThat;
1613
import static org.hamcrest.core.IsEqual.equalTo;
17-
import static org.nlpcn.es4sql.TestsConstants.TEST_INDEX;
14+
import static org.nlpcn.es4sql.TestsConstants.*;
1815

1916
public class DeleteTest {
2017

2118
@Before
2219
public void loadTempData() throws Exception {
23-
MainTestSuite.loadBulk("src/test/resources/accounts_temp.json");
20+
MainTestSuite.loadBulk("src/test/resources/accounts_temp.json", TEST_INDEX_ACCOUNT_TEMP);
21+
MainTestSuite.getSearchDao().getClient().admin().indices().prepareRefresh(TEST_INDEX_ACCOUNT_TEMP).get();
2422
}
2523

2624
@After
@@ -31,31 +29,31 @@ public void deleteTempData() throws Exception {
3129

3230

3331
@Test
34-
public void deleteAllTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
35-
delete(String.format("DELETE FROM %s/account_temp", TEST_INDEX));
32+
public void deleteAllTest() throws SqlParseException, SQLFeatureNotSupportedException {
33+
delete(String.format("DELETE FROM %s/temp_account", TEST_INDEX_ACCOUNT_TEMP), TEST_INDEX_ACCOUNT_TEMP);
3634

3735
// Assert no results exist for this type.
38-
SearchRequestBuilder request = MainTestSuite.getClient().prepareSearch(TEST_INDEX);
39-
request.setTypes("account_temp");
36+
SearchRequestBuilder request = MainTestSuite.getClient().prepareSearch(TEST_INDEX_ACCOUNT_TEMP);
37+
request.setTypes("temp_account");
4038
SearchResponse response = request.setQuery(QueryBuilders.matchAllQuery()).get();
4139
assertThat(response.getHits().getTotalHits(), equalTo(0L));
4240
}
4341

4442

4543
@Test
46-
public void deleteWithConditionTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException {
47-
delete(String.format("DELETE FROM %s/phrase WHERE phrase = 'quick fox here' ", TEST_INDEX));
44+
public void deleteWithConditionTest() throws SqlParseException, SQLFeatureNotSupportedException {
45+
delete(String.format("DELETE FROM %s/phrase WHERE phrase = 'quick fox here' ", TEST_INDEX_PHRASE), TEST_INDEX_PHRASE);
4846
// Assert no results exist for this type.
49-
SearchRequestBuilder request = MainTestSuite.getClient().prepareSearch(TEST_INDEX);
47+
SearchRequestBuilder request = MainTestSuite.getClient().prepareSearch(TEST_INDEX_PHRASE);
5048
request.setTypes("phrase");
5149
SearchResponse response = request.setQuery(QueryBuilders.matchAllQuery()).get();
52-
assertThat(response.getHits().getTotalHits(), equalTo(3L));
50+
assertThat(response.getHits().getTotalHits(), equalTo(5L));
5351
}
5452

5553

56-
private void delete(String deleteStatement) throws SqlParseException, SQLFeatureNotSupportedException {
54+
private void delete(String deleteStatement, String index) throws SqlParseException, SQLFeatureNotSupportedException {
5755
SearchDao searchDao = MainTestSuite.getSearchDao();
5856
searchDao.explain(deleteStatement).explain().get();
59-
searchDao.getClient().admin().indices().prepareRefresh(TEST_INDEX).get();
57+
searchDao.getClient().admin().indices().prepareRefresh(index).get();
6058
}
6159
}

src/test/java/org/nlpcn/es4sql/ExplainTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,70 @@
44
import org.junit.Test;
55
import org.nlpcn.es4sql.exception.SqlParseException;
66
import org.nlpcn.es4sql.query.SqlElasticRequestBuilder;
7-
8-
97
import java.io.File;
108
import java.io.IOException;
119
import java.lang.reflect.InvocationTargetException;
1210
import java.nio.charset.StandardCharsets;
1311
import java.sql.SQLFeatureNotSupportedException;
1412

1513
import static org.hamcrest.MatcherAssert.assertThat;
16-
import static org.nlpcn.es4sql.TestsConstants.TEST_INDEX;
1714
import static org.hamcrest.Matchers.*;
15+
import static org.nlpcn.es4sql.TestsConstants.*;
1816

1917
public class ExplainTest {
2018

2119
@Test
2220
public void searchSanity() throws IOException, SqlParseException, NoSuchMethodException, IllegalAccessException, SQLFeatureNotSupportedException, InvocationTargetException {
2321
String expectedOutput = Files.toString(new File("src/test/resources/expectedOutput/search_explain.json"), StandardCharsets.UTF_8).replaceAll("\r","");
24-
String result = explain(String.format("SELECT * FROM %s WHERE firstname LIKE 'A%%' AND age > 20 GROUP BY gender order by _score", TEST_INDEX));
22+
String result = explain(String.format("SELECT * FROM %s WHERE firstname LIKE 'A%%' AND age > 20 GROUP BY gender order by _score", TEST_INDEX_ACCOUNT));
2523

2624
assertThat(result.replaceAll("\\s+",""), equalTo(expectedOutput.replaceAll("\\s+","")));
2725
}
2826

2927
@Test
3028
public void aggregationQuery() throws IOException, SqlParseException, NoSuchMethodException, IllegalAccessException, SQLFeatureNotSupportedException, InvocationTargetException {
3129
String expectedOutput = Files.toString(new File("src/test/resources/expectedOutput/aggregation_query_explain.json"), StandardCharsets.UTF_8).replaceAll("\r","");
32-
String result = explain(String.format("SELECT a, CASE WHEN gender='0' then 'aaa' else 'bbb'end a2345,count(c) FROM %s GROUP BY terms('field'='a'),a2345", TEST_INDEX));
30+
String result = explain(String.format("SELECT a, CASE WHEN gender='0' then 'aaa' else 'bbb'end a2345,count(c) FROM %s GROUP BY terms('field'='a'),a2345", TEST_INDEX_ACCOUNT));
3331

3432
assertThat(result.replaceAll("\\s+",""), equalTo(expectedOutput.replaceAll("\\s+","")));
3533
}
3634

3735
@Test
3836
public void explainScriptValue() throws IOException, SqlParseException, NoSuchMethodException, IllegalAccessException, SQLFeatureNotSupportedException, InvocationTargetException {
3937
String expectedOutput = Files.toString(new File("src/test/resources/expectedOutput/script_value.json"), StandardCharsets.UTF_8).replaceAll("\r","");
40-
String result = explain(String.format("SELECT case when gender is null then 'aaa' else gender end test , cust_code FROM %s", TEST_INDEX));
38+
String result = explain(String.format("SELECT case when gender is null then 'aaa' else gender end test , cust_code FROM %s", TEST_INDEX_ACCOUNT));
4139

4240
assertThat(result.replaceAll("\\s+",""), equalTo(expectedOutput.replaceAll("\\s+","")));
4341
}
4442

4543
@Test
4644
public void betweenScriptValue() throws IOException, SqlParseException, NoSuchMethodException, IllegalAccessException, SQLFeatureNotSupportedException, InvocationTargetException {
4745
String expectedOutput = Files.toString(new File("src/test/resources/expectedOutput/between_query.json"), StandardCharsets.UTF_8).replaceAll("\r","");
48-
String result = explain(String.format("SELECT case when value between 100 and 200 then 'aaa' else value end test , cust_code FROM %s", TEST_INDEX));
46+
String result = explain(String.format("SELECT case when value between 100 and 200 then 'aaa' else value end test , cust_code FROM %s", TEST_INDEX_ACCOUNT));
4947

5048
assertThat(result.replaceAll("\\s+",""), equalTo(expectedOutput.replaceAll("\\s+","")));
5149
}
5250

5351
@Test
5452
public void searchSanityFilter() throws IOException, SqlParseException, NoSuchMethodException, IllegalAccessException, SQLFeatureNotSupportedException, InvocationTargetException {
5553
String expectedOutput = Files.toString(new File("src/test/resources/expectedOutput/search_explain_filter.json"), StandardCharsets.UTF_8).replaceAll("\r","");
56-
String result = explain(String.format("SELECT * FROM %s WHERE firstname LIKE 'A%%' AND age > 20 GROUP BY gender", TEST_INDEX));
54+
String result = explain(String.format("SELECT * FROM %s WHERE firstname LIKE 'A%%' AND age > 20 GROUP BY gender", TEST_INDEX_ACCOUNT));
5755

5856
assertThat(result.replaceAll("\\s+",""), equalTo(expectedOutput.replaceAll("\\s+","")));
5957
}
6058

6159
@Test
6260
public void deleteSanity() throws IOException, SqlParseException, NoSuchMethodException, IllegalAccessException, SQLFeatureNotSupportedException, InvocationTargetException {
6361
String expectedOutput = Files.toString(new File("src/test/resources/expectedOutput/delete_explain.json"), StandardCharsets.UTF_8).replaceAll("\r","");;
64-
String result = explain(String.format("DELETE FROM %s WHERE firstname LIKE 'A%%' AND age > 20", TEST_INDEX));
62+
String result = explain(String.format("DELETE FROM %s WHERE firstname LIKE 'A%%' AND age > 20", TEST_INDEX_ACCOUNT));
6563

6664
assertThat(result.replaceAll("\\s+",""), equalTo(expectedOutput.replaceAll("\\s+","")));
6765
}
6866

6967
@Test
7068
public void spatialFilterExplainTest() throws IOException, SqlParseException, NoSuchMethodException, IllegalAccessException, SQLFeatureNotSupportedException, InvocationTargetException {
7169
String expectedOutput = Files.toString(new File("src/test/resources/expectedOutput/search_spatial_explain.json"), StandardCharsets.UTF_8).replaceAll("\r","");;
72-
String result = explain(String.format("SELECT * FROM %s WHERE GEO_INTERSECTS(place,'POLYGON ((102 2, 103 2, 103 3, 102 3, 102 2))')", TEST_INDEX));
70+
String result = explain(String.format("SELECT * FROM %s WHERE GEO_INTERSECTS(place,'POLYGON ((102 2, 103 2, 103 3, 102 3, 102 2))')", TEST_INDEX_LOCATION));
7371
assertThat(result.replaceAll("\\s+",""), equalTo(expectedOutput.replaceAll("\\s+","")));
7472
}
7573

src/test/java/org/nlpcn/es4sql/JDBCTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public class JDBCTests {
1919
@Test
2020
public void testJDBC() throws Exception {
2121
Properties properties = new Properties();
22-
properties.put("url", "jdbc:elasticsearch://127.0.0.1:9300/" + TestsConstants.TEST_INDEX);
22+
properties.put("url", "jdbc:elasticsearch://127.0.0.1:9300/" + TestsConstants.TEST_INDEX_ACCOUNT);
2323
DruidDataSource dds = (DruidDataSource) ElasticSearchDruidDataSourceFactory.createDataSource(properties);
2424
Connection connection = dds.getConnection();
25-
PreparedStatement ps = connection.prepareStatement("SELECT gender,lastname,age from " + TestsConstants.TEST_INDEX + " where lastname='Heath'");
25+
PreparedStatement ps = connection.prepareStatement("SELECT gender,lastname,age from " + TestsConstants.TEST_INDEX_ACCOUNT + " where lastname='Heath'");
2626
ResultSet resultSet = ps.executeQuery();
2727
List<String> result = new ArrayList<String>();
2828
while (resultSet.next()) {

0 commit comments

Comments
 (0)