hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aengin...@apache.org
Subject [1/2] hadoop git commit: HDFS-12175. Ozone: Fix Leaking in TestStorageContainerManager#testRpcPermission. Contributed by Xiaoyu Yao.
Date Sat, 22 Jul 2017 04:11:36 GMT
Repository: hadoop
Updated Branches:
  refs/heads/HDFS-7240 c081e831d -> 63e211ff7


HDFS-12175. Ozone: Fix Leaking in TestStorageContainerManager#testRpcPermission. Contributed
by Xiaoyu Yao.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/91b089c8
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/91b089c8
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/91b089c8

Branch: refs/heads/HDFS-7240
Commit: 91b089c8e36572b399d8565ad028bd95c5dc9455
Parents: c081e83
Author: Anu Engineer <aengineer@apache.org>
Authored: Fri Jul 21 21:06:12 2017 -0700
Committer: Anu Engineer <aengineer@apache.org>
Committed: Fri Jul 21 21:06:12 2017 -0700

----------------------------------------------------------------------
 .../ozone/TestStorageContainerManager.java      | 128 ++++++++-----------
 1 file changed, 55 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/91b089c8/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/TestStorageContainerManager.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/TestStorageContainerManager.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/TestStorageContainerManager.java
index 0fb2289..29cf6a8 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/TestStorageContainerManager.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/TestStorageContainerManager.java
@@ -20,24 +20,16 @@ package org.apache.hadoop.ozone;
 import static org.junit.Assert.*;
 
 import java.io.IOException;
-import java.util.Arrays;
-import java.util.LinkedHashSet;
-import java.util.Set;
 
 import org.apache.hadoop.ozone.scm.StorageContainerManager;
 import org.apache.hadoop.scm.client.ScmClient;
 import org.apache.hadoop.scm.container.common.helpers.Pipeline;
 import org.junit.Rule;
 import org.junit.Assert;
-// TODO : We need this when we enable these tests back.
 import org.junit.Test;
-import org.junit.BeforeClass;
-import org.junit.After;
 import org.junit.rules.ExpectedException;
 
 import org.apache.hadoop.io.IOUtils;
-import org.apache.hadoop.scm.protocol.LocatedContainer;
-import org.apache.hadoop.scm.protocolPB.StorageContainerLocationProtocolClientSideTranslatorPB;
 import org.junit.rules.Timeout;
 import org.mockito.Mockito;
 
@@ -54,24 +46,9 @@ public class TestStorageContainerManager {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
-  private static MiniOzoneCluster cluster;
-  private static OzoneConfiguration conf;
-  private static StorageContainerLocationProtocolClientSideTranslatorPB
-      storageContainerLocationClient;
-
   @Rule
   public ExpectedException exception = ExpectedException.none();
 
-  @BeforeClass
-  public static void init() throws IOException {
-    conf = new OzoneConfiguration();
-  }
-
-  @After
-  public void shutdown() throws InterruptedException {
-    IOUtils.cleanup(null, storageContainerLocationClient, cluster);
-  }
-
   @Test
   public void testRpcPermission() throws IOException {
     // Test with default configuration
@@ -91,65 +68,70 @@ public class TestStorageContainerManager {
   private void testRpcPermissionWithConf(
       OzoneConfiguration ozoneConf, String fakeRemoteUsername,
       boolean expectPermissionDenied) throws IOException {
-    cluster = new MiniOzoneCluster.Builder(ozoneConf).numDataNodes(1)
-        .setHandlerType(OzoneConsts.OZONE_HANDLER_DISTRIBUTED).build();
-
-    String fakeUser = fakeRemoteUsername;
-    StorageContainerManager mockScm = Mockito.spy(
-        cluster.getStorageContainerManager());
-    Mockito.when(mockScm.getPpcRemoteUsername())
-        .thenReturn(fakeUser);
-
-    try {
-      mockScm.deleteContainer("container1");
-      fail("Operation should fail, expecting an IOException here.");
-    } catch (Exception e) {
-      if (expectPermissionDenied) {
-        verifyPermissionDeniedException(e, fakeUser);
-      } else {
-        // If passes permission check, it should fail with
-        // container not exist exception.
-        Assert.assertTrue(e.getMessage()
-            .contains("container doesn't exist"));
-      }
-    }
+    MiniOzoneCluster cluster =
+        new MiniOzoneCluster.Builder(ozoneConf).numDataNodes(1)
+            .setHandlerType(OzoneConsts.OZONE_HANDLER_DISTRIBUTED).build();
 
     try {
-      Pipeline pipeLine2 = mockScm.allocateContainer("container2");
-      if(expectPermissionDenied) {
+      String fakeUser = fakeRemoteUsername;
+      StorageContainerManager mockScm = Mockito.spy(
+          cluster.getStorageContainerManager());
+      Mockito.when(mockScm.getPpcRemoteUsername())
+          .thenReturn(fakeUser);
+
+      try {
+        mockScm.deleteContainer("container1");
         fail("Operation should fail, expecting an IOException here.");
-      } else {
-        Assert.assertEquals("container2", pipeLine2.getContainerName());
+      } catch (Exception e) {
+        if (expectPermissionDenied) {
+          verifyPermissionDeniedException(e, fakeUser);
+        } else {
+          // If passes permission check, it should fail with
+          // container not exist exception.
+          Assert.assertTrue(e.getMessage()
+              .contains("container doesn't exist"));
+        }
       }
-    } catch (Exception e) {
-      verifyPermissionDeniedException(e, fakeUser);
-    }
 
-    try {
-      Pipeline pipeLine3 = mockScm.allocateContainer("container3",
-          ScmClient.ReplicationFactor.ONE);
-      if(expectPermissionDenied) {
-        fail("Operation should fail, expecting an IOException here.");
-      } else {
-        Assert.assertEquals("container3", pipeLine3.getContainerName());
-        Assert.assertEquals(1, pipeLine3.getMachines().size());
+      try {
+        Pipeline pipeLine2 = mockScm.allocateContainer("container2");
+        if (expectPermissionDenied) {
+          fail("Operation should fail, expecting an IOException here.");
+        } else {
+          Assert.assertEquals("container2", pipeLine2.getContainerName());
+        }
+      } catch (Exception e) {
+        verifyPermissionDeniedException(e, fakeUser);
       }
-    } catch (Exception e) {
-      verifyPermissionDeniedException(e, fakeUser);
-    }
 
-    try {
-      mockScm.getContainer("container4");
-      fail("Operation should fail, expecting an IOException here.");
-    } catch (Exception e) {
-      if (expectPermissionDenied) {
+      try {
+        Pipeline pipeLine3 = mockScm.allocateContainer("container3",
+            ScmClient.ReplicationFactor.ONE);
+        if (expectPermissionDenied) {
+          fail("Operation should fail, expecting an IOException here.");
+        } else {
+          Assert.assertEquals("container3", pipeLine3.getContainerName());
+          Assert.assertEquals(1, pipeLine3.getMachines().size());
+        }
+      } catch (Exception e) {
         verifyPermissionDeniedException(e, fakeUser);
-      } else {
-        // If passes permission check, it should fail with
-        // key not exist exception.
-        Assert.assertTrue(e.getMessage()
-            .contains("Specified key does not exist"));
       }
+
+      try {
+        mockScm.getContainer("container4");
+        fail("Operation should fail, expecting an IOException here.");
+      } catch (Exception e) {
+        if (expectPermissionDenied) {
+          verifyPermissionDeniedException(e, fakeUser);
+        } else {
+          // If passes permission check, it should fail with
+          // key not exist exception.
+          Assert.assertTrue(e.getMessage()
+              .contains("Specified key does not exist"));
+        }
+      }
+    } finally {
+      IOUtils.cleanup(null, cluster);
     }
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message