1717 * under the License.
1818 */
1919
20- package org .apache .druid .tests .query ;
20+ package org .apache .druid .testing . embedded .query ;
2121
2222import com .google .common .collect .ImmutableList ;
23- import com .google .inject .Inject ;
2423import org .apache .calcite .avatica .AvaticaSqlException ;
25- import org .apache .druid .https .SSLClientConfig ;
2624import org .apache .druid .java .util .common .StringUtils ;
2725import org .apache .druid .java .util .common .logger .Logger ;
28- import org .apache .druid .testing .guice .DruidTestModuleFactory ;
29- import org .apache .druid .testing .tools .IntegrationTestingConfig ;
30- import org .apache .druid .testing .utils .DataLoaderHelper ;
31- import org .apache .druid .tests .TestNGGroup ;
32- import org .testng .Assert ;
33- import org .testng .annotations .BeforeMethod ;
34- import org .testng .annotations .Guice ;
35- import org .testng .annotations .Test ;
26+ import org .junit .jupiter .api .Assertions ;
27+ import org .junit .jupiter .api .Test ;
28+
3629
3730import java .sql .Connection ;
3831import java .sql .DatabaseMetaData ;
4740import java .util .Properties ;
4841import java .util .Set ;
4942
50- @ Test (groups = {TestNGGroup .QUERY , TestNGGroup .CENTRALIZED_DATASOURCE_SCHEMA })
51- @ Guice (moduleFactory = DruidTestModuleFactory .class )
52- public class ITJdbcQueryTest
43+ /**
44+ * JDBC query integration tests.
45+ * Note: we need to correspond queries with TLS support to fullfill the conversion
46+ */
47+ public class JdbcQueryTest extends QueryTestBase
5348{
54- private static final Logger LOG = new Logger (ITJdbcQueryTest .class );
55- private static final String WIKIPEDIA_DATA_SOURCE = "wikipedia_editstream" ;
49+ private static final Logger LOG = new Logger (JdbcQueryTest .class );
5650 private static final String CONNECTION_TEMPLATE = "jdbc:avatica:remote:url=%s/druid/v2/sql/avatica/" ;
5751 private static final String TLS_CONNECTION_TEMPLATE =
5852 "jdbc:avatica:remote:url=%s/druid/v2/sql/avatica/;truststore=%s;truststore_password=%s;keystore=%s;keystore_password=%s;key_password=%s" ;
5953
6054 private static final String QUERY_TEMPLATE =
61- "SELECT \" user\" , SUM(\" added\" ), COUNT(*)" +
62- "FROM \" wikipedia\" " +
63- "WHERE \" __time\" >= CURRENT_TIMESTAMP - INTERVAL '99' YEAR AND \" language\" = %s" +
64- "GROUP BY 1 ORDER BY 3 DESC LIMIT 10" ;
65- private static final String QUERY = StringUtils .format (QUERY_TEMPLATE , "'en'" );
66-
67- private static final String QUERY_PARAMETERIZED = StringUtils .format (QUERY_TEMPLATE , "?" );
55+ "SELECT \" item\" , SUM(\" value\" ), COUNT(*) "
56+ + "FROM \" %s\" "
57+ + "WHERE \" __time\" >= CURRENT_TIMESTAMP - INTERVAL '99' YEAR AND \" value\" < %s \n "
58+ + "GROUP BY 1 ORDER BY 3 DESC LIMIT 10" ;
6859
6960 private String [] connections ;
7061 private Properties connectionProperties ;
7162
72- @ Inject
73- private IntegrationTestingConfig config ;
74-
75- @ Inject
76- SSLClientConfig sslConfig ;
63+ private String dataSourceName ;
7764
78- @ Inject
79- private DataLoaderHelper dataLoaderHelper ;
80-
81- @ BeforeMethod
82- public void before ()
65+ @ Override
66+ protected void beforeAll ()
8367 {
8468 connectionProperties = new Properties ();
8569 connectionProperties .setProperty ("user" , "admin" );
8670 connectionProperties .setProperty ("password" , "priest" );
8771 connections = new String []{
88- StringUtils .format (CONNECTION_TEMPLATE , config .getRouterUrl ()),
89- StringUtils .format (CONNECTION_TEMPLATE , config .getBrokerUrl ()),
90- StringUtils .format (
91- TLS_CONNECTION_TEMPLATE ,
92- config .getRouterTLSUrl (),
93- sslConfig .getTrustStorePath (),
94- sslConfig .getTrustStorePasswordProvider ().getPassword (),
95- sslConfig .getKeyStorePath (),
96- sslConfig .getKeyStorePasswordProvider ().getPassword (),
97- sslConfig .getKeyManagerPasswordProvider ().getPassword ()
98- ),
99- StringUtils .format (
100- TLS_CONNECTION_TEMPLATE ,
101- config .getBrokerTLSUrl (),
102- sslConfig .getTrustStorePath (),
103- sslConfig .getTrustStorePasswordProvider ().getPassword (),
104- sslConfig .getKeyStorePath (),
105- sslConfig .getKeyStorePasswordProvider ().getPassword (),
106- sslConfig .getKeyManagerPasswordProvider ().getPassword ()
107- )
108- };
109- // ensure that wikipedia segments are loaded completely
110- dataLoaderHelper .waitUntilDatasourceIsReady (WIKIPEDIA_DATA_SOURCE );
111- dataLoaderHelper .waitUntilDatasourceIsReady ("wikipedia" );
112- dataLoaderHelper .waitUntilDatasourceIsReady ("twitterstream" );
72+ StringUtils .format (CONNECTION_TEMPLATE , getServerUrl (router )),
73+ StringUtils .format (CONNECTION_TEMPLATE , getServerUrl (broker )),
74+ };
75+
76+ dataSourceName = ingestBasicData ();
11377 }
11478
11579 @ Test
@@ -126,7 +90,7 @@ public void testJdbcMetadata()
12690 catalogs .add (catalog );
12791 }
12892 LOG .info ("catalogs %s" , catalogs );
129- Assert .assertEquals (catalogs , ImmutableList .of ("druid" ));
93+ Assertions .assertEquals (catalogs , ImmutableList .of ("druid" ));
13094
13195 Set <String > schemas = new HashSet <>();
13296 ResultSet schemasMetadata = metadata .getSchemas ("druid" , null );
@@ -136,7 +100,7 @@ public void testJdbcMetadata()
136100 }
137101 LOG .info ("'druid' catalog schemas %s" , schemas );
138102 // maybe more schemas than this, but at least should have these
139- Assert .assertTrue (schemas .containsAll (ImmutableList .of ("INFORMATION_SCHEMA" , "druid" , "lookup" , "sys" )));
103+ Assertions .assertTrue (schemas .containsAll (ImmutableList .of ("INFORMATION_SCHEMA" , "druid" , "lookup" , "sys" )));
140104
141105 Set <String > druidTables = new HashSet <>();
142106 ResultSet tablesMetadata = metadata .getTables ("druid" , "druid" , null , null );
@@ -145,83 +109,90 @@ public void testJdbcMetadata()
145109 druidTables .add (table );
146110 }
147111 LOG .info ("'druid' schema tables %s" , druidTables );
148- // maybe more tables than this, but at least should have these
149- Assert .assertTrue (
150- druidTables .containsAll (ImmutableList .of ("twitterstream" , "wikipedia" , WIKIPEDIA_DATA_SOURCE ))
112+ // There may be more tables than this, but at least should have @tableName
113+ Assertions .assertTrue (
114+ druidTables .containsAll (ImmutableList .of (dataSourceName ))
151115 );
152116
153117 Set <String > wikiColumns = new HashSet <>();
154- ResultSet columnsMetadata = metadata .getColumns ("druid" , "druid" , WIKIPEDIA_DATA_SOURCE , null );
118+ ResultSet columnsMetadata = metadata .getColumns ("druid" , "druid" , dataSourceName , null );
155119 while (columnsMetadata .next ()) {
156120 final String column = columnsMetadata .getString (4 );
157121 wikiColumns .add (column );
158122 }
159- LOG .info ("'%s' columns %s" , WIKIPEDIA_DATA_SOURCE , wikiColumns );
123+ LOG .info ("'%s' columns %s" , dataSourceName , wikiColumns );
160124 // a lot more columns than this, but at least should have these
161- Assert .assertTrue (
162- wikiColumns .containsAll (ImmutableList .of ("added " , "city " , "delta" , "language " ))
125+ Assertions .assertTrue (
126+ wikiColumns .containsAll (ImmutableList .of ("__time " , "item " , "value " ))
163127 );
164128 }
165129 catch (SQLException throwables ) {
166- Assert .fail (throwables .getMessage ());
130+ Assertions .fail (throwables .getMessage ());
167131 }
168132 }
169133 }
170134
171135 @ Test
172136 public void testJdbcStatementQuery ()
173137 {
138+ String query = StringUtils .format (QUERY_TEMPLATE , dataSourceName , "1000" );
174139 for (String url : connections ) {
175140 try (Connection connection = DriverManager .getConnection (url , connectionProperties )) {
176141 try (Statement statement = connection .createStatement ()) {
177- final ResultSet resultSet = statement .executeQuery (QUERY );
142+ final ResultSet resultSet = statement .executeQuery (query );
178143 int resultRowCount = 0 ;
179144 while (resultSet .next ()) {
180145 resultRowCount ++;
181146 LOG .info ("%s,%s,%s" , resultSet .getString (1 ), resultSet .getLong (2 ), resultSet .getLong (3 ));
182147 }
183- Assert .assertEquals (resultRowCount , 10 );
148+ Assertions .assertEquals (7 , resultRowCount );
184149 resultSet .close ();
185150 }
186151 }
187152 catch (SQLException throwables ) {
188- Assert .fail (throwables .getMessage ());
153+ Assertions .fail (throwables .getMessage ());
189154 }
190155 }
191156 }
192157
193158 @ Test
194159 public void testJdbcPrepareStatementQuery ()
195160 {
161+ String query = StringUtils .format (QUERY_TEMPLATE , dataSourceName , "?" );
196162 for (String url : connections ) {
197163 try (Connection connection = DriverManager .getConnection (url , connectionProperties )) {
198- try (PreparedStatement statement = connection .prepareStatement (QUERY_PARAMETERIZED )) {
199- statement .setString (1 , "en" );
164+ try (PreparedStatement statement = connection .prepareStatement (query )) {
165+ statement .setLong (1 , 1000 );
200166 final ResultSet resultSet = statement .executeQuery ();
201167 int resultRowCount = 0 ;
202168 while (resultSet .next ()) {
203169 resultRowCount ++;
204170 LOG .info ("%s,%s,%s" , resultSet .getString (1 ), resultSet .getLong (2 ), resultSet .getLong (3 ));
205171 }
206- Assert .assertEquals (resultRowCount , 10 );
172+ Assertions .assertEquals (7 , resultRowCount );
207173 resultSet .close ();
208174 }
209175 }
210176 catch (SQLException throwables ) {
211- Assert .fail (throwables .getMessage ());
177+ Assertions .fail (throwables .getMessage ());
212178 }
213179 }
214180 }
215181
216- @ Test ( expectedExceptions = AvaticaSqlException . class , expectedExceptionsMessageRegExp = ".* No value bound for parameter \\ (position \\ [1] \\ )" )
217- public void testJdbcPrepareStatementQueryMissingParameters () throws SQLException
182+ @ Test
183+ public void testJdbcPrepareStatementQueryMissingParameters ()
218184 {
185+ String query = StringUtils .format (QUERY_TEMPLATE , dataSourceName , "?" );
219186 for (String url : connections ) {
220187 try (Connection connection = DriverManager .getConnection (url , connectionProperties );
221- PreparedStatement statement = connection .prepareStatement (QUERY_PARAMETERIZED );
188+ PreparedStatement statement = connection .prepareStatement (query );
222189 ResultSet resultSet = statement .executeQuery ()) {
223190 // This won't actually run as we expect the exception to be thrown before it gets here
224- throw new IllegalStateException (resultSet .toString ());
191+ Assertions .fail (resultSet .toString ());
192+ }
193+ catch (SQLException e ) {
194+ Assertions .assertInstanceOf (AvaticaSqlException .class , e );
195+ Assertions .assertTrue (e .getMessage ().contains ("No value bound for parameter (position [1])" ));
225196 }
226197 }
227198 }
0 commit comments