38
38
import org .apache .hadoop .yarn .server .timelineservice .documentstore .collection .document .TimelineDocument ;
39
39
import org .apache .hadoop .yarn .server .timelineservice .documentstore .collection .document .entity .TimelineEntityDocument ;
40
40
41
- import org .junit .After ;
42
- import org .junit .Assert ;
43
- import org .junit .Before ;
44
- import org .junit .Test ;
45
- import org .junit .runner .RunWith ;
41
+ import org .junit .jupiter .api .AfterEach ;
42
+ import org .junit .jupiter .api .BeforeEach ;
43
+ import org .junit .jupiter .api .Test ;
44
+ import org .junit .jupiter .api .extension .ExtendWith ;
46
45
47
46
import org .mockito .ArgumentMatchers ;
48
47
import org .mockito .MockedStatic ;
49
48
50
- import org .powermock .core .classloader .annotations .PrepareForTest ;
51
- import org .powermock .modules .junit4 .PowerMockRunner ;
49
+ import org .mockito .junit .jupiter .MockitoExtension ;
52
50
53
51
import java .io .IOException ;
54
52
import java .util .EnumSet ;
55
53
import java .util .List ;
56
54
import java .util .Set ;
57
55
56
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
57
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
58
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
59
+ import static org .junit .jupiter .api .Assertions .fail ;
58
60
import static org .mockito .Mockito .mockStatic ;
59
61
import static org .mockito .Mockito .when ;
60
62
61
63
/**
62
64
* Test case for {@link DocumentStoreTimelineReaderImpl}.
63
65
*/
64
- @ RunWith (PowerMockRunner .class )
65
- @ PrepareForTest (DocumentStoreFactory .class )
66
+ @ ExtendWith (MockitoExtension .class )
66
67
public class TestDocumentStoreTimelineReaderImpl {
67
68
68
69
private final DocumentStoreReader <TimelineDocument > documentStoreReader = new
@@ -84,7 +85,7 @@ public TestDocumentStoreTimelineReaderImpl() throws IOException {
84
85
85
86
private MockedStatic <DocumentStoreFactory > documentStoreFactoryMockedStatic ;
86
87
87
- @ Before
88
+ @ BeforeEach
88
89
public void setUp () throws YarnException {
89
90
conf .set (DocumentStoreUtils .TIMELINE_SERVICE_DOCUMENTSTORE_DATABASE_NAME ,
90
91
"TestDB" );
@@ -98,14 +99,16 @@ public void setUp() throws YarnException {
98
99
.thenReturn (documentStoreReader );
99
100
}
100
101
101
- @ After
102
+ @ AfterEach
102
103
public void close () {
103
104
documentStoreFactoryMockedStatic .close ();
104
105
}
105
106
106
- @ Test ( expected = YarnException . class )
107
+ @ Test
107
108
public void testFailOnNoCosmosDBConfigs () throws Exception {
108
- DocumentStoreUtils .validateCosmosDBConf (new Configuration ());
109
+ assertThrows (YarnException .class , () -> {
110
+ DocumentStoreUtils .validateCosmosDBConf (new Configuration ());
111
+ });
109
112
}
110
113
111
114
@ Test
@@ -120,12 +123,12 @@ public void testGetEntity() throws Exception {
120
123
TimelineEntity timelineEntity = timelineReader .getEntity (context ,
121
124
dataToRetrieve );
122
125
123
- Assert . assertEquals (appTimelineEntity .getCreatedTime (), timelineEntity
126
+ assertEquals (appTimelineEntity .getCreatedTime (), timelineEntity
124
127
.getCreatedTime ().longValue ());
125
- Assert . assertEquals (0 , timelineEntity .getMetrics ().size ());
126
- Assert . assertEquals (0 , timelineEntity .getEvents ().size ());
127
- Assert . assertEquals (0 , timelineEntity .getConfigs ().size ());
128
- Assert . assertEquals (appTimelineEntity .getInfo ().size (),
128
+ assertEquals (0 , timelineEntity .getMetrics ().size ());
129
+ assertEquals (0 , timelineEntity .getEvents ().size ());
130
+ assertEquals (0 , timelineEntity .getConfigs ().size ());
131
+ assertEquals (appTimelineEntity .getInfo ().size (),
129
132
timelineEntity .getInfo ().size ());
130
133
}
131
134
@@ -139,13 +142,13 @@ public void testGetEntityCustomField() throws Exception {
139
142
TimelineEntity timelineEntity = timelineReader .getEntity (context ,
140
143
dataToRetrieve );
141
144
142
- Assert . assertEquals (appTimelineEntity .getCreatedTime (), timelineEntity
145
+ assertEquals (appTimelineEntity .getCreatedTime (), timelineEntity
143
146
.getCreatedTime ().longValue ());
144
- Assert . assertEquals (appTimelineEntity .getMetrics ().size (),
147
+ assertEquals (appTimelineEntity .getMetrics ().size (),
145
148
timelineEntity .getMetrics ().size ());
146
- Assert . assertEquals (0 , timelineEntity .getEvents ().size ());
147
- Assert . assertEquals (0 , timelineEntity .getConfigs ().size ());
148
- Assert . assertEquals (appTimelineEntity .getInfo ().size (),
149
+ assertEquals (0 , timelineEntity .getEvents ().size ());
150
+ assertEquals (0 , timelineEntity .getConfigs ().size ());
151
+ assertEquals (appTimelineEntity .getInfo ().size (),
149
152
timelineEntity .getInfo ().size ());
150
153
}
151
154
@@ -159,15 +162,15 @@ public void testGetEntityAllFields() throws Exception {
159
162
TimelineEntity timelineEntity = timelineReader .getEntity (context ,
160
163
dataToRetrieve );
161
164
162
- Assert . assertEquals (appTimelineEntity .getCreatedTime (), timelineEntity
165
+ assertEquals (appTimelineEntity .getCreatedTime (), timelineEntity
163
166
.getCreatedTime ().longValue ());
164
- Assert . assertEquals (appTimelineEntity .getMetrics ().size (),
167
+ assertEquals (appTimelineEntity .getMetrics ().size (),
165
168
timelineEntity .getMetrics ().size ());
166
- Assert . assertEquals (appTimelineEntity .getEvents ().size (),
169
+ assertEquals (appTimelineEntity .getEvents ().size (),
167
170
timelineEntity .getEvents ().size ());
168
- Assert . assertEquals (appTimelineEntity .getConfigs ().size (),
171
+ assertEquals (appTimelineEntity .getConfigs ().size (),
169
172
timelineEntity .getConfigs ().size ());
170
- Assert . assertEquals (appTimelineEntity .getInfo ().size (),
173
+ assertEquals (appTimelineEntity .getInfo ().size (),
171
174
timelineEntity .getInfo ().size ());
172
175
}
173
176
@@ -181,7 +184,7 @@ public void testGetAllEntities() throws Exception {
181
184
Set <TimelineEntity > actualEntities = timelineReader .getEntities (context ,
182
185
new TimelineEntityFilters .Builder ().build (), dataToRetrieve );
183
186
184
- Assert . assertEquals (entities .size (), actualEntities .size ());
187
+ assertEquals (entities .size (), actualEntities .size ());
185
188
}
186
189
187
190
@ Test
@@ -194,7 +197,7 @@ public void testGetEntitiesWithLimit() throws Exception {
194
197
new TimelineEntityFilters .Builder ().entityLimit (2L ).build (),
195
198
dataToRetrieve );
196
199
197
- Assert . assertEquals (2 , actualEntities .size ());
200
+ assertEquals (2 , actualEntities .size ());
198
201
}
199
202
200
203
@ Test
@@ -207,7 +210,7 @@ public void testGetEntitiesByWindows() throws Exception {
207
210
new TimelineEntityFilters .Builder ().createdTimeBegin (1533985554927L )
208
211
.createTimeEnd (1533985554927L ).build (), dataToRetrieve );
209
212
210
- Assert . assertEquals (1 , actualEntities .size ());
213
+ assertEquals (1 , actualEntities .size ());
211
214
}
212
215
213
216
@ Test
@@ -227,11 +230,11 @@ public void testGetFilteredEntities() throws Exception {
227
230
new TimelineEntityFilters .Builder ().infoFilters (infoFilterList ).build (),
228
231
dataToRetrieve );
229
232
230
- Assert . assertEquals (1 , actualEntities .size ());
233
+ assertEquals (1 , actualEntities .size ());
231
234
// Only one entity with type YARN_APPLICATION_ATTEMPT should be returned.
232
235
for (TimelineEntity entity : actualEntities ) {
233
236
if (!entity .getType ().equals ("YARN_APPLICATION_ATTEMPT" )) {
234
- Assert . fail ("Incorrect filtering based on info filters" );
237
+ fail ("Incorrect filtering based on info filters" );
235
238
}
236
239
}
237
240
@@ -245,11 +248,11 @@ public void testGetFilteredEntities() throws Exception {
245
248
new TimelineEntityFilters .Builder ().configFilters (confFilterList )
246
249
.build (), dataToRetrieve );
247
250
248
- Assert . assertEquals (1 , actualEntities .size ());
251
+ assertEquals (1 , actualEntities .size ());
249
252
// Only one entity with type YARN_APPLICATION should be returned.
250
253
for (TimelineEntity entity : actualEntities ) {
251
254
if (!entity .getType ().equals ("YARN_APPLICATION" )) {
252
- Assert . fail ("Incorrect filtering based on info filters" );
255
+ fail ("Incorrect filtering based on info filters" );
253
256
}
254
257
}
255
258
@@ -263,11 +266,11 @@ public void testGetFilteredEntities() throws Exception {
263
266
new TimelineEntityFilters .Builder ().eventFilters (eventFilters ).build (),
264
267
dataToRetrieve );
265
268
266
- Assert . assertEquals (1 , actualEntities .size ());
269
+ assertEquals (1 , actualEntities .size ());
267
270
// Only one entity with type YARN_CONTAINER should be returned.
268
271
for (TimelineEntity entity : actualEntities ) {
269
272
if (!entity .getType ().equals ("YARN_CONTAINER" )) {
270
- Assert . fail ("Incorrect filtering based on info filters" );
273
+ fail ("Incorrect filtering based on info filters" );
271
274
}
272
275
}
273
276
@@ -279,11 +282,11 @@ public void testGetFilteredEntities() throws Exception {
279
282
new TimelineEntityFilters .Builder ().metricFilters (metricFilterList )
280
283
.build (), dataToRetrieve );
281
284
282
- Assert . assertEquals (1 , actualEntities .size ());
285
+ assertEquals (1 , actualEntities .size ());
283
286
// Only one entity with type YARN_CONTAINER should be returned.
284
287
for (TimelineEntity entity : actualEntities ) {
285
288
if (!entity .getType ().equals ("YARN_CONTAINER" )) {
286
- Assert . fail ("Incorrect filtering based on info filters" );
289
+ fail ("Incorrect filtering based on info filters" );
287
290
}
288
291
}
289
292
}
@@ -300,23 +303,23 @@ public void testReadingDifferentEntityTypes() throws Exception {
300
303
TimelineEntity timelineEntity = timelineReader .getEntity (context ,
301
304
dataToRetrieve );
302
305
303
- Assert . assertEquals (TimelineEntityType .YARN_FLOW_ACTIVITY .toString (),
306
+ assertEquals (TimelineEntityType .YARN_FLOW_ACTIVITY .toString (),
304
307
timelineEntity .getType ());
305
308
306
309
// reading YARN_FLOW_RUN
307
310
context .setEntityType (TimelineEntityType .YARN_FLOW_RUN .toString ());
308
311
timelineEntity = timelineReader .getEntity (context ,
309
312
dataToRetrieve );
310
313
311
- Assert . assertEquals (TimelineEntityType .YARN_FLOW_RUN .toString (),
314
+ assertEquals (TimelineEntityType .YARN_FLOW_RUN .toString (),
312
315
timelineEntity .getType ());
313
316
314
317
// reading YARN_APPLICATION
315
318
context .setEntityType (TimelineEntityType .YARN_APPLICATION .toString ());
316
319
timelineEntity = timelineReader .getEntity (context ,
317
320
dataToRetrieve );
318
321
319
- Assert . assertEquals (TimelineEntityType .YARN_APPLICATION .toString (),
322
+ assertEquals (TimelineEntityType .YARN_APPLICATION .toString (),
320
323
timelineEntity .getType ());
321
324
}
322
325
@@ -327,9 +330,9 @@ public void testReadingAllEntityTypes() throws Exception {
327
330
328
331
context .setEntityType (TimelineEntityType .YARN_CONTAINER .toString ());
329
332
Set <String > entityTypes = timelineReader .getEntityTypes (context );
330
- Assert . assertTrue (entityTypes .contains (TimelineEntityType .YARN_CONTAINER
333
+ assertTrue (entityTypes .contains (TimelineEntityType .YARN_CONTAINER
331
334
.toString ()));
332
- Assert . assertTrue (entityTypes .contains (TimelineEntityType
335
+ assertTrue (entityTypes .contains (TimelineEntityType
333
336
.YARN_APPLICATION_ATTEMPT .toString ()));
334
337
}
335
338
@@ -351,7 +354,7 @@ public void testMetricsToRetrieve() throws Exception {
351
354
context .setEntityType (TimelineEntityType .YARN_APPLICATION .toString ());
352
355
TimelineEntity timelineEntity = timelineReader .getEntity (context ,
353
356
dataToRetrieve );
354
- Assert . assertEquals (0 , timelineEntity .getMetrics ().size ());
357
+ assertEquals (0 , timelineEntity .getMetrics ().size ());
355
358
356
359
timelineFilterList .addFilter (new TimelinePrefixFilter (
357
360
TimelineCompareOp .EQUAL ,
@@ -361,19 +364,19 @@ public void testMetricsToRetrieve() throws Exception {
361
364
context .setEntityType (TimelineEntityType .YARN_APPLICATION .toString ());
362
365
timelineEntity = timelineReader .getEntity (context ,
363
366
dataToRetrieve );
364
- Assert . assertTrue (timelineEntity .getMetrics ().size () > 0 );
367
+ assertTrue (timelineEntity .getMetrics ().size () > 0 );
365
368
366
369
//testing metrics prefix for AND condition
367
370
timelineFilterList .setOperator (TimelineFilterList .Operator .AND );
368
371
timelineEntity = timelineReader .getEntity (context ,
369
372
dataToRetrieve );
370
- Assert . assertEquals (0 , timelineEntity .getMetrics ().size ());
373
+ assertEquals (0 , timelineEntity .getMetrics ().size ());
371
374
372
375
dataToRetrieve .getMetricsToRetrieve ().getFilterList ().remove (0 );
373
376
context .setEntityType (TimelineEntityType .YARN_APPLICATION .toString ());
374
377
timelineEntity = timelineReader .getEntity (context ,
375
378
dataToRetrieve );
376
- Assert . assertTrue (timelineEntity .getMetrics ().size () > 0 );
379
+ assertTrue (timelineEntity .getMetrics ().size () > 0 );
377
380
}
378
381
379
382
@ Test
@@ -394,7 +397,7 @@ public void testConfigsToRetrieve() throws Exception {
394
397
context .setEntityType (TimelineEntityType .YARN_APPLICATION .toString ());
395
398
TimelineEntity timelineEntity = timelineReader .getEntity (context ,
396
399
dataToRetrieve );
397
- Assert . assertEquals (0 , timelineEntity .getConfigs ().size ());
400
+ assertEquals (0 , timelineEntity .getConfigs ().size ());
398
401
399
402
timelineFilterList .addFilter (new TimelinePrefixFilter (
400
403
TimelineCompareOp .EQUAL , "YARN_AM_NODE_LABEL_EXPRESSION" ));
@@ -403,18 +406,18 @@ public void testConfigsToRetrieve() throws Exception {
403
406
context .setEntityType (TimelineEntityType .YARN_APPLICATION .toString ());
404
407
timelineEntity = timelineReader .getEntity (context ,
405
408
dataToRetrieve );
406
- Assert . assertTrue (timelineEntity .getConfigs ().size () > 0 );
409
+ assertTrue (timelineEntity .getConfigs ().size () > 0 );
407
410
408
411
//testing metrics prefix for AND condition
409
412
timelineFilterList .setOperator (TimelineFilterList .Operator .AND );
410
413
timelineEntity = timelineReader .getEntity (context ,
411
414
dataToRetrieve );
412
- Assert . assertEquals (0 , timelineEntity .getConfigs ().size ());
415
+ assertEquals (0 , timelineEntity .getConfigs ().size ());
413
416
414
417
dataToRetrieve .getConfsToRetrieve ().getFilterList ().remove (0 );
415
418
context .setEntityType (TimelineEntityType .YARN_APPLICATION .toString ());
416
419
timelineEntity = timelineReader .getEntity (context ,
417
420
dataToRetrieve );
418
- Assert . assertTrue (timelineEntity .getConfigs ().size () > 0 );
421
+ assertTrue (timelineEntity .getConfigs ().size () > 0 );
419
422
}
420
423
}
0 commit comments