HDFS-3583. Convert remaining tests to Junit4. Contributed by Andrew Wang.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1363948 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Aaron Myers 2012-07-20 20:44:56 +00:00
parent 45c42817ca
commit 5d110e145e
239 changed files with 1894 additions and 1403 deletions

View File

@ -18,6 +18,18 @@
package org.apache.hadoop.fs.http.client; package org.apache.hadoop.fs.http.client;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
import java.net.URL;
import java.security.PrivilegedExceptionAction;
import java.util.Arrays;
import java.util.Collection;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic; import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.fs.ContentSummary; import org.apache.hadoop.fs.ContentSummary;
@ -44,18 +56,6 @@ import org.junit.runners.Parameterized;
import org.mortbay.jetty.Server; import org.mortbay.jetty.Server;
import org.mortbay.jetty.webapp.WebAppContext; import org.mortbay.jetty.webapp.WebAppContext;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
import java.net.URL;
import java.security.PrivilegedExceptionAction;
import java.util.Arrays;
import java.util.Collection;
@RunWith(value = Parameterized.class) @RunWith(value = Parameterized.class)
public class TestHttpFSFileSystem extends HFSTestCase { public class TestHttpFSFileSystem extends HFSTestCase {

View File

@ -18,6 +18,8 @@
package org.apache.hadoop.fs.http.client; package org.apache.hadoop.fs.http.client;
import java.net.URI;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.hdfs.web.WebHdfsFileSystem; import org.apache.hadoop.hdfs.web.WebHdfsFileSystem;
@ -26,8 +28,6 @@ import org.junit.Assert;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import java.net.URI;
@RunWith(value = Parameterized.class) @RunWith(value = Parameterized.class)
public class TestWebhdfsFileSystem extends TestHttpFSFileSystem { public class TestWebhdfsFileSystem extends TestHttpFSFileSystem {

View File

@ -18,15 +18,15 @@
package org.apache.hadoop.fs.http.server; package org.apache.hadoop.fs.http.server;
import org.apache.hadoop.fs.http.client.HttpFSFileSystem;
import org.junit.Test;
import org.mockito.Mockito;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.hadoop.fs.http.client.HttpFSFileSystem;
import org.junit.Test;
import org.mockito.Mockito;
public class TestCheckUploadContentTypeFilter { public class TestCheckUploadContentTypeFilter {
@Test @Test

View File

@ -18,7 +18,23 @@
package org.apache.hadoop.fs.http.server; package org.apache.hadoop.fs.http.server;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic; import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
@ -38,20 +54,6 @@ import org.junit.Test;
import org.mortbay.jetty.Server; import org.mortbay.jetty.Server;
import org.mortbay.jetty.webapp.WebAppContext; import org.mortbay.jetty.webapp.WebAppContext;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;
public class TestHttpFSServer extends HFSTestCase { public class TestHttpFSServer extends HFSTestCase {
@Test @Test
@ -103,9 +105,9 @@ public class TestHttpFSServer extends HFSTestCase {
} }
private void createHttpFSServer() throws Exception { private void createHttpFSServer() throws Exception {
File homeDir = TestDirHelper.getTestDir(); File homeDir = TestDirHelper.getTestDir();
Assert.assertTrue(new File(homeDir, "conf").mkdir()); assertTrue(new File(homeDir, "conf").mkdir());
Assert.assertTrue(new File(homeDir, "log").mkdir()); assertTrue(new File(homeDir, "log").mkdir());
Assert.assertTrue(new File(homeDir, "temp").mkdir()); assertTrue(new File(homeDir, "temp").mkdir());
HttpFSServerWebApp.setHomeDirForCurrentThread(homeDir.getAbsolutePath()); HttpFSServerWebApp.setHomeDirForCurrentThread(homeDir.getAbsolutePath());
File secretFile = new File(new File(homeDir, "conf"), "secret"); File secretFile = new File(new File(homeDir, "conf"), "secret");
@ -157,23 +159,23 @@ public class TestHttpFSServer extends HFSTestCase {
URL url = new URL(TestJettyHelper.getJettyURL(), URL url = new URL(TestJettyHelper.getJettyURL(),
MessageFormat.format("/webhdfs/v1?user.name={0}&op=instrumentation", "nobody")); MessageFormat.format("/webhdfs/v1?user.name={0}&op=instrumentation", "nobody"));
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_UNAUTHORIZED); assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_UNAUTHORIZED);
url = new URL(TestJettyHelper.getJettyURL(), url = new URL(TestJettyHelper.getJettyURL(),
MessageFormat.format("/webhdfs/v1?user.name={0}&op=instrumentation", MessageFormat.format("/webhdfs/v1?user.name={0}&op=instrumentation",
HadoopUsersConfTestHelper.getHadoopUsers()[0])); HadoopUsersConfTestHelper.getHadoopUsers()[0]));
conn = (HttpURLConnection) url.openConnection(); conn = (HttpURLConnection) url.openConnection();
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK); assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = reader.readLine(); String line = reader.readLine();
reader.close(); reader.close();
Assert.assertTrue(line.contains("\"counters\":{")); assertTrue(line.contains("\"counters\":{"));
url = new URL(TestJettyHelper.getJettyURL(), url = new URL(TestJettyHelper.getJettyURL(),
MessageFormat.format("/webhdfs/v1/foo?user.name={0}&op=instrumentation", MessageFormat.format("/webhdfs/v1/foo?user.name={0}&op=instrumentation",
HadoopUsersConfTestHelper.getHadoopUsers()[0])); HadoopUsersConfTestHelper.getHadoopUsers()[0]));
conn = (HttpURLConnection) url.openConnection(); conn = (HttpURLConnection) url.openConnection();
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_BAD_REQUEST); assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_BAD_REQUEST);
} }
@Test @Test
@ -187,7 +189,7 @@ public class TestHttpFSServer extends HFSTestCase {
URL url = new URL(TestJettyHelper.getJettyURL(), URL url = new URL(TestJettyHelper.getJettyURL(),
MessageFormat.format("/webhdfs/v1/?user.name={0}&op=liststatus", user)); MessageFormat.format("/webhdfs/v1/?user.name={0}&op=liststatus", user));
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK); assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
reader.readLine(); reader.readLine();
reader.close(); reader.close();
@ -208,7 +210,7 @@ public class TestHttpFSServer extends HFSTestCase {
URL url = new URL(TestJettyHelper.getJettyURL(), URL url = new URL(TestJettyHelper.getJettyURL(),
MessageFormat.format("/webhdfs/v1/tmp?user.name={0}&op=liststatus&filter=f*", user)); MessageFormat.format("/webhdfs/v1/tmp?user.name={0}&op=liststatus&filter=f*", user));
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK); assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
reader.readLine(); reader.readLine();
reader.close(); reader.close();
@ -228,7 +230,7 @@ public class TestHttpFSServer extends HFSTestCase {
conn.setDoInput(true); conn.setDoInput(true);
conn.setDoOutput(true); conn.setDoOutput(true);
conn.setRequestMethod("PUT"); conn.setRequestMethod("PUT");
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_BAD_REQUEST); assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_BAD_REQUEST);
} }
} }

View File

@ -19,12 +19,14 @@
package org.apache.hadoop.lib.lang; package org.apache.hadoop.lib.lang;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import org.apache.hadoop.test.HTestCase; import static org.junit.Assert.assertTrue;
import org.junit.Test;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import org.apache.hadoop.test.HTestCase;
import org.junit.Test;
public class TestRunnableCallable extends HTestCase { public class TestRunnableCallable extends HTestCase {
public static class R implements Runnable { public static class R implements Runnable {
@ -59,14 +61,14 @@ public class TestRunnableCallable extends HTestCase {
R r = new R(); R r = new R();
RunnableCallable rc = new RunnableCallable(r); RunnableCallable rc = new RunnableCallable(r);
rc.run(); rc.run();
Assert.assertTrue(r.RUN); assertTrue(r.RUN);
r = new R(); r = new R();
rc = new RunnableCallable(r); rc = new RunnableCallable(r);
rc.call(); rc.call();
Assert.assertTrue(r.RUN); assertTrue(r.RUN);
Assert.assertEquals(rc.toString(), "R"); assertEquals(rc.toString(), "R");
} }
@Test @Test
@ -74,14 +76,14 @@ public class TestRunnableCallable extends HTestCase {
C c = new C(); C c = new C();
RunnableCallable rc = new RunnableCallable(c); RunnableCallable rc = new RunnableCallable(c);
rc.run(); rc.run();
Assert.assertTrue(c.RUN); assertTrue(c.RUN);
c = new C(); c = new C();
rc = new RunnableCallable(c); rc = new RunnableCallable(c);
rc.call(); rc.call();
Assert.assertTrue(c.RUN); assertTrue(c.RUN);
Assert.assertEquals(rc.toString(), "C"); assertEquals(rc.toString(), "C");
} }
@Test(expected = RuntimeException.class) @Test(expected = RuntimeException.class)

View File

@ -19,7 +19,9 @@
package org.apache.hadoop.lib.lang; package org.apache.hadoop.lib.lang;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.apache.hadoop.test.HTestCase; import org.apache.hadoop.test.HTestCase;
import org.junit.Test; import org.junit.Test;
@ -37,26 +39,26 @@ public class TestXException extends HTestCase {
@Test @Test
public void testXException() throws Exception { public void testXException() throws Exception {
XException ex = new XException(TestERROR.TC); XException ex = new XException(TestERROR.TC);
Assert.assertEquals(ex.getError(), TestERROR.TC); assertEquals(ex.getError(), TestERROR.TC);
Assert.assertEquals(ex.getMessage(), "TC: {0}"); assertEquals(ex.getMessage(), "TC: {0}");
Assert.assertNull(ex.getCause()); assertNull(ex.getCause());
ex = new XException(TestERROR.TC, "msg"); ex = new XException(TestERROR.TC, "msg");
Assert.assertEquals(ex.getError(), TestERROR.TC); assertEquals(ex.getError(), TestERROR.TC);
Assert.assertEquals(ex.getMessage(), "TC: msg"); assertEquals(ex.getMessage(), "TC: msg");
Assert.assertNull(ex.getCause()); assertNull(ex.getCause());
Exception cause = new Exception(); Exception cause = new Exception();
ex = new XException(TestERROR.TC, cause); ex = new XException(TestERROR.TC, cause);
Assert.assertEquals(ex.getError(), TestERROR.TC); assertEquals(ex.getError(), TestERROR.TC);
Assert.assertEquals(ex.getMessage(), "TC: " + cause.toString()); assertEquals(ex.getMessage(), "TC: " + cause.toString());
Assert.assertEquals(ex.getCause(), cause); assertEquals(ex.getCause(), cause);
XException xcause = ex; XException xcause = ex;
ex = new XException(xcause); ex = new XException(xcause);
Assert.assertEquals(ex.getError(), TestERROR.TC); assertEquals(ex.getError(), TestERROR.TC);
Assert.assertEquals(ex.getMessage(), xcause.getMessage()); assertEquals(ex.getMessage(), xcause.getMessage());
Assert.assertEquals(ex.getCause(), xcause); assertEquals(ex.getCause(), xcause);
} }
} }

View File

@ -18,7 +18,10 @@
package org.apache.hadoop.lib.server; package org.apache.hadoop.lib.server;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.HTestCase; import org.apache.hadoop.test.HTestCase;
import org.junit.Test; import org.junit.Test;
@ -47,9 +50,9 @@ public class TestBaseService extends HTestCase {
@Test @Test
public void baseService() throws Exception { public void baseService() throws Exception {
BaseService service = new MyService(); BaseService service = new MyService();
Assert.assertNull(service.getInterface()); assertNull(service.getInterface());
Assert.assertEquals(service.getPrefix(), "myservice"); assertEquals(service.getPrefix(), "myservice");
Assert.assertEquals(service.getServiceDependencies().length, 0); assertEquals(service.getServiceDependencies().length, 0);
Server server = Mockito.mock(Server.class); Server server = Mockito.mock(Server.class);
Configuration conf = new Configuration(false); Configuration conf = new Configuration(false);
@ -60,9 +63,9 @@ public class TestBaseService extends HTestCase {
Mockito.when(server.getPrefixedName("myservice.")).thenReturn("server.myservice."); Mockito.when(server.getPrefixedName("myservice.")).thenReturn("server.myservice.");
service.init(server); service.init(server);
Assert.assertEquals(service.getPrefixedName("foo"), "server.myservice.foo"); assertEquals(service.getPrefixedName("foo"), "server.myservice.foo");
Assert.assertEquals(service.getServiceConfig().size(), 1); assertEquals(service.getServiceConfig().size(), 1);
Assert.assertEquals(service.getServiceConfig().get("foo"), "FOO"); assertEquals(service.getServiceConfig().get("foo"), "FOO");
Assert.assertTrue(MyService.INIT); assertTrue(MyService.INIT);
} }
} }

View File

@ -18,16 +18,12 @@
package org.apache.hadoop.lib.server; package org.apache.hadoop.lib.server;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import org.apache.hadoop.conf.Configuration; import static org.junit.Assert.assertFalse;
import org.apache.hadoop.io.IOUtils; import static org.junit.Assert.assertNotNull;
import org.apache.hadoop.lib.lang.XException; import static org.junit.Assert.assertNull;
import org.apache.hadoop.test.HTestCase; import static org.junit.Assert.assertTrue;
import org.apache.hadoop.test.TestDir; import static org.junit.Assert.fail;
import org.apache.hadoop.test.TestDirHelper;
import org.apache.hadoop.test.TestException;
import org.apache.hadoop.util.StringUtils;
import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -39,50 +35,60 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.lib.lang.XException;
import org.apache.hadoop.test.HTestCase;
import org.apache.hadoop.test.TestDir;
import org.apache.hadoop.test.TestDirHelper;
import org.apache.hadoop.test.TestException;
import org.apache.hadoop.util.StringUtils;
import org.junit.Test;
public class TestServer extends HTestCase { public class TestServer extends HTestCase {
@Test @Test
@TestDir @TestDir
public void constructorsGetters() throws Exception { public void constructorsGetters() throws Exception {
Server server = new Server("server", "/a", "/b", "/c", "/d", new Configuration(false)); Server server = new Server("server", "/a", "/b", "/c", "/d", new Configuration(false));
Assert.assertEquals(server.getHomeDir(), "/a"); assertEquals(server.getHomeDir(), "/a");
Assert.assertEquals(server.getConfigDir(), "/b"); assertEquals(server.getConfigDir(), "/b");
Assert.assertEquals(server.getLogDir(), "/c"); assertEquals(server.getLogDir(), "/c");
Assert.assertEquals(server.getTempDir(), "/d"); assertEquals(server.getTempDir(), "/d");
Assert.assertEquals(server.getName(), "server"); assertEquals(server.getName(), "server");
Assert.assertEquals(server.getPrefix(), "server"); assertEquals(server.getPrefix(), "server");
Assert.assertEquals(server.getPrefixedName("name"), "server.name"); assertEquals(server.getPrefixedName("name"), "server.name");
Assert.assertNotNull(server.getConfig()); assertNotNull(server.getConfig());
server = new Server("server", "/a", "/b", "/c", "/d"); server = new Server("server", "/a", "/b", "/c", "/d");
Assert.assertEquals(server.getHomeDir(), "/a"); assertEquals(server.getHomeDir(), "/a");
Assert.assertEquals(server.getConfigDir(), "/b"); assertEquals(server.getConfigDir(), "/b");
Assert.assertEquals(server.getLogDir(), "/c"); assertEquals(server.getLogDir(), "/c");
Assert.assertEquals(server.getTempDir(), "/d"); assertEquals(server.getTempDir(), "/d");
Assert.assertEquals(server.getName(), "server"); assertEquals(server.getName(), "server");
Assert.assertEquals(server.getPrefix(), "server"); assertEquals(server.getPrefix(), "server");
Assert.assertEquals(server.getPrefixedName("name"), "server.name"); assertEquals(server.getPrefixedName("name"), "server.name");
Assert.assertNull(server.getConfig()); assertNull(server.getConfig());
server = new Server("server", TestDirHelper.getTestDir().getAbsolutePath(), new Configuration(false)); server = new Server("server", TestDirHelper.getTestDir().getAbsolutePath(), new Configuration(false));
Assert.assertEquals(server.getHomeDir(), TestDirHelper.getTestDir().getAbsolutePath()); assertEquals(server.getHomeDir(), TestDirHelper.getTestDir().getAbsolutePath());
Assert.assertEquals(server.getConfigDir(), TestDirHelper.getTestDir() + "/conf"); assertEquals(server.getConfigDir(), TestDirHelper.getTestDir() + "/conf");
Assert.assertEquals(server.getLogDir(), TestDirHelper.getTestDir() + "/log"); assertEquals(server.getLogDir(), TestDirHelper.getTestDir() + "/log");
Assert.assertEquals(server.getTempDir(), TestDirHelper.getTestDir() + "/temp"); assertEquals(server.getTempDir(), TestDirHelper.getTestDir() + "/temp");
Assert.assertEquals(server.getName(), "server"); assertEquals(server.getName(), "server");
Assert.assertEquals(server.getPrefix(), "server"); assertEquals(server.getPrefix(), "server");
Assert.assertEquals(server.getPrefixedName("name"), "server.name"); assertEquals(server.getPrefixedName("name"), "server.name");
Assert.assertNotNull(server.getConfig()); assertNotNull(server.getConfig());
server = new Server("server", TestDirHelper.getTestDir().getAbsolutePath()); server = new Server("server", TestDirHelper.getTestDir().getAbsolutePath());
Assert.assertEquals(server.getHomeDir(), TestDirHelper.getTestDir().getAbsolutePath()); assertEquals(server.getHomeDir(), TestDirHelper.getTestDir().getAbsolutePath());
Assert.assertEquals(server.getConfigDir(), TestDirHelper.getTestDir() + "/conf"); assertEquals(server.getConfigDir(), TestDirHelper.getTestDir() + "/conf");
Assert.assertEquals(server.getLogDir(), TestDirHelper.getTestDir() + "/log"); assertEquals(server.getLogDir(), TestDirHelper.getTestDir() + "/log");
Assert.assertEquals(server.getTempDir(), TestDirHelper.getTestDir() + "/temp"); assertEquals(server.getTempDir(), TestDirHelper.getTestDir() + "/temp");
Assert.assertEquals(server.getName(), "server"); assertEquals(server.getName(), "server");
Assert.assertEquals(server.getPrefix(), "server"); assertEquals(server.getPrefix(), "server");
Assert.assertEquals(server.getPrefixedName("name"), "server.name"); assertEquals(server.getPrefixedName("name"), "server.name");
Assert.assertNull(server.getConfig()); assertNull(server.getConfig());
} }
@Test @Test
@ -113,9 +119,9 @@ public class TestServer extends HTestCase {
@TestDir @TestDir
public void initNoConfigDir() throws Exception { public void initNoConfigDir() throws Exception {
File homeDir = new File(TestDirHelper.getTestDir(), "home"); File homeDir = new File(TestDirHelper.getTestDir(), "home");
Assert.assertTrue(homeDir.mkdir()); assertTrue(homeDir.mkdir());
Assert.assertTrue(new File(homeDir, "log").mkdir()); assertTrue(new File(homeDir, "log").mkdir());
Assert.assertTrue(new File(homeDir, "temp").mkdir()); assertTrue(new File(homeDir, "temp").mkdir());
Configuration conf = new Configuration(false); Configuration conf = new Configuration(false);
conf.set("server.services", TestService.class.getName()); conf.set("server.services", TestService.class.getName());
Server server = new Server("server", homeDir.getAbsolutePath(), conf); Server server = new Server("server", homeDir.getAbsolutePath(), conf);
@ -127,9 +133,9 @@ public class TestServer extends HTestCase {
@TestDir @TestDir
public void initConfigDirNotDir() throws Exception { public void initConfigDirNotDir() throws Exception {
File homeDir = new File(TestDirHelper.getTestDir(), "home"); File homeDir = new File(TestDirHelper.getTestDir(), "home");
Assert.assertTrue(homeDir.mkdir()); assertTrue(homeDir.mkdir());
Assert.assertTrue(new File(homeDir, "log").mkdir()); assertTrue(new File(homeDir, "log").mkdir());
Assert.assertTrue(new File(homeDir, "temp").mkdir()); assertTrue(new File(homeDir, "temp").mkdir());
File configDir = new File(homeDir, "conf"); File configDir = new File(homeDir, "conf");
new FileOutputStream(configDir).close(); new FileOutputStream(configDir).close();
Configuration conf = new Configuration(false); Configuration conf = new Configuration(false);
@ -143,9 +149,9 @@ public class TestServer extends HTestCase {
@TestDir @TestDir
public void initNoLogDir() throws Exception { public void initNoLogDir() throws Exception {
File homeDir = new File(TestDirHelper.getTestDir(), "home"); File homeDir = new File(TestDirHelper.getTestDir(), "home");
Assert.assertTrue(homeDir.mkdir()); assertTrue(homeDir.mkdir());
Assert.assertTrue(new File(homeDir, "conf").mkdir()); assertTrue(new File(homeDir, "conf").mkdir());
Assert.assertTrue(new File(homeDir, "temp").mkdir()); assertTrue(new File(homeDir, "temp").mkdir());
Configuration conf = new Configuration(false); Configuration conf = new Configuration(false);
conf.set("server.services", TestService.class.getName()); conf.set("server.services", TestService.class.getName());
Server server = new Server("server", homeDir.getAbsolutePath(), conf); Server server = new Server("server", homeDir.getAbsolutePath(), conf);
@ -157,9 +163,9 @@ public class TestServer extends HTestCase {
@TestDir @TestDir
public void initLogDirNotDir() throws Exception { public void initLogDirNotDir() throws Exception {
File homeDir = new File(TestDirHelper.getTestDir(), "home"); File homeDir = new File(TestDirHelper.getTestDir(), "home");
Assert.assertTrue(homeDir.mkdir()); assertTrue(homeDir.mkdir());
Assert.assertTrue(new File(homeDir, "conf").mkdir()); assertTrue(new File(homeDir, "conf").mkdir());
Assert.assertTrue(new File(homeDir, "temp").mkdir()); assertTrue(new File(homeDir, "temp").mkdir());
File logDir = new File(homeDir, "log"); File logDir = new File(homeDir, "log");
new FileOutputStream(logDir).close(); new FileOutputStream(logDir).close();
Configuration conf = new Configuration(false); Configuration conf = new Configuration(false);
@ -173,9 +179,9 @@ public class TestServer extends HTestCase {
@TestDir @TestDir
public void initNoTempDir() throws Exception { public void initNoTempDir() throws Exception {
File homeDir = new File(TestDirHelper.getTestDir(), "home"); File homeDir = new File(TestDirHelper.getTestDir(), "home");
Assert.assertTrue(homeDir.mkdir()); assertTrue(homeDir.mkdir());
Assert.assertTrue(new File(homeDir, "conf").mkdir()); assertTrue(new File(homeDir, "conf").mkdir());
Assert.assertTrue(new File(homeDir, "log").mkdir()); assertTrue(new File(homeDir, "log").mkdir());
Configuration conf = new Configuration(false); Configuration conf = new Configuration(false);
conf.set("server.services", TestService.class.getName()); conf.set("server.services", TestService.class.getName());
Server server = new Server("server", homeDir.getAbsolutePath(), conf); Server server = new Server("server", homeDir.getAbsolutePath(), conf);
@ -187,9 +193,9 @@ public class TestServer extends HTestCase {
@TestDir @TestDir
public void initTempDirNotDir() throws Exception { public void initTempDirNotDir() throws Exception {
File homeDir = new File(TestDirHelper.getTestDir(), "home"); File homeDir = new File(TestDirHelper.getTestDir(), "home");
Assert.assertTrue(homeDir.mkdir()); assertTrue(homeDir.mkdir());
Assert.assertTrue(new File(homeDir, "conf").mkdir()); assertTrue(new File(homeDir, "conf").mkdir());
Assert.assertTrue(new File(homeDir, "log").mkdir()); assertTrue(new File(homeDir, "log").mkdir());
File tempDir = new File(homeDir, "temp"); File tempDir = new File(homeDir, "temp");
new FileOutputStream(tempDir).close(); new FileOutputStream(tempDir).close();
Configuration conf = new Configuration(false); Configuration conf = new Configuration(false);
@ -204,7 +210,7 @@ public class TestServer extends HTestCase {
public void siteFileNotAFile() throws Exception { public void siteFileNotAFile() throws Exception {
String homeDir = TestDirHelper.getTestDir().getAbsolutePath(); String homeDir = TestDirHelper.getTestDir().getAbsolutePath();
File siteFile = new File(homeDir, "server-site.xml"); File siteFile = new File(homeDir, "server-site.xml");
Assert.assertTrue(siteFile.mkdir()); assertTrue(siteFile.mkdir());
Server server = new Server("server", homeDir, homeDir, homeDir, homeDir); Server server = new Server("server", homeDir, homeDir, homeDir, homeDir);
server.init(); server.init();
} }
@ -234,12 +240,12 @@ public class TestServer extends HTestCase {
@Override @Override
protected void init() throws ServiceException { protected void init() throws ServiceException {
Assert.assertEquals(getServer().getStatus(), Server.Status.BOOTING); assertEquals(getServer().getStatus(), Server.Status.BOOTING);
} }
@Override @Override
public void destroy() { public void destroy() {
Assert.assertEquals(getServer().getStatus(), Server.Status.SHUTTING_DOWN); assertEquals(getServer().getStatus(), Server.Status.SHUTTING_DOWN);
super.destroy(); super.destroy();
} }
@ -255,12 +261,12 @@ public class TestServer extends HTestCase {
Configuration conf = new Configuration(false); Configuration conf = new Configuration(false);
conf.set("server.services", LifeCycleService.class.getName()); conf.set("server.services", LifeCycleService.class.getName());
Server server = createServer(conf); Server server = createServer(conf);
Assert.assertEquals(server.getStatus(), Server.Status.UNDEF); assertEquals(server.getStatus(), Server.Status.UNDEF);
server.init(); server.init();
Assert.assertNotNull(server.get(LifeCycleService.class)); assertNotNull(server.get(LifeCycleService.class));
Assert.assertEquals(server.getStatus(), Server.Status.NORMAL); assertEquals(server.getStatus(), Server.Status.NORMAL);
server.destroy(); server.destroy();
Assert.assertEquals(server.getStatus(), Server.Status.SHUTDOWN); assertEquals(server.getStatus(), Server.Status.SHUTDOWN);
} }
@Test @Test
@ -270,7 +276,7 @@ public class TestServer extends HTestCase {
conf.set("server.startup.status", "ADMIN"); conf.set("server.startup.status", "ADMIN");
Server server = createServer(conf); Server server = createServer(conf);
server.init(); server.init();
Assert.assertEquals(server.getStatus(), Server.Status.ADMIN); assertEquals(server.getStatus(), Server.Status.ADMIN);
server.destroy(); server.destroy();
} }
@ -334,7 +340,7 @@ public class TestServer extends HTestCase {
Server server = createServer(conf); Server server = createServer(conf);
server.init(); server.init();
server.setStatus(Server.Status.ADMIN); server.setStatus(Server.Status.ADMIN);
Assert.assertTrue(TestService.LIFECYCLE.contains("serverStatusChange")); assertTrue(TestService.LIFECYCLE.contains("serverStatusChange"));
} }
@Test @Test
@ -357,7 +363,7 @@ public class TestServer extends HTestCase {
server.init(); server.init();
TestService.LIFECYCLE.clear(); TestService.LIFECYCLE.clear();
server.setStatus(server.getStatus()); server.setStatus(server.getStatus());
Assert.assertFalse(TestService.LIFECYCLE.contains("serverStatusChange")); assertFalse(TestService.LIFECYCLE.contains("serverStatusChange"));
} }
@Test @Test
@ -368,9 +374,9 @@ public class TestServer extends HTestCase {
conf.set("server.services", TestService.class.getName()); conf.set("server.services", TestService.class.getName());
Server server = createServer(conf); Server server = createServer(conf);
server.init(); server.init();
Assert.assertNotNull(server.get(TestService.class)); assertNotNull(server.get(TestService.class));
server.destroy(); server.destroy();
Assert.assertEquals(TestService.LIFECYCLE, Arrays.asList("init", "postInit", "serverStatusChange", "destroy")); assertEquals(TestService.LIFECYCLE, Arrays.asList("init", "postInit", "serverStatusChange", "destroy"));
} }
@Test @Test
@ -379,7 +385,7 @@ public class TestServer extends HTestCase {
String dir = TestDirHelper.getTestDir().getAbsolutePath(); String dir = TestDirHelper.getTestDir().getAbsolutePath();
Server server = new Server("testserver", dir, dir, dir, dir); Server server = new Server("testserver", dir, dir, dir, dir);
server.init(); server.init();
Assert.assertEquals(server.getConfig().get("testserver.a"), "default"); assertEquals(server.getConfig().get("testserver.a"), "default");
} }
@Test @Test
@ -392,7 +398,7 @@ public class TestServer extends HTestCase {
w.close(); w.close();
Server server = new Server("testserver", dir, dir, dir, dir); Server server = new Server("testserver", dir, dir, dir, dir);
server.init(); server.init();
Assert.assertEquals(server.getConfig().get("testserver.a"), "site"); assertEquals(server.getConfig().get("testserver.a"), "site");
} }
@Test @Test
@ -407,7 +413,7 @@ public class TestServer extends HTestCase {
w.close(); w.close();
Server server = new Server("testserver", dir, dir, dir, dir); Server server = new Server("testserver", dir, dir, dir, dir);
server.init(); server.init();
Assert.assertEquals(server.getConfig().get("testserver.a"), "sysprop"); assertEquals(server.getConfig().get("testserver.a"), "sysprop");
} finally { } finally {
System.getProperties().remove("testserver.a"); System.getProperties().remove("testserver.a");
} }
@ -633,7 +639,7 @@ public class TestServer extends HTestCase {
conf = new Configuration(false); conf = new Configuration(false);
server = new Server("server", dir, dir, dir, dir, conf); server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
Assert.assertEquals(ORDER.size(), 0); assertEquals(ORDER.size(), 0);
// 2 services init/destroy // 2 services init/destroy
ORDER.clear(); ORDER.clear();
@ -643,17 +649,17 @@ public class TestServer extends HTestCase {
conf.set("server.services", services); conf.set("server.services", services);
server = new Server("server", dir, dir, dir, dir, conf); server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
Assert.assertEquals(server.get(MyService1.class).getInterface(), MyService1.class); assertEquals(server.get(MyService1.class).getInterface(), MyService1.class);
Assert.assertEquals(server.get(MyService3.class).getInterface(), MyService3.class); assertEquals(server.get(MyService3.class).getInterface(), MyService3.class);
Assert.assertEquals(ORDER.size(), 4); assertEquals(ORDER.size(), 4);
Assert.assertEquals(ORDER.get(0), "s1.init"); assertEquals(ORDER.get(0), "s1.init");
Assert.assertEquals(ORDER.get(1), "s3.init"); assertEquals(ORDER.get(1), "s3.init");
Assert.assertEquals(ORDER.get(2), "s1.postInit"); assertEquals(ORDER.get(2), "s1.postInit");
Assert.assertEquals(ORDER.get(3), "s3.postInit"); assertEquals(ORDER.get(3), "s3.postInit");
server.destroy(); server.destroy();
Assert.assertEquals(ORDER.size(), 6); assertEquals(ORDER.size(), 6);
Assert.assertEquals(ORDER.get(4), "s3.destroy"); assertEquals(ORDER.get(4), "s3.destroy");
Assert.assertEquals(ORDER.get(5), "s1.destroy"); assertEquals(ORDER.get(5), "s1.destroy");
// 3 services, 2nd one fails on init // 3 services, 2nd one fails on init
ORDER.clear(); ORDER.clear();
@ -665,16 +671,16 @@ public class TestServer extends HTestCase {
server = new Server("server", dir, dir, dir, dir, conf); server = new Server("server", dir, dir, dir, dir, conf);
try { try {
server.init(); server.init();
Assert.fail(); fail();
} catch (ServerException ex) { } catch (ServerException ex) {
Assert.assertEquals(MyService2.class, ex.getError().getClass()); assertEquals(MyService2.class, ex.getError().getClass());
} catch (Exception ex) { } catch (Exception ex) {
Assert.fail(); fail();
} }
Assert.assertEquals(ORDER.size(), 3); assertEquals(ORDER.size(), 3);
Assert.assertEquals(ORDER.get(0), "s1.init"); assertEquals(ORDER.get(0), "s1.init");
Assert.assertEquals(ORDER.get(1), "s2.init"); assertEquals(ORDER.get(1), "s2.init");
Assert.assertEquals(ORDER.get(2), "s1.destroy"); assertEquals(ORDER.get(2), "s1.destroy");
// 2 services one fails on destroy // 2 services one fails on destroy
ORDER.clear(); ORDER.clear();
@ -683,15 +689,15 @@ public class TestServer extends HTestCase {
conf.set("server.services", services); conf.set("server.services", services);
server = new Server("server", dir, dir, dir, dir, conf); server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
Assert.assertEquals(ORDER.size(), 4); assertEquals(ORDER.size(), 4);
Assert.assertEquals(ORDER.get(0), "s1.init"); assertEquals(ORDER.get(0), "s1.init");
Assert.assertEquals(ORDER.get(1), "s5.init"); assertEquals(ORDER.get(1), "s5.init");
Assert.assertEquals(ORDER.get(2), "s1.postInit"); assertEquals(ORDER.get(2), "s1.postInit");
Assert.assertEquals(ORDER.get(3), "s5.postInit"); assertEquals(ORDER.get(3), "s5.postInit");
server.destroy(); server.destroy();
Assert.assertEquals(ORDER.size(), 6); assertEquals(ORDER.size(), 6);
Assert.assertEquals(ORDER.get(4), "s5.destroy"); assertEquals(ORDER.get(4), "s5.destroy");
Assert.assertEquals(ORDER.get(5), "s1.destroy"); assertEquals(ORDER.get(5), "s1.destroy");
// service override via ext // service override via ext
@ -705,16 +711,16 @@ public class TestServer extends HTestCase {
server = new Server("server", dir, dir, dir, dir, conf); server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
Assert.assertEquals(server.get(MyService1.class).getClass(), MyService1a.class); assertEquals(server.get(MyService1.class).getClass(), MyService1a.class);
Assert.assertEquals(ORDER.size(), 4); assertEquals(ORDER.size(), 4);
Assert.assertEquals(ORDER.get(0), "s1a.init"); assertEquals(ORDER.get(0), "s1a.init");
Assert.assertEquals(ORDER.get(1), "s3.init"); assertEquals(ORDER.get(1), "s3.init");
Assert.assertEquals(ORDER.get(2), "s1a.postInit"); assertEquals(ORDER.get(2), "s1a.postInit");
Assert.assertEquals(ORDER.get(3), "s3.postInit"); assertEquals(ORDER.get(3), "s3.postInit");
server.destroy(); server.destroy();
Assert.assertEquals(ORDER.size(), 6); assertEquals(ORDER.size(), 6);
Assert.assertEquals(ORDER.get(4), "s3.destroy"); assertEquals(ORDER.get(4), "s3.destroy");
Assert.assertEquals(ORDER.get(5), "s1a.destroy"); assertEquals(ORDER.get(5), "s1a.destroy");
// service override via setService // service override via setService
ORDER.clear(); ORDER.clear();
@ -725,16 +731,16 @@ public class TestServer extends HTestCase {
server.init(); server.init();
server.setService(MyService1a.class); server.setService(MyService1a.class);
Assert.assertEquals(ORDER.size(), 6); assertEquals(ORDER.size(), 6);
Assert.assertEquals(ORDER.get(4), "s1.destroy"); assertEquals(ORDER.get(4), "s1.destroy");
Assert.assertEquals(ORDER.get(5), "s1a.init"); assertEquals(ORDER.get(5), "s1a.init");
Assert.assertEquals(server.get(MyService1.class).getClass(), MyService1a.class); assertEquals(server.get(MyService1.class).getClass(), MyService1a.class);
server.destroy(); server.destroy();
Assert.assertEquals(ORDER.size(), 8); assertEquals(ORDER.size(), 8);
Assert.assertEquals(ORDER.get(6), "s3.destroy"); assertEquals(ORDER.get(6), "s3.destroy");
Assert.assertEquals(ORDER.get(7), "s1a.destroy"); assertEquals(ORDER.get(7), "s1a.destroy");
// service add via setService // service add via setService
ORDER.clear(); ORDER.clear();
@ -745,16 +751,16 @@ public class TestServer extends HTestCase {
server.init(); server.init();
server.setService(MyService5.class); server.setService(MyService5.class);
Assert.assertEquals(ORDER.size(), 5); assertEquals(ORDER.size(), 5);
Assert.assertEquals(ORDER.get(4), "s5.init"); assertEquals(ORDER.get(4), "s5.init");
Assert.assertEquals(server.get(MyService5.class).getClass(), MyService5.class); assertEquals(server.get(MyService5.class).getClass(), MyService5.class);
server.destroy(); server.destroy();
Assert.assertEquals(ORDER.size(), 8); assertEquals(ORDER.size(), 8);
Assert.assertEquals(ORDER.get(5), "s5.destroy"); assertEquals(ORDER.get(5), "s5.destroy");
Assert.assertEquals(ORDER.get(6), "s3.destroy"); assertEquals(ORDER.get(6), "s3.destroy");
Assert.assertEquals(ORDER.get(7), "s1.destroy"); assertEquals(ORDER.get(7), "s1.destroy");
// service add via setService exception // service add via setService exception
ORDER.clear(); ORDER.clear();
@ -765,15 +771,15 @@ public class TestServer extends HTestCase {
server.init(); server.init();
try { try {
server.setService(MyService7.class); server.setService(MyService7.class);
Assert.fail(); fail();
} catch (ServerException ex) { } catch (ServerException ex) {
Assert.assertEquals(ServerException.ERROR.S09, ex.getError()); assertEquals(ServerException.ERROR.S09, ex.getError());
} catch (Exception ex) { } catch (Exception ex) {
Assert.fail(); fail();
} }
Assert.assertEquals(ORDER.size(), 6); assertEquals(ORDER.size(), 6);
Assert.assertEquals(ORDER.get(4), "s3.destroy"); assertEquals(ORDER.get(4), "s3.destroy");
Assert.assertEquals(ORDER.get(5), "s1.destroy"); assertEquals(ORDER.get(5), "s1.destroy");
// service with dependency // service with dependency
ORDER.clear(); ORDER.clear();
@ -782,8 +788,8 @@ public class TestServer extends HTestCase {
conf.set("server.services", services); conf.set("server.services", services);
server = new Server("server", dir, dir, dir, dir, conf); server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
Assert.assertEquals(server.get(MyService1.class).getInterface(), MyService1.class); assertEquals(server.get(MyService1.class).getInterface(), MyService1.class);
Assert.assertEquals(server.get(MyService6.class).getInterface(), MyService6.class); assertEquals(server.get(MyService6.class).getInterface(), MyService6.class);
server.destroy(); server.destroy();
} }

View File

@ -18,15 +18,15 @@
package org.apache.hadoop.lib.server; package org.apache.hadoop.lib.server;
import java.util.Arrays;
import java.util.Collection;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.HTestCase; import org.apache.hadoop.test.HTestCase;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
@RunWith(value = Parameterized.class) @RunWith(value = Parameterized.class)
public class TestServerConstructor extends HTestCase { public class TestServerConstructor extends HTestCase {

View File

@ -18,7 +18,16 @@
package org.apache.hadoop.lib.service.hadoop; package org.apache.hadoop.lib.service.hadoop;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic; import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
@ -38,12 +47,6 @@ import org.apache.hadoop.util.StringUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
public class TestFileSystemAccessService extends HFSTestCase { public class TestFileSystemAccessService extends HFSTestCase {
private void createHadoopConf(Configuration hadoopConf) throws Exception { private void createHadoopConf(Configuration hadoopConf) throws Exception {
@ -71,7 +74,7 @@ public class TestFileSystemAccessService extends HFSTestCase {
conf.set("server.services", services); conf.set("server.services", services);
Server server = new Server("server", dir, dir, dir, dir, conf); Server server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
Assert.assertNotNull(server.get(FileSystemAccess.class)); assertNotNull(server.get(FileSystemAccess.class));
server.destroy(); server.destroy();
} }
@ -148,7 +151,7 @@ public class TestFileSystemAccessService extends HFSTestCase {
Server server = new Server("server", dir, dir, dir, dir, conf); Server server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
FileSystemAccessService fsAccess = (FileSystemAccessService) server.get(FileSystemAccess.class); FileSystemAccessService fsAccess = (FileSystemAccessService) server.get(FileSystemAccess.class);
Assert.assertEquals(fsAccess.serviceHadoopConf.get("foo"), "FOO"); assertEquals(fsAccess.serviceHadoopConf.get("foo"), "FOO");
server.destroy(); server.destroy();
} }
@ -174,7 +177,7 @@ public class TestFileSystemAccessService extends HFSTestCase {
Server server = new Server("server", dir, dir, dir, dir, conf); Server server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
FileSystemAccessService fsAccess = (FileSystemAccessService) server.get(FileSystemAccess.class); FileSystemAccessService fsAccess = (FileSystemAccessService) server.get(FileSystemAccess.class);
Assert.assertEquals(fsAccess.serviceHadoopConf.get("foo"), "BAR"); assertEquals(fsAccess.serviceHadoopConf.get("foo"), "BAR");
server.destroy(); server.destroy();
} }
@ -245,15 +248,15 @@ public class TestFileSystemAccessService extends HFSTestCase {
server.init(); server.init();
FileSystemAccess hadoop = server.get(FileSystemAccess.class); FileSystemAccess hadoop = server.get(FileSystemAccess.class);
FileSystem fs = hadoop.createFileSystem("u", hadoop.getFileSystemConfiguration()); FileSystem fs = hadoop.createFileSystem("u", hadoop.getFileSystemConfiguration());
Assert.assertNotNull(fs); assertNotNull(fs);
fs.mkdirs(new Path("/tmp/foo")); fs.mkdirs(new Path("/tmp/foo"));
hadoop.releaseFileSystem(fs); hadoop.releaseFileSystem(fs);
try { try {
fs.mkdirs(new Path("/tmp/foo")); fs.mkdirs(new Path("/tmp/foo"));
Assert.fail(); fail();
} catch (IOException ex) { } catch (IOException ex) {
} catch (Exception ex) { } catch (Exception ex) {
Assert.fail(); fail();
} }
server.destroy(); server.destroy();
} }
@ -288,10 +291,10 @@ public class TestFileSystemAccessService extends HFSTestCase {
}); });
try { try {
fsa[0].mkdirs(new Path("/tmp/foo")); fsa[0].mkdirs(new Path("/tmp/foo"));
Assert.fail(); fail();
} catch (IOException ex) { } catch (IOException ex) {
} catch (Exception ex) { } catch (Exception ex) {
Assert.fail(); fail();
} }
server.destroy(); server.destroy();
} }
@ -351,19 +354,19 @@ public class TestFileSystemAccessService extends HFSTestCase {
throw new IOException(); throw new IOException();
} }
}); });
Assert.fail(); fail();
} catch (FileSystemAccessException ex) { } catch (FileSystemAccessException ex) {
Assert.assertEquals(ex.getError(), FileSystemAccessException.ERROR.H03); assertEquals(ex.getError(), FileSystemAccessException.ERROR.H03);
} catch (Exception ex) { } catch (Exception ex) {
Assert.fail(); fail();
} }
try { try {
fsa[0].mkdirs(new Path("/tmp/foo")); fsa[0].mkdirs(new Path("/tmp/foo"));
Assert.fail(); fail();
} catch (IOException ex) { } catch (IOException ex) {
} catch (Exception ex) { } catch (Exception ex) {
Assert.fail(); fail();
} }
server.destroy(); server.destroy();
} }

View File

@ -18,7 +18,16 @@
package org.apache.hadoop.lib.service.instrumentation; package org.apache.hadoop.lib.service.instrumentation;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.lib.server.Server; import org.apache.hadoop.lib.server.Server;
import org.apache.hadoop.lib.service.Instrumentation; import org.apache.hadoop.lib.service.Instrumentation;
@ -32,11 +41,6 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser; import org.json.simple.parser.JSONParser;
import org.junit.Test; import org.junit.Test;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
public class TestInstrumentationService extends HTestCase { public class TestInstrumentationService extends HTestCase {
@Override @Override
@ -47,51 +51,51 @@ public class TestInstrumentationService extends HTestCase {
@Test @Test
public void cron() { public void cron() {
InstrumentationService.Cron cron = new InstrumentationService.Cron(); InstrumentationService.Cron cron = new InstrumentationService.Cron();
Assert.assertEquals(cron.start, 0); assertEquals(cron.start, 0);
Assert.assertEquals(cron.lapStart, 0); assertEquals(cron.lapStart, 0);
Assert.assertEquals(cron.own, 0); assertEquals(cron.own, 0);
Assert.assertEquals(cron.total, 0); assertEquals(cron.total, 0);
long begin = Time.now(); long begin = Time.now();
Assert.assertEquals(cron.start(), cron); assertEquals(cron.start(), cron);
Assert.assertEquals(cron.start(), cron); assertEquals(cron.start(), cron);
Assert.assertEquals(cron.start, begin, 20); assertEquals(cron.start, begin, 20);
Assert.assertEquals(cron.start, cron.lapStart); assertEquals(cron.start, cron.lapStart);
sleep(100); sleep(100);
Assert.assertEquals(cron.stop(), cron); assertEquals(cron.stop(), cron);
long end = Time.now(); long end = Time.now();
long delta = end - begin; long delta = end - begin;
Assert.assertEquals(cron.own, delta, 20); assertEquals(cron.own, delta, 20);
Assert.assertEquals(cron.total, 0); assertEquals(cron.total, 0);
Assert.assertEquals(cron.lapStart, 0); assertEquals(cron.lapStart, 0);
sleep(100); sleep(100);
long reStart = Time.now(); long reStart = Time.now();
cron.start(); cron.start();
Assert.assertEquals(cron.start, begin, 20); assertEquals(cron.start, begin, 20);
Assert.assertEquals(cron.lapStart, reStart, 20); assertEquals(cron.lapStart, reStart, 20);
sleep(100); sleep(100);
cron.stop(); cron.stop();
long reEnd = Time.now(); long reEnd = Time.now();
delta += reEnd - reStart; delta += reEnd - reStart;
Assert.assertEquals(cron.own, delta, 20); assertEquals(cron.own, delta, 20);
Assert.assertEquals(cron.total, 0); assertEquals(cron.total, 0);
Assert.assertEquals(cron.lapStart, 0); assertEquals(cron.lapStart, 0);
cron.end(); cron.end();
Assert.assertEquals(cron.total, reEnd - begin, 20); assertEquals(cron.total, reEnd - begin, 20);
try { try {
cron.start(); cron.start();
Assert.fail(); fail();
} catch (IllegalStateException ex) { } catch (IllegalStateException ex) {
} catch (Exception ex) { } catch (Exception ex) {
Assert.fail(); fail();
} }
try { try {
cron.stop(); cron.stop();
Assert.fail(); fail();
} catch (IllegalStateException ex) { } catch (IllegalStateException ex) {
} catch (Exception ex) { } catch (Exception ex) {
Assert.fail(); fail();
} }
} }
@ -135,10 +139,10 @@ public class TestInstrumentationService extends HTestCase {
timer.addCron(cron); timer.addCron(cron);
long[] values = timer.getValues(); long[] values = timer.getValues();
Assert.assertEquals(values[InstrumentationService.Timer.LAST_TOTAL], totalDelta, 20); assertEquals(values[InstrumentationService.Timer.LAST_TOTAL], totalDelta, 20);
Assert.assertEquals(values[InstrumentationService.Timer.LAST_OWN], ownDelta, 20); assertEquals(values[InstrumentationService.Timer.LAST_OWN], ownDelta, 20);
Assert.assertEquals(values[InstrumentationService.Timer.AVG_TOTAL], avgTotal, 20); assertEquals(values[InstrumentationService.Timer.AVG_TOTAL], avgTotal, 20);
Assert.assertEquals(values[InstrumentationService.Timer.AVG_OWN], avgOwn, 20); assertEquals(values[InstrumentationService.Timer.AVG_OWN], avgOwn, 20);
cron = new InstrumentationService.Cron(); cron = new InstrumentationService.Cron();
@ -168,10 +172,10 @@ public class TestInstrumentationService extends HTestCase {
timer.addCron(cron); timer.addCron(cron);
values = timer.getValues(); values = timer.getValues();
Assert.assertEquals(values[InstrumentationService.Timer.LAST_TOTAL], totalDelta, 20); assertEquals(values[InstrumentationService.Timer.LAST_TOTAL], totalDelta, 20);
Assert.assertEquals(values[InstrumentationService.Timer.LAST_OWN], ownDelta, 20); assertEquals(values[InstrumentationService.Timer.LAST_OWN], ownDelta, 20);
Assert.assertEquals(values[InstrumentationService.Timer.AVG_TOTAL], avgTotal, 20); assertEquals(values[InstrumentationService.Timer.AVG_TOTAL], avgTotal, 20);
Assert.assertEquals(values[InstrumentationService.Timer.AVG_OWN], avgOwn, 20); assertEquals(values[InstrumentationService.Timer.AVG_OWN], avgOwn, 20);
avgTotal = totalDelta; avgTotal = totalDelta;
avgOwn = ownDelta; avgOwn = ownDelta;
@ -205,27 +209,27 @@ public class TestInstrumentationService extends HTestCase {
cron.stop(); cron.stop();
timer.addCron(cron); timer.addCron(cron);
values = timer.getValues(); values = timer.getValues();
Assert.assertEquals(values[InstrumentationService.Timer.LAST_TOTAL], totalDelta, 20); assertEquals(values[InstrumentationService.Timer.LAST_TOTAL], totalDelta, 20);
Assert.assertEquals(values[InstrumentationService.Timer.LAST_OWN], ownDelta, 20); assertEquals(values[InstrumentationService.Timer.LAST_OWN], ownDelta, 20);
Assert.assertEquals(values[InstrumentationService.Timer.AVG_TOTAL], avgTotal, 20); assertEquals(values[InstrumentationService.Timer.AVG_TOTAL], avgTotal, 20);
Assert.assertEquals(values[InstrumentationService.Timer.AVG_OWN], avgOwn, 20); assertEquals(values[InstrumentationService.Timer.AVG_OWN], avgOwn, 20);
JSONObject json = (JSONObject) new JSONParser().parse(timer.toJSONString()); JSONObject json = (JSONObject) new JSONParser().parse(timer.toJSONString());
Assert.assertEquals(json.size(), 4); assertEquals(json.size(), 4);
Assert.assertEquals(json.get("lastTotal"), values[InstrumentationService.Timer.LAST_TOTAL]); assertEquals(json.get("lastTotal"), values[InstrumentationService.Timer.LAST_TOTAL]);
Assert.assertEquals(json.get("lastOwn"), values[InstrumentationService.Timer.LAST_OWN]); assertEquals(json.get("lastOwn"), values[InstrumentationService.Timer.LAST_OWN]);
Assert.assertEquals(json.get("avgTotal"), values[InstrumentationService.Timer.AVG_TOTAL]); assertEquals(json.get("avgTotal"), values[InstrumentationService.Timer.AVG_TOTAL]);
Assert.assertEquals(json.get("avgOwn"), values[InstrumentationService.Timer.AVG_OWN]); assertEquals(json.get("avgOwn"), values[InstrumentationService.Timer.AVG_OWN]);
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
timer.writeJSONString(writer); timer.writeJSONString(writer);
writer.close(); writer.close();
json = (JSONObject) new JSONParser().parse(writer.toString()); json = (JSONObject) new JSONParser().parse(writer.toString());
Assert.assertEquals(json.size(), 4); assertEquals(json.size(), 4);
Assert.assertEquals(json.get("lastTotal"), values[InstrumentationService.Timer.LAST_TOTAL]); assertEquals(json.get("lastTotal"), values[InstrumentationService.Timer.LAST_TOTAL]);
Assert.assertEquals(json.get("lastOwn"), values[InstrumentationService.Timer.LAST_OWN]); assertEquals(json.get("lastOwn"), values[InstrumentationService.Timer.LAST_OWN]);
Assert.assertEquals(json.get("avgTotal"), values[InstrumentationService.Timer.AVG_TOTAL]); assertEquals(json.get("avgTotal"), values[InstrumentationService.Timer.AVG_TOTAL]);
Assert.assertEquals(json.get("avgOwn"), values[InstrumentationService.Timer.AVG_OWN]); assertEquals(json.get("avgOwn"), values[InstrumentationService.Timer.AVG_OWN]);
} }
@Test @Test
@ -240,34 +244,34 @@ public class TestInstrumentationService extends HTestCase {
InstrumentationService.Sampler sampler = new InstrumentationService.Sampler(); InstrumentationService.Sampler sampler = new InstrumentationService.Sampler();
sampler.init(4, var); sampler.init(4, var);
Assert.assertEquals(sampler.getRate(), 0f, 0.0001); assertEquals(sampler.getRate(), 0f, 0.0001);
sampler.sample(); sampler.sample();
Assert.assertEquals(sampler.getRate(), 0f, 0.0001); assertEquals(sampler.getRate(), 0f, 0.0001);
value[0] = 1; value[0] = 1;
sampler.sample(); sampler.sample();
Assert.assertEquals(sampler.getRate(), (0d + 1) / 2, 0.0001); assertEquals(sampler.getRate(), (0d + 1) / 2, 0.0001);
value[0] = 2; value[0] = 2;
sampler.sample(); sampler.sample();
Assert.assertEquals(sampler.getRate(), (0d + 1 + 2) / 3, 0.0001); assertEquals(sampler.getRate(), (0d + 1 + 2) / 3, 0.0001);
value[0] = 3; value[0] = 3;
sampler.sample(); sampler.sample();
Assert.assertEquals(sampler.getRate(), (0d + 1 + 2 + 3) / 4, 0.0001); assertEquals(sampler.getRate(), (0d + 1 + 2 + 3) / 4, 0.0001);
value[0] = 4; value[0] = 4;
sampler.sample(); sampler.sample();
Assert.assertEquals(sampler.getRate(), (4d + 1 + 2 + 3) / 4, 0.0001); assertEquals(sampler.getRate(), (4d + 1 + 2 + 3) / 4, 0.0001);
JSONObject json = (JSONObject) new JSONParser().parse(sampler.toJSONString()); JSONObject json = (JSONObject) new JSONParser().parse(sampler.toJSONString());
Assert.assertEquals(json.size(), 2); assertEquals(json.size(), 2);
Assert.assertEquals(json.get("sampler"), sampler.getRate()); assertEquals(json.get("sampler"), sampler.getRate());
Assert.assertEquals(json.get("size"), 4L); assertEquals(json.get("size"), 4L);
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
sampler.writeJSONString(writer); sampler.writeJSONString(writer);
writer.close(); writer.close();
json = (JSONObject) new JSONParser().parse(writer.toString()); json = (JSONObject) new JSONParser().parse(writer.toString());
Assert.assertEquals(json.size(), 2); assertEquals(json.size(), 2);
Assert.assertEquals(json.get("sampler"), sampler.getRate()); assertEquals(json.get("sampler"), sampler.getRate());
Assert.assertEquals(json.get("size"), 4L); assertEquals(json.get("size"), 4L);
} }
@Test @Test
@ -283,15 +287,15 @@ public class TestInstrumentationService extends HTestCase {
}; };
JSONObject json = (JSONObject) new JSONParser().parse(variableHolder.toJSONString()); JSONObject json = (JSONObject) new JSONParser().parse(variableHolder.toJSONString());
Assert.assertEquals(json.size(), 1); assertEquals(json.size(), 1);
Assert.assertEquals(json.get("value"), "foo"); assertEquals(json.get("value"), "foo");
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
variableHolder.writeJSONString(writer); variableHolder.writeJSONString(writer);
writer.close(); writer.close();
json = (JSONObject) new JSONParser().parse(writer.toString()); json = (JSONObject) new JSONParser().parse(writer.toString());
Assert.assertEquals(json.size(), 1); assertEquals(json.size(), 1);
Assert.assertEquals(json.get("value"), "foo"); assertEquals(json.get("value"), "foo");
} }
@Test @Test
@ -306,7 +310,7 @@ public class TestInstrumentationService extends HTestCase {
server.init(); server.init();
Instrumentation instrumentation = server.get(Instrumentation.class); Instrumentation instrumentation = server.get(Instrumentation.class);
Assert.assertNotNull(instrumentation); assertNotNull(instrumentation);
instrumentation.incr("g", "c", 1); instrumentation.incr("g", "c", 1);
instrumentation.incr("g", "c", 2); instrumentation.incr("g", "c", 2);
instrumentation.incr("g", "c1", 2); instrumentation.incr("g", "c1", 2);
@ -339,27 +343,27 @@ public class TestInstrumentationService extends HTestCase {
instrumentation.addSampler("g", "s", 10, varToSample); instrumentation.addSampler("g", "s", 10, varToSample);
Map<String, ?> snapshot = instrumentation.getSnapshot(); Map<String, ?> snapshot = instrumentation.getSnapshot();
Assert.assertNotNull(snapshot.get("os-env")); assertNotNull(snapshot.get("os-env"));
Assert.assertNotNull(snapshot.get("sys-props")); assertNotNull(snapshot.get("sys-props"));
Assert.assertNotNull(snapshot.get("jvm")); assertNotNull(snapshot.get("jvm"));
Assert.assertNotNull(snapshot.get("counters")); assertNotNull(snapshot.get("counters"));
Assert.assertNotNull(snapshot.get("timers")); assertNotNull(snapshot.get("timers"));
Assert.assertNotNull(snapshot.get("variables")); assertNotNull(snapshot.get("variables"));
Assert.assertNotNull(snapshot.get("samplers")); assertNotNull(snapshot.get("samplers"));
Assert.assertNotNull(((Map<String, String>) snapshot.get("os-env")).get("PATH")); assertNotNull(((Map<String, String>) snapshot.get("os-env")).get("PATH"));
Assert.assertNotNull(((Map<String, String>) snapshot.get("sys-props")).get("java.version")); assertNotNull(((Map<String, String>) snapshot.get("sys-props")).get("java.version"));
Assert.assertNotNull(((Map<String, ?>) snapshot.get("jvm")).get("free.memory")); assertNotNull(((Map<String, ?>) snapshot.get("jvm")).get("free.memory"));
Assert.assertNotNull(((Map<String, ?>) snapshot.get("jvm")).get("max.memory")); assertNotNull(((Map<String, ?>) snapshot.get("jvm")).get("max.memory"));
Assert.assertNotNull(((Map<String, ?>) snapshot.get("jvm")).get("total.memory")); assertNotNull(((Map<String, ?>) snapshot.get("jvm")).get("total.memory"));
Assert.assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("counters")).get("g")); assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("counters")).get("g"));
Assert.assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("timers")).get("g")); assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("timers")).get("g"));
Assert.assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("variables")).get("g")); assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("variables")).get("g"));
Assert.assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("samplers")).get("g")); assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("samplers")).get("g"));
Assert.assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("counters")).get("g").get("c")); assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("counters")).get("g").get("c"));
Assert.assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("counters")).get("g").get("c1")); assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("counters")).get("g").get("c1"));
Assert.assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("timers")).get("g").get("t")); assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("timers")).get("g").get("t"));
Assert.assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("variables")).get("g").get("v")); assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("variables")).get("g").get("v"));
Assert.assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("samplers")).get("g").get("s")); assertNotNull(((Map<String, Map<String, Object>>) snapshot.get("samplers")).get("g").get("s"));
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
JSONObject.writeJSONString(snapshot, writer); JSONObject.writeJSONString(snapshot, writer);
@ -392,12 +396,12 @@ public class TestInstrumentationService extends HTestCase {
sleep(2000); sleep(2000);
int i = count.get(); int i = count.get();
Assert.assertTrue(i > 0); assertTrue(i > 0);
Map<String, Map<String, ?>> snapshot = instrumentation.getSnapshot(); Map<String, Map<String, ?>> snapshot = instrumentation.getSnapshot();
Map<String, Map<String, Object>> samplers = (Map<String, Map<String, Object>>) snapshot.get("samplers"); Map<String, Map<String, Object>> samplers = (Map<String, Map<String, Object>>) snapshot.get("samplers");
InstrumentationService.Sampler sampler = (InstrumentationService.Sampler) samplers.get("g").get("s"); InstrumentationService.Sampler sampler = (InstrumentationService.Sampler) samplers.get("g").get("s");
Assert.assertTrue(sampler.getRate() > 0); assertTrue(sampler.getRate() > 0);
server.destroy(); server.destroy();
} }

View File

@ -18,7 +18,10 @@
package org.apache.hadoop.lib.service.scheduler; package org.apache.hadoop.lib.service.scheduler;
import junit.framework.Assert; import static org.junit.Assert.assertNotNull;
import java.util.Arrays;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.lib.server.Server; import org.apache.hadoop.lib.server.Server;
import org.apache.hadoop.lib.service.Scheduler; import org.apache.hadoop.lib.service.Scheduler;
@ -29,8 +32,6 @@ import org.apache.hadoop.test.TestDirHelper;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays;
public class TestSchedulerService extends HTestCase { public class TestSchedulerService extends HTestCase {
@Test @Test
@ -42,7 +43,7 @@ public class TestSchedulerService extends HTestCase {
SchedulerService.class.getName()))); SchedulerService.class.getName())));
Server server = new Server("server", dir, dir, dir, dir, conf); Server server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
Assert.assertNotNull(server.get(Scheduler.class)); assertNotNull(server.get(Scheduler.class));
server.destroy(); server.destroy();
} }

View File

@ -17,14 +17,14 @@
*/ */
package org.apache.hadoop.lib.service.security; package org.apache.hadoop.lib.service.security;
import org.apache.hadoop.security.GroupMappingServiceProvider;
import org.apache.hadoop.test.HadoopUsersConfTestHelper;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.apache.hadoop.security.GroupMappingServiceProvider;
import org.apache.hadoop.test.HadoopUsersConfTestHelper;
public class DummyGroupMapping implements GroupMappingServiceProvider { public class DummyGroupMapping implements GroupMappingServiceProvider {
@Override @Override

View File

@ -18,7 +18,12 @@
package org.apache.hadoop.lib.service.security; package org.apache.hadoop.lib.service.security;
import junit.framework.Assert; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import java.util.Arrays;
import java.util.List;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.lib.server.Server; import org.apache.hadoop.lib.server.Server;
import org.apache.hadoop.lib.service.Groups; import org.apache.hadoop.lib.service.Groups;
@ -28,9 +33,6 @@ import org.apache.hadoop.test.TestDirHelper;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays;
import java.util.List;
public class TestGroupsService extends HTestCase { public class TestGroupsService extends HTestCase {
@Test @Test
@ -42,9 +44,9 @@ public class TestGroupsService extends HTestCase {
Server server = new Server("server", dir, dir, dir, dir, conf); Server server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
Groups groups = server.get(Groups.class); Groups groups = server.get(Groups.class);
Assert.assertNotNull(groups); assertNotNull(groups);
List<String> g = groups.getGroups(System.getProperty("user.name")); List<String> g = groups.getGroups(System.getProperty("user.name"));
Assert.assertNotSame(g.size(), 0); assertNotSame(g.size(), 0);
server.destroy(); server.destroy();
} }

View File

@ -18,7 +18,12 @@
package org.apache.hadoop.lib.service.security; package org.apache.hadoop.lib.service.security;
import junit.framework.Assert; import static org.junit.Assert.assertNotNull;
import java.security.AccessControlException;
import java.util.Arrays;
import java.util.List;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.lib.server.Server; import org.apache.hadoop.lib.server.Server;
import org.apache.hadoop.lib.server.ServiceException; import org.apache.hadoop.lib.server.ServiceException;
@ -31,10 +36,6 @@ import org.apache.hadoop.test.TestException;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.junit.Test; import org.junit.Test;
import java.security.AccessControlException;
import java.util.Arrays;
import java.util.List;
public class TestProxyUserService extends HTestCase { public class TestProxyUserService extends HTestCase {
@Test @Test
@ -47,7 +48,7 @@ public class TestProxyUserService extends HTestCase {
Server server = new Server("server", dir, dir, dir, dir, conf); Server server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
ProxyUser proxyUser = server.get(ProxyUser.class); ProxyUser proxyUser = server.get(ProxyUser.class);
Assert.assertNotNull(proxyUser); assertNotNull(proxyUser);
server.destroy(); server.destroy();
} }
@ -103,7 +104,7 @@ public class TestProxyUserService extends HTestCase {
Server server = new Server("server", dir, dir, dir, dir, conf); Server server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
ProxyUser proxyUser = server.get(ProxyUser.class); ProxyUser proxyUser = server.get(ProxyUser.class);
Assert.assertNotNull(proxyUser); assertNotNull(proxyUser);
proxyUser.validate("foo", "localhost", "bar"); proxyUser.validate("foo", "localhost", "bar");
server.destroy(); server.destroy();
} }
@ -120,7 +121,7 @@ public class TestProxyUserService extends HTestCase {
Server server = new Server("server", dir, dir, dir, dir, conf); Server server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
ProxyUser proxyUser = server.get(ProxyUser.class); ProxyUser proxyUser = server.get(ProxyUser.class);
Assert.assertNotNull(proxyUser); assertNotNull(proxyUser);
proxyUser.validate("bar", "localhost", "foo"); proxyUser.validate("bar", "localhost", "foo");
server.destroy(); server.destroy();
} }
@ -137,7 +138,7 @@ public class TestProxyUserService extends HTestCase {
Server server = new Server("server", dir, dir, dir, dir, conf); Server server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
ProxyUser proxyUser = server.get(ProxyUser.class); ProxyUser proxyUser = server.get(ProxyUser.class);
Assert.assertNotNull(proxyUser); assertNotNull(proxyUser);
proxyUser.validate("foo", "localhost", "bar"); proxyUser.validate("foo", "localhost", "bar");
server.destroy(); server.destroy();
} }
@ -166,7 +167,7 @@ public class TestProxyUserService extends HTestCase {
Server server = new Server("server", dir, dir, dir, dir, conf); Server server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
ProxyUser proxyUser = server.get(ProxyUser.class); ProxyUser proxyUser = server.get(ProxyUser.class);
Assert.assertNotNull(proxyUser); assertNotNull(proxyUser);
proxyUser.validate("foo", "localhost", System.getProperty("user.name")); proxyUser.validate("foo", "localhost", System.getProperty("user.name"));
server.destroy(); server.destroy();
} }
@ -184,7 +185,7 @@ public class TestProxyUserService extends HTestCase {
Server server = new Server("server", dir, dir, dir, dir, conf); Server server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
ProxyUser proxyUser = server.get(ProxyUser.class); ProxyUser proxyUser = server.get(ProxyUser.class);
Assert.assertNotNull(proxyUser); assertNotNull(proxyUser);
proxyUser.validate("foo", "unknownhost.bar.foo", "bar"); proxyUser.validate("foo", "unknownhost.bar.foo", "bar");
server.destroy(); server.destroy();
} }
@ -201,7 +202,7 @@ public class TestProxyUserService extends HTestCase {
Server server = new Server("server", dir, dir, dir, dir, conf); Server server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
ProxyUser proxyUser = server.get(ProxyUser.class); ProxyUser proxyUser = server.get(ProxyUser.class);
Assert.assertNotNull(proxyUser); assertNotNull(proxyUser);
proxyUser.validate("foo", "www.yahoo.com", "bar"); proxyUser.validate("foo", "www.yahoo.com", "bar");
server.destroy(); server.destroy();
} }
@ -218,7 +219,7 @@ public class TestProxyUserService extends HTestCase {
Server server = new Server("server", dir, dir, dir, dir, conf); Server server = new Server("server", dir, dir, dir, dir, conf);
server.init(); server.init();
ProxyUser proxyUser = server.get(ProxyUser.class); ProxyUser proxyUser = server.get(ProxyUser.class);
Assert.assertNotNull(proxyUser); assertNotNull(proxyUser);
proxyUser.validate("foo", "localhost", System.getProperty("user.name")); proxyUser.validate("foo", "localhost", System.getProperty("user.name"));
server.destroy(); server.destroy();
} }

View File

@ -18,18 +18,21 @@
package org.apache.hadoop.lib.servlet; package org.apache.hadoop.lib.servlet;
import junit.framework.Assert; import static org.junit.Assert.assertNull;
import org.apache.hadoop.test.HTestCase; import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.mockito.Mockito; import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean; import org.apache.hadoop.test.HTestCase;
import org.junit.Test;
import org.mockito.Mockito;
public class TestHostnameFilter extends HTestCase { public class TestHostnameFilter extends HTestCase {
@ -47,17 +50,17 @@ public class TestHostnameFilter extends HTestCase {
@Override @Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse)
throws IOException, ServletException { throws IOException, ServletException {
Assert.assertTrue(HostnameFilter.get().contains("localhost")); assertTrue(HostnameFilter.get().contains("localhost"));
invoked.set(true); invoked.set(true);
} }
}; };
Filter filter = new HostnameFilter(); Filter filter = new HostnameFilter();
filter.init(null); filter.init(null);
Assert.assertNull(HostnameFilter.get()); assertNull(HostnameFilter.get());
filter.doFilter(request, response, chain); filter.doFilter(request, response, chain);
Assert.assertTrue(invoked.get()); assertTrue(invoked.get());
Assert.assertNull(HostnameFilter.get()); assertNull(HostnameFilter.get());
filter.destroy(); filter.destroy();
} }

View File

@ -18,11 +18,13 @@
package org.apache.hadoop.lib.servlet; package org.apache.hadoop.lib.servlet;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import org.apache.hadoop.test.HTestCase; import static org.junit.Assert.assertNull;
import org.junit.Test; import static org.junit.Assert.assertTrue;
import org.mockito.Mockito;
import org.slf4j.MDC; import java.io.IOException;
import java.security.Principal;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
@ -30,9 +32,11 @@ import javax.servlet.ServletException;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.security.Principal; import org.apache.hadoop.test.HTestCase;
import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Test;
import org.mockito.Mockito;
import org.slf4j.MDC;
public class TestMDCFilter extends HTestCase { public class TestMDCFilter extends HTestCase {
@ -52,10 +56,10 @@ public class TestMDCFilter extends HTestCase {
@Override @Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse)
throws IOException, ServletException { throws IOException, ServletException {
Assert.assertEquals(MDC.get("hostname"), null); assertEquals(MDC.get("hostname"), null);
Assert.assertEquals(MDC.get("user"), null); assertEquals(MDC.get("user"), null);
Assert.assertEquals(MDC.get("method"), "METHOD"); assertEquals(MDC.get("method"), "METHOD");
Assert.assertEquals(MDC.get("path"), "/pathinfo"); assertEquals(MDC.get("path"), "/pathinfo");
invoked.set(true); invoked.set(true);
} }
}; };
@ -65,11 +69,11 @@ public class TestMDCFilter extends HTestCase {
filter.init(null); filter.init(null);
filter.doFilter(request, response, chain); filter.doFilter(request, response, chain);
Assert.assertTrue(invoked.get()); assertTrue(invoked.get());
Assert.assertNull(MDC.get("hostname")); assertNull(MDC.get("hostname"));
Assert.assertNull(MDC.get("user")); assertNull(MDC.get("user"));
Assert.assertNull(MDC.get("method")); assertNull(MDC.get("method"));
Assert.assertNull(MDC.get("path")); assertNull(MDC.get("path"));
Mockito.when(request.getUserPrincipal()).thenReturn(new Principal() { Mockito.when(request.getUserPrincipal()).thenReturn(new Principal() {
@Override @Override
@ -83,15 +87,15 @@ public class TestMDCFilter extends HTestCase {
@Override @Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse)
throws IOException, ServletException { throws IOException, ServletException {
Assert.assertEquals(MDC.get("hostname"), null); assertEquals(MDC.get("hostname"), null);
Assert.assertEquals(MDC.get("user"), "name"); assertEquals(MDC.get("user"), "name");
Assert.assertEquals(MDC.get("method"), "METHOD"); assertEquals(MDC.get("method"), "METHOD");
Assert.assertEquals(MDC.get("path"), "/pathinfo"); assertEquals(MDC.get("path"), "/pathinfo");
invoked.set(true); invoked.set(true);
} }
}; };
filter.doFilter(request, response, chain); filter.doFilter(request, response, chain);
Assert.assertTrue(invoked.get()); assertTrue(invoked.get());
HostnameFilter.HOSTNAME_TL.set("HOST"); HostnameFilter.HOSTNAME_TL.set("HOST");
@ -100,15 +104,15 @@ public class TestMDCFilter extends HTestCase {
@Override @Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse)
throws IOException, ServletException { throws IOException, ServletException {
Assert.assertEquals(MDC.get("hostname"), "HOST"); assertEquals(MDC.get("hostname"), "HOST");
Assert.assertEquals(MDC.get("user"), "name"); assertEquals(MDC.get("user"), "name");
Assert.assertEquals(MDC.get("method"), "METHOD"); assertEquals(MDC.get("method"), "METHOD");
Assert.assertEquals(MDC.get("path"), "/pathinfo"); assertEquals(MDC.get("path"), "/pathinfo");
invoked.set(true); invoked.set(true);
} }
}; };
filter.doFilter(request, response, chain); filter.doFilter(request, response, chain);
Assert.assertTrue(invoked.get()); assertTrue(invoked.get());
HostnameFilter.HOSTNAME_TL.remove(); HostnameFilter.HOSTNAME_TL.remove();

View File

@ -18,7 +18,8 @@
package org.apache.hadoop.lib.servlet; package org.apache.hadoop.lib.servlet;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import org.apache.hadoop.lib.server.Server; import org.apache.hadoop.lib.server.Server;
import org.apache.hadoop.test.HTestCase; import org.apache.hadoop.test.HTestCase;
import org.apache.hadoop.test.TestDir; import org.apache.hadoop.test.TestDir;
@ -35,10 +36,10 @@ public class TestServerWebApp extends HTestCase {
@Test @Test
public void getHomeDir() { public void getHomeDir() {
System.setProperty("TestServerWebApp0.home.dir", "/tmp"); System.setProperty("TestServerWebApp0.home.dir", "/tmp");
Assert.assertEquals(ServerWebApp.getHomeDir("TestServerWebApp0"), "/tmp"); assertEquals(ServerWebApp.getHomeDir("TestServerWebApp0"), "/tmp");
Assert.assertEquals(ServerWebApp.getDir("TestServerWebApp0", ".log.dir", "/tmp/log"), "/tmp/log"); assertEquals(ServerWebApp.getDir("TestServerWebApp0", ".log.dir", "/tmp/log"), "/tmp/log");
System.setProperty("TestServerWebApp0.log.dir", "/tmplog"); System.setProperty("TestServerWebApp0.log.dir", "/tmplog");
Assert.assertEquals(ServerWebApp.getDir("TestServerWebApp0", ".log.dir", "/tmp/log"), "/tmplog"); assertEquals(ServerWebApp.getDir("TestServerWebApp0", ".log.dir", "/tmp/log"), "/tmplog");
} }
@Test @Test
@ -52,11 +53,11 @@ public class TestServerWebApp extends HTestCase {
ServerWebApp server = new ServerWebApp("TestServerWebApp1") { ServerWebApp server = new ServerWebApp("TestServerWebApp1") {
}; };
Assert.assertEquals(server.getStatus(), Server.Status.UNDEF); assertEquals(server.getStatus(), Server.Status.UNDEF);
server.contextInitialized(null); server.contextInitialized(null);
Assert.assertEquals(server.getStatus(), Server.Status.NORMAL); assertEquals(server.getStatus(), Server.Status.NORMAL);
server.contextDestroyed(null); server.contextDestroyed(null);
Assert.assertEquals(server.getStatus(), Server.Status.SHUTDOWN); assertEquals(server.getStatus(), Server.Status.SHUTDOWN);
} }
@Test(expected = RuntimeException.class) @Test(expected = RuntimeException.class)

View File

@ -19,18 +19,19 @@
package org.apache.hadoop.lib.util; package org.apache.hadoop.lib.util;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import org.apache.hadoop.test.HTestCase;
import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import org.apache.hadoop.test.HTestCase;
import org.junit.Test;
public class TestCheck extends HTestCase { public class TestCheck extends HTestCase {
@Test @Test
public void notNullNotNull() { public void notNullNotNull() {
Assert.assertEquals(Check.notNull("value", "name"), "value"); assertEquals(Check.notNull("value", "name"), "value");
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
@ -79,7 +80,7 @@ public class TestCheck extends HTestCase {
@Test @Test
public void notEmptyNotEmtpy() { public void notEmptyNotEmtpy() {
Assert.assertEquals(Check.notEmpty("value", "name"), "value"); assertEquals(Check.notEmpty("value", "name"), "value");
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
@ -94,10 +95,10 @@ public class TestCheck extends HTestCase {
@Test @Test
public void validIdentifierValid() throws Exception { public void validIdentifierValid() throws Exception {
Assert.assertEquals(Check.validIdentifier("a", 1, ""), "a"); assertEquals(Check.validIdentifier("a", 1, ""), "a");
Assert.assertEquals(Check.validIdentifier("a1", 2, ""), "a1"); assertEquals(Check.validIdentifier("a1", 2, ""), "a1");
Assert.assertEquals(Check.validIdentifier("a_", 3, ""), "a_"); assertEquals(Check.validIdentifier("a_", 3, ""), "a_");
Assert.assertEquals(Check.validIdentifier("_", 1, ""), "_"); assertEquals(Check.validIdentifier("_", 1, ""), "_");
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
@ -117,7 +118,7 @@ public class TestCheck extends HTestCase {
@Test @Test
public void checkGTZeroGreater() { public void checkGTZeroGreater() {
Assert.assertEquals(Check.gt0(120, "test"), 120); assertEquals(Check.gt0(120, "test"), 120);
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
@ -132,8 +133,8 @@ public class TestCheck extends HTestCase {
@Test @Test
public void checkGEZero() { public void checkGEZero() {
Assert.assertEquals(Check.ge0(120, "test"), 120); assertEquals(Check.ge0(120, "test"), 120);
Assert.assertEquals(Check.ge0(0, "test"), 0); assertEquals(Check.ge0(0, "test"), 0);
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)

View File

@ -18,27 +18,29 @@
package org.apache.hadoop.lib.util; package org.apache.hadoop.lib.util;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import org.apache.hadoop.conf.Configuration; import static org.junit.Assert.assertNull;
import org.junit.Test;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import org.apache.hadoop.conf.Configuration;
import org.junit.Test;
public class TestConfigurationUtils { public class TestConfigurationUtils {
@Test @Test
public void constructors() throws Exception { public void constructors() throws Exception {
Configuration conf = new Configuration(false); Configuration conf = new Configuration(false);
Assert.assertEquals(conf.size(), 0); assertEquals(conf.size(), 0);
byte[] bytes = "<configuration><property><name>a</name><value>A</value></property></configuration>".getBytes(); byte[] bytes = "<configuration><property><name>a</name><value>A</value></property></configuration>".getBytes();
InputStream is = new ByteArrayInputStream(bytes); InputStream is = new ByteArrayInputStream(bytes);
conf = new Configuration(false); conf = new Configuration(false);
ConfigurationUtils.load(conf, is); ConfigurationUtils.load(conf, is);
Assert.assertEquals(conf.size(), 1); assertEquals(conf.size(), 1);
Assert.assertEquals(conf.get("a"), "A"); assertEquals(conf.get("a"), "A");
} }
@ -62,9 +64,9 @@ public class TestConfigurationUtils {
ConfigurationUtils.copy(srcConf, targetConf); ConfigurationUtils.copy(srcConf, targetConf);
Assert.assertEquals("valueFromSource", targetConf.get("testParameter1")); assertEquals("valueFromSource", targetConf.get("testParameter1"));
Assert.assertEquals("valueFromSource", targetConf.get("testParameter2")); assertEquals("valueFromSource", targetConf.get("testParameter2"));
Assert.assertEquals("valueFromTarget", targetConf.get("testParameter3")); assertEquals("valueFromTarget", targetConf.get("testParameter3"));
} }
@Test @Test
@ -80,13 +82,13 @@ public class TestConfigurationUtils {
ConfigurationUtils.injectDefaults(srcConf, targetConf); ConfigurationUtils.injectDefaults(srcConf, targetConf);
Assert.assertEquals("valueFromSource", targetConf.get("testParameter1")); assertEquals("valueFromSource", targetConf.get("testParameter1"));
Assert.assertEquals("originalValueFromTarget", targetConf.get("testParameter2")); assertEquals("originalValueFromTarget", targetConf.get("testParameter2"));
Assert.assertEquals("originalValueFromTarget", targetConf.get("testParameter3")); assertEquals("originalValueFromTarget", targetConf.get("testParameter3"));
Assert.assertEquals("valueFromSource", srcConf.get("testParameter1")); assertEquals("valueFromSource", srcConf.get("testParameter1"));
Assert.assertEquals("valueFromSource", srcConf.get("testParameter2")); assertEquals("valueFromSource", srcConf.get("testParameter2"));
Assert.assertNull(srcConf.get("testParameter3")); assertNull(srcConf.get("testParameter3"));
} }
@ -95,11 +97,11 @@ public class TestConfigurationUtils {
Configuration conf = new Configuration(false); Configuration conf = new Configuration(false);
conf.set("a", "A"); conf.set("a", "A");
conf.set("b", "${a}"); conf.set("b", "${a}");
Assert.assertEquals(conf.getRaw("a"), "A"); assertEquals(conf.getRaw("a"), "A");
Assert.assertEquals(conf.getRaw("b"), "${a}"); assertEquals(conf.getRaw("b"), "${a}");
conf = ConfigurationUtils.resolve(conf); conf = ConfigurationUtils.resolve(conf);
Assert.assertEquals(conf.getRaw("a"), "A"); assertEquals(conf.getRaw("a"), "A");
Assert.assertEquals(conf.getRaw("b"), "A"); assertEquals(conf.getRaw("b"), "A");
} }
@Test @Test
@ -110,16 +112,16 @@ public class TestConfigurationUtils {
conf.set("b", "${a}"); conf.set("b", "${a}");
conf.set("c", "${user.name}"); conf.set("c", "${user.name}");
conf.set("d", "${aaa}"); conf.set("d", "${aaa}");
Assert.assertEquals(conf.getRaw("a"), "A"); assertEquals(conf.getRaw("a"), "A");
Assert.assertEquals(conf.getRaw("b"), "${a}"); assertEquals(conf.getRaw("b"), "${a}");
Assert.assertEquals(conf.getRaw("c"), "${user.name}"); assertEquals(conf.getRaw("c"), "${user.name}");
Assert.assertEquals(conf.get("a"), "A"); assertEquals(conf.get("a"), "A");
Assert.assertEquals(conf.get("b"), "A"); assertEquals(conf.get("b"), "A");
Assert.assertEquals(conf.get("c"), userName); assertEquals(conf.get("c"), userName);
Assert.assertEquals(conf.get("d"), "${aaa}"); assertEquals(conf.get("d"), "${aaa}");
conf.set("user.name", "foo"); conf.set("user.name", "foo");
Assert.assertEquals(conf.get("user.name"), "foo"); assertEquals(conf.get("user.name"), "foo");
} }
} }

View File

@ -18,13 +18,14 @@
package org.apache.hadoop.lib.wsrs; package org.apache.hadoop.lib.wsrs;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import org.junit.Test;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.InputStream; import java.io.InputStream;
import org.junit.Test;
public class TestInputStreamEntity { public class TestInputStreamEntity {
@Test @Test
@ -34,14 +35,14 @@ public class TestInputStreamEntity {
InputStreamEntity i = new InputStreamEntity(is); InputStreamEntity i = new InputStreamEntity(is);
i.write(baos); i.write(baos);
baos.close(); baos.close();
Assert.assertEquals(new String(baos.toByteArray()), "abc"); assertEquals(new String(baos.toByteArray()), "abc");
is = new ByteArrayInputStream("abc".getBytes()); is = new ByteArrayInputStream("abc".getBytes());
baos = new ByteArrayOutputStream(); baos = new ByteArrayOutputStream();
i = new InputStreamEntity(is, 1, 1); i = new InputStreamEntity(is, 1, 1);
i.write(baos); i.write(baos);
baos.close(); baos.close();
Assert.assertEquals(baos.toByteArray()[0], 'b'); assertEquals(baos.toByteArray()[0], 'b');
} }
} }

View File

@ -18,28 +18,31 @@
package org.apache.hadoop.lib.wsrs; package org.apache.hadoop.lib.wsrs;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import org.json.simple.JSONObject; import static org.junit.Assert.assertFalse;
import org.junit.Test; import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.util.Map; import java.util.Map;
import org.json.simple.JSONObject;
import org.junit.Test;
public class TestJSONMapProvider { public class TestJSONMapProvider {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void test() throws Exception { public void test() throws Exception {
JSONMapProvider p = new JSONMapProvider(); JSONMapProvider p = new JSONMapProvider();
Assert.assertTrue(p.isWriteable(Map.class, null, null, null)); assertTrue(p.isWriteable(Map.class, null, null, null));
Assert.assertFalse(p.isWriteable(this.getClass(), null, null, null)); assertFalse(p.isWriteable(this.getClass(), null, null, null));
Assert.assertEquals(p.getSize(null, null, null, null, null), -1); assertEquals(p.getSize(null, null, null, null, null), -1);
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("a", "A"); json.put("a", "A");
p.writeTo(json, JSONObject.class, null, null, null, null, baos); p.writeTo(json, JSONObject.class, null, null, null, null, baos);
baos.close(); baos.close();
Assert.assertEquals(new String(baos.toByteArray()).trim(), "{\"a\":\"A\"}"); assertEquals(new String(baos.toByteArray()).trim(), "{\"a\":\"A\"}");
} }
} }

View File

@ -18,27 +18,30 @@
package org.apache.hadoop.lib.wsrs; package org.apache.hadoop.lib.wsrs;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import org.json.simple.JSONObject; import static org.junit.Assert.assertFalse;
import org.junit.Test; import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import org.json.simple.JSONObject;
import org.junit.Test;
public class TestJSONProvider { public class TestJSONProvider {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void test() throws Exception { public void test() throws Exception {
JSONProvider p = new JSONProvider(); JSONProvider p = new JSONProvider();
Assert.assertTrue(p.isWriteable(JSONObject.class, null, null, null)); assertTrue(p.isWriteable(JSONObject.class, null, null, null));
Assert.assertFalse(p.isWriteable(this.getClass(), null, null, null)); assertFalse(p.isWriteable(this.getClass(), null, null, null));
Assert.assertEquals(p.getSize(null, null, null, null, null), -1); assertEquals(p.getSize(null, null, null, null, null), -1);
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("a", "A"); json.put("a", "A");
p.writeTo(json, JSONObject.class, null, null, null, null, baos); p.writeTo(json, JSONObject.class, null, null, null, null, baos);
baos.close(); baos.close();
Assert.assertEquals(new String(baos.toByteArray()).trim(), "{\"a\":\"A\"}"); assertEquals(new String(baos.toByteArray()).trim(), "{\"a\":\"A\"}");
} }
} }

View File

@ -18,41 +18,43 @@
package org.apache.hadoop.lib.wsrs; package org.apache.hadoop.lib.wsrs;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import org.junit.Test; import static org.junit.Assert.fail;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.junit.Test;
public class TestParam { public class TestParam {
private <T> void test(Param<T> param, String name, private <T> void test(Param<T> param, String name,
String domain, T defaultValue, T validValue, String domain, T defaultValue, T validValue,
String invalidStrValue, String outOfRangeValue) throws Exception { String invalidStrValue, String outOfRangeValue) throws Exception {
Assert.assertEquals(name, param.getName()); assertEquals(name, param.getName());
Assert.assertEquals(domain, param.getDomain()); assertEquals(domain, param.getDomain());
Assert.assertEquals(defaultValue, param.value()); assertEquals(defaultValue, param.value());
Assert.assertEquals(defaultValue, param.parseParam("")); assertEquals(defaultValue, param.parseParam(""));
Assert.assertEquals(defaultValue, param.parseParam(null)); assertEquals(defaultValue, param.parseParam(null));
Assert.assertEquals(validValue, param.parseParam(validValue.toString())); assertEquals(validValue, param.parseParam(validValue.toString()));
if (invalidStrValue != null) { if (invalidStrValue != null) {
try { try {
param.parseParam(invalidStrValue); param.parseParam(invalidStrValue);
Assert.fail(); fail();
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
//NOP //NOP
} catch (Exception ex) { } catch (Exception ex) {
Assert.fail(); fail();
} }
} }
if (outOfRangeValue != null) { if (outOfRangeValue != null) {
try { try {
param.parseParam(outOfRangeValue); param.parseParam(outOfRangeValue);
Assert.fail(); fail();
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
//NOP //NOP
} catch (Exception ex) { } catch (Exception ex) {
Assert.fail(); fail();
} }
} }
} }
@ -81,7 +83,7 @@ public class TestParam {
param = new ShortParam("S", (short) 1, 8) { param = new ShortParam("S", (short) 1, 8) {
}; };
Assert.assertEquals(new Short((short)01777), param.parse("01777")); assertEquals(new Short((short)01777), param.parse("01777"));
} }
@Test @Test

View File

@ -18,16 +18,20 @@
package org.apache.hadoop.lib.wsrs; package org.apache.hadoop.lib.wsrs;
import com.sun.jersey.api.core.HttpContext; import static org.junit.Assert.assertEquals;
import com.sun.jersey.api.core.HttpRequestContext; import static org.junit.Assert.assertNull;
import com.sun.jersey.core.spi.component.ComponentScope;
import junit.framework.Assert; import java.security.Principal;
import javax.ws.rs.core.MultivaluedMap;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.slf4j.MDC; import org.slf4j.MDC;
import javax.ws.rs.core.MultivaluedMap; import com.sun.jersey.api.core.HttpContext;
import java.security.Principal; import com.sun.jersey.api.core.HttpRequestContext;
import com.sun.jersey.core.spi.component.ComponentScope;
public class TestUserProvider { public class TestUserProvider {
@ -43,8 +47,8 @@ public class TestUserProvider {
HttpContext context = Mockito.mock(HttpContext.class); HttpContext context = Mockito.mock(HttpContext.class);
Mockito.when(context.getRequest()).thenReturn(request); Mockito.when(context.getRequest()).thenReturn(request);
UserProvider up = new UserProvider(); UserProvider up = new UserProvider();
Assert.assertNull(up.getValue(context)); assertNull(up.getValue(context));
Assert.assertNull(MDC.get("user")); assertNull(MDC.get("user"));
} }
@Test @Test
@ -59,8 +63,8 @@ public class TestUserProvider {
HttpContext context = Mockito.mock(HttpContext.class); HttpContext context = Mockito.mock(HttpContext.class);
Mockito.when(context.getRequest()).thenReturn(request); Mockito.when(context.getRequest()).thenReturn(request);
UserProvider up = new UserProvider(); UserProvider up = new UserProvider();
Assert.assertEquals(up.getValue(context).getName(), "foo"); assertEquals(up.getValue(context).getName(), "foo");
Assert.assertEquals(MDC.get("user"), "foo"); assertEquals(MDC.get("user"), "foo");
} }
@Test @Test
@ -77,15 +81,15 @@ public class TestUserProvider {
HttpContext context = Mockito.mock(HttpContext.class); HttpContext context = Mockito.mock(HttpContext.class);
Mockito.when(context.getRequest()).thenReturn(request); Mockito.when(context.getRequest()).thenReturn(request);
UserProvider up = new UserProvider(); UserProvider up = new UserProvider();
Assert.assertEquals(up.getValue(context).getName(), "bar"); assertEquals(up.getValue(context).getName(), "bar");
Assert.assertEquals(MDC.get("user"), "bar"); assertEquals(MDC.get("user"), "bar");
} }
@Test @Test
public void getters() { public void getters() {
UserProvider up = new UserProvider(); UserProvider up = new UserProvider();
Assert.assertEquals(up.getScope(), ComponentScope.PerRequest); assertEquals(up.getScope(), ComponentScope.PerRequest);
Assert.assertEquals(up.getInjectable(null, null, Principal.class), up); assertEquals(up.getInjectable(null, null, Principal.class), up);
Assert.assertNull(up.getInjectable(null, null, String.class)); assertNull(up.getInjectable(null, null, String.class));
} }
} }

View File

@ -17,14 +17,14 @@
*/ */
package org.apache.hadoop.test; package org.apache.hadoop.test;
import junit.framework.Assert; import static org.junit.Assert.fail;
import java.text.MessageFormat;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.junit.Rule; import org.junit.Rule;
import org.junit.rules.MethodRule; import org.junit.rules.MethodRule;
import java.text.MessageFormat;
public abstract class HTestCase { public abstract class HTestCase {
public static final String TEST_WAITFOR_RATIO_PROP = "test.waitfor.ratio"; public static final String TEST_WAITFOR_RATIO_PROP = "test.waitfor.ratio";
@ -161,7 +161,7 @@ public abstract class HTestCase {
} }
if (!eval) { if (!eval) {
if (failIfTimeout) { if (failIfTimeout) {
Assert.fail(MessageFormat.format("Waiting timed out after [{0}] msec", timeout)); fail(MessageFormat.format("Waiting timed out after [{0}] msec", timeout));
} else { } else {
System.out.println(MessageFormat.format("Waiting timed out after [{0}] msec", timeout)); System.out.println(MessageFormat.format("Waiting timed out after [{0}] msec", timeout));
} }

View File

@ -17,12 +17,12 @@
*/ */
package org.apache.hadoop.test; package org.apache.hadoop.test;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;
/** /**
* Helper to configure FileSystemAccess user/group and proxyuser * Helper to configure FileSystemAccess user/group and proxyuser
* configuration for testing using Java System properties. * configuration for testing using Java System properties.

View File

@ -17,16 +17,16 @@
*/ */
package org.apache.hadoop.test; package org.apache.hadoop.test;
import org.junit.Test;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
public class TestDirHelper implements MethodRule { public class TestDirHelper implements MethodRule {
@Test @Test

View File

@ -17,14 +17,15 @@
*/ */
package org.apache.hadoop.test; package org.apache.hadoop.test;
import junit.framework.Assert; import static org.junit.Assert.fail;
import java.util.regex.Pattern;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.MethodRule; import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement; import org.junit.runners.model.Statement;
import java.util.regex.Pattern;
public class TestExceptionHelper implements MethodRule { public class TestExceptionHelper implements MethodRule {
@Test @Test
@ -41,7 +42,7 @@ public class TestExceptionHelper implements MethodRule {
statement.evaluate(); statement.evaluate();
if (testExceptionAnnotation != null) { if (testExceptionAnnotation != null) {
Class<? extends Throwable> klass = testExceptionAnnotation.exception(); Class<? extends Throwable> klass = testExceptionAnnotation.exception();
Assert.fail("Expected Exception: " + klass.getSimpleName()); fail("Expected Exception: " + klass.getSimpleName());
} }
} catch (Throwable ex) { } catch (Throwable ex) {
if (testExceptionAnnotation != null) { if (testExceptionAnnotation != null) {
@ -50,10 +51,10 @@ public class TestExceptionHelper implements MethodRule {
String regExp = testExceptionAnnotation.msgRegExp(); String regExp = testExceptionAnnotation.msgRegExp();
Pattern pattern = Pattern.compile(regExp); Pattern pattern = Pattern.compile(regExp);
if (!pattern.matcher(ex.getMessage()).find()) { if (!pattern.matcher(ex.getMessage()).find()) {
Assert.fail("Expected Exception Message pattern: " + regExp + " got message: " + ex.getMessage()); fail("Expected Exception Message pattern: " + regExp + " got message: " + ex.getMessage());
} }
} else { } else {
Assert.fail("Expected Exception: " + klass.getSimpleName() + " got: " + ex.getClass().getSimpleName()); fail("Expected Exception: " + klass.getSimpleName() + " got: " + ex.getClass().getSimpleName());
} }
} else { } else {
throw ex; throw ex;

View File

@ -18,19 +18,9 @@
package org.apache.hadoop.test; package org.apache.hadoop.test;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import org.apache.hadoop.conf.Configuration; import static org.junit.Assert.assertNotNull;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.util.Time;
import org.junit.Test;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -39,6 +29,19 @@ import java.io.OutputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.util.Time;
import org.junit.Test;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
public class TestHFSTestCase extends HFSTestCase { public class TestHFSTestCase extends HFSTestCase {
@Test(expected = IllegalStateException.class) @Test(expected = IllegalStateException.class)
@ -69,7 +72,7 @@ public class TestHFSTestCase extends HFSTestCase {
@Test @Test
@TestDir @TestDir
public void testDirAnnotation() throws Exception { public void testDirAnnotation() throws Exception {
Assert.assertNotNull(TestDirHelper.getTestDir()); assertNotNull(TestDirHelper.getTestDir());
} }
@Test @Test
@ -81,8 +84,8 @@ public class TestHFSTestCase extends HFSTestCase {
} }
}); });
long end = Time.now(); long end = Time.now();
Assert.assertEquals(waited, 0, 50); assertEquals(waited, 0, 50);
Assert.assertEquals(end - start - waited, 0, 50); assertEquals(end - start - waited, 0, 50);
} }
@Test @Test
@ -95,8 +98,8 @@ public class TestHFSTestCase extends HFSTestCase {
} }
}); });
long end = Time.now(); long end = Time.now();
Assert.assertEquals(waited, -1); assertEquals(waited, -1);
Assert.assertEquals(end - start, 200, 50); assertEquals(end - start, 200, 50);
} }
@Test @Test
@ -109,8 +112,8 @@ public class TestHFSTestCase extends HFSTestCase {
} }
}); });
long end = Time.now(); long end = Time.now();
Assert.assertEquals(waited, -1); assertEquals(waited, -1);
Assert.assertEquals(end - start, 200 * getWaitForRatio(), 50 * getWaitForRatio()); assertEquals(end - start, 200 * getWaitForRatio(), 50 * getWaitForRatio());
} }
@Test @Test
@ -119,7 +122,7 @@ public class TestHFSTestCase extends HFSTestCase {
long start = Time.now(); long start = Time.now();
sleep(100); sleep(100);
long end = Time.now(); long end = Time.now();
Assert.assertEquals(end - start, 100, 50); assertEquals(end - start, 100, 50);
} }
@Test @Test
@ -128,7 +131,7 @@ public class TestHFSTestCase extends HFSTestCase {
long start = Time.now(); long start = Time.now();
sleep(100); sleep(100);
long end = Time.now(); long end = Time.now();
Assert.assertEquals(end - start, 100 * getWaitForRatio(), 50 * getWaitForRatio()); assertEquals(end - start, 100 * getWaitForRatio(), 50 * getWaitForRatio());
} }
@Test @Test
@ -141,8 +144,8 @@ public class TestHFSTestCase extends HFSTestCase {
os.write(new byte[]{1}); os.write(new byte[]{1});
os.close(); os.close();
InputStream is = fs.open(new Path(TestHdfsHelper.getHdfsTestDir(), "foo")); InputStream is = fs.open(new Path(TestHdfsHelper.getHdfsTestDir(), "foo"));
Assert.assertEquals(is.read(), 1); assertEquals(is.read(), 1);
Assert.assertEquals(is.read(), -1); assertEquals(is.read(), -1);
is.close(); is.close();
} finally { } finally {
fs.close(); fs.close();
@ -167,9 +170,9 @@ public class TestHFSTestCase extends HFSTestCase {
server.start(); server.start();
URL url = new URL(TestJettyHelper.getJettyURL(), "/bar"); URL url = new URL(TestJettyHelper.getJettyURL(), "/bar");
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK); assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
Assert.assertEquals(reader.readLine(), "foo"); assertEquals(reader.readLine(), "foo");
reader.close(); reader.close();
} }

View File

@ -18,23 +18,25 @@
package org.apache.hadoop.test; package org.apache.hadoop.test;
import junit.framework.Assert; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.apache.hadoop.util.Time;
import org.junit.Test;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.hadoop.util.Time;
import org.junit.Test;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
public class TestHTestCase extends HTestCase { public class TestHTestCase extends HTestCase {
@Test(expected = IllegalStateException.class) @Test(expected = IllegalStateException.class)
@ -55,7 +57,7 @@ public class TestHTestCase extends HTestCase {
@Test @Test
@TestDir @TestDir
public void testDirAnnotation() throws Exception { public void testDirAnnotation() throws Exception {
Assert.assertNotNull(TestDirHelper.getTestDir()); assertNotNull(TestDirHelper.getTestDir());
} }
@Test @Test
@ -67,8 +69,8 @@ public class TestHTestCase extends HTestCase {
} }
}); });
long end = Time.now(); long end = Time.now();
Assert.assertEquals(waited, 0, 50); assertEquals(waited, 0, 50);
Assert.assertEquals(end - start - waited, 0, 50); assertEquals(end - start - waited, 0, 50);
} }
@Test @Test
@ -81,8 +83,8 @@ public class TestHTestCase extends HTestCase {
} }
}); });
long end = Time.now(); long end = Time.now();
Assert.assertEquals(waited, -1); assertEquals(waited, -1);
Assert.assertEquals(end - start, 200, 50); assertEquals(end - start, 200, 50);
} }
@Test @Test
@ -95,8 +97,8 @@ public class TestHTestCase extends HTestCase {
} }
}); });
long end = Time.now(); long end = Time.now();
Assert.assertEquals(waited, -1); assertEquals(waited, -1);
Assert.assertEquals(end - start, 200 * getWaitForRatio(), 50 * getWaitForRatio()); assertEquals(end - start, 200 * getWaitForRatio(), 50 * getWaitForRatio());
} }
@Test @Test
@ -105,7 +107,7 @@ public class TestHTestCase extends HTestCase {
long start = Time.now(); long start = Time.now();
sleep(100); sleep(100);
long end = Time.now(); long end = Time.now();
Assert.assertEquals(end - start, 100, 50); assertEquals(end - start, 100, 50);
} }
@Test @Test
@ -114,7 +116,7 @@ public class TestHTestCase extends HTestCase {
long start = Time.now(); long start = Time.now();
sleep(100); sleep(100);
long end = Time.now(); long end = Time.now();
Assert.assertEquals(end - start, 100 * getWaitForRatio(), 50 * getWaitForRatio()); assertEquals(end - start, 100 * getWaitForRatio(), 50 * getWaitForRatio());
} }
public static class MyServlet extends HttpServlet { public static class MyServlet extends HttpServlet {
@ -135,9 +137,9 @@ public class TestHTestCase extends HTestCase {
server.start(); server.start();
URL url = new URL(TestJettyHelper.getJettyURL(), "/bar"); URL url = new URL(TestJettyHelper.getJettyURL(), "/bar");
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK); assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_OK);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
Assert.assertEquals(reader.readLine(), "foo"); assertEquals(reader.readLine(), "foo");
reader.close(); reader.close();
} }

View File

@ -17,6 +17,9 @@
*/ */
package org.apache.hadoop.test; package org.apache.hadoop.test;
import java.io.File;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
@ -26,9 +29,6 @@ import org.junit.Test;
import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement; import org.junit.runners.model.Statement;
import java.io.File;
import java.util.concurrent.atomic.AtomicInteger;
public class TestHdfsHelper extends TestDirHelper { public class TestHdfsHelper extends TestDirHelper {
@Test @Test

View File

@ -17,17 +17,17 @@
*/ */
package org.apache.hadoop.test; package org.apache.hadoop.test;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.URL;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.MethodRule; import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement; import org.junit.runners.model.Statement;
import org.mortbay.jetty.Server; import org.mortbay.jetty.Server;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.URL;
public class TestJettyHelper implements MethodRule { public class TestJettyHelper implements MethodRule {
@Test @Test

View File

@ -168,6 +168,8 @@ Release 2.0.1-alpha - UNRELEASED
HDFS-1249. With fuse-dfs, chown which only has owner (or only group) HDFS-1249. With fuse-dfs, chown which only has owner (or only group)
argument fails with Input/output error. (Colin Patrick McCabe via eli) argument fails with Input/output error. (Colin Patrick McCabe via eli)
HDFS-3583. Convert remaining tests to Junit4. (Andrew Wang via atm)
OPTIMIZATIONS OPTIMIZATIONS
HDFS-2982. Startup performance suffers when there are many edit log HDFS-2982. Startup performance suffers when there are many edit log

View File

@ -17,7 +17,11 @@
*/ */
package org.apache.hadoop.cli; package org.apache.hadoop.cli;
import org.apache.hadoop.cli.util.*; import org.apache.hadoop.cli.util.CLICommandDFSAdmin;
import org.apache.hadoop.cli.util.CLICommandTypes;
import org.apache.hadoop.cli.util.CLITestCmd;
import org.apache.hadoop.cli.util.CommandExecutor;
import org.apache.hadoop.cli.util.FSCmdExecutor;
import org.apache.hadoop.hdfs.tools.DFSAdmin; import org.apache.hadoop.hdfs.tools.DFSAdmin;
public class CLITestCmdDFS extends CLITestCmd { public class CLITestCmdDFS extends CLITestCmd {

View File

@ -18,6 +18,8 @@
package org.apache.hadoop.cli; package org.apache.hadoop.cli;
import static org.junit.Assert.assertTrue;
import org.apache.hadoop.cli.util.CLICommand; import org.apache.hadoop.cli.util.CLICommand;
import org.apache.hadoop.cli.util.CommandExecutor.Result; import org.apache.hadoop.cli.util.CommandExecutor.Result;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
@ -27,7 +29,6 @@ import org.apache.hadoop.hdfs.HDFSPolicyProvider;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.security.authorize.PolicyProvider; import org.apache.hadoop.security.authorize.PolicyProvider;
import org.junit.After; import org.junit.After;
import static org.junit.Assert.assertTrue;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -17,16 +17,20 @@
*/ */
package org.apache.hadoop.fs; package org.apache.hadoop.fs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import junit.framework.TestCase; public class TestGlobPaths {
public class TestGlobPaths extends TestCase {
static class RegexPathFilter implements PathFilter { static class RegexPathFilter implements PathFilter {
@ -48,8 +52,8 @@ public class TestGlobPaths extends TestCase {
static final String USER_DIR = "/user/"+System.getProperty("user.name"); static final String USER_DIR = "/user/"+System.getProperty("user.name");
private Path[] path = new Path[NUM_OF_PATHS]; private Path[] path = new Path[NUM_OF_PATHS];
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
try { try {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
dfsCluster = new MiniDFSCluster.Builder(conf).build(); dfsCluster = new MiniDFSCluster.Builder(conf).build();
@ -59,13 +63,14 @@ public class TestGlobPaths extends TestCase {
} }
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
if(dfsCluster!=null) { if(dfsCluster!=null) {
dfsCluster.shutdown(); dfsCluster.shutdown();
} }
} }
@Test
public void testPathFilter() throws IOException { public void testPathFilter() throws IOException {
try { try {
String[] files = new String[] { USER_DIR + "/a", USER_DIR + "/a/b" }; String[] files = new String[] { USER_DIR + "/a", USER_DIR + "/a/b" };
@ -78,6 +83,7 @@ public class TestGlobPaths extends TestCase {
} }
} }
@Test
public void testPathFilterWithFixedLastComponent() throws IOException { public void testPathFilterWithFixedLastComponent() throws IOException {
try { try {
String[] files = new String[] { USER_DIR + "/a", USER_DIR + "/a/b", String[] files = new String[] { USER_DIR + "/a", USER_DIR + "/a/b",
@ -91,6 +97,7 @@ public class TestGlobPaths extends TestCase {
} }
} }
@Test
public void testGlob() throws Exception { public void testGlob() throws Exception {
//pTestEscape(); // need to wait until HADOOP-1995 is fixed //pTestEscape(); // need to wait until HADOOP-1995 is fixed
pTestJavaRegexSpecialChars(); pTestJavaRegexSpecialChars();

View File

@ -18,6 +18,9 @@
package org.apache.hadoop.fs; package org.apache.hadoop.fs;
import static org.apache.hadoop.fs.FileContextTestHelper.exists;
import static org.apache.hadoop.fs.FileContextTestHelper.getTestRootPath;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -27,8 +30,8 @@ import org.apache.hadoop.fs.Options.Rename;
import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.ipc.RemoteException;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -37,8 +40,6 @@ import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import static org.apache.hadoop.fs.FileContextTestHelper.*;
public class TestHDFSFileContextMainOperations extends public class TestHDFSFileContextMainOperations extends
FileContextMainOperationsBaseTest { FileContextMainOperationsBaseTest {
private static MiniDFSCluster cluster; private static MiniDFSCluster cluster;

View File

@ -28,7 +28,6 @@ import org.apache.hadoop.hdfs.DFSTestUtil;
import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier; import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.token.Token; import org.apache.hadoop.security.token.Token;
import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier; import org.apache.hadoop.security.token.delegation.AbstractDelegationTokenIdentifier;

View File

@ -17,6 +17,9 @@
*/ */
package org.apache.hadoop.fs; package org.apache.hadoop.fs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -25,19 +28,15 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.fs.FileSystem; import org.junit.Test;
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
import org.apache.hadoop.fs.Path;
/** /**
* Test of the URL stream handler factory. * Test of the URL stream handler factory.
*/ */
public class TestUrlStreamHandler extends TestCase { public class TestUrlStreamHandler {
/** /**
* Test opening and reading from an InputStream through a hdfs:// URL. * Test opening and reading from an InputStream through a hdfs:// URL.
@ -47,6 +46,7 @@ public class TestUrlStreamHandler extends TestCase {
* *
* @throws IOException * @throws IOException
*/ */
@Test
public void testDfsUrls() throws IOException { public void testDfsUrls() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
@ -105,6 +105,7 @@ public class TestUrlStreamHandler extends TestCase {
* @throws IOException * @throws IOException
* @throws URISyntaxException * @throws URISyntaxException
*/ */
@Test
public void testFileUrls() throws IOException, URISyntaxException { public void testFileUrls() throws IOException, URISyntaxException {
// URLStreamHandler is already set in JVM by testDfsUrls() // URLStreamHandler is already set in JVM by testDfsUrls()
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();

View File

@ -17,6 +17,8 @@
*/ */
package org.apache.hadoop.fs.loadGenerator; package org.apache.hadoop.fs.loadGenerator;
import static org.junit.Assert.assertEquals;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
@ -27,9 +29,6 @@ import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
import static org.junit.Assert.*;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner; import org.apache.hadoop.util.ToolRunner;

View File

@ -17,9 +17,12 @@
*/ */
package org.apache.hadoop.fs.permission; package org.apache.hadoop.fs.permission;
import java.io.IOException; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import junit.framework.TestCase; import java.io.IOException;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
@ -32,8 +35,9 @@ import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.security.AccessControlException; import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.junit.Test;
public class TestStickyBit extends TestCase { public class TestStickyBit {
static UserGroupInformation user1 = static UserGroupInformation user1 =
UserGroupInformation.createUserForTesting("theDoctor", new String[] {"tardis"}); UserGroupInformation.createUserForTesting("theDoctor", new String[] {"tardis"});
@ -158,6 +162,7 @@ public class TestStickyBit extends TestCase {
assertFalse(hdfs.getFileStatus(f).getPermission().getStickyBit()); assertFalse(hdfs.getFileStatus(f).getPermission().getStickyBit());
} }
@Test
public void testGeneralSBBehavior() throws IOException, InterruptedException { public void testGeneralSBBehavior() throws IOException, InterruptedException {
MiniDFSCluster cluster = null; MiniDFSCluster cluster = null;
try { try {
@ -195,6 +200,7 @@ public class TestStickyBit extends TestCase {
* Test that one user can't rename/move another user's file when the sticky * Test that one user can't rename/move another user's file when the sticky
* bit is set. * bit is set.
*/ */
@Test
public void testMovingFiles() throws IOException, InterruptedException { public void testMovingFiles() throws IOException, InterruptedException {
MiniDFSCluster cluster = null; MiniDFSCluster cluster = null;
@ -243,6 +249,7 @@ public class TestStickyBit extends TestCase {
* the sticky bit back on re-start, and that no extra sticky bits appear after * the sticky bit back on re-start, and that no extra sticky bits appear after
* re-start. * re-start.
*/ */
@Test
public void testStickyBitPersistence() throws IOException { public void testStickyBitPersistence() throws IOException {
MiniDFSCluster cluster = null; MiniDFSCluster cluster = null;
try { try {

View File

@ -23,6 +23,9 @@ package org.apache.hadoop.fs.viewfs;
* Since viewfs has overlayed ViewFsFileStatus, we ran into * Since viewfs has overlayed ViewFsFileStatus, we ran into
* serialization problems. THis test is test the fix. * serialization problems. THis test is test the fix.
*/ */
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -40,11 +43,9 @@ import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.io.DataInputBuffer; import org.apache.hadoop.io.DataInputBuffer;
import org.apache.hadoop.io.DataOutputBuffer; import org.apache.hadoop.io.DataOutputBuffer;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
public class TestViewFsFileStatusHdfs { public class TestViewFsFileStatusHdfs {

View File

@ -17,13 +17,12 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Random; import java.util.Random;
import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -121,16 +120,16 @@ public class AppendTestUtil {
FSDataInputStream in = fs.open(p); FSDataInputStream in = fs.open(p);
if (in.getWrappedStream() instanceof DFSInputStream) { if (in.getWrappedStream() instanceof DFSInputStream) {
long len = ((DFSInputStream)in.getWrappedStream()).getFileLength(); long len = ((DFSInputStream)in.getWrappedStream()).getFileLength();
TestCase.assertEquals(length, len); assertEquals(length, len);
} else { } else {
TestCase.assertEquals(length, status.getLen()); assertEquals(length, status.getLen());
} }
for(i++; i < length; i++) { for(i++; i < length; i++) {
TestCase.assertEquals((byte)i, (byte)in.read()); assertEquals((byte)i, (byte)in.read());
} }
i = -(int)length; i = -(int)length;
TestCase.assertEquals(-1, in.read()); //EOF assertEquals(-1, in.read()); //EOF
in.close(); in.close();
} catch(IOException ioe) { } catch(IOException ioe) {
throw new IOException("p=" + p + ", length=" + length + ", i=" + i, ioe); throw new IOException("p=" + p + ", length=" + length + ", i=" + i, ioe);
@ -175,7 +174,7 @@ public class AppendTestUtil {
private static void checkData(final byte[] actual, int from, private static void checkData(final byte[] actual, int from,
final byte[] expected, String message) { final byte[] expected, String message) {
for (int idx = 0; idx < actual.length; idx++) { for (int idx = 0; idx < actual.length; idx++) {
Assert.assertEquals(message+" byte "+(from+idx)+" differs. expected "+ assertEquals(message+" byte "+(from+idx)+" differs. expected "+
expected[from+idx]+" actual "+actual[idx], expected[from+idx]+" actual "+actual[idx],
expected[from+idx], actual[idx]); expected[from+idx], actual[idx]);
actual[idx] = 0; actual[idx] = 0;
@ -189,7 +188,7 @@ public class AppendTestUtil {
final FSDataOutputStream out = fs.create(p, (short)1); final FSDataOutputStream out = fs.create(p, (short)1);
out.write(bytes); out.write(bytes);
out.close(); out.close();
Assert.assertEquals(bytes.length, fs.getFileStatus(p).getLen()); assertEquals(bytes.length, fs.getFileStatus(p).getLen());
} }
for(int i = 2; i < 500; i++) { for(int i = 2; i < 500; i++) {
@ -197,7 +196,7 @@ public class AppendTestUtil {
final FSDataOutputStream out = fs.append(p); final FSDataOutputStream out = fs.append(p);
out.write(bytes); out.write(bytes);
out.close(); out.close();
Assert.assertEquals(i*bytes.length, fs.getFileStatus(p).getLen()); assertEquals(i*bytes.length, fs.getFileStatus(p).getLen());
} }
} }
} }

View File

@ -36,7 +36,6 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner; import org.apache.hadoop.util.ToolRunner;
import org.apache.log4j.Level; import org.apache.log4j.Level;
/** /**

View File

@ -18,25 +18,26 @@
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import java.net.Socket; import static org.junit.Assert.assertEquals;
import java.net.InetSocketAddress; import static org.junit.Assert.assertTrue;
import java.io.DataOutputStream;
import java.util.Random;
import java.util.List;
import java.io.IOException;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.List;
import java.util.Random;
import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.hdfs.protocol.ExtendedBlock; import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
import org.apache.hadoop.hdfs.protocol.LocatedBlock; import org.apache.hadoop.hdfs.protocol.LocatedBlock;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants;
import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.net.NetUtils;
import static org.junit.Assert.*;
/** /**
* A helper class to setup the cluster, and get to BlockReader and DataNode for a block. * A helper class to setup the cluster, and get to BlockReader and DataNode for a block.
*/ */

View File

@ -55,7 +55,6 @@ import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileSystem.Statistics; import org.apache.hadoop.fs.FileSystem.Statistics;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DFSTestUtil.Builder;
import org.apache.hadoop.hdfs.MiniDFSCluster.NameNodeInfo; import org.apache.hadoop.hdfs.MiniDFSCluster.NameNodeInfo;
import org.apache.hadoop.hdfs.client.HdfsDataInputStream; import org.apache.hadoop.hdfs.client.HdfsDataInputStream;
import org.apache.hadoop.hdfs.protocol.DatanodeID; import org.apache.hadoop.hdfs.protocol.DatanodeID;

View File

@ -17,6 +17,8 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import java.io.IOException;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -27,8 +29,6 @@ import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.io.IOException;
/** This is a comprehensive append test that tries /** This is a comprehensive append test that tries
* all combinations of file length and number of appended bytes * all combinations of file length and number of appended bytes
* In each iteration, it creates a file of len1. Then reopen * In each iteration, it creates a file of len1. Then reopen

View File

@ -17,18 +17,20 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*; import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.protocol.LocatedBlock; import org.apache.hadoop.hdfs.protocol.LocatedBlock;
import org.apache.hadoop.hdfs.protocol.LocatedBlocks; import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
import org.apache.hadoop.hdfs.protocol.QuotaExceededException; import org.apache.hadoop.hdfs.protocol.QuotaExceededException;
import static org.junit.Assert.*;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -17,27 +17,27 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import java.util.ArrayList; import static org.junit.Assert.assertEquals;
import junit.framework.TestCase; import java.util.ArrayList;
import org.apache.hadoop.conf.Configuration;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.DFSConfigKeys; import org.junit.Test;
/** /**
* This test ensures that the balancer bandwidth is dynamically adjusted * This test ensures that the balancer bandwidth is dynamically adjusted
* correctly. * correctly.
*/ */
public class TestBalancerBandwidth extends TestCase { public class TestBalancerBandwidth {
final static private Configuration conf = new Configuration(); final static private Configuration conf = new Configuration();
final static private int NUM_OF_DATANODES = 2; final static private int NUM_OF_DATANODES = 2;
final static private int DEFAULT_BANDWIDTH = 1024*1024; final static private int DEFAULT_BANDWIDTH = 1024*1024;
public static final Log LOG = LogFactory.getLog(TestBalancerBandwidth.class); public static final Log LOG = LogFactory.getLog(TestBalancerBandwidth.class);
@Test
public void testBalancerBandwidth() throws Exception { public void testBalancerBandwidth() throws Exception {
/* Set bandwidthPerSec to a low value of 1M bps. */ /* Set bandwidthPerSec to a low value of 1M bps. */
conf.setLong( conf.setLong(

View File

@ -17,26 +17,24 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.protocol.ExtendedBlock; import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
import org.apache.hadoop.hdfs.protocol.LocatedBlocks; import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
import org.apache.hadoop.hdfs.DistributedFileSystem; import org.junit.Test;
import org.apache.hadoop.hdfs.BlockMissingException;
public class TestBlockMissingException extends TestCase { public class TestBlockMissingException {
final static Log LOG = LogFactory.getLog("org.apache.hadoop.hdfs.TestBlockMissing"); final static Log LOG = LogFactory.getLog("org.apache.hadoop.hdfs.TestBlockMissing");
final static int NUM_DATANODES = 3; final static int NUM_DATANODES = 3;
@ -47,6 +45,7 @@ public class TestBlockMissingException extends TestCase {
/** /**
* Test DFS Raid * Test DFS Raid
*/ */
@Test
public void testBlockMissingException() throws Exception { public void testBlockMissingException() throws Exception {
LOG.info("Test testBlockMissingException started."); LOG.info("Test testBlockMissingException started.");
long blockSize = 1024L; long blockSize = 1024L;

View File

@ -17,24 +17,26 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import junit.framework.TestCase;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor; import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeManager; import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeManager;
import org.junit.Test;
/** /**
* This class tests DatanodeDescriptor.getBlocksScheduled() at the * This class tests DatanodeDescriptor.getBlocksScheduled() at the
* NameNode. This counter is supposed to keep track of blocks currently * NameNode. This counter is supposed to keep track of blocks currently
* scheduled to a datanode. * scheduled to a datanode.
*/ */
public class TestBlocksScheduledCounter extends TestCase { public class TestBlocksScheduledCounter {
@Test
public void testBlocksScheduledCounter() throws IOException { public void testBlocksScheduledCounter() throws IOException {
MiniDFSCluster cluster = new MiniDFSCluster.Builder(new HdfsConfiguration()) MiniDFSCluster cluster = new MiniDFSCluster.Builder(new HdfsConfiguration())
.build(); .build();

View File

@ -18,21 +18,20 @@
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import java.util.List; import static org.mockito.Mockito.never;
import org.apache.hadoop.hdfs.DFSClient;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
import org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.Status;
import org.apache.hadoop.fs.Path;
import org.apache.log4j.Level;
import org.junit.Test;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.never;
import java.util.List;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
import org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.Status;
import org.apache.log4j.Level;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class TestClientBlockVerification { public class TestClientBlockVerification {

View File

@ -26,11 +26,9 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.protocol.ExtendedBlock; import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
import org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException; import org.apache.hadoop.hdfs.server.namenode.LeaseExpiredException;
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols; import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocols;
import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.junit.Test;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test;
/** /**
* This tests pipeline recovery related client protocol works correct or not. * This tests pipeline recovery related client protocol works correct or not.

View File

@ -17,37 +17,33 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.spy;
import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.io.IOException;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DFSClient; import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.hdfs.DFSInputStream;
import org.apache.hadoop.hdfs.SocketCache;
import org.apache.hadoop.hdfs.protocol.ExtendedBlock; import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
import org.apache.hadoop.hdfs.protocol.LocatedBlock; import org.apache.hadoop.hdfs.protocol.LocatedBlock;
import org.apache.hadoop.hdfs.security.token.block.BlockTokenIdentifier; import org.apache.hadoop.hdfs.security.token.block.BlockTokenIdentifier;
import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.security.token.Token; import org.apache.hadoop.security.token.Token;
import org.junit.Test;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import static org.junit.Assert.*; import org.junit.Test;
import org.mockito.Matchers; import org.mockito.Matchers;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import static org.mockito.Mockito.spy; import org.mockito.stubbing.Answer;
/** /**
* This class tests the client connection caching in a single node * This class tests the client connection caching in a single node

View File

@ -18,21 +18,23 @@
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.RandomAccessFile;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.util.Random; import java.util.Random;
import org.junit.Test;
import static org.junit.Assert.*;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.protocol.ExtendedBlock; import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.junit.Test;
/** /**
* A JUnit test for corrupted file handling. * A JUnit test for corrupted file handling.

View File

@ -24,20 +24,25 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import java.io.IOException;
import java.util.ArrayList;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_ADDRESS_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_ADDRESS_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_HTTP_ADDRESS_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_HTTP_ADDRESS_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_IPC_ADDRESS_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_IPC_ADDRESS_KEY;
import org.apache.hadoop.hdfs.server.datanode.DataNode; import static org.junit.Assert.assertNotNull;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption; import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.MiniDFSCluster.DataNodeProperties; import org.apache.hadoop.hdfs.MiniDFSCluster.DataNodeProperties;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.junit.Test;
public class TestDFSAddressConfig extends TestCase { public class TestDFSAddressConfig {
@Test
public void testDFSAddressConfig() throws IOException { public void testDFSAddressConfig() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();

View File

@ -17,15 +17,15 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import org.junit.*;
import static org.junit.Assert.fail;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.junit.Test;
/** /**

View File

@ -17,6 +17,10 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
@ -38,8 +42,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Log4JLogger; import org.apache.commons.logging.impl.Log4JLogger;
@ -75,6 +77,7 @@ import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.internal.stubbing.answers.ThrowsException; import org.mockito.internal.stubbing.answers.ThrowsException;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
@ -86,7 +89,7 @@ import com.google.common.base.Joiner;
* These tests make sure that DFSClient retries fetching data from DFS * These tests make sure that DFSClient retries fetching data from DFS
* properly in case of errors. * properly in case of errors.
*/ */
public class TestDFSClientRetries extends TestCase { public class TestDFSClientRetries {
private static final String ADDRESS = "0.0.0.0"; private static final String ADDRESS = "0.0.0.0";
final static private int PING_INTERVAL = 1000; final static private int PING_INTERVAL = 1000;
final static private int MIN_SLEEP_TIME = 1000; final static private int MIN_SLEEP_TIME = 1000;
@ -146,6 +149,7 @@ public class TestDFSClientRetries extends TestCase {
* This makes sure that when DN closes clients socket after client had * This makes sure that when DN closes clients socket after client had
* successfully connected earlier, the data can still be fetched. * successfully connected earlier, the data can still be fetched.
*/ */
@Test
public void testWriteTimeoutAtDataNode() throws IOException, public void testWriteTimeoutAtDataNode() throws IOException,
InterruptedException { InterruptedException {
final int writeTimeout = 100; //milliseconds. final int writeTimeout = 100; //milliseconds.
@ -198,6 +202,7 @@ public class TestDFSClientRetries extends TestCase {
* of times trying to add a block * of times trying to add a block
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
@Test
public void testNotYetReplicatedErrors() throws IOException public void testNotYetReplicatedErrors() throws IOException
{ {
final String exceptionMsg = "Nope, not replicated yet..."; final String exceptionMsg = "Nope, not replicated yet...";
@ -242,6 +247,7 @@ public class TestDFSClientRetries extends TestCase {
* operation, and not over the lifetime of the stream. It is a regression * operation, and not over the lifetime of the stream. It is a regression
* test for HDFS-127. * test for HDFS-127.
*/ */
@Test
public void testFailuresArePerOperation() throws Exception public void testFailuresArePerOperation() throws Exception
{ {
long fileSize = 4096; long fileSize = 4096;
@ -317,6 +323,7 @@ public class TestDFSClientRetries extends TestCase {
* a client to safely retry a call and still produce a correct * a client to safely retry a call and still produce a correct
* file. See HDFS-3031. * file. See HDFS-3031.
*/ */
@Test
public void testIdempotentAllocateBlockAndClose() throws Exception { public void testIdempotentAllocateBlockAndClose() throws Exception {
final String src = "/testIdempotentAllocateBlock"; final String src = "/testIdempotentAllocateBlock";
Path file = new Path(src); Path file = new Path(src);
@ -457,6 +464,7 @@ public class TestDFSClientRetries extends TestCase {
/** /**
* Test that a DFSClient waits for random time before retry on busy blocks. * Test that a DFSClient waits for random time before retry on busy blocks.
*/ */
@Test
public void testDFSClientRetriesOnBusyBlocks() throws IOException { public void testDFSClientRetriesOnBusyBlocks() throws IOException {
System.out.println("Testing DFSClient random waiting on busy blocks."); System.out.println("Testing DFSClient random waiting on busy blocks.");
@ -695,6 +703,7 @@ public class TestDFSClientRetries extends TestCase {
public int get() { return counter; } public int get() { return counter; }
} }
@Test
public void testGetFileChecksum() throws Exception { public void testGetFileChecksum() throws Exception {
final String f = "/testGetFileChecksum"; final String f = "/testGetFileChecksum";
final Path p = new Path(f); final Path p = new Path(f);
@ -731,6 +740,7 @@ public class TestDFSClientRetries extends TestCase {
* RPC to the server and set rpcTimeout to less than n and ensure * RPC to the server and set rpcTimeout to less than n and ensure
* that socketTimeoutException is obtained * that socketTimeoutException is obtained
*/ */
@Test
public void testClientDNProtocolTimeout() throws IOException { public void testClientDNProtocolTimeout() throws IOException {
final Server server = new TestServer(1, true); final Server server = new TestServer(1, true);
server.start(); server.start();
@ -760,6 +770,7 @@ public class TestDFSClientRetries extends TestCase {
} }
/** Test client retry with namenode restarting. */ /** Test client retry with namenode restarting. */
@Test
public void testNamenodeRestart() throws Exception { public void testNamenodeRestart() throws Exception {
((Log4JLogger)DFSClient.LOG).getLogger().setLevel(Level.ALL); ((Log4JLogger)DFSClient.LOG).getLogger().setLevel(Level.ALL);
@ -885,6 +896,7 @@ public class TestDFSClientRetries extends TestCase {
} }
} }
@Test
public void testMultipleLinearRandomRetry() { public void testMultipleLinearRandomRetry() {
parseMultipleLinearRandomRetry(null, ""); parseMultipleLinearRandomRetry(null, "");
parseMultipleLinearRandomRetry(null, "11"); parseMultipleLinearRandomRetry(null, "11");
@ -922,6 +934,7 @@ public class TestDFSClientRetries extends TestCase {
* read call, so the client should expect consecutive calls to behave the same * read call, so the client should expect consecutive calls to behave the same
* way. See HDFS-3067. * way. See HDFS-3067.
*/ */
@Test
public void testRetryOnChecksumFailure() public void testRetryOnChecksumFailure()
throws UnresolvedLinkException, IOException { throws UnresolvedLinkException, IOException {
HdfsConfiguration conf = new HdfsConfiguration(); HdfsConfiguration conf = new HdfsConfiguration();

View File

@ -17,17 +17,21 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.DATA_NODE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.io.File; import java.io.File;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.DATA_NODE;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil; import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil;
import org.junit.After;
import org.junit.Test;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -35,7 +39,7 @@ import com.google.common.collect.Lists;
* This test ensures the appropriate response from the system when * This test ensures the appropriate response from the system when
* the system is finalized. * the system is finalized.
*/ */
public class TestDFSFinalize extends TestCase { public class TestDFSFinalize {
private static final Log LOG = LogFactory.getLog( private static final Log LOG = LogFactory.getLog(
"org.apache.hadoop.hdfs.TestDFSFinalize"); "org.apache.hadoop.hdfs.TestDFSFinalize");
@ -86,6 +90,7 @@ public class TestDFSFinalize extends TestCase {
/** /**
* This test attempts to finalize the NameNode and DataNode. * This test attempts to finalize the NameNode and DataNode.
*/ */
@Test
public void testFinalize() throws Exception { public void testFinalize() throws Exception {
UpgradeUtilities.initialize(); UpgradeUtilities.initialize();
@ -125,8 +130,8 @@ public class TestDFSFinalize extends TestCase {
} // end numDir loop } // end numDir loop
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
LOG.info("Shutting down MiniDFSCluster"); LOG.info("Shutting down MiniDFSCluster");
if (cluster != null) cluster.shutdown(); if (cluster != null) cluster.shutdown();
} }

View File

@ -17,21 +17,27 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import junit.framework.TestCase; import static org.junit.Assert.assertFalse;
import java.io.*; import static org.junit.Assert.assertTrue;
import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.ParentNotDirectoryException; import org.apache.hadoop.fs.ParentNotDirectoryException;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.junit.Test;
/** /**
* This class tests that the DFS command mkdirs cannot create subdirectories * This class tests that the DFS command mkdirs cannot create subdirectories
* from a file when passed an illegal path. HADOOP-281. * from a file when passed an illegal path. HADOOP-281.
*/ */
public class TestDFSMkdirs extends TestCase { public class TestDFSMkdirs {
private void writeFile(FileSystem fileSys, Path name) throws IOException { private void writeFile(FileSystem fileSys, Path name) throws IOException {
DataOutputStream stm = fileSys.create(name); DataOutputStream stm = fileSys.create(name);
@ -43,6 +49,7 @@ public class TestDFSMkdirs extends TestCase {
* Tests mkdirs can create a directory that does not exist and will * Tests mkdirs can create a directory that does not exist and will
* not create a subdirectory off a file. * not create a subdirectory off a file.
*/ */
@Test
public void testDFSMkdirs() throws IOException { public void testDFSMkdirs() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
@ -80,6 +87,7 @@ public class TestDFSMkdirs extends TestCase {
/** /**
* Tests mkdir will not create directory when parent is missing. * Tests mkdir will not create directory when parent is missing.
*/ */
@Test
public void testMkdir() throws IOException { public void testMkdir() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();

View File

@ -17,14 +17,15 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -35,13 +36,15 @@ import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.hdfs.server.common.Util;
import org.apache.hadoop.security.AccessControlException; import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/** Unit tests for permission */ /** Unit tests for permission */
public class TestDFSPermission extends TestCase { public class TestDFSPermission {
public static final Log LOG = LogFactory.getLog(TestDFSPermission.class); public static final Log LOG = LogFactory.getLog(TestDFSPermission.class);
final private static Configuration conf = new HdfsConfiguration(); final private static Configuration conf = new HdfsConfiguration();
@ -106,13 +109,13 @@ public class TestDFSPermission extends TestCase {
} }
} }
@Override @Before
public void setUp() throws IOException { public void setUp() throws IOException {
cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build(); cluster = new MiniDFSCluster.Builder(conf).numDataNodes(3).build();
cluster.waitActive(); cluster.waitActive();
} }
@Override @After
public void tearDown() throws IOException { public void tearDown() throws IOException {
if (cluster != null) { if (cluster != null) {
cluster.shutdown(); cluster.shutdown();
@ -122,6 +125,7 @@ public class TestDFSPermission extends TestCase {
/** This tests if permission setting in create, mkdir, and /** This tests if permission setting in create, mkdir, and
* setPermission works correctly * setPermission works correctly
*/ */
@Test
public void testPermissionSetting() throws Exception { public void testPermissionSetting() throws Exception {
testPermissionSetting(OpType.CREATE); // test file creation testPermissionSetting(OpType.CREATE); // test file creation
testPermissionSetting(OpType.MKDIRS); // test directory creation testPermissionSetting(OpType.MKDIRS); // test directory creation
@ -257,6 +261,7 @@ public class TestDFSPermission extends TestCase {
* check that ImmutableFsPermission can be used as the argument * check that ImmutableFsPermission can be used as the argument
* to setPermission * to setPermission
*/ */
@Test
public void testImmutableFsPermission() throws IOException { public void testImmutableFsPermission() throws IOException {
fs = FileSystem.get(conf); fs = FileSystem.get(conf);
@ -266,6 +271,7 @@ public class TestDFSPermission extends TestCase {
} }
/* check if the ownership of a file/directory is set correctly */ /* check if the ownership of a file/directory is set correctly */
@Test
public void testOwnership() throws Exception { public void testOwnership() throws Exception {
testOwnership(OpType.CREATE); // test file creation testOwnership(OpType.CREATE); // test file creation
testOwnership(OpType.MKDIRS); // test directory creation testOwnership(OpType.MKDIRS); // test directory creation
@ -354,6 +360,7 @@ public class TestDFSPermission extends TestCase {
/* Check if namenode performs permission checking correctly for /* Check if namenode performs permission checking correctly for
* superuser, file owner, group owner, and other users */ * superuser, file owner, group owner, and other users */
@Test
public void testPermissionChecking() throws Exception { public void testPermissionChecking() throws Exception {
try { try {
fs = FileSystem.get(conf); fs = FileSystem.get(conf);
@ -533,7 +540,7 @@ public class TestDFSPermission extends TestCase {
} catch(AccessControlException e) { } catch(AccessControlException e) {
assertTrue(expectPermissionDeny()); assertTrue(expectPermissionDeny());
} }
} catch (AssertionFailedError ae) { } catch (AssertionError ae) {
logPermissions(); logPermissions();
throw ae; throw ae;
} }

View File

@ -16,6 +16,8 @@
* limitations under the License. * limitations under the License.
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@ -26,8 +28,9 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.datanode.DataNodeTestUtils; import org.apache.hadoop.hdfs.server.datanode.DataNodeTestUtils;
import org.junit.Test;
public class TestDFSRemove extends junit.framework.TestCase { public class TestDFSRemove {
final Path dir = new Path("/test/remove/"); final Path dir = new Path("/test/remove/");
void list(FileSystem fs, String name) throws IOException { void list(FileSystem fs, String name) throws IOException {
@ -51,6 +54,7 @@ public class TestDFSRemove extends junit.framework.TestCase {
return total; return total;
} }
@Test
public void testRemove() throws Exception { public void testRemove() throws Exception {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();

View File

@ -16,6 +16,9 @@
* limitations under the License. * limitations under the License.
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
@ -25,8 +28,9 @@ import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter; import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
import org.junit.Test;
public class TestDFSRename extends junit.framework.TestCase { public class TestDFSRename {
static int countLease(MiniDFSCluster cluster) { static int countLease(MiniDFSCluster cluster) {
return NameNodeAdapter.getLeaseManager(cluster.getNamesystem()).countLease(); return NameNodeAdapter.getLeaseManager(cluster.getNamesystem()).countLease();
} }
@ -46,6 +50,7 @@ public class TestDFSRename extends junit.framework.TestCase {
a_out.close(); a_out.close();
} }
@Test
public void testRename() throws Exception { public void testRename() throws Exception {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();

View File

@ -19,22 +19,25 @@ package org.apache.hadoop.hdfs;
import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.DATA_NODE; import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.DATA_NODE;
import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.NAME_NODE; import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.NAME_NODE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.server.common.StorageInfo;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
import org.apache.hadoop.hdfs.server.common.StorageInfo;
import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil; import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.junit.After;
import org.junit.Test;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -44,7 +47,7 @@ import com.google.common.collect.Lists;
* the system when the system is rolled back under various storage state and * the system when the system is rolled back under various storage state and
* version conditions. * version conditions.
*/ */
public class TestDFSRollback extends TestCase { public class TestDFSRollback {
private static final Log LOG = LogFactory.getLog( private static final Log LOG = LogFactory.getLog(
"org.apache.hadoop.hdfs.TestDFSRollback"); "org.apache.hadoop.hdfs.TestDFSRollback");
@ -131,6 +134,7 @@ public class TestDFSRollback extends TestCase {
* This test attempts to rollback the NameNode and DataNode under * This test attempts to rollback the NameNode and DataNode under
* a number of valid and invalid conditions. * a number of valid and invalid conditions.
*/ */
@Test
public void testRollback() throws Exception { public void testRollback() throws Exception {
File[] baseDirs; File[] baseDirs;
UpgradeUtilities.initialize(); UpgradeUtilities.initialize();
@ -299,8 +303,8 @@ public class TestDFSRollback extends TestCase {
} }
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
LOG.info("Shutting down MiniDFSCluster"); LOG.info("Shutting down MiniDFSCluster");
if (cluster != null) cluster.shutdown(); if (cluster != null) cluster.shutdown();
} }

View File

@ -17,6 +17,10 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.File; import java.io.File;
@ -33,8 +37,6 @@ import java.util.Random;
import java.util.Scanner; import java.util.Scanner;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -53,11 +55,12 @@ import org.apache.hadoop.io.Text;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.util.ToolRunner; import org.apache.hadoop.util.ToolRunner;
import org.junit.Test;
/** /**
* This class tests commands from DFSShell. * This class tests commands from DFSShell.
*/ */
public class TestDFSShell extends TestCase { public class TestDFSShell {
private static final Log LOG = LogFactory.getLog(TestDFSShell.class); private static final Log LOG = LogFactory.getLog(TestDFSShell.class);
static final String TEST_ROOT_DIR = static final String TEST_ROOT_DIR =
@ -94,6 +97,7 @@ public class TestDFSShell extends TestCase {
System.out.println(Thread.currentThread().getStackTrace()[2] + " " + s); System.out.println(Thread.currentThread().getStackTrace()[2] + " " + s);
} }
@Test
public void testZeroSizeFile() throws IOException { public void testZeroSizeFile() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
@ -136,6 +140,7 @@ public class TestDFSShell extends TestCase {
} }
} }
@Test
public void testRecrusiveRm() throws IOException { public void testRecrusiveRm() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
@ -161,6 +166,7 @@ public class TestDFSShell extends TestCase {
} }
} }
@Test
public void testDu() throws IOException { public void testDu() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
@ -210,6 +216,7 @@ public class TestDFSShell extends TestCase {
} }
} }
@Test
public void testPut() throws IOException { public void testPut() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
@ -308,6 +315,7 @@ public class TestDFSShell extends TestCase {
/** check command error outputs and exit statuses. */ /** check command error outputs and exit statuses. */
@Test
public void testErrOutPut() throws Exception { public void testErrOutPut() throws Exception {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = null; MiniDFSCluster cluster = null;
@ -448,6 +456,7 @@ public class TestDFSShell extends TestCase {
} }
} }
@Test
public void testURIPaths() throws Exception { public void testURIPaths() throws Exception {
Configuration srcConf = new HdfsConfiguration(); Configuration srcConf = new HdfsConfiguration();
Configuration dstConf = new HdfsConfiguration(); Configuration dstConf = new HdfsConfiguration();
@ -540,6 +549,7 @@ public class TestDFSShell extends TestCase {
} }
} }
@Test
public void testText() throws Exception { public void testText() throws Exception {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = null; MiniDFSCluster cluster = null;
@ -614,6 +624,7 @@ public class TestDFSShell extends TestCase {
} }
} }
@Test
public void testCopyToLocal() throws IOException { public void testCopyToLocal() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
@ -711,6 +722,7 @@ public class TestDFSShell extends TestCase {
return path; return path;
} }
@Test
public void testCount() throws Exception { public void testCount() throws Exception {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
@ -877,6 +889,7 @@ public class TestDFSShell extends TestCase {
} }
} }
@Test
public void testFilePermissions() throws IOException { public void testFilePermissions() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
@ -942,6 +955,7 @@ public class TestDFSShell extends TestCase {
/** /**
* Tests various options of DFSShell. * Tests various options of DFSShell.
*/ */
@Test
public void testDFSShell() throws IOException { public void testDFSShell() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
/* This tests some properties of ChecksumFileSystem as well. /* This tests some properties of ChecksumFileSystem as well.
@ -1209,6 +1223,7 @@ public class TestDFSShell extends TestCase {
String run(int exitcode, String... options) throws IOException; String run(int exitcode, String... options) throws IOException;
} }
@Test
public void testRemoteException() throws Exception { public void testRemoteException() throws Exception {
UserGroupInformation tmpUGI = UserGroupInformation tmpUGI =
UserGroupInformation.createUserForTesting("tmpname", new String[] {"mygroup"}); UserGroupInformation.createUserForTesting("tmpname", new String[] {"mygroup"});
@ -1252,6 +1267,7 @@ public class TestDFSShell extends TestCase {
} }
} }
@Test
public void testGet() throws IOException { public void testGet() throws IOException {
DFSTestUtil.setLogLevel2All(FSInputChecker.LOG); DFSTestUtil.setLogLevel2All(FSInputChecker.LOG);
final Configuration conf = new HdfsConfiguration(); final Configuration conf = new HdfsConfiguration();
@ -1312,6 +1328,7 @@ public class TestDFSShell extends TestCase {
} }
} }
@Test
public void testLsr() throws Exception { public void testLsr() throws Exception {
final Configuration conf = new HdfsConfiguration(); final Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
@ -1369,6 +1386,7 @@ public class TestDFSShell extends TestCase {
* and return -1 exit code. * and return -1 exit code.
* @throws Exception * @throws Exception
*/ */
@Test
public void testInvalidShell() throws Exception { public void testInvalidShell() throws Exception {
Configuration conf = new Configuration(); // default FS (non-DFS) Configuration conf = new Configuration(); // default FS (non-DFS)
DFSAdmin admin = new DFSAdmin(); DFSAdmin admin = new DFSAdmin();
@ -1378,6 +1396,7 @@ public class TestDFSShell extends TestCase {
} }
// force Copy Option is -f // force Copy Option is -f
@Test
public void testCopyCommandsWithForceOption() throws Exception { public void testCopyCommandsWithForceOption() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1) MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1)

View File

@ -17,22 +17,24 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FsShell; import org.apache.hadoop.fs.FsShell;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.util.ToolRunner; import org.apache.hadoop.util.ToolRunner;
import org.junit.Test;
public class TestDFSShellGenericOptions extends TestCase { public class TestDFSShellGenericOptions {
@Test
public void testDFSCommand() throws IOException { public void testDFSCommand() throws IOException {
String namenode = null; String namenode = null;
MiniDFSCluster cluster = null; MiniDFSCluster cluster = null;

View File

@ -19,25 +19,27 @@ package org.apache.hadoop.hdfs;
import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.DATA_NODE; import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.DATA_NODE;
import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.NAME_NODE; import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.NAME_NODE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.server.common.Storage;
import org.apache.hadoop.hdfs.server.common.StorageInfo;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
import org.apache.hadoop.hdfs.server.common.Storage;
import org.apache.hadoop.hdfs.server.common.StorageInfo;
import org.junit.After;
import org.junit.Test;
/** /**
* This test ensures the appropriate response (successful or failure) from * This test ensures the appropriate response (successful or failure) from
* a Datanode when the system is started with differing version combinations. * a Datanode when the system is started with differing version combinations.
*/ */
public class TestDFSStartupVersions extends TestCase { public class TestDFSStartupVersions {
private static final Log LOG = LogFactory.getLog( private static final Log LOG = LogFactory.getLog(
"org.apache.hadoop.hdfs.TestDFSStartupVersions"); "org.apache.hadoop.hdfs.TestDFSStartupVersions");
@ -235,6 +237,7 @@ public class TestDFSStartupVersions extends TestCase {
* this iterations version 3-tuple * this iterations version 3-tuple
* </pre> * </pre>
*/ */
@Test
public void testVersions() throws Exception { public void testVersions() throws Exception {
UpgradeUtilities.initialize(); UpgradeUtilities.initialize();
Configuration conf = UpgradeUtilities.initializeStorageStateConf(1, Configuration conf = UpgradeUtilities.initializeStorageStateConf(1,
@ -276,8 +279,8 @@ public class TestDFSStartupVersions extends TestCase {
} }
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
LOG.info("Shutting down MiniDFSCluster"); LOG.info("Shutting down MiniDFSCluster");
if (cluster != null) cluster.shutdown(); if (cluster != null) cluster.shutdown();
} }

View File

@ -17,25 +17,32 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.DATA_NODE;
import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.NAME_NODE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.server.common.Storage;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
import org.apache.hadoop.hdfs.server.common.Storage;
import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil; import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil;
import org.junit.After;
import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.NAME_NODE; import org.junit.Before;
import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.DATA_NODE; import org.junit.Test;
/** /**
* This test ensures the appropriate response (successful or failure) from * This test ensures the appropriate response (successful or failure) from
* the system when the system is started under various storage state and * the system when the system is started under various storage state and
* version conditions. * version conditions.
*/ */
public class TestDFSStorageStateRecovery extends TestCase { public class TestDFSStorageStateRecovery {
private static final Log LOG = LogFactory.getLog( private static final Log LOG = LogFactory.getLog(
"org.apache.hadoop.hdfs.TestDFSStorageStateRecovery"); "org.apache.hadoop.hdfs.TestDFSStorageStateRecovery");
@ -311,6 +318,7 @@ public class TestDFSStorageStateRecovery extends TestCase {
* This test iterates over the testCases table and attempts * This test iterates over the testCases table and attempts
* to startup the NameNode normally. * to startup the NameNode normally.
*/ */
@Test
public void testNNStorageStates() throws Exception { public void testNNStorageStates() throws Exception {
String[] baseDirs; String[] baseDirs;
@ -354,6 +362,7 @@ public class TestDFSStorageStateRecovery extends TestCase {
* This test iterates over the testCases table for Datanode storage and * This test iterates over the testCases table for Datanode storage and
* attempts to startup the DataNode normally. * attempts to startup the DataNode normally.
*/ */
@Test
public void testDNStorageStates() throws Exception { public void testDNStorageStates() throws Exception {
String[] baseDirs; String[] baseDirs;
@ -394,6 +403,7 @@ public class TestDFSStorageStateRecovery extends TestCase {
* This test iterates over the testCases table for block pool storage and * This test iterates over the testCases table for block pool storage and
* attempts to startup the DataNode normally. * attempts to startup the DataNode normally.
*/ */
@Test
public void testBlockPoolStorageStates() throws Exception { public void testBlockPoolStorageStates() throws Exception {
String[] baseDirs; String[] baseDirs;
@ -431,14 +441,14 @@ public class TestDFSStorageStateRecovery extends TestCase {
} // end numDirs loop } // end numDirs loop
} }
@Override @Before
protected void setUp() throws Exception { public void setUp() throws Exception {
LOG.info("Setting up the directory structures."); LOG.info("Setting up the directory structures.");
UpgradeUtilities.initialize(); UpgradeUtilities.initialize();
} }
@Override @After
protected void tearDown() throws Exception { public void tearDown() throws Exception {
LOG.info("Shutting down MiniDFSCluster"); LOG.info("Shutting down MiniDFSCluster");
if (cluster != null) cluster.shutdown(); if (cluster != null) cluster.shutdown();
} }

View File

@ -19,6 +19,13 @@ package org.apache.hadoop.hdfs;
import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.DATA_NODE; import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.DATA_NODE;
import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.NAME_NODE; import static org.apache.hadoop.hdfs.server.common.HdfsServerConstants.NodeType.NAME_NODE;
import static org.apache.hadoop.hdfs.server.namenode.NNStorage.getImageFileName;
import static org.apache.hadoop.hdfs.server.namenode.NNStorage.getInProgressEditsFileName;
import static org.apache.hadoop.test.GenericTestUtils.assertExists;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -27,14 +34,10 @@ import java.util.regex.Pattern;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
import org.apache.hadoop.hdfs.server.common.Storage; import org.apache.hadoop.hdfs.server.common.Storage;
import org.apache.hadoop.hdfs.server.common.StorageInfo; import org.apache.hadoop.hdfs.server.common.StorageInfo;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
import org.apache.hadoop.hdfs.server.namenode.TestParallelImageWrite; import org.apache.hadoop.hdfs.server.namenode.TestParallelImageWrite;
import static org.apache.hadoop.hdfs.server.namenode.NNStorage.getInProgressEditsFileName;
import static org.apache.hadoop.hdfs.server.namenode.NNStorage.getImageFileName;
import static org.apache.hadoop.test.GenericTestUtils.assertExists;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Ignore; import org.junit.Ignore;
@ -43,8 +46,6 @@ import org.junit.Test;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import static org.junit.Assert.*;
/** /**
* This test ensures the appropriate response (successful or failure) from * This test ensures the appropriate response (successful or failure) from
* the system when the system is upgraded under various storage state and * the system when the system is upgraded under various storage state and

View File

@ -18,13 +18,22 @@
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import java.io.*; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSInputStream; import org.apache.hadoop.fs.FSInputStream;
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
@ -34,8 +43,7 @@ import org.apache.hadoop.hdfs.protocol.HdfsConstants;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil; import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.apache.commons.logging.Log; import org.junit.Test;
import org.apache.commons.logging.LogFactory;
/** /**
* This tests data transfer protocol handling in the Datanode. It sends * This tests data transfer protocol handling in the Datanode. It sends
@ -46,7 +54,7 @@ import org.apache.commons.logging.LogFactory;
* 2) hadoop-dfs-dir.txt : checksums that are compared in this test. * 2) hadoop-dfs-dir.txt : checksums that are compared in this test.
* Please read hadoop-dfs-dir.txt for more information. * Please read hadoop-dfs-dir.txt for more information.
*/ */
public class TestDFSUpgradeFromImage extends TestCase { public class TestDFSUpgradeFromImage {
private static final Log LOG = LogFactory private static final Log LOG = LogFactory
.getLog(TestDFSUpgradeFromImage.class); .getLog(TestDFSUpgradeFromImage.class);
@ -182,6 +190,7 @@ public class TestDFSUpgradeFromImage extends TestCase {
* Test that sets up a fake image from Hadoop 0.3.0 and tries to start a * Test that sets up a fake image from Hadoop 0.3.0 and tries to start a
* NN, verifying that the correct error message is thrown. * NN, verifying that the correct error message is thrown.
*/ */
@Test
public void testFailOnPreUpgradeImage() throws IOException { public void testFailOnPreUpgradeImage() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
@ -225,6 +234,7 @@ public class TestDFSUpgradeFromImage extends TestCase {
/** /**
* Test upgrade from 0.22 image * Test upgrade from 0.22 image
*/ */
@Test
public void testUpgradeFromRel22Image() throws IOException { public void testUpgradeFromRel22Image() throws IOException {
unpackStorage(HADOOP22_IMAGE); unpackStorage(HADOOP22_IMAGE);
upgradeAndVerify(); upgradeAndVerify();
@ -234,6 +244,7 @@ public class TestDFSUpgradeFromImage extends TestCase {
* Test upgrade from 0.22 image with corrupt md5, make sure it * Test upgrade from 0.22 image with corrupt md5, make sure it
* fails to upgrade * fails to upgrade
*/ */
@Test
public void testUpgradeFromCorruptRel22Image() throws IOException { public void testUpgradeFromCorruptRel22Image() throws IOException {
unpackStorage(HADOOP22_IMAGE); unpackStorage(HADOOP22_IMAGE);

View File

@ -18,10 +18,22 @@
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import org.junit.Before; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY;
import org.junit.Test; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_HA_NAMENODES_KEY_PREFIX;
import static org.junit.Assert.*; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_BACKUP_ADDRESS_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_HTTPS_PORT_DEFAULT;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_HTTP_PORT_DEFAULT;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_RPC_ADDRESS_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SECONDARY_HTTP_ADDRESS_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMESERVICES;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMESERVICE_ID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -34,18 +46,18 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.hadoop.HadoopIllegalArgumentException; import org.apache.hadoop.HadoopIllegalArgumentException;
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.BlockLocation; import org.apache.hadoop.fs.BlockLocation;
import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import static org.apache.hadoop.hdfs.DFSConfigKeys.*; import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
import org.apache.hadoop.hdfs.protocol.LocatedBlock;
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.security.UserGroupInformation;
import org.junit.Before;
import org.junit.Test;
public class TestDFSUtil { public class TestDFSUtil {

View File

@ -20,7 +20,10 @@ package org.apache.hadoop.hdfs;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_CLIENT_MAX_BLOCK_ACQUIRE_FAILURES_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_CLIENT_MAX_BLOCK_ACQUIRE_FAILURES_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_SOCKET_REUSE_KEEPALIVE_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_SOCKET_REUSE_KEEPALIVE_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_SOCKET_WRITE_TIMEOUT_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_DATANODE_SOCKET_WRITE_TIMEOUT_KEY;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintWriter; import java.io.PrintWriter;

View File

@ -18,6 +18,10 @@
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
@ -28,8 +32,6 @@ import java.util.concurrent.TimeoutException;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -40,11 +42,12 @@ import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType; import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.junit.Test;
/** /**
* This test verifies that block verification occurs on the datanode * This test verifies that block verification occurs on the datanode
*/ */
public class TestDatanodeBlockScanner extends TestCase { public class TestDatanodeBlockScanner {
private static final Log LOG = private static final Log LOG =
LogFactory.getLog(TestDatanodeBlockScanner.class); LogFactory.getLog(TestDatanodeBlockScanner.class);
@ -118,6 +121,7 @@ public class TestDatanodeBlockScanner extends TestCase {
return verificationTime; return verificationTime;
} }
@Test
public void testDatanodeBlockScanner() throws IOException, TimeoutException { public void testDatanodeBlockScanner() throws IOException, TimeoutException {
long startTime = Time.now(); long startTime = Time.now();
@ -168,6 +172,7 @@ public class TestDatanodeBlockScanner extends TestCase {
return MiniDFSCluster.corruptReplica(replica, blk); return MiniDFSCluster.corruptReplica(replica, blk);
} }
@Test
public void testBlockCorruptionPolicy() throws IOException { public void testBlockCorruptionPolicy() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 1000L); conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 1000L);
@ -232,12 +237,14 @@ public class TestDatanodeBlockScanner extends TestCase {
* 4. Test again waits until the block is reported with expected number * 4. Test again waits until the block is reported with expected number
* of good replicas. * of good replicas.
*/ */
@Test
public void testBlockCorruptionRecoveryPolicy1() throws Exception { public void testBlockCorruptionRecoveryPolicy1() throws Exception {
// Test recovery of 1 corrupt replica // Test recovery of 1 corrupt replica
LOG.info("Testing corrupt replica recovery for one corrupt replica"); LOG.info("Testing corrupt replica recovery for one corrupt replica");
blockCorruptionRecoveryPolicy(4, (short)3, 1); blockCorruptionRecoveryPolicy(4, (short)3, 1);
} }
@Test
public void testBlockCorruptionRecoveryPolicy2() throws Exception { public void testBlockCorruptionRecoveryPolicy2() throws Exception {
// Test recovery of 2 corrupt replicas // Test recovery of 2 corrupt replicas
LOG.info("Testing corrupt replica recovery for two corrupt replicas"); LOG.info("Testing corrupt replica recovery for two corrupt replicas");
@ -302,6 +309,7 @@ public class TestDatanodeBlockScanner extends TestCase {
} }
/** Test if NameNode handles truncated blocks in block report */ /** Test if NameNode handles truncated blocks in block report */
@Test
public void testTruncatedBlockReport() throws Exception { public void testTruncatedBlockReport() throws Exception {
final Configuration conf = new HdfsConfiguration(); final Configuration conf = new HdfsConfiguration();
final short REPLICATION_FACTOR = (short)2; final short REPLICATION_FACTOR = (short)2;

View File

@ -17,9 +17,10 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import java.io.IOException; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import junit.framework.TestCase; import java.io.IOException;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Log4JLogger; import org.apache.commons.logging.impl.Log4JLogger;
@ -31,18 +32,19 @@ import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.hdfs.server.protocol.InterDatanodeProtocol;
import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.LeaseManager; import org.apache.hadoop.hdfs.server.namenode.LeaseManager;
import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.protocol.InterDatanodeProtocol;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import org.junit.Test;
/** /**
* This class tests that a file need not be closed before its * This class tests that a file need not be closed before its
* data can be read by another client. * data can be read by another client.
*/ */
public class TestDatanodeDeath extends TestCase { public class TestDatanodeDeath {
{ {
((Log4JLogger)NameNode.stateChangeLog).getLogger().setLevel(Level.ALL); ((Log4JLogger)NameNode.stateChangeLog).getLogger().setLevel(Level.ALL);
((Log4JLogger)LeaseManager.LOG).getLogger().setLevel(Level.ALL); ((Log4JLogger)LeaseManager.LOG).getLogger().setLevel(Level.ALL);
@ -411,11 +413,15 @@ public class TestDatanodeDeath extends TestCase {
} }
} }
@Test
public void testSimple0() throws IOException {simpleTest(0);} public void testSimple0() throws IOException {simpleTest(0);}
@Test
public void testSimple1() throws IOException {simpleTest(1);} public void testSimple1() throws IOException {simpleTest(1);}
@Test
public void testSimple2() throws IOException {simpleTest(2);} public void testSimple2() throws IOException {simpleTest(2);}
@Test
public void testComplex() throws IOException {complexTest();} public void testComplex() throws IOException {complexTest();}
} }

View File

@ -19,7 +19,8 @@ package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;

View File

@ -17,27 +17,30 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.apache.hadoop.test.MetricsAsserts.assertGauge;
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
import static org.junit.Assert.assertEquals;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.ArrayList; import java.util.ArrayList;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType; import org.apache.hadoop.hdfs.protocol.HdfsConstants.DatanodeReportType;
import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.DataNode;
import static org.apache.hadoop.test.MetricsAsserts.*; import org.junit.Test;
/** /**
* This test ensures the all types of data node report work correctly. * This test ensures the all types of data node report work correctly.
*/ */
public class TestDatanodeReport extends TestCase { public class TestDatanodeReport {
final static private Configuration conf = new HdfsConfiguration(); final static private Configuration conf = new HdfsConfiguration();
final static private int NUM_OF_DATANODES = 4; final static private int NUM_OF_DATANODES = 4;
/** /**
* This test attempts to different types of datanode report. * This test attempts to different types of datanode report.
*/ */
@Test
public void testDatanodeReport() throws Exception { public void testDatanodeReport() throws Exception {
conf.setInt( conf.setInt(
DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY, 500); // 0.5s DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY, 500); // 0.5s

View File

@ -17,18 +17,20 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.URI; import java.net.URI;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.junit.Test;
/** Test NameNode port defaulting code. */ /** Test NameNode port defaulting code. */
public class TestDefaultNameNodePort extends TestCase { public class TestDefaultNameNodePort {
@Test
public void testGetAddressFromString() throws Exception { public void testGetAddressFromString() throws Exception {
assertEquals(NameNode.getAddress("foo").getPort(), assertEquals(NameNode.getAddress("foo").getPort(),
NameNode.DEFAULT_PORT); NameNode.DEFAULT_PORT);
@ -40,6 +42,7 @@ public class TestDefaultNameNodePort extends TestCase {
555); 555);
} }
@Test
public void testGetAddressFromConf() throws Exception { public void testGetAddressFromConf() throws Exception {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
FileSystem.setDefaultUri(conf, "hdfs://foo/"); FileSystem.setDefaultUri(conf, "hdfs://foo/");
@ -50,6 +53,7 @@ public class TestDefaultNameNodePort extends TestCase {
assertEquals(NameNode.getAddress(conf).getPort(), NameNode.DEFAULT_PORT); assertEquals(NameNode.getAddress(conf).getPort(), NameNode.DEFAULT_PORT);
} }
@Test
public void testGetUri() { public void testGetUri() {
assertEquals(NameNode.getUri(new InetSocketAddress("foo", 555)), assertEquals(NameNode.getUri(new InetSocketAddress("foo", 555)),
URI.create("hdfs://foo:555")); URI.create("hdfs://foo:555"));

View File

@ -18,13 +18,15 @@
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import org.apache.hadoop.hdfs.DFSConfigKeys; import static org.junit.Assert.assertTrue;
import org.apache.hadoop.conf.Configuration;
import junit.framework.TestCase;
public class TestDeprecatedKeys extends TestCase { import org.apache.hadoop.conf.Configuration;
import org.junit.Test;
public class TestDeprecatedKeys {
//Tests a deprecated key //Tests a deprecated key
@Test
public void testDeprecatedKeys() throws Exception { public void testDeprecatedKeys() throws Exception {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
conf.set("topology.script.file.name", "xyz"); conf.set("topology.script.file.name", "xyz");

View File

@ -17,14 +17,16 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.util.Random; import java.util.Random;
import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.ChecksumException; import org.apache.hadoop.fs.ChecksumException;
import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.fs.CommonConfigurationKeys;
@ -35,11 +37,12 @@ import org.apache.hadoop.fs.LocalFileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.junit.Test;
/** /**
* This class tests if FSInputChecker works correctly. * This class tests if FSInputChecker works correctly.
*/ */
public class TestFSInputChecker extends TestCase { public class TestFSInputChecker {
static final long seed = 0xDEADBEEFL; static final long seed = 0xDEADBEEFL;
static final int BYTES_PER_SUM = 10; static final int BYTES_PER_SUM = 10;
static final int BLOCK_SIZE = 2*BYTES_PER_SUM; static final int BLOCK_SIZE = 2*BYTES_PER_SUM;
@ -291,6 +294,7 @@ public class TestFSInputChecker extends TestCase {
in.close(); in.close();
} }
@Test
public void testFSInputChecker() throws Exception { public void testFSInputChecker() throws Exception {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, BLOCK_SIZE); conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, BLOCK_SIZE);

View File

@ -17,21 +17,24 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import junit.framework.TestCase; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IO_FILE_BUFFER_SIZE_KEY;
import java.io.*; import static org.junit.Assert.assertEquals;
import java.util.Random; import static org.junit.Assert.assertTrue;
import org.apache.hadoop.conf.Configuration;
import static org.apache.hadoop.fs.CommonConfigurationKeys.IO_FILE_BUFFER_SIZE_KEY;
import java.io.IOException;
import java.util.Random;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.junit.Test;
/** /**
* This class tests if FSOutputSummer works correctly. * This class tests if FSOutputSummer works correctly.
*/ */
public class TestFSOutputSummer extends TestCase { public class TestFSOutputSummer {
private static final long seed = 0xDEADBEEFL; private static final long seed = 0xDEADBEEFL;
private static final int BYTES_PER_CHECKSUM = 10; private static final int BYTES_PER_CHECKSUM = 10;
private static final int BLOCK_SIZE = 2*BYTES_PER_CHECKSUM; private static final int BLOCK_SIZE = 2*BYTES_PER_CHECKSUM;
@ -111,6 +114,7 @@ public class TestFSOutputSummer extends TestCase {
/** /**
* Test write opeation for output stream in DFS. * Test write opeation for output stream in DFS.
*/ */
@Test
public void testFSOutputSummer() throws Exception { public void testFSOutputSummer() throws Exception {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, BLOCK_SIZE); conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, BLOCK_SIZE);

View File

@ -17,12 +17,16 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import junit.framework.TestCase; import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
@ -36,16 +40,14 @@ import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.security.AccessControlException; import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import org.junit.Test;
/** /**
* This class tests the building blocks that are needed to * This class tests the building blocks that are needed to
* support HDFS appends. * support HDFS appends.
*/ */
public class TestFileAppend2 extends TestCase { public class TestFileAppend2 {
{ {
((Log4JLogger)NameNode.stateChangeLog).getLogger().setLevel(Level.ALL); ((Log4JLogger)NameNode.stateChangeLog).getLogger().setLevel(Level.ALL);
@ -79,6 +81,7 @@ public class TestFileAppend2 extends TestCase {
* Verify that all data exists in file. * Verify that all data exists in file.
* @throws IOException an exception might be thrown * @throws IOException an exception might be thrown
*/ */
@Test
public void testSimpleAppend() throws IOException { public void testSimpleAppend() throws IOException {
final Configuration conf = new HdfsConfiguration(); final Configuration conf = new HdfsConfiguration();
if (simulatedStorage) { if (simulatedStorage) {
@ -329,6 +332,7 @@ public class TestFileAppend2 extends TestCase {
* Test that appends to files at random offsets. * Test that appends to files at random offsets.
* @throws IOException an exception might be thrown * @throws IOException an exception might be thrown
*/ */
@Test
public void testComplexAppend() throws IOException { public void testComplexAppend() throws IOException {
fileContents = AppendTestUtil.initBuffer(AppendTestUtil.FILE_SIZE); fileContents = AppendTestUtil.initBuffer(AppendTestUtil.FILE_SIZE);
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();

View File

@ -17,6 +17,10 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
@ -42,7 +46,6 @@ import org.apache.log4j.Level;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
/** This class implements some of tests posted in HADOOP-2658. */ /** This class implements some of tests posted in HADOOP-2658. */
public class TestFileAppend3 { public class TestFileAppend3 {

View File

@ -23,7 +23,6 @@ import static org.junit.Assert.assertEquals;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.Random;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic; import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
@ -32,8 +31,6 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
import org.apache.hadoop.hdfs.server.namenode.FSEditLog;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp;
import org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes; import org.apache.hadoop.hdfs.server.namenode.FSEditLogOpCodes;
import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil; import org.apache.hadoop.hdfs.server.namenode.FSImageTestUtil;
import org.apache.hadoop.hdfs.server.namenode.NNStorage; import org.apache.hadoop.hdfs.server.namenode.NNStorage;

View File

@ -17,6 +17,11 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Log4JLogger; import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -33,10 +38,6 @@ import org.apache.hadoop.util.StringUtils;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.atomic.*;
/** /**
* This class tests the cases of a concurrent reads/writes to a file; * This class tests the cases of a concurrent reads/writes to a file;

View File

@ -18,14 +18,16 @@
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Log4JLogger; import org.apache.commons.logging.impl.Log4JLogger;
@ -42,11 +44,12 @@ import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration; import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import org.junit.Test;
/** /**
* A JUnit test for corrupted file handling. * A JUnit test for corrupted file handling.
*/ */
public class TestFileCorruption extends TestCase { public class TestFileCorruption {
{ {
((Log4JLogger)NameNode.stateChangeLog).getLogger().setLevel(Level.ALL); ((Log4JLogger)NameNode.stateChangeLog).getLogger().setLevel(Level.ALL);
((Log4JLogger)LogFactory.getLog(FSNamesystem.class)).getLogger().setLevel(Level.ALL); ((Log4JLogger)LogFactory.getLog(FSNamesystem.class)).getLogger().setLevel(Level.ALL);
@ -56,6 +59,7 @@ public class TestFileCorruption extends TestCase {
static Log LOG = ((Log4JLogger)NameNode.stateChangeLog); static Log LOG = ((Log4JLogger)NameNode.stateChangeLog);
/** check if DFS can handle corrupted blocks properly */ /** check if DFS can handle corrupted blocks properly */
@Test
public void testFileCorruption() throws Exception { public void testFileCorruption() throws Exception {
MiniDFSCluster cluster = null; MiniDFSCluster cluster = null;
DFSTestUtil util = new DFSTestUtil.Builder().setName("TestFileCorruption"). DFSTestUtil util = new DFSTestUtil.Builder().setName("TestFileCorruption").
@ -88,6 +92,7 @@ public class TestFileCorruption extends TestCase {
} }
/** check if local FS can handle corrupted blocks properly */ /** check if local FS can handle corrupted blocks properly */
@Test
public void testLocalFileCorruption() throws Exception { public void testLocalFileCorruption() throws Exception {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
Path file = new Path(System.getProperty("test.build.data"), "corruptFile"); Path file = new Path(System.getProperty("test.build.data"), "corruptFile");
@ -114,6 +119,7 @@ public class TestFileCorruption extends TestCase {
* in blocksMap. Make sure that ArrayIndexOutOfBounds does not thrown. * in blocksMap. Make sure that ArrayIndexOutOfBounds does not thrown.
* See Hadoop-4351. * See Hadoop-4351.
*/ */
@Test
public void testArrayOutOfBoundsException() throws Exception { public void testArrayOutOfBoundsException() throws Exception {
MiniDFSCluster cluster = null; MiniDFSCluster cluster = null;
try { try {

View File

@ -16,7 +16,6 @@
* limitations under the License. * limitations under the License.
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IO_FILE_BUFFER_SIZE_DEFAULT; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IO_FILE_BUFFER_SIZE_DEFAULT;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IO_FILE_BUFFER_SIZE_KEY; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.IO_FILE_BUFFER_SIZE_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCK_SIZE_DEFAULT; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_BLOCK_SIZE_DEFAULT;
@ -31,6 +30,9 @@ import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHEC
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_REPLICATION_MIN_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_REPLICATION_MIN_KEY;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_REPLICATION_DEFAULT; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_REPLICATION_DEFAULT;
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_REPLICATION_KEY; import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_REPLICATION_KEY;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -70,11 +72,12 @@ import org.apache.hadoop.hdfs.server.namenode.LeaseManager;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import org.junit.Test;
/** /**
* This class tests various cases during file creation. * This class tests various cases during file creation.
*/ */
public class TestFileCreation extends junit.framework.TestCase { public class TestFileCreation {
static final String DIR = "/" + TestFileCreation.class.getSimpleName() + "/"; static final String DIR = "/" + TestFileCreation.class.getSimpleName() + "/";
{ {
@ -123,6 +126,7 @@ public class TestFileCreation extends junit.framework.TestCase {
/** /**
* Test that server default values can be retrieved on the client side * Test that server default values can be retrieved on the client side
*/ */
@Test
public void testServerDefaults() throws IOException { public void testServerDefaults() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
conf.setLong(DFS_BLOCK_SIZE_KEY, DFS_BLOCK_SIZE_DEFAULT); conf.setLong(DFS_BLOCK_SIZE_KEY, DFS_BLOCK_SIZE_DEFAULT);
@ -148,11 +152,13 @@ public class TestFileCreation extends junit.framework.TestCase {
} }
} }
@Test
public void testFileCreation() throws IOException { public void testFileCreation() throws IOException {
checkFileCreation(null); checkFileCreation(null);
} }
/** Same test but the client should bind to a local interface */ /** Same test but the client should bind to a local interface */
@Test
public void testFileCreationSetLocalInterface() throws IOException { public void testFileCreationSetLocalInterface() throws IOException {
assumeTrue(System.getProperty("os.name").startsWith("Linux")); assumeTrue(System.getProperty("os.name").startsWith("Linux"));
@ -255,6 +261,7 @@ public class TestFileCreation extends junit.framework.TestCase {
/** /**
* Test deleteOnExit * Test deleteOnExit
*/ */
@Test
public void testDeleteOnExit() throws IOException { public void testDeleteOnExit() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
if (simulatedStorage) { if (simulatedStorage) {
@ -317,6 +324,7 @@ public class TestFileCreation extends junit.framework.TestCase {
/** /**
* Test that file data does not become corrupted even in the face of errors. * Test that file data does not become corrupted even in the face of errors.
*/ */
@Test
public void testFileCreationError1() throws IOException { public void testFileCreationError1() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
conf.setInt(DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY, 1000); conf.setInt(DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY, 1000);
@ -389,6 +397,7 @@ public class TestFileCreation extends junit.framework.TestCase {
* Test that the filesystem removes the last block from a file if its * Test that the filesystem removes the last block from a file if its
* lease expires. * lease expires.
*/ */
@Test
public void testFileCreationError2() throws IOException { public void testFileCreationError2() throws IOException {
long leasePeriod = 1000; long leasePeriod = 1000;
System.out.println("testFileCreationError2 start"); System.out.println("testFileCreationError2 start");
@ -454,6 +463,7 @@ public class TestFileCreation extends junit.framework.TestCase {
} }
/** test addBlock(..) when replication<min and excludeNodes==null. */ /** test addBlock(..) when replication<min and excludeNodes==null. */
@Test
public void testFileCreationError3() throws IOException { public void testFileCreationError3() throws IOException {
System.out.println("testFileCreationError3 start"); System.out.println("testFileCreationError3 start");
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
@ -626,6 +636,7 @@ public class TestFileCreation extends junit.framework.TestCase {
/** /**
* Test that all open files are closed when client dies abnormally. * Test that all open files are closed when client dies abnormally.
*/ */
@Test
public void testDFSClientDeath() throws IOException, InterruptedException { public void testDFSClientDeath() throws IOException, InterruptedException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
System.out.println("Testing adbornal client death."); System.out.println("Testing adbornal client death.");
@ -662,6 +673,7 @@ public class TestFileCreation extends junit.framework.TestCase {
/** /**
* Test file creation using createNonRecursive(). * Test file creation using createNonRecursive().
*/ */
@Test
public void testFileCreationNonRecursive() throws IOException { public void testFileCreationNonRecursive() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
if (simulatedStorage) { if (simulatedStorage) {
@ -756,6 +768,7 @@ public class TestFileCreation extends junit.framework.TestCase {
/** /**
* Test that file data becomes available before file is closed. * Test that file data becomes available before file is closed.
*/ */
@Test
public void testFileCreationSimulated() throws IOException { public void testFileCreationSimulated() throws IOException {
simulatedStorage = true; simulatedStorage = true;
testFileCreation(); testFileCreation();
@ -765,6 +778,7 @@ public class TestFileCreation extends junit.framework.TestCase {
/** /**
* Test creating two files at the same time. * Test creating two files at the same time.
*/ */
@Test
public void testConcurrentFileCreation() throws IOException { public void testConcurrentFileCreation() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
@ -797,6 +811,7 @@ public class TestFileCreation extends junit.framework.TestCase {
/** /**
* Test creating a file whose data gets sync when closed * Test creating a file whose data gets sync when closed
*/ */
@Test
public void testFileCreationSyncOnClose() throws IOException { public void testFileCreationSyncOnClose() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
conf.setBoolean(DFS_DATANODE_SYNCONCLOSE_KEY, true); conf.setBoolean(DFS_DATANODE_SYNCONCLOSE_KEY, true);
@ -832,6 +847,7 @@ public class TestFileCreation extends junit.framework.TestCase {
* Then change lease period and wait for lease recovery. * Then change lease period and wait for lease recovery.
* Finally, read the block directly from each Datanode and verify the content. * Finally, read the block directly from each Datanode and verify the content.
*/ */
@Test
public void testLeaseExpireHardLimit() throws Exception { public void testLeaseExpireHardLimit() throws Exception {
System.out.println("testLeaseExpireHardLimit start"); System.out.println("testLeaseExpireHardLimit start");
final long leasePeriod = 1000; final long leasePeriod = 1000;
@ -895,6 +911,7 @@ public class TestFileCreation extends junit.framework.TestCase {
} }
// test closing file system before all file handles are closed. // test closing file system before all file handles are closed.
@Test
public void testFsClose() throws Exception { public void testFsClose() throws Exception {
System.out.println("test file system close start"); System.out.println("test file system close start");
final int DATANODE_NUM = 3; final int DATANODE_NUM = 3;
@ -923,6 +940,7 @@ public class TestFileCreation extends junit.framework.TestCase {
} }
// test closing file after cluster is shutdown // test closing file after cluster is shutdown
@Test
public void testFsCloseAfterClusterShutdown() throws IOException { public void testFsCloseAfterClusterShutdown() throws IOException {
System.out.println("test testFsCloseAfterClusterShutdown start"); System.out.println("test testFsCloseAfterClusterShutdown start");
final int DATANODE_NUM = 3; final int DATANODE_NUM = 3;

View File

@ -16,6 +16,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.impl.Log4JLogger; import org.apache.commons.logging.impl.Log4JLogger;
@ -30,12 +31,13 @@ import org.apache.hadoop.hdfs.server.namenode.LeaseManager;
import org.apache.hadoop.hdfs.server.protocol.InterDatanodeProtocol; import org.apache.hadoop.hdfs.server.protocol.InterDatanodeProtocol;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import org.junit.Test;
/** /**
* This class tests that a file need not be closed before its * This class tests that a file need not be closed before its
* data can be read by another client. * data can be read by another client.
*/ */
public class TestFileCreationClient extends junit.framework.TestCase { public class TestFileCreationClient {
static final String DIR = "/" + TestFileCreationClient.class.getSimpleName() + "/"; static final String DIR = "/" + TestFileCreationClient.class.getSimpleName() + "/";
{ {
@ -46,6 +48,7 @@ public class TestFileCreationClient extends junit.framework.TestCase {
} }
/** Test lease recovery Triggered by DFSClient. */ /** Test lease recovery Triggered by DFSClient. */
@Test
public void testClientTriggeredLeaseRecovery() throws Exception { public void testClientTriggeredLeaseRecovery() throws Exception {
final int REPLICATION = 3; final int REPLICATION = 3;
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();

View File

@ -16,6 +16,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
@ -29,14 +30,16 @@ import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
import org.apache.hadoop.hdfs.server.namenode.LeaseManager; import org.apache.hadoop.hdfs.server.namenode.LeaseManager;
import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import org.junit.Test;
public class TestFileCreationDelete extends junit.framework.TestCase { public class TestFileCreationDelete {
{ {
((Log4JLogger)NameNode.stateChangeLog).getLogger().setLevel(Level.ALL); ((Log4JLogger)NameNode.stateChangeLog).getLogger().setLevel(Level.ALL);
((Log4JLogger)LeaseManager.LOG).getLogger().setLevel(Level.ALL); ((Log4JLogger)LeaseManager.LOG).getLogger().setLevel(Level.ALL);
((Log4JLogger)LogFactory.getLog(FSNamesystem.class)).getLogger().setLevel(Level.ALL); ((Log4JLogger)LogFactory.getLog(FSNamesystem.class)).getLogger().setLevel(Level.ALL);
} }
@Test
public void testFileCreationDeleteParent() throws IOException { public void testFileCreationDeleteParent() throws IOException {
Configuration conf = new HdfsConfiguration(); Configuration conf = new HdfsConfiguration();
final int MAX_IDLE_TIME = 2000; // 2s final int MAX_IDLE_TIME = 2000; // 2s

View File

@ -16,17 +16,19 @@
* limitations under the License. * limitations under the License.
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertFalse;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.server.namenode.LeaseManager; import org.apache.hadoop.hdfs.server.namenode.LeaseManager;
import org.junit.Test;
/** /**
* Test empty file creation. * Test empty file creation.
*/ */
public class TestFileCreationEmpty extends junit.framework.TestCase { public class TestFileCreationEmpty {
private boolean isConcurrentModificationException = false; private boolean isConcurrentModificationException = false;
/** /**
@ -35,6 +37,7 @@ public class TestFileCreationEmpty extends junit.framework.TestCase {
* The empty files are supposed to be closed by that * The empty files are supposed to be closed by that
* without causing ConcurrentModificationException. * without causing ConcurrentModificationException.
*/ */
@Test
public void testLeaseExpireEmptyFiles() throws Exception { public void testLeaseExpireEmptyFiles() throws Exception {
final Thread.UncaughtExceptionHandler oldUEH = Thread.getDefaultUncaughtExceptionHandler(); final Thread.UncaughtExceptionHandler oldUEH = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

View File

@ -16,8 +16,10 @@
* limitations under the License. * limitations under the License.
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import org.junit.Test;
public class TestFileCreationNamenodeRestart extends junit.framework.TestCase { public class TestFileCreationNamenodeRestart {
@Test
public void testFileCreationNamenodeRestart() throws Exception { public void testFileCreationNamenodeRestart() throws Exception {
new TestFileCreation().xxxtestFileCreationNamenodeRestart(); new TestFileCreation().xxxtestFileCreationNamenodeRestart();
} }

View File

@ -17,28 +17,35 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.*; import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.protocol.Block; import org.apache.hadoop.hdfs.protocol.Block;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo; import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.hdfs.protocol.LocatedBlock; import org.apache.hadoop.hdfs.protocol.LocatedBlock;
import org.apache.hadoop.hdfs.server.common.GenerationStamp; import org.apache.hadoop.hdfs.server.common.GenerationStamp;
import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocol;
import org.apache.hadoop.hdfs.server.protocol.BlocksWithLocations.BlockWithLocations; import org.apache.hadoop.hdfs.server.protocol.BlocksWithLocations.BlockWithLocations;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.hdfs.server.protocol.NamenodeProtocol;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.ipc.RemoteException;
import junit.framework.TestCase; import org.junit.Test;
/** /**
* This class tests if block replacement request to data nodes work correctly. * This class tests if block replacement request to data nodes work correctly.
*/ */
public class TestGetBlocks extends TestCase { public class TestGetBlocks {
/** test getBlocks */ /** test getBlocks */
@Test
public void testGetBlocks() throws Exception { public void testGetBlocks() throws Exception {
final Configuration CONF = new HdfsConfiguration(); final Configuration CONF = new HdfsConfiguration();
@ -141,6 +148,7 @@ public class TestGetBlocks extends TestCase {
assertTrue(getException); assertTrue(getException);
} }
@Test
public void testBlockKey() { public void testBlockKey() {
Map<Block, Long> map = new HashMap<Block, Long>(); Map<Block, Long> map = new HashMap<Block, Long>();
final Random RAN = new Random(); final Random RAN = new Random();

View File

@ -17,25 +17,26 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.apache.hadoop.hdfs.server.common.Util.fileAsURI;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import junit.framework.TestCase;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.FileUtil;
import static org.apache.hadoop.hdfs.server.common.Util.fileAsURI;
import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption; import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.StartupOption;
import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.namenode.BackupNode; import org.apache.hadoop.hdfs.server.namenode.BackupNode;
import org.apache.hadoop.hdfs.server.namenode.NameNode; import org.apache.hadoop.hdfs.server.namenode.NameNode;
import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem; import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.hadoop.net.DNS; import org.apache.hadoop.net.DNS;
import org.junit.Test;
/** /**
* This test checks correctness of port usage by hdfs components: * This test checks correctness of port usage by hdfs components:
@ -47,7 +48,7 @@ import org.apache.hadoop.net.DNS;
* - if the port = 0 (ephemeral) then the server should choose * - if the port = 0 (ephemeral) then the server should choose
* a free port and start on it. * a free port and start on it.
*/ */
public class TestHDFSServerPorts extends TestCase { public class TestHDFSServerPorts {
public static final Log LOG = LogFactory.getLog(TestHDFSServerPorts.class); public static final Log LOG = LogFactory.getLog(TestHDFSServerPorts.class);
// reset default 0.0.0.0 addresses in order to avoid IPv6 problem // reset default 0.0.0.0 addresses in order to avoid IPv6 problem
@ -250,6 +251,7 @@ public class TestHDFSServerPorts extends TestCase {
return true; return true;
} }
@Test
public void testNameNodePorts() throws Exception { public void testNameNodePorts() throws Exception {
runTestNameNodePorts(false); runTestNameNodePorts(false);
runTestNameNodePorts(true); runTestNameNodePorts(true);
@ -300,6 +302,7 @@ public class TestHDFSServerPorts extends TestCase {
/** /**
* Verify datanode port usage. * Verify datanode port usage.
*/ */
@Test
public void testDataNodePorts() throws Exception { public void testDataNodePorts() throws Exception {
NameNode nn = null; NameNode nn = null;
try { try {
@ -335,6 +338,7 @@ public class TestHDFSServerPorts extends TestCase {
/** /**
* Verify secondary namenode port usage. * Verify secondary namenode port usage.
*/ */
@Test
public void testSecondaryNodePorts() throws Exception { public void testSecondaryNodePorts() throws Exception {
NameNode nn = null; NameNode nn = null;
try { try {
@ -363,6 +367,7 @@ public class TestHDFSServerPorts extends TestCase {
/** /**
* Verify BackupNode port usage. * Verify BackupNode port usage.
*/ */
@Test
public void testBackupNodePorts() throws Exception { public void testBackupNodePorts() throws Exception {
NameNode nn = null; NameNode nn = null;
try { try {

View File

@ -17,6 +17,13 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.io.InterruptedIOException;
import org.apache.commons.logging.impl.Log4JLogger; import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataInputStream;
@ -24,15 +31,8 @@ import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
import java.io.InterruptedIOException;
import java.io.IOException;
/** Class contains a set of tests to verify the correctness of /** Class contains a set of tests to verify the correctness of
* newly introduced {@link FSDataOutputStream#hflush()} method */ * newly introduced {@link FSDataOutputStream#hflush()} method */
public class TestHFlush { public class TestHFlush {

View File

@ -17,7 +17,8 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;

View File

@ -18,15 +18,16 @@
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION;
org.apache.hadoop.fs.CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.net.URI; import java.net.URI;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import org.junit.Test;
import static org.junit.Assert.*;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
@ -36,6 +37,7 @@ import org.apache.hadoop.security.SecurityUtilTestHelper;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.token.Token; import org.apache.hadoop.security.token.Token;
import org.apache.hadoop.security.token.TokenIdentifier; import org.apache.hadoop.security.token.TokenIdentifier;
import org.junit.Test;
public class TestHftpDelegationToken { public class TestHftpDelegationToken {

View File

@ -18,19 +18,18 @@
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URI;
import java.net.URL;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Random; import java.util.Random;
import org.junit.Test;
import org.junit.BeforeClass;
import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.apache.commons.logging.impl.Log4JLogger; import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.BlockLocation; import org.apache.hadoop.fs.BlockLocation;
@ -38,12 +37,14 @@ import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.server.datanode.DataNodeTestUtils; import org.apache.hadoop.hdfs.server.datanode.DataNodeTestUtils;
import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration; import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration;
import org.apache.hadoop.util.ServletUtil; import org.apache.hadoop.util.ServletUtil;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class TestHftpFileSystem { public class TestHftpFileSystem {
private static final Random RAN = new Random(); private static final Random RAN = new Random();

View File

@ -27,7 +27,6 @@ import java.net.InetAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.net.URI; import java.net.URI;
import java.net.URLConnection;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;

View File

@ -17,12 +17,12 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import java.io.*;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.net.*;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -37,12 +37,13 @@ import org.apache.hadoop.hdfs.protocol.LocatedBlock;
import org.apache.hadoop.hdfs.protocol.LocatedBlocks; import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
import org.apache.hadoop.hdfs.server.datanode.SimulatedFSDataset; import org.apache.hadoop.hdfs.server.datanode.SimulatedFSDataset;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.junit.Test;
/** /**
* This class tests the replication and injection of blocks of a DFS file for simulated storage. * This class tests the replication and injection of blocks of a DFS file for simulated storage.
*/ */
public class TestInjectionForSimulatedStorage extends TestCase { public class TestInjectionForSimulatedStorage {
private int checksumSize = 16; private int checksumSize = 16;
private int blockSize = checksumSize*2; private int blockSize = checksumSize*2;
private int numBlocks = 4; private int numBlocks = 4;
@ -122,6 +123,7 @@ public class TestInjectionForSimulatedStorage extends TestCase {
* The blocks are then injected in one of the DNs. The expected behaviour is * The blocks are then injected in one of the DNs. The expected behaviour is
* that the NN will arrange for themissing replica will be copied from a valid source. * that the NN will arrange for themissing replica will be copied from a valid source.
*/ */
@Test
public void testInjection() throws IOException { public void testInjection() throws IOException {
MiniDFSCluster cluster = null; MiniDFSCluster cluster = null;

View File

@ -17,11 +17,12 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import junit.framework.Assert;
import org.apache.hadoop.hdfs.protocol.ClientProtocol; import org.apache.hadoop.hdfs.protocol.ClientProtocol;
import org.apache.hadoop.hdfs.protocolPB.ClientDatanodeProtocolTranslatorPB; import org.apache.hadoop.hdfs.protocolPB.ClientDatanodeProtocolTranslatorPB;
import org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB; import org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolTranslatorPB;
@ -78,16 +79,16 @@ public class TestIsMethodSupported {
nnAddress, NamenodeProtocol.class, UserGroupInformation.getCurrentUser(), nnAddress, NamenodeProtocol.class, UserGroupInformation.getCurrentUser(),
true).getProxy(); true).getProxy();
boolean exists = translator.isMethodSupported("rollEditLog"); boolean exists = translator.isMethodSupported("rollEditLog");
Assert.assertTrue(exists); assertTrue(exists);
exists = translator.isMethodSupported("bogusMethod"); exists = translator.isMethodSupported("bogusMethod");
Assert.assertFalse(exists); assertFalse(exists);
} }
@Test @Test
public void testDatanodeProtocol() throws IOException { public void testDatanodeProtocol() throws IOException {
DatanodeProtocolClientSideTranslatorPB translator = DatanodeProtocolClientSideTranslatorPB translator =
new DatanodeProtocolClientSideTranslatorPB(nnAddress, conf); new DatanodeProtocolClientSideTranslatorPB(nnAddress, conf);
Assert.assertTrue(translator.isMethodSupported("sendHeartbeat")); assertTrue(translator.isMethodSupported("sendHeartbeat"));
} }
@Test @Test
@ -97,12 +98,12 @@ public class TestIsMethodSupported {
UserGroupInformation.getCurrentUser(), conf, UserGroupInformation.getCurrentUser(), conf,
NetUtils.getDefaultSocketFactory(conf)); NetUtils.getDefaultSocketFactory(conf));
//Namenode doesn't implement ClientDatanodeProtocol //Namenode doesn't implement ClientDatanodeProtocol
Assert.assertFalse(translator.isMethodSupported("refreshNamenodes")); assertFalse(translator.isMethodSupported("refreshNamenodes"));
translator = new ClientDatanodeProtocolTranslatorPB( translator = new ClientDatanodeProtocolTranslatorPB(
dnAddress, UserGroupInformation.getCurrentUser(), conf, dnAddress, UserGroupInformation.getCurrentUser(), conf,
NetUtils.getDefaultSocketFactory(conf)); NetUtils.getDefaultSocketFactory(conf));
Assert.assertTrue(translator.isMethodSupported("refreshNamenodes")); assertTrue(translator.isMethodSupported("refreshNamenodes"));
} }
@Test @Test
@ -111,7 +112,7 @@ public class TestIsMethodSupported {
(ClientNamenodeProtocolTranslatorPB) NameNodeProxies.createNonHAProxy( (ClientNamenodeProtocolTranslatorPB) NameNodeProxies.createNonHAProxy(
conf, nnAddress, ClientProtocol.class, conf, nnAddress, ClientProtocol.class,
UserGroupInformation.getCurrentUser(), true).getProxy(); UserGroupInformation.getCurrentUser(), true).getProxy();
Assert.assertTrue(translator.isMethodSupported("mkdirs")); assertTrue(translator.isMethodSupported("mkdirs"));
} }
@Test @Test
@ -120,7 +121,7 @@ public class TestIsMethodSupported {
NameNodeProxies.createNonHAProxy(conf, nnAddress, JournalProtocol.class, NameNodeProxies.createNonHAProxy(conf, nnAddress, JournalProtocol.class,
UserGroupInformation.getCurrentUser(), true).getProxy(); UserGroupInformation.getCurrentUser(), true).getProxy();
//Nameode doesn't implement JournalProtocol //Nameode doesn't implement JournalProtocol
Assert.assertFalse(translator.isMethodSupported("startLogSegment")); assertFalse(translator.isMethodSupported("startLogSegment"));
} }
@Test @Test
@ -130,12 +131,12 @@ public class TestIsMethodSupported {
nnAddress, UserGroupInformation.getCurrentUser(), conf, nnAddress, UserGroupInformation.getCurrentUser(), conf,
NetUtils.getDefaultSocketFactory(conf), 0); NetUtils.getDefaultSocketFactory(conf), 0);
//Not supported at namenode //Not supported at namenode
Assert.assertFalse(translator.isMethodSupported("initReplicaRecovery")); assertFalse(translator.isMethodSupported("initReplicaRecovery"));
translator = new InterDatanodeProtocolTranslatorPB( translator = new InterDatanodeProtocolTranslatorPB(
dnAddress, UserGroupInformation.getCurrentUser(), conf, dnAddress, UserGroupInformation.getCurrentUser(), conf,
NetUtils.getDefaultSocketFactory(conf), 0); NetUtils.getDefaultSocketFactory(conf), 0);
Assert.assertTrue(translator.isMethodSupported("initReplicaRecovery")); assertTrue(translator.isMethodSupported("initReplicaRecovery"));
} }
@Test @Test
@ -145,7 +146,7 @@ public class TestIsMethodSupported {
NameNodeProxies.createNonHAProxy(conf, nnAddress, NameNodeProxies.createNonHAProxy(conf, nnAddress,
GetUserMappingsProtocol.class, UserGroupInformation.getCurrentUser(), GetUserMappingsProtocol.class, UserGroupInformation.getCurrentUser(),
true).getProxy(); true).getProxy();
Assert.assertTrue(translator.isMethodSupported("getGroupsForUser")); assertTrue(translator.isMethodSupported("getGroupsForUser"));
} }
@Test @Test
@ -155,7 +156,7 @@ public class TestIsMethodSupported {
NameNodeProxies.createNonHAProxy(conf, nnAddress, NameNodeProxies.createNonHAProxy(conf, nnAddress,
RefreshAuthorizationPolicyProtocol.class, RefreshAuthorizationPolicyProtocol.class,
UserGroupInformation.getCurrentUser(), true).getProxy(); UserGroupInformation.getCurrentUser(), true).getProxy();
Assert.assertTrue(translator.isMethodSupported("refreshServiceAcl")); assertTrue(translator.isMethodSupported("refreshServiceAcl"));
} }
@Test @Test
@ -165,7 +166,7 @@ public class TestIsMethodSupported {
NameNodeProxies.createNonHAProxy(conf, nnAddress, NameNodeProxies.createNonHAProxy(conf, nnAddress,
RefreshUserMappingsProtocol.class, RefreshUserMappingsProtocol.class,
UserGroupInformation.getCurrentUser(), true).getProxy(); UserGroupInformation.getCurrentUser(), true).getProxy();
Assert.assertTrue( assertTrue(
translator.isMethodSupported("refreshUserToGroupsMappings")); translator.isMethodSupported("refreshUserToGroupsMappings"));
} }
} }

Some files were not shown because too many files have changed in this diff Show More