Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions hadoop-hdfs-project/hadoop-hdfs-nfs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,36 @@ https://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>bcprov-jdk18on</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import org.apache.hadoop.hdfs.nfs.nfs3.Nfs3;
import org.apache.hadoop.hdfs.nfs.nfs3.RpcProgramNfs3;
import org.apache.hadoop.oncrpc.XDR;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TestMountd {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hdfs.nfs.nfs3;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
import java.net.InetSocketAddress;
Expand All @@ -36,11 +36,13 @@
import org.apache.hadoop.oncrpc.security.SecurityHandler;
import org.apache.hadoop.security.authorize.DefaultImpersonationProvider;
import org.apache.hadoop.security.authorize.ProxyUsers;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class TestClientAccessPrivilege {
static MiniDFSCluster cluster = null;
Expand All @@ -50,7 +52,7 @@ public class TestClientAccessPrivilege {
static String testdir = "/tmp";
static SecurityHandler securityHandler;

@BeforeClass
@BeforeAll
public static void setup() throws Exception {

String currentUser = System.getProperty("user.name");
Expand All @@ -68,26 +70,27 @@ public static void setup() throws Exception {
config.setInt("nfs3.mountd.port", 0);
config.setInt("nfs3.server.port", 0);

securityHandler = Mockito.mock(SecurityHandler.class);
Mockito.when(securityHandler.getUser()).thenReturn(
securityHandler = mock(SecurityHandler.class);
when(securityHandler.getUser()).thenReturn(
System.getProperty("user.name"));
}

@AfterClass
@AfterAll
public static void shutdown() throws Exception {
if (cluster != null) {
cluster.shutdown();
}
}

@Before
@BeforeEach
public void createFiles() throws IllegalArgumentException, IOException {
hdfs.delete(new Path(testdir), true);
hdfs.mkdirs(new Path(testdir));
DFSTestUtil.createFile(hdfs, new Path(testdir + "/f1"), 0, (short) 1, 0);
}

@Test(timeout = 60000)
@Test
@Timeout(value = 60)
public void testClientAccessPrivilegeForRemove() throws Exception {
// Configure ro access for nfs1 service
config.set("dfs.nfs.exports.allowed.hosts", "* ro");
Expand All @@ -113,9 +116,8 @@ public void testClientAccessPrivilegeForRemove() throws Exception {
securityHandler, new InetSocketAddress("localhost", 1234));

// Assert on return code
assertEquals("Incorrect return code", Nfs3Status.NFS3ERR_ACCES,
response.getStatus());

assertEquals(Nfs3Status.NFS3ERR_ACCES,
response.getStatus(), "Incorrect return code");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,22 @@
package org.apache.hadoop.hdfs.nfs.nfs3;

import static org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod.KERBEROS;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.hdfs.DFSClient;
import org.apache.hadoop.hdfs.nfs.conf.NfsConfiguration;
import org.apache.hadoop.security.UserGroupInformation;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

public class TestDFSClientCache {
@After
@AfterEach
public void cleanup() {
UserGroupInformation.reset();
}
Expand All @@ -58,8 +57,8 @@ public void testEviction() throws IOException {

cache.getDfsClient("test2", namenodeId);
assertTrue(isDfsClientClose(c1));
assertTrue("cache size should be the max size or less",
cache.getClientCache().size() <= MAX_CACHE_SIZE);
assertTrue(cache.getClientCache().size() <= MAX_CACHE_SIZE,
"cache size should be the max size or less");
}

@Test
Expand All @@ -79,11 +78,10 @@ public void testGetUserGroupInformationSecure() throws IOException {
UserGroupInformation ugiResult
= cache.getUserGroupInformation(userName, currentUserUgi);

assertThat(ugiResult.getUserName(), is(userName));
assertThat(ugiResult.getRealUser(), is(currentUserUgi));
assertThat(
ugiResult.getAuthenticationMethod(),
is(UserGroupInformation.AuthenticationMethod.PROXY));
assertThat(ugiResult.getUserName()).isEqualTo(userName);
assertThat(ugiResult.getRealUser()).isEqualTo(currentUserUgi);
assertThat(ugiResult.getAuthenticationMethod()).isEqualTo(
UserGroupInformation.AuthenticationMethod.PROXY);
}

@Test
Expand All @@ -99,11 +97,10 @@ public void testGetUserGroupInformation() throws IOException {
UserGroupInformation ugiResult
= cache.getUserGroupInformation(userName, currentUserUgi);

assertThat(ugiResult.getUserName(), is(userName));
assertThat(ugiResult.getRealUser(), is(currentUserUgi));
assertThat(
ugiResult.getAuthenticationMethod(),
is(UserGroupInformation.AuthenticationMethod.PROXY));
assertThat(ugiResult.getUserName()).isEqualTo(userName);
assertThat(ugiResult.getRealUser()).isEqualTo(currentUserUgi);
assertThat(ugiResult.getAuthenticationMethod()).isEqualTo(
UserGroupInformation.AuthenticationMethod.PROXY);
}

private static boolean isDfsClientClose(DFSClient c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
*/
package org.apache.hadoop.hdfs.nfs.nfs3;

import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.nio.file.FileSystemException;

Expand All @@ -34,15 +32,13 @@
import org.apache.hadoop.hdfs.nfs.conf.NfsConfiguration;
import org.apache.hadoop.hdfs.nfs.mount.Mountd;
import org.apache.hadoop.hdfs.nfs.mount.RpcProgramMountd;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TestExportsTable {

@Rule
public ExpectedException exception = ExpectedException.none();

@Test
public void testHdfsExportPoint() throws IOException {
NfsConfiguration config = new NfsConfiguration();
Expand Down Expand Up @@ -224,13 +220,13 @@ public void testViewFsRootExportPoint() throws IOException {
ConfigUtil.addLink(config, clusterName, "/hdfs2",
hdfs2.makeQualified(base2).toUri());

exception.expect(FileSystemException.class);
exception.
expectMessage("Only HDFS is supported as underlyingFileSystem, "
+ "fs scheme:viewfs");
// Start nfs
final Nfs3 nfsServer = new Nfs3(config);
nfsServer.startServiceInternal(false);
FileSystemException fileSystemException = assertThrows(FileSystemException.class, () -> {
// Start nfs
final Nfs3 nfsServer = new Nfs3(config);
nfsServer.startServiceInternal(false);
});
assertTrue(fileSystemException.getMessage().
contains("Only HDFS is supported as underlyingFileSystem, fs scheme:viewfs"));
} finally {
if (cluster != null) {
cluster.shutdown();
Expand Down Expand Up @@ -292,13 +288,14 @@ public void testInvalidFsExport() throws IOException {
config.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY,
FsConstants.LOCAL_FS_URI.toString());

exception.expect(FileSystemException.class);
exception.
expectMessage("Only HDFS is supported as underlyingFileSystem, "
+ "fs scheme:file");
// Start nfs
final Nfs3 nfsServer = new Nfs3(config);
nfsServer.startServiceInternal(false);
FileSystemException fileSystemException =
assertThrows(FileSystemException.class, () -> {
// Start nfs
final Nfs3 nfsServer = new Nfs3(config);
nfsServer.startServiceInternal(false);
});
assertTrue(fileSystemException.getMessage().
contains("Only HDFS is supported as underlyingFileSystem, fs scheme:file"));
} finally {
if (cluster != null) {
cluster.shutdown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hdfs.nfs.nfs3;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.net.URL;
Expand All @@ -31,9 +31,9 @@
import org.apache.hadoop.http.HttpConfig;
import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class TestNfs3HttpServer {
private static final String BASEDIR =
Expand All @@ -43,7 +43,7 @@ public class TestNfs3HttpServer {
private static String keystoresDir;
private static String sslConfDir;

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
conf.set(DFSConfigKeys.DFS_HTTP_POLICY_KEY,
HttpConfig.Policy.HTTP_AND_HTTPS.name());
Expand All @@ -64,7 +64,7 @@ public static void setUp() throws Exception {
cluster.waitActive();
}

@AfterClass
@AfterAll
public static void tearDown() throws Exception {
FileUtil.fullyDelete(new File(BASEDIR));
if (cluster != null) {
Expand All @@ -84,11 +84,11 @@ public void testHttpServer() throws Exception {

// Check default servlets.
String pageContents = DFSTestUtil.urlGet(new URL(urlRoot + "/jmx"));
assertTrue("Bad contents: " + pageContents,
pageContents.contains("java.lang:type="));
assertTrue(pageContents.contains("java.lang:type="),
"Bad contents: " + pageContents);
System.out.println("pc:" + pageContents);

int port = infoServer.getSecurePort();
assertTrue("Can't get https port", port > 0);
assertTrue(port > 0, "Can't get https port");
}
}
Loading