Skip to content

Commit 5239a9f

Browse files
author
Ben Roling
committed
Skip tests that require versionId when bucket doesn't have versioning enabled
1 parent 4c6331e commit 5239a9f

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/ITestS3ARemoteFileChanged.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,7 @@ public void testReadFileChangedStreamOpen() throws Throwable {
186186
writeDataset(fs, testpath, originalDataset, originalDataset.length,
187187
1024, false);
188188

189-
if (fs.getChangeDetectionPolicy().getSource() == Source.VersionId) {
190-
// skip versionId tests if the bucket doesn't have object versioning
191-
// enabled
192-
Assume.assumeTrue(
193-
"Target filesystem does not support versioning",
194-
fs.getObjectMetadata(fs.pathToKey(testpath)).getVersionId() != null);
195-
}
189+
skipIfVersionPolicyAndNoVersionId(testpath);
196190

197191
try(FSDataInputStream instream = fs.open(testpath)) {
198192
// seek forward and read successfully
@@ -272,6 +266,9 @@ public void testReadFileChangedStreamOpen() throws Throwable {
272266
@Test
273267
public void testReadFileChangedOutOfSyncMetadata() throws Throwable {
274268
final Path testpath = writeOutOfSyncFileVersion("read.dat");
269+
270+
skipIfVersionPolicyAndNoVersionId(testpath);
271+
275272
final FSDataInputStream instream = fs.open(testpath);
276273
if (expectedExceptionInteractions.contains(InteractionType.READ)) {
277274
intercept(RemoteFileChangedException.class, "", "read()",
@@ -290,6 +287,9 @@ public void testReadFileChangedOutOfSyncMetadata() throws Throwable {
290287
@Test
291288
public void testReadWithNoVersionMetadata() throws Throwable {
292289
final Path testpath = writeFileWithNoVersionMetadata("readnoversion.dat");
290+
291+
skipIfVersionPolicyAndNoVersionId(testpath);
292+
293293
final FSDataInputStream instream = fs.open(testpath);
294294
assertEquals(TEST_DATA,
295295
IOUtils.toString(instream, Charset.forName("UTF-8")).trim());
@@ -302,6 +302,9 @@ public void testReadWithNoVersionMetadata() throws Throwable {
302302
@Test
303303
public void testSelectChangedFile() throws Throwable {
304304
final Path testpath = writeOutOfSyncFileVersion("select.dat");
305+
306+
skipIfVersionPolicyAndNoVersionId(testpath);
307+
305308
if (expectedExceptionInteractions.contains(InteractionType.SELECT)) {
306309
interceptFuture(RemoteFileChangedException.class, "select",
307310
fs.openFile(testpath)
@@ -320,6 +323,9 @@ public void testSelectChangedFile() throws Throwable {
320323
public void testSelectWithNoVersionMetadata() throws Throwable {
321324
final Path testpath =
322325
writeFileWithNoVersionMetadata("selectnoversion.dat");
326+
327+
skipIfVersionPolicyAndNoVersionId(testpath);
328+
323329
FSDataInputStream instream = fs.openFile(testpath)
324330
.must(SELECT_SQL, "SELECT * FROM S3OBJECT").build().get();
325331
assertEquals(QUOTED_TEST_DATA,
@@ -334,6 +340,9 @@ public void testSelectWithNoVersionMetadata() throws Throwable {
334340
@Test
335341
public void testRenameChangedFile() throws Throwable {
336342
final Path testpath = writeOutOfSyncFileVersion("rename.dat");
343+
344+
skipIfVersionPolicyAndNoVersionId(testpath);
345+
337346
final Path dest = path("dest.dat");
338347
if (expectedExceptionInteractions.contains(InteractionType.COPY)) {
339348
intercept(RemoteFileChangedException.class, "", "copy()",
@@ -353,6 +362,9 @@ public void testRenameChangedFile() throws Throwable {
353362
public void testRenameWithNoVersionMetadata() throws Throwable {
354363
final Path testpath =
355364
writeFileWithNoVersionMetadata("renamenoversion.dat");
365+
366+
skipIfVersionPolicyAndNoVersionId(testpath);
367+
356368
final Path dest = path("noversiondest.dat");
357369
fs.rename(testpath, dest);
358370
FSDataInputStream inputStream = fs.open(dest);
@@ -415,4 +427,18 @@ private Path writeFileWithNoVersionMetadata(String filename)
415427

416428
return testpath;
417429
}
430+
431+
/**
432+
* The test is invalid if the policy uses versionId but the bucket doesn't
433+
* have versioning enabled.
434+
*/
435+
private void skipIfVersionPolicyAndNoVersionId(Path testpath) throws IOException {
436+
if (fs.getChangeDetectionPolicy().getSource() == Source.VersionId) {
437+
// skip versionId tests if the bucket doesn't have object versioning
438+
// enabled
439+
Assume.assumeTrue(
440+
"Target filesystem does not support versioning",
441+
fs.getObjectMetadata(fs.pathToKey(testpath)).getVersionId() != null);
442+
}
443+
}
418444
}

0 commit comments

Comments
 (0)