Skip to content

Commit e0ceded

Browse files
authored
HADOOP-17086. ABFS: Making the ListStatus response ignore unknown properties. (#2101)
Contributed by Bilahari T H.
1 parent 3b5c9a9 commit e0ceded

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/contracts/services/ListResultEntrySchema.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.hadoop.fs.azurebfs.contracts.services;
2020

21+
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
2122
import org.codehaus.jackson.annotate.JsonProperty;
2223

2324
import org.apache.hadoop.classification.InterfaceStability;
@@ -26,6 +27,7 @@
2627
* The ListResultEntrySchema model.
2728
*/
2829
@InterfaceStability.Evolving
30+
@JsonIgnoreProperties(ignoreUnknown = true)
2931
public class ListResultEntrySchema {
3032
/**
3133
* The name property.

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/contracts/services/ListResultSchema.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.util.List;
2222

23+
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
2324
import org.codehaus.jackson.annotate.JsonProperty;
2425

2526
import org.apache.hadoop.classification.InterfaceStability;
@@ -28,6 +29,7 @@
2829
* The ListResultSchema model.
2930
*/
3031
@InterfaceStability.Evolving
32+
@JsonIgnoreProperties(ignoreUnknown = true)
3133
public class ListResultSchema {
3234
/**
3335
* The paths property.
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
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+
19+
package org.apache.hadoop.fs.azurebfs.contract;
20+
21+
import java.io.IOException;
22+
23+
import org.codehaus.jackson.map.ObjectMapper;
24+
import org.junit.Test;
25+
26+
import org.apache.hadoop.fs.azurebfs.contracts.services.ListResultEntrySchema;
27+
import org.apache.hadoop.fs.azurebfs.contracts.services.ListResultSchema;
28+
29+
import static org.assertj.core.api.Assertions.assertThat;
30+
31+
/**
32+
* Tests the JSON parsing for the listfilestatus response to ListResultSchema
33+
*/
34+
public class ListResultSchemaTest {
35+
36+
/**
37+
* Test parsing a JSON which matches the properties in the ListResultSchema
38+
* and ListResultEntrySchema
39+
* <p>
40+
* {
41+
* "paths": [
42+
* {
43+
* "contentLength": "0",
44+
* "etag": "0x8D8186452785ADA",
45+
* "group": "$superuser",
46+
* "lastModified": "Wed, 24 Jun 2020 17:30:43 GMT",
47+
* "name": "dest/filename",
48+
* "owner": "$superuser",
49+
* "permissions": "rw-r--r--"
50+
* }
51+
* ]
52+
* }
53+
*/
54+
@Test
55+
public void testMatchingJSON() throws IOException {
56+
57+
String matchingJson =
58+
"{ \"paths\": [ { \"contentLength\": \"0\", \"etag\": "
59+
+ "\"0x8D8186452785ADA\", \"group\": \"$superuser\", "
60+
+ "\"lastModified\": \"Wed, 24 Jun 2020 17:30:43 GMT\", \"name\": "
61+
+ "\"dest/filename\", \"owner\": \"$superuser\", \"permissions\": "
62+
+ "\"rw-r--r--\" } ] } ";
63+
64+
final ObjectMapper objectMapper = new ObjectMapper();
65+
final ListResultSchema listResultSchema = objectMapper
66+
.readValue(matchingJson, ListResultSchema.class);
67+
68+
assertThat(listResultSchema.paths().size())
69+
.describedAs("Only one path is expected as present in the input JSON")
70+
.isEqualTo(1);
71+
72+
ListResultEntrySchema path = listResultSchema.paths().get(0);
73+
assertThat(path.contentLength())
74+
.describedAs("contentLength should match the value in the input JSON")
75+
.isEqualTo(0L);
76+
assertThat(path.eTag())
77+
.describedAs("eTag should match the value in the input JSON")
78+
.isEqualTo("0x8D8186452785ADA");
79+
assertThat(path.group())
80+
.describedAs("group should match the value in the input JSON")
81+
.isEqualTo("$superuser");
82+
assertThat(path.lastModified())
83+
.describedAs("lastModified should match the value in the input JSON")
84+
.isEqualTo("Wed, 24 Jun 2020 17:30:43 GMT");
85+
assertThat(path.name())
86+
.describedAs("lastModified should match the value in the input JSON")
87+
.isEqualTo("dest/filename");
88+
assertThat(path.owner())
89+
.describedAs("lastModified should match the value in the input JSON")
90+
.isEqualTo("$superuser");
91+
assertThat(path.permissions())
92+
.describedAs("lastModified should match the value in the input JSON")
93+
.isEqualTo("rw-r--r--");
94+
}
95+
96+
/**
97+
* Test parsing a JSON which matches the properties in the ListResultSchema
98+
* and ListResultEntrySchema along with an unknown property
99+
* <p>
100+
* {
101+
* "paths": [
102+
* {
103+
* "contentLength": "0",
104+
* "unknownProperty": "132374934429527192",
105+
* "etag": "0x8D8186452785ADA",
106+
* "group": "$superuser",
107+
* "lastModified": "Wed, 24 Jun 2020 17:30:43 GMT",
108+
* "name": "dest/filename",
109+
* "owner": "$superuser",
110+
* "permissions": "rw-r--r--"
111+
* }
112+
* ]
113+
* }
114+
*/
115+
@Test
116+
public void testJSONWithUnknownFields() throws IOException {
117+
118+
String matchingJson = "{ \"paths\": [ { \"contentLength\": \"0\", "
119+
+ "\"unknownProperty\": \"132374934429527192\", \"etag\": "
120+
+ "\"0x8D8186452785ADA\", \"group\": \"$superuser\", "
121+
+ "\"lastModified\": \"Wed, 24 Jun 2020 17:30:43 GMT\", \"name\": "
122+
+ "\"dest/filename\", \"owner\": \"$superuser\", \"permissions\": "
123+
+ "\"rw-r--r--\" } ] } ";
124+
125+
final ObjectMapper objectMapper = new ObjectMapper();
126+
final ListResultSchema listResultSchema = objectMapper
127+
.readValue(matchingJson, ListResultSchema.class);
128+
129+
assertThat(listResultSchema.paths().size())
130+
.describedAs("Only one path is expected as present in the input JSON")
131+
.isEqualTo(1);
132+
133+
ListResultEntrySchema path = listResultSchema.paths().get(0);
134+
assertThat(path.contentLength())
135+
.describedAs("contentLength should match the value in the input JSON")
136+
.isEqualTo(0L);
137+
assertThat(path.eTag())
138+
.describedAs("eTag should match the value in the input JSON")
139+
.isEqualTo("0x8D8186452785ADA");
140+
assertThat(path.group())
141+
.describedAs("group should match the value in the input JSON")
142+
.isEqualTo("$superuser");
143+
assertThat(path.lastModified())
144+
.describedAs("lastModified should match the value in the input JSON")
145+
.isEqualTo("Wed, 24 Jun 2020 17:30:43 GMT");
146+
assertThat(path.name())
147+
.describedAs("lastModified should match the value in the input JSON")
148+
.isEqualTo("dest/filename");
149+
assertThat(path.owner())
150+
.describedAs("lastModified should match the value in the input JSON")
151+
.isEqualTo("$superuser");
152+
assertThat(path.permissions())
153+
.describedAs("lastModified should match the value in the input JSON")
154+
.isEqualTo("rw-r--r--");
155+
}
156+
157+
}

0 commit comments

Comments
 (0)