Skip to content

Commit 4f4e693

Browse files
committed
HADOOP-19501 Skip tests that depend on SecurityManager if the JVM does not support it
1 parent cd8f18b commit 4f4e693

File tree

7 files changed

+53
-28
lines changed

7 files changed

+53
-28
lines changed

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import static org.hamcrest.CoreMatchers.is;
8686
import static org.hamcrest.CoreMatchers.not;
8787
import static org.junit.Assert.*;
88+
import static org.junit.Assume.assumeTrue;
8889
import static org.hamcrest.core.StringContains.containsString;
8990

9091
/**
@@ -576,26 +577,32 @@ public void run() {
576577
//use SecurityManager to pause the copying of f1 and begin copying f2
577578
SecurityManager sm = System.getSecurityManager();
578579
System.out.println("SecurityManager = " + sm);
579-
System.setSecurityManager(new SecurityManager() {
580-
private boolean firstTime = true;
580+
try {
581+
System.setSecurityManager(new SecurityManager() {
582+
private boolean firstTime = true;
581583

582-
@Override
583-
public void checkPermission(Permission perm) {
584-
if (firstTime) {
585-
Thread t = Thread.currentThread();
586-
if (!t.toString().contains("DataNode")) {
587-
String s = "" + Arrays.asList(t.getStackTrace());
588-
if (s.contains("FileUtil.copyContent")) {
589-
//pause at FileUtil.copyContent
590-
591-
firstTime = false;
592-
copy2ndFileThread.start();
593-
try {Thread.sleep(5000);} catch (InterruptedException e) {}
584+
@Override
585+
public void checkPermission(Permission perm) {
586+
if (firstTime) {
587+
Thread t = Thread.currentThread();
588+
if (!t.toString().contains("DataNode")) {
589+
String s = "" + Arrays.asList(t.getStackTrace());
590+
if (s.contains("FileUtil.copyContent")) {
591+
//pause at FileUtil.copyContent
592+
593+
firstTime = false;
594+
copy2ndFileThread.start();
595+
try {Thread.sleep(5000);} catch (InterruptedException e) {}
596+
}
594597
}
595598
}
596599
}
597-
}
598-
});
600+
});
601+
} catch (UnsupportedOperationException e) {
602+
// Test is skipped because SecurityManager cannot be set (JEP411)
603+
// TODO add message when migrating to Junit 5
604+
assumeTrue(false);
605+
}
599606
show("copy local " + f1 + " to remote " + dst);
600607
dfs.copyFromLocalFile(false, false, new Path(f1.getPath()), dst);
601608
show("done");

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDatanodeRegistration.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.util.concurrent.TimeoutException;
4949

5050
import static org.junit.Assert.*;
51+
import static org.junit.Assume.assumeTrue;
5152
import static org.mockito.Mockito.doReturn;
5253
import static org.mockito.Mockito.mock;
5354

@@ -79,7 +80,13 @@ public void checkConnect(String host, int port) {
7980
@Test
8081
public void testDNSLookups() throws Exception {
8182
MonitorDNS sm = new MonitorDNS();
82-
System.setSecurityManager(sm);
83+
try {
84+
System.setSecurityManager(sm);
85+
} catch (UnsupportedOperationException e) {
86+
// Test is skipped because SecurityManager cannot be set (JEP411)
87+
// TODO add message when migrating to Junit 5
88+
assumeTrue(false);
89+
}
8390

8491
MiniDFSCluster cluster = null;
8592
try {

hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-jobclient/src/test/java/org/apache/hadoop/mapred/pipes/TestPipeApplication.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,6 @@ public void testSubmitter() throws Exception {
272272
Submitter.setJavaPartitioner(conf, partitioner.getClass());
273273

274274
assertEquals(PipesPartitioner.class, (Submitter.getJavaPartitioner(conf)));
275-
// test going to call main method with System.exit(). Change Security
276-
SecurityManager securityManager = System.getSecurityManager();
277275
// store System.out
278276
PrintStream oldps = System.out;
279277
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -330,8 +328,6 @@ public void testSubmitter() throws Exception {
330328
+ "archives to be unarchived on the compute machines"));
331329
} finally {
332330
System.setOut(oldps);
333-
// restore
334-
System.setSecurityManager(securityManager);
335331
if (psw != null) {
336332
// remove password files
337333
for (File file : psw) {
@@ -381,7 +377,6 @@ public void testSubmitter() throws Exception {
381377

382378
} finally {
383379
System.setOut(oldps);
384-
System.setSecurityManager(securityManager);
385380
}
386381

387382
}

hadoop-tools/hadoop-distcp/src/test/java/org/apache/hadoop/tools/TestExternalCall.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static org.junit.jupiter.api.Assertions.assertEquals;
3939
import static org.junit.jupiter.api.Assertions.assertTrue;
4040
import static org.junit.jupiter.api.Assertions.fail;
41+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
4142
import static org.mockito.Mockito.any;
4243
import static org.mockito.Mockito.anyBoolean;
4344
import static org.mockito.Mockito.doReturn;
@@ -66,7 +67,12 @@ private static Configuration getConf() {
6667
public void setup() {
6768

6869
securityManager = System.getSecurityManager();
69-
System.setSecurityManager(new NoExitSecurityManager());
70+
try {
71+
System.setSecurityManager(new NoExitSecurityManager());
72+
} catch (UnsupportedOperationException e) {
73+
assumeTrue(false,
74+
"Test is skipped because SecurityManager cannot be set (JEP411)");
75+
}
7076
try {
7177
fs = FileSystem.get(getConf());
7278
root = new Path("target/tmp").makeQualified(fs.getUri(),

hadoop-tools/hadoop-gridmix/src/test/java/org/apache/hadoop/mapred/gridmix/TestGridmixSubmission.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ public void testStressSubmit() throws Exception {
174174
@Test (timeout=100000)
175175
public void testMain() throws Exception {
176176

177-
SecurityManager securityManager = System.getSecurityManager();
178-
179177
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
180178
final PrintStream out = new PrintStream(bytes);
181179
final PrintStream oldOut = System.out;
@@ -190,7 +188,6 @@ public void testMain() throws Exception {
190188
ExitUtil.resetFirstExitException();
191189
} finally {
192190
System.setErr(oldOut);
193-
System.setSecurityManager(securityManager);
194191
}
195192
String print = bytes.toString();
196193
// should be printed tip in std error stream

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/TestCGroupsHandlerImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import static org.junit.jupiter.api.Assertions.assertFalse;
4747
import static org.junit.jupiter.api.Assertions.assertTrue;
4848
import static org.junit.jupiter.api.Assertions.fail;
49+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
4950
import static org.mockito.ArgumentMatchers.eq;
5051
import static org.mockito.Mockito.verify;
5152
import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -371,7 +372,12 @@ private void testPreMountedControllerInitialization(String myHierarchy)
371372
assertFalse(cpuCgroupMountDir.delete(), "Could not delete cgroups");
372373
assertFalse(cpuCgroupMountDir.exists(), "Directory should be deleted");
373374
SecurityManager manager = System.getSecurityManager();
374-
System.setSecurityManager(new MockSecurityManagerDenyWrite());
375+
try {
376+
System.setSecurityManager(new MockSecurityManagerDenyWrite());
377+
} catch (UnsupportedOperationException e) {
378+
assumeTrue(false,
379+
"Test is skipped because SecurityManager cannot be set (JEP411)");
380+
}
375381
try {
376382
cGroupsHandler.initializeCGroupController(
377383
CGroupsHandler.CGroupController.CPU);

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestCapacitySchedulerAsyncScheduling.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey;
6767
import org.apache.hadoop.yarn.util.resource.Resources;
6868
import org.junit.Assert;
69+
import org.junit.Assume;
6970
import org.junit.Before;
7071
import org.junit.Test;
7172
import org.junit.contrib.java.lang.system.internal.NoExitSecurityManager;
@@ -1090,7 +1091,13 @@ public void testAsyncScheduleThreadExit() throws Exception {
10901091
SecurityManager originalSecurityManager = System.getSecurityManager();
10911092
NoExitSecurityManager noExitSecurityManager =
10921093
new NoExitSecurityManager(originalSecurityManager);
1093-
System.setSecurityManager(noExitSecurityManager);
1094+
try {
1095+
System.setSecurityManager(noExitSecurityManager);
1096+
} catch (UnsupportedOperationException e) {
1097+
// Test is skipped because SecurityManager cannot be set (JEP411)
1098+
// TODO add message when migrating to Junit 5
1099+
Assume.assumeTrue(false);
1100+
}
10941101

10951102
// test async-scheduling thread exit
10961103
try{

0 commit comments

Comments
 (0)