echonesis commented on code in PR #11408:
URL: https://github.com/apache/ozone/pull/11408#discussion_r4215596902
##########
hadoop-ozone/client/src/test/java/org/apache/hadoop/ozone/client/TestOzoneBucket.java:
##########
@@ -69,4 +96,110 @@ public void clientProtocol3argDefaultDelegates() throws
IOException {
assertSame(status, proxy.getOzoneFileStatus("vol", "bucket", "key"));
verify(proxy).getOzoneFileStatus("vol", "bucket", "key", false);
}
+
+ @ParameterizedTest
+ @NullAndEmptySource
+ void shallowRootListingStartsAtRoot(String prevKey) throws IOException {
+ ClientProtocol proxy = mock(ClientProtocol.class);
+ when(proxy.listStatusLight(any())).thenAnswer(invocation -> new
ArrayList<>(Arrays.asList(
+ keyStatus("a-file", false), keyStatus("b-dir", true),
keyStatus("c-file", false))));
+
+ Iterator<? extends OzoneKey> keys = fsoBucket(proxy).listKeys("", prevKey,
true);
+
+ ArgumentCaptor<ListStatusLightOptions> options =
ArgumentCaptor.forClass(ListStatusLightOptions.class);
+ verify(proxy).listStatusLight(options.capture());
+ assertEquals("vol", options.getValue().getVolumeName());
+ assertEquals("bucket", options.getValue().getBucketName());
+ assertEquals("", options.getValue().getKeyName());
+ assertEquals("", options.getValue().getStartKey());
+ assertEquals("", options.getValue().getListPrefix());
+ assertEquals(3, options.getValue().getNumEntries());
+ assertFalse(options.getValue().isRecursive());
+ assertFalse(options.getValue().isAllowPartialPrefixes());
+ verifyNoMoreInteractions(proxy);
+
+ OzoneKey file = keys.next();
+ assertEquals("a-file", file.getName());
+ assertEquals("owner", file.getOwner());
+ assertEquals(10, file.getDataSize());
+ assertEquals(RatisReplicationConfig.getInstance(ReplicationFactor.ONE),
file.getReplicationConfig());
+ OzoneKey directory = keys.next();
+ assertEquals("b-dir/", directory.getName());
+ assertFalse(directory.isFile());
+ }
+
+ @ParameterizedTest
+ @MethodSource("rootListings")
+ void shallowRootListingPreservesPages(String shape, int size, String
prevKey) throws IOException {
+ ClientProtocol proxy = mock(ClientProtocol.class);
+ List<OzoneFileStatusLight> statuses = new ArrayList<>();
+ List<String> expected = new ArrayList<>();
+ for (int i = 0; i < size; i++) {
+ String name = "key-" + i;
+ boolean directory = shape.equals("directories") ||
(shape.equals("mixed") && i % 2 == 0);
+ statuses.add(keyStatus(name, directory));
+ expected.add(name + (directory ? "/" : ""));
+ }
+ when(proxy.listStatusLight(any())).thenAnswer(invocation -> {
+ ListStatusLightOptions options = invocation.getArgument(0);
+ String startKey =
OzoneFSUtils.removeTrailingSlashIfNeeded(options.getStartKey());
+ int start = 0;
+ while (start < statuses.size() &&
statuses.get(start).getTrimmedName().compareTo(startKey) < 0) {
+ start++;
+ }
+ int end = Math.min(statuses.size(), start + (int)
options.getNumEntries());
+ return new ArrayList<>(statuses.subList(start, end));
+ });
+
+ Iterator<? extends OzoneKey> keys = fsoBucket(proxy).listKeys("", prevKey,
true);
+ verify(proxy).listStatusLight(any());
+ verifyNoMoreInteractions(proxy);
+ List<String> actual = new ArrayList<>();
+ keys.forEachRemaining(key -> actual.add(key.getName()));
+ assertEquals(expected, actual);
+ }
+
+ private static Stream<Arguments> rootListings() {
+ return Stream.of("files", "directories", "mixed").flatMap(shape ->
+ IntStream.of(0, 1, 3, 4, 6, 7).boxed().flatMap(size ->
+ Stream.of(Arguments.of(shape, size, null), Arguments.of(shape,
size, ""))));
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"dir/", "/"})
+ void shallowListingWithPrefixKeepsSeed(String prefix) throws IOException {
+ ClientProtocol proxy = mock(ClientProtocol.class);
+ when(proxy.listStatusLight(any())).thenAnswer(invocation ->
+ new ArrayList<>(Arrays.asList(keyStatus(prefix + "file", false))));
+
+ fsoBucket(proxy).listKeys(prefix, null, true);
+
+ ArgumentCaptor<ListStatusLightOptions> options =
ArgumentCaptor.forClass(ListStatusLightOptions.class);
+ verify(proxy, times(2)).listStatusLight(options.capture());
+ assertTrue(options.getAllValues().get(0).isAllowPartialPrefixes());
+ assertFalse(options.getAllValues().get(1).isAllowPartialPrefixes());
Review Comment:
nit: Could we also add a case with an empty prefix and a non-empty
`prevKey`? This would verify that marker-based listings still make both
`ListStatusLight` calls and exclude the marker from the results.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]