28
28
import org .apache .flink .runtime .entrypoint .parser .CommandLineParser ;
29
29
import org .apache .flink .runtime .jobgraph .SavepointRestoreSettings ;
30
30
import org .apache .flink .util .ExceptionUtils ;
31
- import org .apache .flink .util .TestLogger ;
32
31
33
- import org .junit .Before ;
34
- import org .junit .Rule ;
35
- import org .junit .Test ;
36
- import org .junit .rules .TemporaryFolder ;
32
+ import org .junit .jupiter .api .BeforeEach ;
33
+ import org .junit .jupiter .api .Test ;
34
+ import org .junit .jupiter .api .io .TempDir ;
37
35
38
36
import java .io .File ;
39
37
import java .io .IOException ;
38
+ import java .nio .file .Path ;
40
39
import java .util .Optional ;
41
40
import java .util .Properties ;
42
41
43
- import static org .hamcrest .Matchers .arrayContaining ;
44
- import static org .hamcrest .Matchers .containsString ;
45
- import static org .hamcrest .Matchers .equalTo ;
46
- import static org .hamcrest .Matchers .hasEntry ;
47
- import static org .hamcrest .Matchers .is ;
48
- import static org .hamcrest .core .IsNull .nullValue ;
49
- import static org .junit .Assert .assertThat ;
50
- import static org .junit .Assert .assertTrue ;
51
- import static org .junit .Assert .fail ;
42
+ import static org .assertj .core .api .Assertions .assertThat ;
43
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
44
+ import static org .assertj .core .api .Fail .fail ;
52
45
53
46
/** Tests for the {@link StandaloneApplicationClusterConfigurationParserFactory}. */
54
- public class StandaloneApplicationClusterConfigurationParserFactoryTest extends TestLogger {
47
+ class StandaloneApplicationClusterConfigurationParserFactoryTest {
55
48
56
- @ Rule public TemporaryFolder tempFolder = new TemporaryFolder ();
57
49
private File confFile ;
58
50
private String confDirPath ;
59
51
60
- @ Before
61
- public void createEmptyFlinkConfiguration () throws IOException {
62
- File confDir = tempFolder .getRoot ();
63
- confDirPath = confDir .getAbsolutePath ();
64
- confFile = new File (confDir , GlobalConfiguration .FLINK_CONF_FILENAME );
52
+ @ BeforeEach
53
+ void createEmptyFlinkConfiguration (@ TempDir Path tempFolder ) throws IOException {
54
+ confDirPath = tempFolder .toFile ().getAbsolutePath ();
55
+ confFile = new File (tempFolder .toFile (), GlobalConfiguration .FLINK_CONF_FILENAME );
65
56
confFile .createNewFile ();
66
57
}
67
58
@@ -72,8 +63,7 @@ public void createEmptyFlinkConfiguration() throws IOException {
72
63
private static final String JOB_CLASS_NAME = "foobar" ;
73
64
74
65
@ Test
75
- public void testEntrypointClusterConfigurationToConfigurationParsing ()
76
- throws FlinkParseException {
66
+ void testEntrypointClusterConfigurationToConfigurationParsing () throws FlinkParseException {
77
67
final JobID jobID = JobID .generate ();
78
68
final SavepointRestoreSettings savepointRestoreSettings =
79
69
SavepointRestoreSettings .forPath ("/test/savepoint/path" , true );
@@ -101,25 +91,24 @@ public void testEntrypointClusterConfigurationToConfigurationParsing()
101
91
102
92
final StandaloneApplicationClusterConfiguration clusterConfiguration =
103
93
commandLineParser .parse (args );
104
- assertThat (clusterConfiguration .getJobClassName (), is ( equalTo ( JOB_CLASS_NAME )) );
105
- assertThat (clusterConfiguration .getArgs (), arrayContaining (arg1 , arg2 ) );
94
+ assertThat (clusterConfiguration .getJobClassName ()). isEqualTo ( JOB_CLASS_NAME );
95
+ assertThat (clusterConfiguration .getArgs ()). contains (arg1 , arg2 );
106
96
107
97
final Configuration configuration =
108
98
StandaloneApplicationClusterEntryPoint .loadConfigurationFromClusterConfig (
109
99
clusterConfiguration );
110
100
111
101
final String strJobId = configuration .get (PipelineOptionsInternal .PIPELINE_FIXED_JOB_ID );
112
- assertThat (JobID .fromHexString (strJobId ), is (equalTo (jobID )));
113
- assertThat (
114
- SavepointRestoreSettings .fromConfiguration (configuration ),
115
- is (equalTo (savepointRestoreSettings )));
102
+ assertThat (JobID .fromHexString (strJobId )).isEqualTo (jobID );
103
+ assertThat (SavepointRestoreSettings .fromConfiguration (configuration ))
104
+ .isEqualTo (savepointRestoreSettings );
116
105
117
- assertThat (configuration .get (RestOptions .PORT ), is ( equalTo ( restPort )) );
118
- assertThat (configuration .get (DeploymentOptions .TARGET ), is ( equalTo ( value )) );
106
+ assertThat (configuration .get (RestOptions .PORT )). isEqualTo ( restPort );
107
+ assertThat (configuration .get (DeploymentOptions .TARGET )). isEqualTo ( value );
119
108
}
120
109
121
110
@ Test
122
- public void testEntrypointClusterConfigWOSavepointSettingsToConfigurationParsing ()
111
+ void testEntrypointClusterConfigWOSavepointSettingsToConfigurationParsing ()
123
112
throws FlinkParseException {
124
113
final JobID jobID = JobID .generate ();
125
114
final String [] args = {"-c" , confDirPath , "--job-id" , jobID .toHexString ()};
@@ -131,14 +120,13 @@ public void testEntrypointClusterConfigWOSavepointSettingsToConfigurationParsing
131
120
clusterConfiguration );
132
121
133
122
final String strJobId = configuration .get (PipelineOptionsInternal .PIPELINE_FIXED_JOB_ID );
134
- assertThat (JobID .fromHexString (strJobId ), is (equalTo (jobID )));
135
- assertThat (
136
- SavepointRestoreSettings .fromConfiguration (configuration ),
137
- is (equalTo (SavepointRestoreSettings .none ())));
123
+ assertThat (JobID .fromHexString (strJobId )).isEqualTo (jobID );
124
+ assertThat (SavepointRestoreSettings .fromConfiguration (configuration ))
125
+ .isEqualTo (SavepointRestoreSettings .none ());
138
126
}
139
127
140
128
@ Test
141
- public void testEntrypointClusterConfigurationParsing () throws FlinkParseException {
129
+ void testEntrypointClusterConfigurationParsing () throws FlinkParseException {
142
130
final String key = "key" ;
143
131
final String value = "value" ;
144
132
final int restPort = 1234 ;
@@ -159,50 +147,48 @@ public void testEntrypointClusterConfigurationParsing() throws FlinkParseExcepti
159
147
final StandaloneApplicationClusterConfiguration clusterConfiguration =
160
148
commandLineParser .parse (args );
161
149
162
- assertThat (clusterConfiguration .getConfigDir (), is ( equalTo ( confDirPath )) );
163
- assertThat (clusterConfiguration .getJobClassName (), is ( equalTo ( JOB_CLASS_NAME )) );
164
- assertThat (clusterConfiguration .getRestPort (), is ( equalTo ( restPort )) );
150
+ assertThat (clusterConfiguration .getConfigDir ()). isEqualTo ( confDirPath );
151
+ assertThat (clusterConfiguration .getJobClassName ()). isEqualTo ( JOB_CLASS_NAME );
152
+ assertThat (clusterConfiguration .getRestPort ()). isEqualTo ( restPort );
165
153
final Properties dynamicProperties = clusterConfiguration .getDynamicProperties ();
166
154
167
- assertThat (dynamicProperties , hasEntry (key , value ) );
155
+ assertThat (dynamicProperties ). containsEntry (key , value );
168
156
169
- assertThat (clusterConfiguration .getArgs (), arrayContaining (arg1 , arg2 ) );
157
+ assertThat (clusterConfiguration .getArgs ()). contains (arg1 , arg2 );
170
158
171
- assertThat (
172
- clusterConfiguration .getSavepointRestoreSettings (),
173
- is (equalTo (SavepointRestoreSettings .none ())));
159
+ assertThat (clusterConfiguration .getSavepointRestoreSettings ())
160
+ .isEqualTo (SavepointRestoreSettings .none ());
174
161
175
- assertThat (clusterConfiguration .getJobId (), is ( nullValue ()) );
162
+ assertThat (clusterConfiguration .getJobId ()). isNull ( );
176
163
}
177
164
178
165
@ Test
179
- public void testOnlyRequiredArguments () throws FlinkParseException {
166
+ void testOnlyRequiredArguments () throws FlinkParseException {
180
167
final String [] args = {"--configDir" , confDirPath };
181
168
182
169
final StandaloneApplicationClusterConfiguration clusterConfiguration =
183
170
commandLineParser .parse (args );
184
171
185
- assertThat (clusterConfiguration .getConfigDir (), is (equalTo (confDirPath )));
186
- assertThat (clusterConfiguration .getDynamicProperties (), is (equalTo (new Properties ())));
187
- assertThat (clusterConfiguration .getArgs (), is (new String [0 ]));
188
- assertThat (clusterConfiguration .getRestPort (), is (equalTo (-1 )));
189
- assertThat (clusterConfiguration .getHostname (), is (nullValue ()));
190
- assertThat (
191
- clusterConfiguration .getSavepointRestoreSettings (),
192
- is (equalTo (SavepointRestoreSettings .none ())));
193
- assertThat (clusterConfiguration .getJobId (), is (nullValue ()));
194
- assertThat (clusterConfiguration .getJobClassName (), is (nullValue ()));
172
+ assertThat (clusterConfiguration .getConfigDir ()).isEqualTo (confDirPath );
173
+ assertThat (clusterConfiguration .getDynamicProperties ()).isEqualTo (new Properties ());
174
+ assertThat (clusterConfiguration .getArgs ()).isEqualTo (new String [0 ]);
175
+ assertThat (clusterConfiguration .getRestPort ()).isEqualTo (-1 );
176
+ assertThat (clusterConfiguration .getHostname ()).isNull ();
177
+ assertThat (clusterConfiguration .getSavepointRestoreSettings ())
178
+ .isEqualTo (SavepointRestoreSettings .none ());
179
+ assertThat (clusterConfiguration .getJobId ()).isNull ();
180
+ assertThat (clusterConfiguration .getJobClassName ()).isNull ();
195
181
}
196
182
197
- @ Test ( expected = FlinkParseException . class )
198
- public void testMissingRequiredArgument () throws FlinkParseException {
183
+ @ Test
184
+ void testMissingRequiredArgument () {
199
185
final String [] args = {};
200
-
201
- commandLineParser . parse ( args );
186
+ assertThatThrownBy (() -> commandLineParser . parse ( args ))
187
+ . isInstanceOf ( FlinkParseException . class );
202
188
}
203
189
204
190
@ Test
205
- public void testSavepointRestoreSettingsParsing () throws FlinkParseException {
191
+ void testSavepointRestoreSettingsParsing () throws FlinkParseException {
206
192
final String restorePath = "foobar" ;
207
193
final String [] args = {"-c" , confDirPath , "-j" , JOB_CLASS_NAME , "-s" , restorePath , "-n" };
208
194
final StandaloneApplicationClusterConfiguration standaloneApplicationClusterConfiguration =
@@ -211,13 +197,13 @@ public void testSavepointRestoreSettingsParsing() throws FlinkParseException {
211
197
final SavepointRestoreSettings savepointRestoreSettings =
212
198
standaloneApplicationClusterConfiguration .getSavepointRestoreSettings ();
213
199
214
- assertThat (savepointRestoreSettings .restoreSavepoint (), is ( true ) );
215
- assertThat (savepointRestoreSettings .getRestorePath (), is ( equalTo ( restorePath )) );
216
- assertThat (savepointRestoreSettings .allowNonRestoredState (), is ( true ) );
200
+ assertThat (savepointRestoreSettings .restoreSavepoint ()). isTrue ( );
201
+ assertThat (savepointRestoreSettings .getRestorePath ()). isEqualTo ( restorePath );
202
+ assertThat (savepointRestoreSettings .allowNonRestoredState ()). isTrue ( );
217
203
}
218
204
219
205
@ Test
220
- public void testSetJobIdManually () throws FlinkParseException {
206
+ void testSetJobIdManually () throws FlinkParseException {
221
207
final JobID jobId = new JobID ();
222
208
final String [] args = {
223
209
"--configDir" , confDirPath , "--job-classname" , "foobar" , "--job-id" , jobId .toString ()
@@ -226,11 +212,11 @@ public void testSetJobIdManually() throws FlinkParseException {
226
212
final StandaloneApplicationClusterConfiguration standaloneApplicationClusterConfiguration =
227
213
commandLineParser .parse (args );
228
214
229
- assertThat (standaloneApplicationClusterConfiguration .getJobId (), is ( equalTo ( jobId )) );
215
+ assertThat (standaloneApplicationClusterConfiguration .getJobId ()). isEqualTo ( jobId );
230
216
}
231
217
232
218
@ Test
233
- public void testInvalidJobIdThrows () {
219
+ void testInvalidJobIdThrows () {
234
220
final String invalidJobId = "0xINVALID" ;
235
221
final String [] args = {
236
222
"--configDir" , confDirPath , "--job-classname" , "foobar" , "--job-id" , invalidJobId
@@ -242,13 +228,13 @@ public void testInvalidJobIdThrows() {
242
228
} catch (FlinkParseException e ) {
243
229
Optional <IllegalArgumentException > cause =
244
230
ExceptionUtils .findThrowable (e , IllegalArgumentException .class );
245
- assertTrue (cause .isPresent () );
246
- assertThat (cause .get ().getMessage (), containsString (invalidJobId ) );
231
+ assertThat (cause ) .isPresent ();
232
+ assertThat (cause .get ().getMessage ()). containsSequence (invalidJobId );
247
233
}
248
234
}
249
235
250
236
@ Test
251
- public void testShortOptions () throws FlinkParseException {
237
+ void testShortOptions () throws FlinkParseException {
252
238
final String jobClassName = "foobar" ;
253
239
final JobID jobId = new JobID ();
254
240
final String savepointRestorePath = "s3://foo/bar" ;
@@ -264,25 +250,25 @@ public void testShortOptions() throws FlinkParseException {
264
250
final StandaloneApplicationClusterConfiguration clusterConfiguration =
265
251
commandLineParser .parse (args );
266
252
267
- assertThat (clusterConfiguration .getConfigDir (), is ( equalTo ( confDirPath )) );
268
- assertThat (clusterConfiguration .getJobClassName (), is ( equalTo ( jobClassName )) );
269
- assertThat (clusterConfiguration .getJobId (), is ( equalTo ( jobId )) );
253
+ assertThat (clusterConfiguration .getConfigDir ()). isEqualTo ( confDirPath );
254
+ assertThat (clusterConfiguration .getJobClassName ()). isEqualTo ( jobClassName );
255
+ assertThat (clusterConfiguration .getJobId ()). isEqualTo ( jobId );
270
256
271
257
final SavepointRestoreSettings savepointRestoreSettings =
272
258
clusterConfiguration .getSavepointRestoreSettings ();
273
- assertThat (savepointRestoreSettings .restoreSavepoint (), is ( true ) );
274
- assertThat (savepointRestoreSettings .getRestorePath (), is ( equalTo ( savepointRestorePath )) );
275
- assertThat (savepointRestoreSettings .allowNonRestoredState (), is ( true ) );
259
+ assertThat (savepointRestoreSettings .restoreSavepoint ()). isTrue ( );
260
+ assertThat (savepointRestoreSettings .getRestorePath ()). isEqualTo ( savepointRestorePath );
261
+ assertThat (savepointRestoreSettings .allowNonRestoredState ()). isTrue ( );
276
262
}
277
263
278
264
@ Test
279
- public void testHostOption () throws FlinkParseException {
265
+ void testHostOption () throws FlinkParseException {
280
266
final String hostName = "user-specified-hostname" ;
281
267
final String [] args = {
282
268
"--configDir" , confDirPath , "--job-classname" , "foobar" , "--host" , hostName
283
269
};
284
270
final StandaloneApplicationClusterConfiguration applicationClusterConfiguration =
285
271
commandLineParser .parse (args );
286
- assertThat (applicationClusterConfiguration .getHostname (), is (hostName ) );
272
+ assertThat (applicationClusterConfiguration .getHostname ()). isEqualTo (hostName );
287
273
}
288
274
}
0 commit comments