19
19
package org .apache .flink .table .client ;
20
20
21
21
import org .apache .flink .configuration .Configuration ;
22
- import org .apache .flink .core .testutils .CommonTestUtils ;
23
- import org .apache .flink .table .client .cli .TerminalUtils ;
24
22
import org .apache .flink .table .gateway .rest .util .SqlGatewayRestEndpointExtension ;
25
23
import org .apache .flink .table .gateway .service .utils .SqlGatewayServiceExtension ;
26
24
import org .apache .flink .util .FileUtils ;
27
25
import org .apache .flink .util .Preconditions ;
28
26
29
- import org .jline .terminal .Size ;
30
- import org .jline .terminal .Terminal ;
31
- import org .junit .jupiter .api .AfterEach ;
32
- import org .junit .jupiter .api .BeforeEach ;
33
27
import org .junit .jupiter .api .Order ;
34
28
import org .junit .jupiter .api .Test ;
35
29
import org .junit .jupiter .api .extension .RegisterExtension ;
36
- import org .junit .jupiter .api .io .TempDir ;
37
30
38
- import java .io .ByteArrayInputStream ;
39
- import java .io .ByteArrayOutputStream ;
40
31
import java .io .File ;
41
- import java .io .IOException ;
42
- import java .io .OutputStream ;
43
32
import java .net .URL ;
44
- import java .nio .charset .StandardCharsets ;
45
33
import java .nio .file .Files ;
46
- import java .nio .file .Path ;
47
34
import java .nio .file .Paths ;
48
- import java .nio .file .StandardOpenOption ;
49
35
import java .util .Arrays ;
50
36
import java .util .Collections ;
51
- import java .util .HashMap ;
52
37
import java .util .List ;
53
- import java .util .Map ;
54
38
55
- import static org .apache .flink .configuration .ConfigConstants .ENV_FLINK_CONF_DIR ;
56
39
import static org .apache .flink .configuration .DeploymentOptions .TARGET ;
57
40
import static org .apache .flink .core .testutils .CommonTestUtils .assertThrows ;
58
41
import static org .assertj .core .api .Assertions .assertThat ;
59
42
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
60
43
61
44
/** Tests for {@link SqlClient}. */
62
- class SqlClientTest {
63
-
64
- @ TempDir private Path tempFolder ;
45
+ class SqlClientTest extends SqlClientTestBase {
65
46
66
47
@ RegisterExtension
67
48
@ Order (1 )
@@ -78,34 +59,6 @@ class SqlClientTest {
78
59
private static final SqlGatewayRestEndpointExtension SQL_GATEWAY_REST_ENDPOINT_EXTENSION =
79
60
new SqlGatewayRestEndpointExtension (SQL_GATEWAY_SERVICE_EXTENSION ::getService );
80
61
81
- private Map <String , String > originalEnv ;
82
-
83
- private String historyPath ;
84
-
85
- @ BeforeEach
86
- void before () throws IOException {
87
- originalEnv = System .getenv ();
88
-
89
- // prepare conf dir
90
- File confFolder = Files .createTempDirectory (tempFolder , "conf" ).toFile ();
91
- File confYaml = new File (confFolder , "config.yaml" );
92
- if (!confYaml .createNewFile ()) {
93
- throw new IOException ("Can't create testing config.yaml file." );
94
- }
95
-
96
- // adjust the test environment for the purposes of this test
97
- Map <String , String > map = new HashMap <>(System .getenv ());
98
- map .put (ENV_FLINK_CONF_DIR , confFolder .getAbsolutePath ());
99
- CommonTestUtils .setEnv (map );
100
-
101
- historyPath = Files .createTempFile (tempFolder , "history" , "" ).toFile ().getPath ();
102
- }
103
-
104
- @ AfterEach
105
- void after () {
106
- CommonTestUtils .setEnv (originalEnv );
107
- }
108
-
109
62
@ Test
110
63
void testEmbeddedWithOptions () throws Exception {
111
64
String [] args = new String [] {"embedded" , "-hist" , historyPath };
@@ -332,42 +285,4 @@ private void runTestCliHelp(String[] args, String expected) throws Exception {
332
285
.toURI ())));
333
286
assertThat (runSqlClient (args )).isEqualTo (actual );
334
287
}
335
-
336
- private String runSqlClient (String [] args ) throws Exception {
337
- return runSqlClient (args , "QUIT;\n " , false );
338
- }
339
-
340
- private String runSqlClient (String [] args , String statements , boolean printInput )
341
- throws Exception {
342
- try (OutputStream out = new ByteArrayOutputStream ();
343
- Terminal terminal =
344
- TerminalUtils .createDumbTerminal (
345
- new ByteArrayInputStream (
346
- statements .getBytes (StandardCharsets .UTF_8 )),
347
- out )) {
348
- if (printInput ) {
349
- // The default terminal has an empty size. Here increase the terminal to allow
350
- // the line reader print the input string.
351
- terminal .setSize (new Size (160 , 80 ));
352
- }
353
- SqlClient .startClient (args , () -> terminal );
354
- return out .toString ().replace ("\r \n " , System .lineSeparator ());
355
- }
356
- }
357
-
358
- private String createSqlFile (List <String > statements , String name ) throws IOException {
359
- // create sql file
360
- File sqlFileFolder = Files .createTempDirectory (tempFolder , "sql-file" ).toFile ();
361
- File sqlFile = new File (sqlFileFolder , name );
362
- if (!sqlFile .createNewFile ()) {
363
- throw new IOException (String .format ("Can't create testing %s." , name ));
364
- }
365
- String sqlFilePath = sqlFile .getPath ();
366
- Files .write (
367
- Paths .get (sqlFilePath ),
368
- statements ,
369
- StandardCharsets .UTF_8 ,
370
- StandardOpenOption .APPEND );
371
- return sqlFilePath ;
372
- }
373
288
}
0 commit comments