11package io .questdb .kafka ;
22
3+ import okhttp3 .ConnectionSpec ;
34import okhttp3 .OkHttpClient ;
45import okhttp3 .Request ;
56import okhttp3 .Response ;
67import org .testcontainers .containers .GenericContainer ;
78
89import java .io .IOException ;
910import java .net .URLEncoder ;
11+ import java .util .Collections ;
1012import java .util .concurrent .TimeUnit ;
1113
1214import static org .awaitility .Awaitility .await ;
1315import static org .junit .jupiter .api .Assertions .assertEquals ;
1416import static org .junit .jupiter .api .Assertions .fail ;
1517
1618public final class QuestDBUtils {
19+ public enum Endpoint {
20+ EXPORT ("exp" ),
21+ EXEC ("exec" );
22+
23+ private String endpoint ;
24+
25+ Endpoint (String endpoint ) {
26+ this .endpoint = endpoint ;
27+ }
28+
29+
30+ String getEndpoint () {
31+ return endpoint ;
32+ }
33+ }
34+
35+
1736 public static final int QUESTDB_ILP_PORT = 9009 ;
1837 public static final int QUESTDB_HTTP_PORT = 9000 ;
1938
2039 private static final int QUERY_WAITING_TIME_SECONDS = 30 ;
21- private static final OkHttpClient CLIENT = new OkHttpClient ();
40+ private static final OkHttpClient CLIENT = new OkHttpClient (new OkHttpClient . Builder (). connectionSpecs ( Collections . singletonList ( ConnectionSpec . CLEARTEXT )) );
2241
2342 private QuestDBUtils () {
2443
@@ -28,8 +47,12 @@ public static void assertSqlEventually(GenericContainer<?> questdbContainer, Str
2847 await ().atMost (QUERY_WAITING_TIME_SECONDS , TimeUnit .SECONDS ).untilAsserted (() -> assertSql (questdbContainer , expectedResult , query ));
2948 }
3049
31- private static void assertSql (GenericContainer <?> questdbContainer , String expectedResult , String query ) throws IOException {
32- try (Response response = executeQuery (questdbContainer , query )) {
50+ public static void assertSql (GenericContainer <?> questdbContainer , String expectedResult , String query ) {
51+ assertSql (questdbContainer , expectedResult , query , Endpoint .EXPORT );
52+ }
53+
54+ public static void assertSql (GenericContainer <?> questdbContainer , String expectedResult , String query , Endpoint endpoint ) {
55+ try (Response response = executeQuery (questdbContainer , query , endpoint )) {
3356 if (response .code () != 200 ) {
3457 fail ("Query failed, returned code " + response .code ());
3558 }
@@ -39,14 +62,16 @@ private static void assertSql(GenericContainer<?> questdbContainer, String expec
3962 assertEquals (expectedResult , bodyString );
4063 }
4164 }
65+ } catch (IOException e ) {
66+ fail ("Query failed" , e );
4267 }
4368 }
4469
45- private static Response executeQuery (GenericContainer <?> questContainer , String query ) throws IOException {
70+ private static Response executeQuery (GenericContainer <?> questContainer , String query , Endpoint endpoint ) throws IOException {
4671 String encodedQuery = URLEncoder .encode (query , "UTF-8" );
4772 String baseUrl = "http://" + questContainer .getHost () + ":" + questContainer .getMappedPort (QUESTDB_HTTP_PORT );
4873 Request request = new Request .Builder ()
49- .url (baseUrl + "/exp ?query=" + encodedQuery )
74+ .url (baseUrl + "/" + endpoint . endpoint + " ?query=" + encodedQuery )
5075 .build ();
5176 return CLIENT .newCall (request ).execute ();
5277 }
0 commit comments