This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new ba8e7efaf4 HDDS-9351. ManagedChannel not shutdown properly in 
TestRootedOzoneFileSystemWithFSO (#5370)
ba8e7efaf4 is described below

commit ba8e7efaf4b69050bf0898dae0029d656d650619
Author: Doroszlai, Attila <[email protected]>
AuthorDate: Sat Sep 30 19:56:35 2023 +0200

    HDDS-9351. ManagedChannel not shutdown properly in 
TestRootedOzoneFileSystemWithFSO (#5370)
---
 .../apache/hadoop/fs/ozone/TestLeaseRecovery.java  | 41 ++++++++++++++++------
 .../fs/ozone/TestOzoneFileSystemWithFSO.java       | 22 +++++++-----
 .../hadoop/fs/ozone/TestRootedOzoneFileSystem.java |  2 +-
 .../fs/ozone/TestRootedOzoneFileSystemWithFSO.java | 20 +++++++----
 4 files changed, 58 insertions(+), 27 deletions(-)

diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestLeaseRecovery.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestLeaseRecovery.java
index d47ad54103..e1dfe332e8 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestLeaseRecovery.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestLeaseRecovery.java
@@ -30,6 +30,7 @@ import org.apache.hadoop.ozone.OzoneConfigKeys;
 import org.apache.hadoop.ozone.TestDataUtil;
 import org.apache.hadoop.ozone.client.OzoneBucket;
 import org.apache.hadoop.ozone.client.OzoneClient;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
 import org.apache.hadoop.ozone.om.helpers.BucketLayout;
 import org.junit.After;
 import org.junit.Before;
@@ -38,6 +39,7 @@ import org.junit.Test;
 import org.junit.rules.Timeout;
 
 import java.io.IOException;
+import java.io.OutputStream;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.TimeoutException;
 
@@ -66,6 +68,19 @@ public class TestLeaseRecovery {
   private OzoneClient client;
   private final OzoneConfiguration conf = new OzoneConfiguration();
 
+  /**
+   * Closing the output stream after lease recovery throws because the key
+   * is no longer open in OM.  This is currently expected (see HDDS-9358).
+   */
+  public static void closeIgnoringKeyNotFound(OutputStream stream)
+      throws IOException {
+    try {
+      stream.close();
+    } catch (OMException e) {
+      assertEquals(OMException.ResultCodes.KEY_NOT_FOUND, e.getResult());
+    }
+  }
+
   @Before
   public void init() throws IOException, InterruptedException,
       TimeoutException {
@@ -117,21 +132,27 @@ public class TestLeaseRecovery {
     final Path file = new Path(dir, "file");
 
     RootedOzoneFileSystem fs = (RootedOzoneFileSystem)FileSystem.get(conf);
-    final FSDataOutputStream stream = fs.create(file, true);
 
     final byte[] data = new byte[1 << 20];
     ThreadLocalRandom.current().nextBytes(data);
-    stream.write(data);
-    stream.hsync();
-    assertFalse(fs.isFileClosed(file));
 
-    int count = 0;
-    while (count++ < 15 && !fs.recoverLease(file)) {
-      Thread.sleep(1000);
+    final FSDataOutputStream stream = fs.create(file, true);
+    try {
+      stream.write(data);
+      stream.hsync();
+      assertFalse(fs.isFileClosed(file));
+
+      int count = 0;
+      while (count++ < 15 && !fs.recoverLease(file)) {
+        Thread.sleep(1000);
+      }
+      // The lease should have been recovered.
+      assertTrue("File should be closed", fs.recoverLease(file));
+      assertTrue(fs.isFileClosed(file));
+    } finally {
+      closeIgnoringKeyNotFound(stream);
     }
-    // The lease should have been recovered.
-    assertTrue("File should be closed", fs.recoverLease(file));
-    assertTrue(fs.isFileClosed(file));
+
     // open it again, make sure the data is correct
     byte[] readData = new byte[1 << 20];
     try (FSDataInputStream fdis = fs.open(file)) {
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystemWithFSO.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystemWithFSO.java
index 0a4d2cecb1..5e15cc77a1 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystemWithFSO.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystemWithFSO.java
@@ -578,15 +578,19 @@ public class TestOzoneFileSystemWithFSO extends 
TestOzoneFileSystem {
 
     LeaseRecoverable fs = (LeaseRecoverable)getFs();
     FSDataOutputStream stream = getFs().create(source);
-    // file not visible yet
-    assertThrows(OMException.class, () -> fs.isFileClosed(source));
-    stream.write(1);
-    stream.hsync();
-    // file is visible and open
-    assertFalse(fs.isFileClosed(source));
-    assertTrue(fs.recoverLease(source));
-    // file is closed after lease recovery
-    assertTrue(fs.isFileClosed(source));
+    try {
+      // file not visible yet
+      assertThrows(OMException.class, () -> fs.isFileClosed(source));
+      stream.write(1);
+      stream.hsync();
+      // file is visible and open
+      assertFalse(fs.isFileClosed(source));
+      assertTrue(fs.recoverLease(source));
+      // file is closed after lease recovery
+      assertTrue(fs.isFileClosed(source));
+    } finally {
+      TestLeaseRecovery.closeIgnoringKeyNotFound(stream);
+    }
   }
 
   @Test
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java
index bcd1d0e41c..7a970d7bdc 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystem.java
@@ -182,7 +182,7 @@ public class TestRootedOzoneFileSystem {
     if (cluster != null) {
       cluster.shutdown();
     }
-    IOUtils.closeQuietly(fs);
+    IOUtils.closeQuietly(fs, userOfs);
   }
 
   @Before
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystemWithFSO.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystemWithFSO.java
index d923f41a75..0ae54e1b63 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystemWithFSO.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestRootedOzoneFileSystemWithFSO.java
@@ -39,6 +39,7 @@ import java.util.Collection;
 import java.util.concurrent.TimeoutException;
 
 import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
@@ -268,7 +269,7 @@ public class TestRootedOzoneFileSystemWithFSO
 
     FileStatus[] fileStatuses = getFs().listStatus(
         new Path(getBucketPath() + "/testListStatusFSO"));
-    Assert.assertEquals(valueGreaterBatchSize, fileStatuses.length);
+    assertEquals(valueGreaterBatchSize, fileStatuses.length);
   }
 
   @Test
@@ -280,11 +281,16 @@ public class TestRootedOzoneFileSystemWithFSO
 
     LeaseRecoverable fs = (LeaseRecoverable)getFs();
     FSDataOutputStream stream = getFs().create(source);
-    assertThrows(OMException.class, () -> fs.isFileClosed(source));
-    stream.write(1);
-    stream.hsync();
-    assertFalse(fs.isFileClosed(source));
-    assertTrue(fs.recoverLease(source));
-    assertTrue(fs.isFileClosed(source));
+    try {
+      assertThrows(OMException.class, () -> fs.isFileClosed(source));
+      stream.write(1);
+      stream.hsync();
+      assertFalse(fs.isFileClosed(source));
+      assertTrue(fs.recoverLease(source));
+      assertTrue(fs.isFileClosed(source));
+    } finally {
+      TestLeaseRecovery.closeIgnoringKeyNotFound(stream);
+    }
   }
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to