Skip to content

Commit 07e1538

Browse files
committed
fix junit test.
1 parent 54f79ce commit 07e1538

File tree

3 files changed

+84
-9
lines changed

3 files changed

+84
-9
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/AbstractTimelineReaderHBaseTestBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ protected Client createClient() {
115115
.register(FlowActivityEntityReader.class)
116116
.register(FlowRunEntityReader.class)
117117
.register(FlowActivityEntitySetReader.class)
118-
.register(FlowActivityEntityListReader.class);
118+
.register(FlowActivityEntityListReader.class)
119+
.register(FlowRunEntitySetReader.class);
119120
}
120121

121122
protected Response getResponse(Client client, URI uri)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.yarn.server.timelineservice.reader;
19+
20+
import com.fasterxml.jackson.databind.JsonNode;
21+
import com.fasterxml.jackson.databind.ObjectMapper;
22+
import org.apache.hadoop.yarn.api.records.timelineservice.FlowRunEntity;
23+
24+
import javax.ws.rs.Consumes;
25+
import javax.ws.rs.WebApplicationException;
26+
import javax.ws.rs.core.MediaType;
27+
import javax.ws.rs.core.MultivaluedMap;
28+
import javax.ws.rs.ext.MessageBodyReader;
29+
import javax.ws.rs.ext.Provider;
30+
import java.io.IOException;
31+
import java.io.InputStream;
32+
import java.lang.annotation.Annotation;
33+
import java.lang.reflect.Type;
34+
import java.util.HashSet;
35+
import java.util.Map;
36+
import java.util.Set;
37+
38+
/**
39+
* We have defined a dedicated Reader for `Set<FlowActivityEntity>`,
40+
* aimed at adapting to the Jersey2 framework
41+
* to ensure that JSON can be converted into `Set<FlowActivityEntity>`.
42+
*/
43+
@Provider
44+
@Consumes(MediaType.APPLICATION_JSON)
45+
public class FlowRunEntitySetReader implements MessageBodyReader<Set<FlowRunEntity>> {
46+
47+
private ObjectMapper objectMapper = new ObjectMapper();
48+
private String timelineEntityType =
49+
"java.util.Set<org.apache.hadoop.yarn.api.records.timelineservice.FlowRunEntity>";
50+
51+
@Override
52+
public boolean isReadable(Class<?> type, Type genericType,
53+
Annotation[] annotations, MediaType mediaType) {
54+
return timelineEntityType.equals(genericType.getTypeName());
55+
}
56+
57+
@Override
58+
public Set<FlowRunEntity> readFrom(Class<Set<FlowRunEntity>> type,
59+
Type genericType, Annotation[] annotations, MediaType mediaType,
60+
MultivaluedMap<String, String> httpHeaders,
61+
InputStream entityStream) throws IOException, WebApplicationException {
62+
Set<FlowRunEntity> flowRunEntitySet = new HashSet<>();
63+
64+
JsonNode jsonNode = objectMapper.readTree(entityStream);
65+
if (jsonNode.isArray()) {
66+
for (JsonNode jNode : jsonNode) {
67+
FlowRunEntity flowRunEntity = objectMapper.treeToValue(jNode, FlowRunEntity.class);
68+
flowRunEntitySet.add(flowRunEntity);
69+
}
70+
}
71+
72+
return flowRunEntitySet;
73+
}
74+
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWebServicesHBaseStorage.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ public void testGetFlowRuns() throws Exception {
500500
Response resp = getResponse(client, uri);
501501
Set<FlowRunEntity> entities =
502502
resp.readEntity(new GenericType<Set<FlowRunEntity>>(){});
503-
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8",
503+
assertEquals(MediaType.APPLICATION_JSON_TYPE + ";charset=utf-8",
504504
resp.getMediaType().toString());
505505
assertNotNull(entities);
506506
assertEquals(2, entities.size());
@@ -520,7 +520,7 @@ public void testGetFlowRuns() throws Exception {
520520
+ "clusters/cluster1/users/user1/flows/flow_name/runs?limit=1");
521521
resp = getResponse(client, uri);
522522
entities = resp.readEntity(new GenericType<Set<FlowRunEntity>>(){});
523-
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8",
523+
assertEquals(MediaType.APPLICATION_JSON_TYPE + ";charset=utf-8",
524524
resp.getMediaType().toString());
525525
assertNotNull(entities);
526526
assertEquals(1, entities.size());
@@ -537,7 +537,7 @@ public void testGetFlowRuns() throws Exception {
537537
"createdtimestart=1425016501030");
538538
resp = getResponse(client, uri);
539539
entities = resp.readEntity(new GenericType<Set<FlowRunEntity>>(){});
540-
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8",
540+
assertEquals(MediaType.APPLICATION_JSON_TYPE + ";charset=utf-8",
541541
resp.getMediaType().toString());
542542
assertNotNull(entities);
543543
assertEquals(1, entities.size());
@@ -554,7 +554,7 @@ public void testGetFlowRuns() throws Exception {
554554
"createdtimestart=1425016500999&createdtimeend=1425016501035");
555555
resp = getResponse(client, uri);
556556
entities = resp.readEntity(new GenericType<Set<FlowRunEntity>>(){});
557-
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8",
557+
assertEquals(MediaType.APPLICATION_JSON_TYPE + ";charset=utf-8",
558558
resp.getMediaType().toString());
559559
assertNotNull(entities);
560560
assertEquals(2, entities.size());
@@ -574,7 +574,7 @@ public void testGetFlowRuns() throws Exception {
574574
"createdtimeend=1425016501030");
575575
resp = getResponse(client, uri);
576576
entities = resp.readEntity(new GenericType<Set<FlowRunEntity>>(){});
577-
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8",
577+
assertEquals(MediaType.APPLICATION_JSON_TYPE + ";charset=utf-8",
578578
resp.getMediaType().toString());
579579
assertNotNull(entities);
580580
assertEquals(1, entities.size());
@@ -591,7 +591,7 @@ public void testGetFlowRuns() throws Exception {
591591
"fields=metrics");
592592
resp = getResponse(client, uri);
593593
entities = resp.readEntity(new GenericType<Set<FlowRunEntity>>(){});
594-
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8",
594+
assertEquals(MediaType.APPLICATION_JSON_TYPE + ";charset=utf-8",
595595
resp.getMediaType().toString());
596596
assertNotNull(entities);
597597
assertEquals(2, entities.size());
@@ -628,7 +628,7 @@ public void testGetFlowRunsMetricsToRetrieve() throws Exception {
628628
Response resp = getResponse(client, uri);
629629
Set<FlowRunEntity> entities =
630630
resp.readEntity(new GenericType<Set<FlowRunEntity>>(){});
631-
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8",
631+
assertEquals(MediaType.APPLICATION_JSON_TYPE + ";charset=utf-8",
632632
resp.getMediaType().toString());
633633
assertNotNull(entities);
634634
assertEquals(2, entities.size());
@@ -647,7 +647,7 @@ public void testGetFlowRunsMetricsToRetrieve() throws Exception {
647647
"metricstoretrieve=!(MAP_,HDFS_)");
648648
resp = getResponse(client, uri);
649649
entities = resp.readEntity(new GenericType<Set<FlowRunEntity>>(){});
650-
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8",
650+
assertEquals(MediaType.APPLICATION_JSON_TYPE + ";charset=utf-8",
651651
resp.getMediaType().toString());
652652
assertNotNull(entities);
653653
assertEquals(2, entities.size());

0 commit comments

Comments
 (0)