HADOOP-17685. Fix junit deprecation warnings in hadoop-common module. (#2983)
Signed-off-by: Takanobu Asanuma <tasanuma@apache.org>
This commit is contained in:
parent
fdd20a3cf4
commit
35ca1dcb9d
@ -50,9 +50,9 @@
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
||||||
|
import org.assertj.core.api.Assertions;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.apache.hadoop.conf.StorageUnit.BYTES;
|
import static org.apache.hadoop.conf.StorageUnit.BYTES;
|
||||||
@ -60,7 +60,6 @@
|
|||||||
import static org.apache.hadoop.conf.StorageUnit.KB;
|
import static org.apache.hadoop.conf.StorageUnit.KB;
|
||||||
import static org.apache.hadoop.conf.StorageUnit.MB;
|
import static org.apache.hadoop.conf.StorageUnit.MB;
|
||||||
import static org.apache.hadoop.conf.StorageUnit.TB;
|
import static org.apache.hadoop.conf.StorageUnit.TB;
|
||||||
import static org.hamcrest.core.Is.is;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -78,14 +77,10 @@
|
|||||||
import org.apache.log4j.AppenderSkeleton;
|
import org.apache.log4j.AppenderSkeleton;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.apache.log4j.spi.LoggingEvent;
|
import org.apache.log4j.spi.LoggingEvent;
|
||||||
import org.hamcrest.CoreMatchers;
|
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
public class TestConfiguration {
|
public class TestConfiguration {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown= ExpectedException.none();
|
|
||||||
private static final double DOUBLE_DELTA = 0.000000001f;
|
private static final double DOUBLE_DELTA = 0.000000001f;
|
||||||
private Configuration conf;
|
private Configuration conf;
|
||||||
final static String CONFIG = new File("./test-config-TestConfiguration.xml").getAbsolutePath();
|
final static String CONFIG = new File("./test-config-TestConfiguration.xml").getAbsolutePath();
|
||||||
@ -1488,61 +1483,64 @@ public void testStorageUnit() {
|
|||||||
|
|
||||||
conf.setStorageSize(key, 10, MB);
|
conf.setStorageSize(key, 10, MB);
|
||||||
// This call returns the value specified in the Key as a double in MBs.
|
// This call returns the value specified in the Key as a double in MBs.
|
||||||
assertThat(conf.getStorageSize(key, "1GB", MB),
|
Assertions.assertThat(conf.getStorageSize(key, "1GB", MB))
|
||||||
is(10.0));
|
.isEqualTo(10.0);
|
||||||
|
|
||||||
// Since this key is missing, This call converts the default value of 1GB
|
// Since this key is missing, This call converts the default value of 1GB
|
||||||
// to MBs are returns that value.
|
// to MBs are returns that value.
|
||||||
assertThat(conf.getStorageSize(nonKey, "1GB", MB),
|
Assertions.assertThat(conf.getStorageSize(nonKey, "1GB", MB))
|
||||||
is(1024.0));
|
.isEqualTo(1024.0);
|
||||||
|
|
||||||
|
|
||||||
conf.setStorageSize(key, 1024, BYTES);
|
conf.setStorageSize(key, 1024, BYTES);
|
||||||
assertThat(conf.getStorageSize(key, 100, KB), is(1.0));
|
Assertions.assertThat(conf.getStorageSize(key, 100, KB)).isEqualTo(1.0);
|
||||||
|
|
||||||
assertThat(conf.getStorageSize(nonKey, 100.0, KB), is(100.0));
|
Assertions.assertThat(conf.getStorageSize(nonKey, 100.0, KB))
|
||||||
|
.isEqualTo(100.0);
|
||||||
|
|
||||||
// We try out different kind of String formats to see if they work and
|
// We try out different kind of String formats to see if they work and
|
||||||
// during read, we also try to read using a different Storage Units.
|
// during read, we also try to read using a different Storage Units.
|
||||||
conf.setStrings(key, "1TB");
|
conf.setStrings(key, "1TB");
|
||||||
assertThat(conf.getStorageSize(key, "1PB", GB), is(1024.0));
|
Assertions.assertThat(conf.getStorageSize(key, "1PB", GB))
|
||||||
|
.isEqualTo(1024.0);
|
||||||
|
|
||||||
conf.setStrings(key, "1bytes");
|
conf.setStrings(key, "1bytes");
|
||||||
assertThat(conf.getStorageSize(key, "1PB", KB), is(0.001));
|
Assertions.assertThat(conf.getStorageSize(key, "1PB", KB))
|
||||||
|
.isEqualTo(0.001);
|
||||||
|
|
||||||
conf.setStrings(key, "2048b");
|
conf.setStrings(key, "2048b");
|
||||||
assertThat(conf.getStorageSize(key, "1PB", KB), is(2.0));
|
Assertions.assertThat(conf.getStorageSize(key, "1PB", KB)).isEqualTo(2.0);
|
||||||
|
|
||||||
conf.setStrings(key, "64 GB");
|
conf.setStrings(key, "64 GB");
|
||||||
assertThat(conf.getStorageSize(key, "1PB", GB), is(64.0));
|
Assertions.assertThat(conf.getStorageSize(key, "1PB", GB)).isEqualTo(64.0);
|
||||||
|
|
||||||
// Match the parsing patterns of getLongBytes, which takes single char
|
// Match the parsing patterns of getLongBytes, which takes single char
|
||||||
// suffix.
|
// suffix.
|
||||||
conf.setStrings(key, "1T");
|
conf.setStrings(key, "1T");
|
||||||
assertThat(conf.getStorageSize(key, "1GB", TB), is(1.0));
|
Assertions.assertThat(conf.getStorageSize(key, "1GB", TB)).isEqualTo(1.0);
|
||||||
|
|
||||||
conf.setStrings(key, "1k");
|
conf.setStrings(key, "1k");
|
||||||
assertThat(conf.getStorageSize(key, "1GB", KB), is(1.0));
|
Assertions.assertThat(conf.getStorageSize(key, "1GB", KB)).isEqualTo(1.0);
|
||||||
|
|
||||||
conf.setStrings(key, "10m");
|
conf.setStrings(key, "10m");
|
||||||
assertThat(conf.getStorageSize(key, "1GB", MB), is(10.0));
|
Assertions.assertThat(conf.getStorageSize(key, "1GB", MB)).isEqualTo(10.0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Missing format specification, this should throw.
|
// Missing format specification, this should throw.
|
||||||
conf.setStrings(key, "100");
|
conf.setStrings(key, "100");
|
||||||
thrown.expect(IllegalArgumentException.class);
|
assertThrows(IllegalArgumentException.class,
|
||||||
conf.getStorageSize(key, "1PB", GB);
|
() -> conf.getStorageSize(key, "1PB", GB));
|
||||||
|
|
||||||
// illegal format specification, this should throw.
|
// illegal format specification, this should throw.
|
||||||
conf.setStrings(key, "1HB");
|
conf.setStrings(key, "1HB");
|
||||||
thrown.expect(IllegalArgumentException.class);
|
assertThrows(IllegalArgumentException.class,
|
||||||
conf.getStorageSize(key, "1PB", GB);
|
() -> conf.getStorageSize(key, "1PB", GB));
|
||||||
|
|
||||||
// Illegal number specification, this should throw.
|
// Illegal number specification, this should throw.
|
||||||
conf.setStrings(key, "HadoopGB");
|
conf.setStrings(key, "HadoopGB");
|
||||||
thrown.expect(IllegalArgumentException.class);
|
assertThrows(IllegalArgumentException.class,
|
||||||
conf.getStorageSize(key, "1PB", GB);
|
() -> conf.getStorageSize(key, "1PB", GB));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -2424,10 +2422,10 @@ public void testGetPasswordDeprecatedKeyStored() throws Exception {
|
|||||||
|
|
||||||
Configuration.addDeprecation(oldKey, newKey);
|
Configuration.addDeprecation(oldKey, newKey);
|
||||||
|
|
||||||
assertThat(conf.getPassword(newKey),
|
Assertions.assertThat(conf.getPassword(newKey))
|
||||||
CoreMatchers.is(password.toCharArray()));
|
.isEqualTo(password.toCharArray());
|
||||||
assertThat(conf.getPassword(oldKey),
|
Assertions.assertThat(conf.getPassword(oldKey))
|
||||||
CoreMatchers.is(password.toCharArray()));
|
.isEqualTo(password.toCharArray());
|
||||||
|
|
||||||
FileUtil.fullyDelete(tmpDir);
|
FileUtil.fullyDelete(tmpDir);
|
||||||
}
|
}
|
||||||
@ -2453,10 +2451,10 @@ public void testGetPasswordByDeprecatedKey() throws Exception {
|
|||||||
|
|
||||||
Configuration.addDeprecation(oldKey, newKey);
|
Configuration.addDeprecation(oldKey, newKey);
|
||||||
|
|
||||||
assertThat(conf.getPassword(newKey),
|
Assertions.assertThat(conf.getPassword(newKey))
|
||||||
CoreMatchers.is(password.toCharArray()));
|
.isEqualTo(password.toCharArray());
|
||||||
assertThat(conf.getPassword(oldKey),
|
Assertions.assertThat(conf.getPassword(oldKey))
|
||||||
CoreMatchers.is(password.toCharArray()));
|
.isEqualTo(password.toCharArray());
|
||||||
|
|
||||||
FileUtil.fullyDelete(tmpDir);
|
FileUtil.fullyDelete(tmpDir);
|
||||||
}
|
}
|
||||||
@ -2469,7 +2467,7 @@ public void testGettingPropertiesWithPrefix() throws Exception {
|
|||||||
}
|
}
|
||||||
conf.set("different.prefix" + ".name", "value");
|
conf.set("different.prefix" + ".name", "value");
|
||||||
Map<String, String> prefixedProps = conf.getPropsWithPrefix("prefix.");
|
Map<String, String> prefixedProps = conf.getPropsWithPrefix("prefix.");
|
||||||
assertThat(prefixedProps.size(), is(10));
|
Assertions.assertThat(prefixedProps).hasSize(10);
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
assertEquals("value" + i, prefixedProps.get("name" + i));
|
assertEquals("value" + i, prefixedProps.get("name" + i));
|
||||||
}
|
}
|
||||||
@ -2480,7 +2478,7 @@ public void testGettingPropertiesWithPrefix() throws Exception {
|
|||||||
conf.set("subprefix." + "subname" + i, "value_${foo}" + i);
|
conf.set("subprefix." + "subname" + i, "value_${foo}" + i);
|
||||||
}
|
}
|
||||||
prefixedProps = conf.getPropsWithPrefix("subprefix.");
|
prefixedProps = conf.getPropsWithPrefix("subprefix.");
|
||||||
assertThat(prefixedProps.size(), is(10));
|
Assertions.assertThat(prefixedProps).hasSize(10);
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
assertEquals("value_bar" + i, prefixedProps.get("subname" + i));
|
assertEquals("value_bar" + i, prefixedProps.get("subname" + i));
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
import javax.crypto.spec.IvParameterSpec;
|
import javax.crypto.spec.IvParameterSpec;
|
||||||
@ -58,7 +59,7 @@ public class TestKeyProviderCryptoExtension {
|
|||||||
private static KeyVersion encryptionKey;
|
private static KeyVersion encryptionKey;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout testTimeout = new Timeout(180000);
|
public Timeout testTimeout = new Timeout(180000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setup() throws Exception {
|
public static void setup() throws Exception {
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.apache.hadoop.crypto.key.kms.KMSDelegationToken.TOKEN_KIND;
|
import static org.apache.hadoop.crypto.key.kms.KMSDelegationToken.TOKEN_KIND;
|
||||||
|
|
||||||
@ -57,7 +58,7 @@ public class TestKMSClientProvider {
|
|||||||
private final String oldTokenService = "host:16000";
|
private final String oldTokenService = "host:16000";
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(60000);
|
public Timeout globalTimeout = new Timeout(60000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
{
|
{
|
||||||
GenericTestUtils.setLogLevel(KMSClientProvider.LOG, Level.TRACE);
|
GenericTestUtils.setLogLevel(KMSClientProvider.LOG, Level.TRACE);
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
import java.security.PrivilegedExceptionAction;
|
import java.security.PrivilegedExceptionAction;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.net.ssl.SSLHandshakeException;
|
import javax.net.ssl.SSLHandshakeException;
|
||||||
|
|
||||||
@ -67,7 +68,7 @@
|
|||||||
public class TestLoadBalancingKMSClientProvider {
|
public class TestLoadBalancingKMSClientProvider {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout testTimeout = new Timeout(30 * 1000);
|
public Timeout testTimeout = new Timeout(30, TimeUnit.SECONDS);
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setup() throws IOException {
|
public static void setup() throws IOException {
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -36,7 +37,6 @@
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.rules.Timeout;
|
import org.junit.rules.Timeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,7 +61,8 @@ public abstract class FileSystemContractBaseTest {
|
|||||||
protected byte[] data = dataset(getBlockSize() * 2, 0, 255);
|
protected byte[] data = dataset(getBlockSize() * 2, 0, 255);
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(getGlobalTimeout());
|
public Timeout globalTimeout =
|
||||||
|
new Timeout(getGlobalTimeout(), TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the timeout in milliseconds for each test case.
|
* Get the timeout in milliseconds for each test case.
|
||||||
@ -71,9 +72,6 @@ protected int getGlobalTimeout() {
|
|||||||
return 30 * 1000;
|
return 30 * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
if (fs != null) {
|
if (fs != null) {
|
||||||
|
@ -18,9 +18,7 @@
|
|||||||
package org.apache.hadoop.fs;
|
package org.apache.hadoop.fs;
|
||||||
|
|
||||||
import static org.apache.hadoop.fs.FileSystem.FS_DEFAULT_NAME_KEY;
|
import static org.apache.hadoop.fs.FileSystem.FS_DEFAULT_NAME_KEY;
|
||||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
@ -40,32 +38,32 @@ public class TestDefaultUri {
|
|||||||
public void tetGetDefaultUri() {
|
public void tetGetDefaultUri() {
|
||||||
conf.set(FS_DEFAULT_NAME_KEY, "hdfs://nn_host");
|
conf.set(FS_DEFAULT_NAME_KEY, "hdfs://nn_host");
|
||||||
URI uri = FileSystem.getDefaultUri(conf);
|
URI uri = FileSystem.getDefaultUri(conf);
|
||||||
assertThat(uri.getScheme(), is("hdfs"));
|
assertThat(uri.getScheme()).isEqualTo("hdfs");
|
||||||
assertThat(uri.getAuthority(), is("nn_host"));
|
assertThat(uri.getAuthority()).isEqualTo("nn_host");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tetGetDefaultUriWithPort() {
|
public void tetGetDefaultUriWithPort() {
|
||||||
conf.set(FS_DEFAULT_NAME_KEY, "hdfs://nn_host:5432");
|
conf.set(FS_DEFAULT_NAME_KEY, "hdfs://nn_host:5432");
|
||||||
URI uri = FileSystem.getDefaultUri(conf);
|
URI uri = FileSystem.getDefaultUri(conf);
|
||||||
assertThat(uri.getScheme(), is("hdfs"));
|
assertThat(uri.getScheme()).isEqualTo("hdfs");
|
||||||
assertThat(uri.getAuthority(), is("nn_host:5432"));
|
assertThat(uri.getAuthority()).isEqualTo("nn_host:5432");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tetGetDefaultUriTrailingSlash() {
|
public void tetGetDefaultUriTrailingSlash() {
|
||||||
conf.set(FS_DEFAULT_NAME_KEY, "hdfs://nn_host/");
|
conf.set(FS_DEFAULT_NAME_KEY, "hdfs://nn_host/");
|
||||||
URI uri = FileSystem.getDefaultUri(conf);
|
URI uri = FileSystem.getDefaultUri(conf);
|
||||||
assertThat(uri.getScheme(), is("hdfs"));
|
assertThat(uri.getScheme()).isEqualTo("hdfs");
|
||||||
assertThat(uri.getAuthority(), is("nn_host"));
|
assertThat(uri.getAuthority()).isEqualTo("nn_host");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tetGetDefaultUriNoScheme() {
|
public void tetGetDefaultUriNoScheme() {
|
||||||
conf.set(FS_DEFAULT_NAME_KEY, "nn_host");
|
conf.set(FS_DEFAULT_NAME_KEY, "nn_host");
|
||||||
URI uri = FileSystem.getDefaultUri(conf);
|
URI uri = FileSystem.getDefaultUri(conf);
|
||||||
assertThat(uri.getScheme(), is("hdfs"));
|
assertThat(uri.getScheme()).isEqualTo("hdfs");
|
||||||
assertThat(uri.getAuthority(), is("nn_host"));
|
assertThat(uri.getAuthority()).isEqualTo("nn_host");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -81,7 +79,7 @@ public void tetGetDefaultUriNoSchemeTrailingSlash() throws Exception {
|
|||||||
public void tetFsGet() throws IOException {
|
public void tetFsGet() throws IOException {
|
||||||
conf.set(FS_DEFAULT_NAME_KEY, "file:///");
|
conf.set(FS_DEFAULT_NAME_KEY, "file:///");
|
||||||
FileSystem fs = FileSystem.get(conf);
|
FileSystem fs = FileSystem.get(conf);
|
||||||
assertThat(fs, instanceOf(LocalFileSystem.class));
|
assertThat(fs).isInstanceOf(LocalFileSystem.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -25,12 +25,12 @@
|
|||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.rules.Timeout;
|
import org.junit.rules.Timeout;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
@ -61,9 +61,7 @@ public class TestFileSystemStorageStatistics {
|
|||||||
new FileSystemStorageStatistics(FS_STORAGE_STATISTICS_NAME, statistics);
|
new FileSystemStorageStatistics(FS_STORAGE_STATISTICS_NAME, statistics);
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final Timeout globalTimeout = new Timeout(10 * 1000);
|
public final Timeout globalTimeout = new Timeout(10, TimeUnit.SECONDS);
|
||||||
@Rule
|
|
||||||
public final ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
|
@ -22,8 +22,7 @@
|
|||||||
import org.apache.hadoop.fs.shell.CommandFactory;
|
import org.apache.hadoop.fs.shell.CommandFactory;
|
||||||
import org.apache.hadoop.test.GenericTestUtils;
|
import org.apache.hadoop.test.GenericTestUtils;
|
||||||
import org.apache.hadoop.util.ToolRunner;
|
import org.apache.hadoop.util.ToolRunner;
|
||||||
import org.hamcrest.core.StringContains;
|
import org.assertj.core.api.Assertions;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
@ -66,14 +65,14 @@ public void testDFSWithInvalidCommmand() throws Throwable {
|
|||||||
try (GenericTestUtils.SystemErrCapturer capture =
|
try (GenericTestUtils.SystemErrCapturer capture =
|
||||||
new GenericTestUtils.SystemErrCapturer()) {
|
new GenericTestUtils.SystemErrCapturer()) {
|
||||||
ToolRunner.run(shell, new String[]{"dfs -mkdirs"});
|
ToolRunner.run(shell, new String[]{"dfs -mkdirs"});
|
||||||
Assert.assertThat("FSShell dfs command did not print the error " +
|
Assertions.assertThat(capture.getOutput())
|
||||||
"message when invalid command is passed",
|
.as("FSShell dfs command did not print the error " +
|
||||||
capture.getOutput(), StringContains.containsString(
|
"message when invalid command is passed")
|
||||||
"-mkdirs: Unknown command"));
|
.contains("-mkdirs: Unknown command");
|
||||||
Assert.assertThat("FSShell dfs command did not print help " +
|
Assertions.assertThat(capture.getOutput())
|
||||||
"message when invalid command is passed",
|
.as("FSShell dfs command did not print help " +
|
||||||
capture.getOutput(), StringContains.containsString(
|
"message when invalid command is passed")
|
||||||
"Usage: hadoop fs [generic options]"));
|
.contains("Usage: hadoop fs [generic options]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,9 +94,8 @@ public void testExceptionNullMessage() throws Exception {
|
|||||||
try (GenericTestUtils.SystemErrCapturer capture =
|
try (GenericTestUtils.SystemErrCapturer capture =
|
||||||
new GenericTestUtils.SystemErrCapturer()) {
|
new GenericTestUtils.SystemErrCapturer()) {
|
||||||
ToolRunner.run(shell, new String[]{cmdName});
|
ToolRunner.run(shell, new String[]{cmdName});
|
||||||
Assert.assertThat(capture.getOutput(),
|
Assertions.assertThat(capture.getOutput())
|
||||||
StringContains.containsString(cmdName
|
.contains(cmdName + ": Null exception message");
|
||||||
+ ": Null exception message"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,10 @@
|
|||||||
package org.apache.hadoop.fs;
|
package org.apache.hadoop.fs;
|
||||||
|
|
||||||
import static org.apache.hadoop.test.PlatformAssumptions.assumeWindows;
|
import static org.apache.hadoop.test.PlatformAssumptions.assumeWindows;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.hamcrest.CoreMatchers.not;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@ -640,15 +638,16 @@ public void testCopyNoParent() throws Exception {
|
|||||||
final String noDirName = "noDir";
|
final String noDirName = "noDir";
|
||||||
final Path noDir = new Path(noDirName);
|
final Path noDir = new Path(noDirName);
|
||||||
lfs.delete(noDir, true);
|
lfs.delete(noDir, true);
|
||||||
assertThat(lfs.exists(noDir), is(false));
|
assertThat(lfs.exists(noDir)).isFalse();
|
||||||
|
|
||||||
assertThat("Expected failed put to a path without parent directory",
|
assertThat(shellRun("-put", srcPath.toString(), noDirName + "/foo"))
|
||||||
shellRun("-put", srcPath.toString(), noDirName + "/foo"), is(not(0)));
|
.as("Expected failed put to a path without parent directory")
|
||||||
|
.isNotEqualTo(0);
|
||||||
|
|
||||||
// Note the trailing '/' in the target path.
|
// Note the trailing '/' in the target path.
|
||||||
assertThat("Expected failed copyFromLocal to a non-existent directory",
|
assertThat(shellRun("-copyFromLocal", srcPath.toString(), noDirName + "/"))
|
||||||
shellRun("-copyFromLocal", srcPath.toString(), noDirName + "/"),
|
.as("Expected failed copyFromLocal to a non-existent directory")
|
||||||
is(not(0)));
|
.isNotEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -18,14 +18,13 @@
|
|||||||
|
|
||||||
package org.apache.hadoop.fs;
|
package org.apache.hadoop.fs;
|
||||||
|
|
||||||
import static org.hamcrest.core.Is.is;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
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.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test FsShell -ls command.
|
* Test FsShell -ls command.
|
||||||
*/
|
*/
|
||||||
@ -45,7 +44,7 @@ public static void setup() throws Exception {
|
|||||||
|
|
||||||
String root = System.getProperty("test.build.data", "test/build/data");
|
String root = System.getProperty("test.build.data", "test/build/data");
|
||||||
testRootDir = lfs.makeQualified(new Path(root, "testFsShellList"));
|
testRootDir = lfs.makeQualified(new Path(root, "testFsShellList"));
|
||||||
assertThat(lfs.mkdirs(testRootDir), is(true));
|
assertThat(lfs.mkdirs(testRootDir)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
@ -57,23 +56,23 @@ private void createFile(Path filePath) throws Exception {
|
|||||||
FSDataOutputStream out = lfs.create(filePath);
|
FSDataOutputStream out = lfs.create(filePath);
|
||||||
out.writeChars("I am " + filePath);
|
out.writeChars("I am " + filePath);
|
||||||
out.close();
|
out.close();
|
||||||
assertThat(lfs.exists(lfs.getChecksumFile(filePath)), is(true));
|
assertThat(lfs.exists(lfs.getChecksumFile(filePath))).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testList() throws Exception {
|
public void testList() throws Exception {
|
||||||
createFile(new Path(testRootDir, "abc"));
|
createFile(new Path(testRootDir, "abc"));
|
||||||
String[] lsArgv = new String[]{"-ls", testRootDir.toString()};
|
String[] lsArgv = new String[]{"-ls", testRootDir.toString()};
|
||||||
assertThat(shell.run(lsArgv), is(0));
|
assertThat(shell.run(lsArgv)).isEqualTo(0);
|
||||||
|
|
||||||
createFile(new Path(testRootDir, "abc\bd\tef"));
|
createFile(new Path(testRootDir, "abc\bd\tef"));
|
||||||
createFile(new Path(testRootDir, "ghi"));
|
createFile(new Path(testRootDir, "ghi"));
|
||||||
createFile(new Path(testRootDir, "qq\r123"));
|
createFile(new Path(testRootDir, "qq\r123"));
|
||||||
lsArgv = new String[]{"-ls", testRootDir.toString()};
|
lsArgv = new String[]{"-ls", testRootDir.toString()};
|
||||||
assertThat(shell.run(lsArgv), is(0));
|
assertThat(shell.run(lsArgv)).isEqualTo(0);
|
||||||
|
|
||||||
lsArgv = new String[]{"-ls", "-q", testRootDir.toString()};
|
lsArgv = new String[]{"-ls", "-q", testRootDir.toString()};
|
||||||
assertThat(shell.run(lsArgv), is(0));
|
assertThat(shell.run(lsArgv)).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -17,10 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.fs;
|
package org.apache.hadoop.fs;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
|
||||||
import static org.hamcrest.CoreMatchers.not;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@ -34,6 +30,8 @@
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class TestFsShellTouch {
|
public class TestFsShellTouch {
|
||||||
static final Logger LOG = LoggerFactory.getLogger(TestFsShellTouch.class);
|
static final Logger LOG = LoggerFactory.getLogger(TestFsShellTouch.class);
|
||||||
|
|
||||||
@ -71,23 +69,25 @@ public void testTouchz() throws Exception {
|
|||||||
final String newFileName = "newFile";
|
final String newFileName = "newFile";
|
||||||
final Path newFile = new Path(newFileName);
|
final Path newFile = new Path(newFileName);
|
||||||
lfs.delete(newFile, true);
|
lfs.delete(newFile, true);
|
||||||
assertThat(lfs.exists(newFile), is(false));
|
assertThat(lfs.exists(newFile)).isFalse();
|
||||||
|
|
||||||
assertThat("Expected successful touchz on a new file",
|
assertThat(shellRun("-touchz", newFileName))
|
||||||
shellRun("-touchz", newFileName), is(0));
|
.as("Expected successful touchz on a new file").isEqualTo(0);
|
||||||
shellRun("-ls", newFileName);
|
shellRun("-ls", newFileName);
|
||||||
|
|
||||||
assertThat("Expected successful touchz on an existing zero-length file",
|
assertThat(shellRun("-touchz", newFileName))
|
||||||
shellRun("-touchz", newFileName), is(0));
|
.as("Expected successful touchz on an existing zero-length file")
|
||||||
|
.isEqualTo(0);
|
||||||
|
|
||||||
// Ensure noDir does not exist
|
// Ensure noDir does not exist
|
||||||
final String noDirName = "noDir";
|
final String noDirName = "noDir";
|
||||||
final Path noDir = new Path(noDirName);
|
final Path noDir = new Path(noDirName);
|
||||||
lfs.delete(noDir, true);
|
lfs.delete(noDir, true);
|
||||||
assertThat(lfs.exists(noDir), is(false));
|
assertThat(lfs.exists(noDir)).isFalse();
|
||||||
|
|
||||||
assertThat("Expected failed touchz in a non-existent directory",
|
assertThat(shellRun("-touchz", noDirName + "/foo"))
|
||||||
shellRun("-touchz", noDirName + "/foo"), is(not(0)));
|
.as("Expected failed touchz in a non-existent directory")
|
||||||
|
.isNotEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -96,25 +96,28 @@ public void testTouch() throws Exception {
|
|||||||
final String newFileName = "newFile2";
|
final String newFileName = "newFile2";
|
||||||
final Path newFile = new Path(newFileName);
|
final Path newFile = new Path(newFileName);
|
||||||
lfs.delete(newFile, true);
|
lfs.delete(newFile, true);
|
||||||
assertThat(lfs.exists(newFile), is(false));
|
assertThat(lfs.exists(newFile)).isFalse();
|
||||||
|
|
||||||
{
|
{
|
||||||
assertThat(
|
assertThat(shellRun("-touch", "-c", newFileName))
|
||||||
"Expected successful touch on a non-existent file with -c option",
|
.as("Expected successful touch on a non-existent file" +
|
||||||
shellRun("-touch", "-c", newFileName), is(0));
|
" with -c option")
|
||||||
assertThat(lfs.exists(newFile), is(false));
|
.isEqualTo(0);
|
||||||
|
assertThat(lfs.exists(newFile)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
String strTime = formatTimestamp(System.currentTimeMillis());
|
String strTime = formatTimestamp(System.currentTimeMillis());
|
||||||
Date dateObj = parseTimestamp(strTime);
|
Date dateObj = parseTimestamp(strTime);
|
||||||
|
|
||||||
assertThat(
|
assertThat(shellRun("-touch", "-t", strTime, newFileName))
|
||||||
"Expected successful touch on a new file with a specified timestamp",
|
.as("Expected successful touch on a new file" +
|
||||||
shellRun("-touch", "-t", strTime, newFileName), is(0));
|
" with a specified timestamp")
|
||||||
|
.isEqualTo(0);
|
||||||
FileStatus new_status = lfs.getFileStatus(newFile);
|
FileStatus new_status = lfs.getFileStatus(newFile);
|
||||||
assertThat(new_status.getAccessTime(), is(dateObj.getTime()));
|
assertThat(new_status.getAccessTime()).isEqualTo(dateObj.getTime());
|
||||||
assertThat(new_status.getModificationTime(), is(dateObj.getTime()));
|
assertThat(new_status.getModificationTime())
|
||||||
|
.isEqualTo(dateObj.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
FileStatus fstatus = lfs.getFileStatus(newFile);
|
FileStatus fstatus = lfs.getFileStatus(newFile);
|
||||||
@ -123,14 +126,15 @@ public void testTouch() throws Exception {
|
|||||||
String strTime = formatTimestamp(System.currentTimeMillis());
|
String strTime = formatTimestamp(System.currentTimeMillis());
|
||||||
Date dateObj = parseTimestamp(strTime);
|
Date dateObj = parseTimestamp(strTime);
|
||||||
|
|
||||||
assertThat("Expected successful touch with a specified access time",
|
assertThat(shellRun("-touch", "-a", "-t", strTime, newFileName))
|
||||||
shellRun("-touch", "-a", "-t", strTime, newFileName), is(0));
|
.as("Expected successful touch with a specified access time")
|
||||||
|
.isEqualTo(0);
|
||||||
FileStatus new_status = lfs.getFileStatus(newFile);
|
FileStatus new_status = lfs.getFileStatus(newFile);
|
||||||
// Verify if access time is recorded correctly (and modification time
|
// Verify if access time is recorded correctly (and modification time
|
||||||
// remains unchanged).
|
// remains unchanged).
|
||||||
assertThat(new_status.getAccessTime(), is(dateObj.getTime()));
|
assertThat(new_status.getAccessTime()).isEqualTo(dateObj.getTime());
|
||||||
assertThat(new_status.getModificationTime(),
|
assertThat(new_status.getModificationTime())
|
||||||
is(fstatus.getModificationTime()));
|
.isEqualTo(fstatus.getModificationTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
fstatus = lfs.getFileStatus(newFile);
|
fstatus = lfs.getFileStatus(newFile);
|
||||||
@ -139,56 +143,63 @@ public void testTouch() throws Exception {
|
|||||||
String strTime = formatTimestamp(System.currentTimeMillis());
|
String strTime = formatTimestamp(System.currentTimeMillis());
|
||||||
Date dateObj = parseTimestamp(strTime);
|
Date dateObj = parseTimestamp(strTime);
|
||||||
|
|
||||||
assertThat(
|
assertThat(shellRun("-touch", "-m", "-t", strTime, newFileName))
|
||||||
"Expected successful touch with a specified modification time",
|
.as("Expected successful touch with a specified modification time")
|
||||||
shellRun("-touch", "-m", "-t", strTime, newFileName), is(0));
|
.isEqualTo(0);
|
||||||
// Verify if modification time is recorded correctly (and access time
|
// Verify if modification time is recorded correctly (and access time
|
||||||
// remains unchanged).
|
// remains unchanged).
|
||||||
FileStatus new_status = lfs.getFileStatus(newFile);
|
FileStatus new_status = lfs.getFileStatus(newFile);
|
||||||
assertThat(new_status.getAccessTime(), is(fstatus.getAccessTime()));
|
assertThat(new_status.getAccessTime())
|
||||||
assertThat(new_status.getModificationTime(), is(dateObj.getTime()));
|
.isEqualTo(fstatus.getAccessTime());
|
||||||
|
assertThat(new_status.getModificationTime())
|
||||||
|
.isEqualTo(dateObj.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
String strTime = formatTimestamp(System.currentTimeMillis());
|
String strTime = formatTimestamp(System.currentTimeMillis());
|
||||||
Date dateObj = parseTimestamp(strTime);
|
Date dateObj = parseTimestamp(strTime);
|
||||||
|
|
||||||
assertThat("Expected successful touch with a specified timestamp",
|
assertThat(shellRun("-touch", "-t", strTime, newFileName))
|
||||||
shellRun("-touch", "-t", strTime, newFileName), is(0));
|
.as("Expected successful touch with a specified timestamp")
|
||||||
|
.isEqualTo(0);
|
||||||
|
|
||||||
// Verify if both modification and access times are recorded correctly
|
// Verify if both modification and access times are recorded correctly
|
||||||
FileStatus new_status = lfs.getFileStatus(newFile);
|
FileStatus new_status = lfs.getFileStatus(newFile);
|
||||||
assertThat(new_status.getAccessTime(), is(dateObj.getTime()));
|
assertThat(new_status.getAccessTime()).isEqualTo(dateObj.getTime());
|
||||||
assertThat(new_status.getModificationTime(), is(dateObj.getTime()));
|
assertThat(new_status.getModificationTime())
|
||||||
|
.isEqualTo(dateObj.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
String strTime = formatTimestamp(System.currentTimeMillis());
|
String strTime = formatTimestamp(System.currentTimeMillis());
|
||||||
Date dateObj = parseTimestamp(strTime);
|
Date dateObj = parseTimestamp(strTime);
|
||||||
|
|
||||||
assertThat("Expected successful touch with a specified timestamp",
|
assertThat(shellRun("-touch", "-a", "-m", "-t", strTime, newFileName))
|
||||||
shellRun("-touch", "-a", "-m", "-t", strTime, newFileName), is(0));
|
.as("Expected successful touch with a specified timestamp")
|
||||||
|
.isEqualTo(0);
|
||||||
|
|
||||||
// Verify if both modification and access times are recorded correctly
|
// Verify if both modification and access times are recorded correctly
|
||||||
FileStatus new_status = lfs.getFileStatus(newFile);
|
FileStatus new_status = lfs.getFileStatus(newFile);
|
||||||
assertThat(new_status.getAccessTime(), is(dateObj.getTime()));
|
assertThat(new_status.getAccessTime()).isEqualTo(dateObj.getTime());
|
||||||
assertThat(new_status.getModificationTime(), is(dateObj.getTime()));
|
assertThat(new_status.getModificationTime())
|
||||||
|
.isEqualTo(dateObj.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
assertThat("Expected failed touch with a missing timestamp",
|
assertThat(shellRun("-touch", "-t", newFileName))
|
||||||
shellRun("-touch", "-t", newFileName), is(not(0)));
|
.as("Expected failed touch with a missing timestamp")
|
||||||
|
.isNotEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify -c option when file exists.
|
// Verify -c option when file exists.
|
||||||
String strTime = formatTimestamp(System.currentTimeMillis());
|
String strTime = formatTimestamp(System.currentTimeMillis());
|
||||||
Date dateObj = parseTimestamp(strTime);
|
Date dateObj = parseTimestamp(strTime);
|
||||||
assertThat(
|
assertThat(shellRun("-touch", "-c", "-t", strTime, newFileName))
|
||||||
"Expected successful touch on a non-existent file with -c option",
|
.as("Expected successful touch on a non-existent file with -c option")
|
||||||
shellRun("-touch", "-c", "-t", strTime, newFileName), is(0));
|
.isEqualTo(0);
|
||||||
FileStatus fileStatus = lfs.getFileStatus(newFile);
|
FileStatus fileStatus = lfs.getFileStatus(newFile);
|
||||||
assertThat(fileStatus.getAccessTime(), is(dateObj.getTime()));
|
assertThat(fileStatus.getAccessTime()).isEqualTo(dateObj.getTime());
|
||||||
assertThat(fileStatus.getModificationTime(), is(dateObj.getTime()));
|
assertThat(fileStatus.getModificationTime()).isEqualTo(dateObj.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatTimestamp(long timeInMillis) {
|
private String formatTimestamp(long timeInMillis) {
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
|
import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
|
||||||
@ -74,16 +75,11 @@ public class TestLocalFileSystem {
|
|||||||
private Configuration conf;
|
private Configuration conf;
|
||||||
private LocalFileSystem fileSys;
|
private LocalFileSystem fileSys;
|
||||||
|
|
||||||
/**
|
|
||||||
* standard test timeout: {@value}.
|
|
||||||
*/
|
|
||||||
public static final int DEFAULT_TEST_TIMEOUT = 60 * 1000;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the timeout for every test.
|
* Set the timeout for every test.
|
||||||
*/
|
*/
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout testTimeout = new Timeout(DEFAULT_TEST_TIMEOUT);
|
public Timeout testTimeout = new Timeout(60, TimeUnit.SECONDS);
|
||||||
|
|
||||||
private void cleanupFile(FileSystem fs, Path name) throws IOException {
|
private void cleanupFile(FileSystem fs, Path name) throws IOException {
|
||||||
assertTrue(fs.exists(name));
|
assertTrue(fs.exists(name));
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
import org.apache.hadoop.fs.permission.FsPermission;
|
import org.apache.hadoop.fs.permission.FsPermission;
|
||||||
import org.apache.hadoop.test.GenericTestUtils;
|
import org.apache.hadoop.test.GenericTestUtils;
|
||||||
import org.apache.hadoop.util.Shell;
|
import org.apache.hadoop.util.Shell;
|
||||||
|
import org.assertj.core.api.Assertions;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -32,8 +33,6 @@
|
|||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
|
import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
|
||||||
import static org.hamcrest.CoreMatchers.not;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -245,9 +244,9 @@ public void testSetUmaskInRealTime() throws Exception {
|
|||||||
assertTrue(localfs.mkdirs(dir2));
|
assertTrue(localfs.mkdirs(dir2));
|
||||||
FsPermission finalPermission = localfs.getFileStatus(dir2)
|
FsPermission finalPermission = localfs.getFileStatus(dir2)
|
||||||
.getPermission();
|
.getPermission();
|
||||||
assertThat("With umask 062 permission should not be 755 since the " +
|
Assertions.assertThat(new FsPermission("755")).as(
|
||||||
"default permission is 777", new FsPermission("755"),
|
"With umask 062 permission should not be 755 since the " +
|
||||||
is(not(finalPermission)));
|
"default permission is 777").isNotEqualTo(finalPermission);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"With umask 062 we expect 715 since the default permission is 777",
|
"With umask 062 we expect 715 since the default permission is 777",
|
||||||
new FsPermission("715"), finalPermission);
|
new FsPermission("715"), finalPermission);
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.internal.AssumptionViolatedException;
|
import org.junit.AssumptionViolatedException;
|
||||||
import org.junit.rules.TestName;
|
import org.junit.rules.TestName;
|
||||||
import org.junit.rules.Timeout;
|
import org.junit.rules.Timeout;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.apache.hadoop.fs.contract.ContractTestUtils.cleanup;
|
import static org.apache.hadoop.fs.contract.ContractTestUtils.cleanup;
|
||||||
import static org.apache.hadoop.fs.contract.ContractTestUtils.skip;
|
import static org.apache.hadoop.fs.contract.ContractTestUtils.skip;
|
||||||
@ -164,7 +165,8 @@ protected Configuration createConfiguration() {
|
|||||||
* Set the timeout for every test.
|
* Set the timeout for every test.
|
||||||
*/
|
*/
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout testTimeout = new Timeout(getTestTimeoutMillis());
|
public Timeout testTimeout =
|
||||||
|
new Timeout(getTestTimeoutMillis(), TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Option for tests to override the default timeout value.
|
* Option for tests to override the default timeout value.
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.hadoop.thirdparty.com.google.common.base.Preconditions;
|
import org.apache.hadoop.thirdparty.com.google.common.base.Preconditions;
|
||||||
import org.apache.commons.net.ftp.FTP;
|
import org.apache.commons.net.ftp.FTP;
|
||||||
@ -57,7 +58,7 @@ public class TestFTPFileSystem {
|
|||||||
private FtpTestServer server;
|
private FtpTestServer server;
|
||||||
private java.nio.file.Path testDir;
|
private java.nio.file.Path testDir;
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout testTimeout = new Timeout(180000);
|
public Timeout testTimeout = new Timeout(180000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
@ -44,14 +44,15 @@
|
|||||||
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
|
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
|
||||||
import org.apache.sshd.server.session.ServerSession;
|
import org.apache.sshd.server.session.ServerSession;
|
||||||
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
|
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
|
||||||
import static org.hamcrest.core.Is.is;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
@ -193,8 +194,9 @@ public void testCreateFile() throws Exception {
|
|||||||
assertTrue(localFs.exists(file));
|
assertTrue(localFs.exists(file));
|
||||||
assertTrue(sftpFs.delete(file, false));
|
assertTrue(sftpFs.delete(file, false));
|
||||||
assertFalse(localFs.exists(file));
|
assertFalse(localFs.exists(file));
|
||||||
assertThat(((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount(),
|
assertThat(
|
||||||
is(1));
|
((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount())
|
||||||
|
.isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -210,8 +212,9 @@ public void testFileExists() throws Exception {
|
|||||||
assertTrue(sftpFs.delete(file, false));
|
assertTrue(sftpFs.delete(file, false));
|
||||||
assertFalse(sftpFs.exists(file));
|
assertFalse(sftpFs.exists(file));
|
||||||
assertFalse(localFs.exists(file));
|
assertFalse(localFs.exists(file));
|
||||||
assertThat(((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount(),
|
assertThat(
|
||||||
is(1));
|
((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount())
|
||||||
|
.isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -235,8 +238,9 @@ public void testReadFile() throws Exception {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertTrue(sftpFs.delete(file, false));
|
assertTrue(sftpFs.delete(file, false));
|
||||||
assertThat(((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount(),
|
assertThat(
|
||||||
is(1));
|
((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount())
|
||||||
|
.isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -258,8 +262,9 @@ public void testStatFile() throws Exception {
|
|||||||
assertEquals(data.length, sstat.getLen());
|
assertEquals(data.length, sstat.getLen());
|
||||||
assertEquals(lstat.getLen(), sstat.getLen());
|
assertEquals(lstat.getLen(), sstat.getLen());
|
||||||
assertTrue(sftpFs.delete(file, false));
|
assertTrue(sftpFs.delete(file, false));
|
||||||
assertThat(((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount(),
|
assertThat(
|
||||||
is(1));
|
((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount())
|
||||||
|
.isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -271,8 +276,9 @@ public void testStatFile() throws Exception {
|
|||||||
public void testDeleteNonEmptyDir() throws Exception {
|
public void testDeleteNonEmptyDir() throws Exception {
|
||||||
Path file = touch(localFs, name.getMethodName().toLowerCase());
|
Path file = touch(localFs, name.getMethodName().toLowerCase());
|
||||||
sftpFs.delete(localDir, false);
|
sftpFs.delete(localDir, false);
|
||||||
assertThat(((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount(),
|
assertThat(
|
||||||
is(1));
|
((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount())
|
||||||
|
.isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -284,8 +290,9 @@ public void testDeleteNonEmptyDir() throws Exception {
|
|||||||
public void testDeleteNonExistFile() throws Exception {
|
public void testDeleteNonExistFile() throws Exception {
|
||||||
Path file = new Path(localDir, name.getMethodName().toLowerCase());
|
Path file = new Path(localDir, name.getMethodName().toLowerCase());
|
||||||
assertFalse(sftpFs.delete(file, false));
|
assertFalse(sftpFs.delete(file, false));
|
||||||
assertThat(((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount(),
|
assertThat(
|
||||||
is(1));
|
((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount())
|
||||||
|
.isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -308,8 +315,9 @@ public void testRenameFile() throws Exception {
|
|||||||
assertFalse(localFs.exists(file1));
|
assertFalse(localFs.exists(file1));
|
||||||
|
|
||||||
assertTrue(sftpFs.delete(file2, false));
|
assertTrue(sftpFs.delete(file2, false));
|
||||||
assertThat(((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount(),
|
assertThat(
|
||||||
is(1));
|
((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount())
|
||||||
|
.isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -347,8 +355,9 @@ public void testGetAccessTime() throws IOException {
|
|||||||
accessTime1 = (accessTime1 / 1000) * 1000;
|
accessTime1 = (accessTime1 / 1000) * 1000;
|
||||||
long accessTime2 = sftpFs.getFileStatus(file).getAccessTime();
|
long accessTime2 = sftpFs.getFileStatus(file).getAccessTime();
|
||||||
assertEquals(accessTime1, accessTime2);
|
assertEquals(accessTime1, accessTime2);
|
||||||
assertThat(((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount(),
|
assertThat(
|
||||||
is(1));
|
((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount())
|
||||||
|
.isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -360,8 +369,9 @@ public void testGetModifyTime() throws IOException {
|
|||||||
modifyTime1 = (modifyTime1 / 1000) * 1000;
|
modifyTime1 = (modifyTime1 / 1000) * 1000;
|
||||||
long modifyTime2 = sftpFs.getFileStatus(file).getModificationTime();
|
long modifyTime2 = sftpFs.getFileStatus(file).getModificationTime();
|
||||||
assertEquals(modifyTime1, modifyTime2);
|
assertEquals(modifyTime1, modifyTime2);
|
||||||
assertThat(((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount(),
|
assertThat(
|
||||||
is(1));
|
((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount())
|
||||||
|
.isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -371,17 +381,18 @@ public void testMkDirs() throws IOException {
|
|||||||
sftpFs.mkdirs(path);
|
sftpFs.mkdirs(path);
|
||||||
assertTrue(localFs.exists(path));
|
assertTrue(localFs.exists(path));
|
||||||
assertTrue(localFs.getFileStatus(path).isDirectory());
|
assertTrue(localFs.getFileStatus(path).isDirectory());
|
||||||
assertThat(((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount(),
|
assertThat(
|
||||||
is(1));
|
((SFTPFileSystem) sftpFs).getConnectionPool().getLiveConnCount())
|
||||||
|
.isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCloseFileSystemClosesConnectionPool() throws Exception {
|
public void testCloseFileSystemClosesConnectionPool() throws Exception {
|
||||||
SFTPFileSystem fs = (SFTPFileSystem) sftpFs;
|
SFTPFileSystem fs = (SFTPFileSystem) sftpFs;
|
||||||
fs.getHomeDirectory();
|
fs.getHomeDirectory();
|
||||||
assertThat(fs.getConnectionPool().getLiveConnCount(), is(1));
|
assertThat(fs.getConnectionPool().getLiveConnCount()).isEqualTo(1);
|
||||||
fs.close();
|
fs.close();
|
||||||
assertThat(fs.getConnectionPool().getLiveConnCount(), is(0));
|
assertThat(fs.getConnectionPool().getLiveConnCount()).isEqualTo(0);
|
||||||
///making sure that re-entrant close calls are safe
|
///making sure that re-entrant close calls are safe
|
||||||
fs.close();
|
fs.close();
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,18 @@
|
|||||||
|
|
||||||
package org.apache.hadoop.fs.shell;
|
package org.apache.hadoop.fs.shell;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@code PrintableString} class.
|
* Test {@code PrintableString} class.
|
||||||
*/
|
*/
|
||||||
public class TestPrintableString {
|
public class TestPrintableString {
|
||||||
|
|
||||||
private void expect(String reason, String raw, String expected) {
|
private void expect(String reason, String raw, String expected) {
|
||||||
assertThat(reason, new PrintableString(raw).toString(), is(expected));
|
assertThat(new PrintableString(raw).toString()).as(reason)
|
||||||
|
.isEqualTo(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.hadoop.fs.shell.PathData;
|
import org.apache.hadoop.fs.shell.PathData;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
@ -33,7 +34,7 @@
|
|||||||
public class TestAnd {
|
public class TestAnd {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(10000);
|
public Timeout globalTimeout = new Timeout(10000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
// test all expressions passing
|
// test all expressions passing
|
||||||
@Test
|
@Test
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.hadoop.fs.shell.PathData;
|
import org.apache.hadoop.fs.shell.PathData;
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ public class TestFilterExpression {
|
|||||||
private FilterExpression test;
|
private FilterExpression test;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(10000);
|
public Timeout globalTimeout = new Timeout(10000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.FileStatus;
|
import org.apache.hadoop.fs.FileStatus;
|
||||||
@ -50,7 +51,7 @@
|
|||||||
public class TestFind {
|
public class TestFind {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout timeout = new Timeout(10000);
|
public Timeout timeout = new Timeout(10000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
private static FileSystem mockFs;
|
private static FileSystem mockFs;
|
||||||
private static Configuration conf;
|
private static Configuration conf;
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
import static org.apache.hadoop.fs.shell.find.TestHelper.*;
|
import static org.apache.hadoop.fs.shell.find.TestHelper.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.apache.hadoop.fs.shell.PathData;
|
import org.apache.hadoop.fs.shell.PathData;
|
||||||
@ -34,7 +35,7 @@ public class TestIname {
|
|||||||
private Name.Iname name;
|
private Name.Iname name;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(10000);
|
public Timeout globalTimeout = new Timeout(10000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void resetMock() throws IOException {
|
public void resetMock() throws IOException {
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
import static org.apache.hadoop.fs.shell.find.TestHelper.*;
|
import static org.apache.hadoop.fs.shell.find.TestHelper.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.apache.hadoop.fs.shell.PathData;
|
import org.apache.hadoop.fs.shell.PathData;
|
||||||
@ -34,7 +35,7 @@ public class TestName {
|
|||||||
private Name name;
|
private Name name;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(10000);
|
public Timeout globalTimeout = new Timeout(10000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void resetMock() throws IOException {
|
public void resetMock() throws IOException {
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
import org.apache.hadoop.fs.shell.PathData;
|
import org.apache.hadoop.fs.shell.PathData;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -36,7 +37,7 @@ public class TestPrint {
|
|||||||
private FileSystem mockFs;
|
private FileSystem mockFs;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(10000);
|
public Timeout globalTimeout = new Timeout(10000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void resetMock() throws IOException {
|
public void resetMock() throws IOException {
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
import org.apache.hadoop.fs.shell.PathData;
|
import org.apache.hadoop.fs.shell.PathData;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -36,7 +37,7 @@ public class TestPrint0 {
|
|||||||
private FileSystem mockFs;
|
private FileSystem mockFs;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(10000);
|
public Timeout globalTimeout = new Timeout(10000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void resetMock() throws IOException {
|
public void resetMock() throws IOException {
|
||||||
|
@ -23,10 +23,12 @@
|
|||||||
import org.junit.rules.Timeout;
|
import org.junit.rules.Timeout;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class TestResult {
|
public class TestResult {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(10000);
|
public Timeout globalTimeout = new Timeout(10000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
// test the PASS value
|
// test the PASS value
|
||||||
@Test
|
@Test
|
||||||
|
@ -60,6 +60,7 @@
|
|||||||
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.test.GenericTestUtils;
|
import org.apache.hadoop.test.GenericTestUtils;
|
||||||
|
import org.assertj.core.api.Assertions;
|
||||||
import org.junit.Assume;
|
import org.junit.Assume;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
@ -74,8 +75,6 @@
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains;
|
import static org.apache.hadoop.test.GenericTestUtils.assertExceptionContains;
|
||||||
import static org.hamcrest.CoreMatchers.containsString;
|
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -486,11 +485,13 @@ void compareBLs(BlockLocation[] viewBL, BlockLocation[] targetBL) {
|
|||||||
Assert.assertEquals(targetBL.length, viewBL.length);
|
Assert.assertEquals(targetBL.length, viewBL.length);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (BlockLocation vbl : viewBL) {
|
for (BlockLocation vbl : viewBL) {
|
||||||
assertThat(vbl.toString(), equalTo(targetBL[i].toString()));
|
Assertions.assertThat(vbl.toString()).isEqualTo(targetBL[i].toString());
|
||||||
assertThat(vbl.getOffset(), equalTo(targetBL[i].getOffset()));
|
Assertions.assertThat(vbl.getOffset())
|
||||||
assertThat(vbl.getLength(), equalTo(targetBL[i].getLength()));
|
.isEqualTo(targetBL[i].getOffset());
|
||||||
|
Assertions.assertThat(vbl.getLength())
|
||||||
|
.isEqualTo(targetBL[i].getLength());
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1025,7 +1026,7 @@ public void testConfLinkSlash() throws Exception {
|
|||||||
if (e instanceof UnsupportedFileSystemException) {
|
if (e instanceof UnsupportedFileSystemException) {
|
||||||
String msg = " Use " + Constants.CONFIG_VIEWFS_LINK_MERGE_SLASH +
|
String msg = " Use " + Constants.CONFIG_VIEWFS_LINK_MERGE_SLASH +
|
||||||
" instead";
|
" instead";
|
||||||
assertThat(e.getMessage(), containsString(msg));
|
GenericTestUtils.assertExceptionContains(msg, e);
|
||||||
} else {
|
} else {
|
||||||
fail("Unexpected exception: " + e.getMessage());
|
fail("Unexpected exception: " + e.getMessage());
|
||||||
}
|
}
|
||||||
@ -1262,8 +1263,7 @@ public void testLinkTarget() throws Exception {
|
|||||||
fail("Resolving link target for a ViewFs mount link should fail!");
|
fail("Resolving link target for a ViewFs mount link should fail!");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.info("Expected exception: " + e);
|
LOG.info("Expected exception: " + e);
|
||||||
assertThat(e.getMessage(),
|
GenericTestUtils.assertExceptionContains("not a symbolic link", e);
|
||||||
containsString("not a symbolic link"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -1272,8 +1272,7 @@ public void testLinkTarget() throws Exception {
|
|||||||
fail("Resolving link target for a non sym link should fail!");
|
fail("Resolving link target for a non sym link should fail!");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.info("Expected exception: " + e);
|
LOG.info("Expected exception: " + e);
|
||||||
assertThat(e.getMessage(),
|
GenericTestUtils.assertExceptionContains("not a symbolic link", e);
|
||||||
containsString("not a symbolic link"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -1281,8 +1280,7 @@ public void testLinkTarget() throws Exception {
|
|||||||
fail("Resolving link target for a non existing link should fail!");
|
fail("Resolving link target for a non existing link should fail!");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.info("Expected exception: " + e);
|
LOG.info("Expected exception: " + e);
|
||||||
assertThat(e.getMessage(),
|
GenericTestUtils.assertExceptionContains("File does not exist:", e);
|
||||||
containsString("File does not exist:"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import org.apache.hadoop.HadoopIllegalArgumentException;
|
import org.apache.hadoop.HadoopIllegalArgumentException;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
@ -56,7 +57,7 @@ public class TestZKFailoverController extends ClientBaseWithFixes {
|
|||||||
* Set the timeout for every test
|
* Set the timeout for every test
|
||||||
*/
|
*/
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout testTimeout = new Timeout(3 * 60 * 1000);
|
public Timeout testTimeout = new Timeout(3, TimeUnit.MINUTES);
|
||||||
|
|
||||||
// Set up ZK digest-based credentials for the purposes of the tests,
|
// Set up ZK digest-based credentials for the purposes of the tests,
|
||||||
// to make sure all of our functionality works with auth and ACLs
|
// to make sure all of our functionality works with auth and ACLs
|
||||||
|
@ -38,9 +38,7 @@
|
|||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -81,9 +79,6 @@ public class TestHttpServer extends HttpServerFunctionalTest {
|
|||||||
private static HttpServer2 server;
|
private static HttpServer2 server;
|
||||||
private static final int MAX_THREADS = 10;
|
private static final int MAX_THREADS = 10;
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public static class EchoMapServlet extends HttpServlet {
|
public static class EchoMapServlet extends HttpServlet {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@ -368,11 +363,11 @@ private HttpURLConnection getHttpURLConnection(HttpServer2 httpServer)
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHttpResonseInvalidValueType() throws Exception {
|
public void testHttpResonseInvalidValueType() {
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
boolean xFrameEnabled = true;
|
boolean xFrameEnabled = true;
|
||||||
exception.expect(IllegalArgumentException.class);
|
assertThrows(IllegalArgumentException.class, () ->
|
||||||
createServer(xFrameEnabled, "Hadoop", conf);
|
createServer(xFrameEnabled, "Hadoop", conf));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,8 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.io.compress;
|
package org.apache.hadoop.io.compress;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@ -48,7 +47,7 @@ public void setUp() throws IOException {
|
|||||||
@Test
|
@Test
|
||||||
public void testReadOneByte() throws IOException {
|
public void testReadOneByte() throws IOException {
|
||||||
for (int i = 0; i < TEST_STRING.length(); ++i) {
|
for (int i = 0; i < TEST_STRING.length(); ++i) {
|
||||||
assertThat(decompressorStream.read(), is((int) TEST_STRING.charAt(i)));
|
assertThat(decompressorStream.read()).isEqualTo(TEST_STRING.charAt(i));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
int ret = decompressorStream.read();
|
int ret = decompressorStream.read();
|
||||||
@ -68,8 +67,8 @@ public void testReadBuffer() throws IOException {
|
|||||||
int n = Math.min(bytesToRead, buf.length);
|
int n = Math.min(bytesToRead, buf.length);
|
||||||
int bytesRead = decompressorStream.read(buf, 0, n);
|
int bytesRead = decompressorStream.read(buf, 0, n);
|
||||||
assertTrue(bytesRead > 0 && bytesRead <= n);
|
assertTrue(bytesRead > 0 && bytesRead <= n);
|
||||||
assertThat(new String(buf, 0, bytesRead),
|
assertThat(new String(buf, 0, bytesRead))
|
||||||
is(TEST_STRING.substring(i, i + bytesRead)));
|
.isEqualTo(TEST_STRING.substring(i, i + bytesRead));
|
||||||
bytesToRead = bytesToRead - bytesRead;
|
bytesToRead = bytesToRead - bytesRead;
|
||||||
i = i + bytesRead;
|
i = i + bytesRead;
|
||||||
}
|
}
|
||||||
@ -83,12 +82,12 @@ public void testReadBuffer() throws IOException {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSkip() throws IOException {
|
public void testSkip() throws IOException {
|
||||||
assertThat(decompressorStream.skip(12), is(12L));
|
assertThat(decompressorStream.skip(12)).isEqualTo(12L);
|
||||||
assertThat(decompressorStream.read(), is((int)TEST_STRING.charAt(12)));
|
assertThat(decompressorStream.read()).isEqualTo(TEST_STRING.charAt(12));
|
||||||
assertThat(decompressorStream.read(), is((int)TEST_STRING.charAt(13)));
|
assertThat(decompressorStream.read()).isEqualTo(TEST_STRING.charAt(13));
|
||||||
assertThat(decompressorStream.read(), is((int)TEST_STRING.charAt(14)));
|
assertThat(decompressorStream.read()).isEqualTo(TEST_STRING.charAt(14));
|
||||||
assertThat(decompressorStream.skip(10), is(10L));
|
assertThat(decompressorStream.skip(10)).isEqualTo(10L);
|
||||||
assertThat(decompressorStream.read(), is((int)TEST_STRING.charAt(25)));
|
assertThat(decompressorStream.read()).isEqualTo(TEST_STRING.charAt(25));
|
||||||
try {
|
try {
|
||||||
long ret = decompressorStream.skip(1000);
|
long ret = decompressorStream.skip(1000);
|
||||||
fail("Not reachable but got ret " + ret);
|
fail("Not reachable but got ret " + ret);
|
||||||
|
@ -27,11 +27,12 @@
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class TestECSchema {
|
public class TestECSchema {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(300000);
|
public Timeout globalTimeout = new Timeout(300000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGoodSchema() {
|
public void testGoodSchema() {
|
||||||
|
@ -25,12 +25,14 @@
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.Timeout;
|
import org.junit.rules.Timeout;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Reed-Solomon encoding and decoding.
|
* Test Reed-Solomon encoding and decoding.
|
||||||
*/
|
*/
|
||||||
public class TestRSErasureCoder extends TestErasureCoderBase {
|
public class TestRSErasureCoder extends TestErasureCoderBase {
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(300000);
|
public Timeout globalTimeout = new Timeout(300000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
|
@ -22,13 +22,15 @@
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.Timeout;
|
import org.junit.rules.Timeout;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test XOR encoding and decoding.
|
* Test XOR encoding and decoding.
|
||||||
*/
|
*/
|
||||||
public class TestXORCoder extends TestErasureCoderBase {
|
public class TestXORCoder extends TestErasureCoderBase {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(300000);
|
public Timeout globalTimeout = new Timeout(300000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
|
@ -27,16 +27,16 @@
|
|||||||
import org.junit.rules.Timeout;
|
import org.junit.rules.Timeout;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.hamcrest.core.Is.is;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the behavior of the default retry policy.
|
* Test the behavior of the default retry policy.
|
||||||
*/
|
*/
|
||||||
public class TestDefaultRetryPolicy {
|
public class TestDefaultRetryPolicy {
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout timeout = new Timeout(30000);
|
public Timeout timeout = new Timeout(30000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
/** Verify FAIL < RETRY < FAILOVER_AND_RETRY. */
|
/** Verify FAIL < RETRY < FAILOVER_AND_RETRY. */
|
||||||
@Test
|
@Test
|
||||||
@ -65,8 +65,8 @@ public void testWithRetriable() throws Exception {
|
|||||||
null);
|
null);
|
||||||
RetryPolicy.RetryAction action = policy.shouldRetry(
|
RetryPolicy.RetryAction action = policy.shouldRetry(
|
||||||
new RetriableException("Dummy exception"), 0, 0, true);
|
new RetriableException("Dummy exception"), 0, 0, true);
|
||||||
assertThat(action.action,
|
assertThat(action.action)
|
||||||
is(RetryPolicy.RetryAction.RetryDecision.RETRY));
|
.isEqualTo(RetryPolicy.RetryAction.RetryDecision.RETRY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,8 +87,8 @@ public void testWithWrappedRetriable() throws Exception {
|
|||||||
RetryPolicy.RetryAction action = policy.shouldRetry(
|
RetryPolicy.RetryAction action = policy.shouldRetry(
|
||||||
new RemoteException(RetriableException.class.getName(),
|
new RemoteException(RetriableException.class.getName(),
|
||||||
"Dummy exception"), 0, 0, true);
|
"Dummy exception"), 0, 0, true);
|
||||||
assertThat(action.action,
|
assertThat(action.action)
|
||||||
is(RetryPolicy.RetryAction.RetryDecision.RETRY));
|
.isEqualTo(RetryPolicy.RetryAction.RetryDecision.RETRY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,7 +107,7 @@ public void testWithRetriableAndRetryDisabled() throws Exception {
|
|||||||
null);
|
null);
|
||||||
RetryPolicy.RetryAction action = policy.shouldRetry(
|
RetryPolicy.RetryAction action = policy.shouldRetry(
|
||||||
new RetriableException("Dummy exception"), 0, 0, true);
|
new RetriableException("Dummy exception"), 0, 0, true);
|
||||||
assertThat(action.action,
|
assertThat(action.action).isEqualTo(
|
||||||
is(RetryPolicy.RetryAction.RetryDecision.FAIL));
|
RetryPolicy.RetryAction.RetryDecision.FAIL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.apache.hadoop.metrics2.source.JvmMetricsInfo.*;
|
import static org.apache.hadoop.metrics2.source.JvmMetricsInfo.*;
|
||||||
import static org.apache.hadoop.metrics2.impl.MsInfo.*;
|
import static org.apache.hadoop.metrics2.impl.MsInfo.*;
|
||||||
@ -47,7 +48,7 @@
|
|||||||
public class TestJvmMetrics {
|
public class TestJvmMetrics {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout timeout = new Timeout(30000);
|
public Timeout timeout = new Timeout(30000, TimeUnit.MILLISECONDS);
|
||||||
private JvmPauseMonitor pauseMonitor;
|
private JvmPauseMonitor pauseMonitor;
|
||||||
private GcTimeMonitor gcTimeMonitor;
|
private GcTimeMonitor gcTimeMonitor;
|
||||||
|
|
||||||
|
@ -30,13 +30,12 @@
|
|||||||
|
|
||||||
import org.apache.hadoop.util.Time;
|
import org.apache.hadoop.util.Time;
|
||||||
|
|
||||||
|
import org.assertj.core.api.Assertions;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
|
import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
|
||||||
import static org.hamcrest.CoreMatchers.not;
|
|
||||||
import static org.hamcrest.core.Is.is;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,7 +103,7 @@ private InetAddress getLocalIPAddr() throws UnknownHostException {
|
|||||||
@Test
|
@Test
|
||||||
public void testNullInterface() throws Exception {
|
public void testNullInterface() throws Exception {
|
||||||
String host = DNS.getDefaultHost(null); // should work.
|
String host = DNS.getDefaultHost(null); // should work.
|
||||||
assertThat(host, is(DNS.getDefaultHost(DEFAULT)));
|
Assertions.assertThat(host).isEqualTo(DNS.getDefaultHost(DEFAULT));
|
||||||
try {
|
try {
|
||||||
String ip = DNS.getDefaultIP(null);
|
String ip = DNS.getDefaultIP(null);
|
||||||
fail("Expected a NullPointerException, got " + ip);
|
fail("Expected a NullPointerException, got " + ip);
|
||||||
@ -120,7 +119,8 @@ public void testNullInterface() throws Exception {
|
|||||||
@Test
|
@Test
|
||||||
public void testNullDnsServer() throws Exception {
|
public void testNullDnsServer() throws Exception {
|
||||||
String host = DNS.getDefaultHost(getLoopbackInterface(), null);
|
String host = DNS.getDefaultHost(getLoopbackInterface(), null);
|
||||||
assertThat(host, is(DNS.getDefaultHost(getLoopbackInterface())));
|
Assertions.assertThat(host)
|
||||||
|
.isEqualTo(DNS.getDefaultHost(getLoopbackInterface()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -130,7 +130,8 @@ public void testNullDnsServer() throws Exception {
|
|||||||
@Test
|
@Test
|
||||||
public void testDefaultDnsServer() throws Exception {
|
public void testDefaultDnsServer() throws Exception {
|
||||||
String host = DNS.getDefaultHost(getLoopbackInterface(), DEFAULT);
|
String host = DNS.getDefaultHost(getLoopbackInterface(), DEFAULT);
|
||||||
assertThat(host, is(DNS.getDefaultHost(getLoopbackInterface())));
|
Assertions.assertThat(host)
|
||||||
|
.isEqualTo(DNS.getDefaultHost(getLoopbackInterface()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -204,7 +205,7 @@ public void testLookupWithHostsFallback() throws Exception {
|
|||||||
getLoopbackInterface(), INVALID_DNS_SERVER, true);
|
getLoopbackInterface(), INVALID_DNS_SERVER, true);
|
||||||
|
|
||||||
// Expect to get back something other than the cached host name.
|
// Expect to get back something other than the cached host name.
|
||||||
assertThat(hostname, not(DUMMY_HOSTNAME));
|
Assertions.assertThat(hostname).isNotEqualTo(DUMMY_HOSTNAME);
|
||||||
} finally {
|
} finally {
|
||||||
// Restore DNS#cachedHostname for subsequent tests.
|
// Restore DNS#cachedHostname for subsequent tests.
|
||||||
changeDnsCachedHostname(oldHostname);
|
changeDnsCachedHostname(oldHostname);
|
||||||
@ -227,7 +228,7 @@ public void testLookupWithoutHostsFallback() throws Exception {
|
|||||||
|
|
||||||
// Expect to get back the cached host name since there was no hosts
|
// Expect to get back the cached host name since there was no hosts
|
||||||
// file lookup.
|
// file lookup.
|
||||||
assertThat(hostname, is(DUMMY_HOSTNAME));
|
Assertions.assertThat(hostname).isEqualTo(DUMMY_HOSTNAME);
|
||||||
} finally {
|
} finally {
|
||||||
// Restore DNS#cachedHostname for subsequent tests.
|
// Restore DNS#cachedHostname for subsequent tests.
|
||||||
changeDnsCachedHostname(oldHostname);
|
changeDnsCachedHostname(oldHostname);
|
||||||
|
@ -20,15 +20,14 @@
|
|||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertThrows;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class mainly test the MockDomainNameResolver comes working as expected.
|
* This class mainly test the MockDomainNameResolver comes working as expected.
|
||||||
@ -37,9 +36,6 @@ public class TestMockDomainNameResolver {
|
|||||||
|
|
||||||
private Configuration conf;
|
private Configuration conf;
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
conf = new Configuration();
|
conf = new Configuration();
|
||||||
@ -60,12 +56,10 @@ public void testMockDomainNameResolverCanBeCreated() throws IOException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMockDomainNameResolverCanNotBeCreated()
|
public void testMockDomainNameResolverCanNotBeCreated() {
|
||||||
throws UnknownHostException {
|
|
||||||
DomainNameResolver resolver = DomainNameResolverFactory.newInstance(
|
DomainNameResolver resolver = DomainNameResolverFactory.newInstance(
|
||||||
conf, CommonConfigurationKeys.HADOOP_DOMAINNAME_RESOLVER_IMPL);
|
conf, CommonConfigurationKeys.HADOOP_DOMAINNAME_RESOLVER_IMPL);
|
||||||
exception.expect(UnknownHostException.class);
|
assertThrows(UnknownHostException.class, () ->
|
||||||
resolver.getAllByDomainName(
|
resolver.getAllByDomainName(MockDomainNameResolver.UNKNOW_DOMAIN));
|
||||||
MockDomainNameResolver.UNKNOW_DOMAIN);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION;
|
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION;
|
||||||
import static org.apache.hadoop.security.KDiag.*;
|
import static org.apache.hadoop.security.KDiag.*;
|
||||||
@ -52,7 +53,7 @@ public class TestKDiag extends Assert {
|
|||||||
public TestName methodName = new TestName();
|
public TestName methodName = new TestName();
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout testTimeout = new Timeout(30000);
|
public Timeout testTimeout = new Timeout(30000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void nameThread() {
|
public static void nameThread() {
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_TOKEN_FILES;
|
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_TOKEN_FILES;
|
||||||
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION;
|
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION;
|
||||||
@ -58,7 +59,7 @@ public class TestKDiagNoKDC extends Assert {
|
|||||||
public TestName methodName = new TestName();
|
public TestName methodName = new TestName();
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout testTimeout = new Timeout(30000);
|
public Timeout testTimeout = new Timeout(30000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void nameThread() {
|
public static void nameThread() {
|
||||||
|
@ -36,13 +36,13 @@
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.rules.TestName;
|
import org.junit.rules.TestName;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertThrows;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class TestCredentialProviderFactory {
|
public class TestCredentialProviderFactory {
|
||||||
@ -52,9 +52,6 @@ public class TestCredentialProviderFactory {
|
|||||||
@Rule
|
@Rule
|
||||||
public final TestName test = new TestName();
|
public final TestName test = new TestName();
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void announce() {
|
public void announce() {
|
||||||
LOG.info("Running test " + test.getMethodName());
|
LOG.info("Running test " + test.getMethodName());
|
||||||
@ -250,18 +247,15 @@ public void testLocalJksProvider() throws Exception {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocalBCFKSProvider() throws Exception {
|
public void testLocalBCFKSProvider() {
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
final Path ksPath = new Path(tmpDir.toString(), "test.bcfks");
|
final Path ksPath = new Path(tmpDir.toString(), "test.bcfks");
|
||||||
final String ourUrl = LocalBouncyCastleFipsKeyStoreProvider.SCHEME_NAME +
|
final String ourUrl = LocalBouncyCastleFipsKeyStoreProvider.SCHEME_NAME +
|
||||||
"://file" + ksPath.toUri();
|
"://file" + ksPath.toUri();
|
||||||
conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, ourUrl);
|
conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH, ourUrl);
|
||||||
|
Exception exception = assertThrows(IOException.class,
|
||||||
exception.expect(IOException.class);
|
() -> CredentialProviderFactory.getProviders(conf));
|
||||||
exception.expectMessage("Can't create keystore");
|
assertEquals("Can't create keystore", exception.getMessage());
|
||||||
List<CredentialProvider> providers =
|
|
||||||
CredentialProviderFactory.getProviders(conf);
|
|
||||||
assertTrue("BCFKS needs additional JDK setup", providers.isEmpty());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkPermissionRetention(Configuration conf, String ourUrl,
|
public void checkPermissionRetention(Configuration conf, String ourUrl,
|
||||||
@ -290,4 +284,3 @@ public void checkPermissionRetention(Configuration conf, String ourUrl,
|
|||||||
"keystore.", "rwxrwxrwx", s.getPermission().toString());
|
"keystore.", "rwxrwxrwx", s.getPermission().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
import org.junit.rules.Timeout;
|
import org.junit.rules.Timeout;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for @DefaultImpersonationProvider
|
* Test class for @DefaultImpersonationProvider
|
||||||
*/
|
*/
|
||||||
@ -43,7 +45,7 @@ public class TestDefaultImpersonationProvider {
|
|||||||
.mock(UserGroupInformation.class);
|
.mock(UserGroupInformation.class);
|
||||||
private Configuration conf;
|
private Configuration conf;
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(10000);
|
public Timeout globalTimeout = new Timeout(10000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import org.apache.curator.RetryPolicy;
|
import org.apache.curator.RetryPolicy;
|
||||||
import org.apache.curator.framework.CuratorFramework;
|
import org.apache.curator.framework.CuratorFramework;
|
||||||
@ -70,7 +71,7 @@ public class TestZKDelegationTokenSecretManager {
|
|||||||
protected TestingServer zkServer;
|
protected TestingServer zkServer;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(300000);
|
public Timeout globalTimeout = new Timeout(300000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class TestDelegationTokenAuthenticationHandlerWithMocks {
|
public class TestDelegationTokenAuthenticationHandlerWithMocks {
|
||||||
|
|
||||||
@ -93,7 +94,7 @@ public AuthenticationToken authenticate(HttpServletRequest request,
|
|||||||
private DelegationTokenAuthenticationHandler handler;
|
private DelegationTokenAuthenticationHandler handler;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout testTimeout = new Timeout(120000);
|
public Timeout testTimeout = new Timeout(120000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
@ -30,8 +30,7 @@
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
import static org.apache.hadoop.test.GenericTestUtils.LogCapturer.captureLogs;
|
import static org.apache.hadoop.test.GenericTestUtils.LogCapturer.captureLogs;
|
||||||
import static org.hamcrest.CoreMatchers.containsString;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@ -56,8 +55,8 @@ public void testStopQuietlyWhenServiceStopThrowsException() throws Exception {
|
|||||||
|
|
||||||
ServiceOperations.stopQuietly(logger, service);
|
ServiceOperations.stopQuietly(logger, service);
|
||||||
|
|
||||||
assertThat(logCapturer.getOutput(),
|
assertThat(logCapturer.getOutput())
|
||||||
containsString("When stopping the service " + service.getName()));
|
.contains("When stopping the service " + service.getName());
|
||||||
verify(e, times(1)).printStackTrace(Mockito.any(PrintWriter.class));
|
verify(e, times(1)).printStackTrace(Mockito.any(PrintWriter.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class AbstractServiceLauncherTestBase extends Assert implements
|
public class AbstractServiceLauncherTestBase extends Assert implements
|
||||||
LauncherExitCodes {
|
LauncherExitCodes {
|
||||||
@ -57,7 +58,7 @@ public class AbstractServiceLauncherTestBase extends Assert implements
|
|||||||
* All tests have a short life.
|
* All tests have a short life.
|
||||||
*/
|
*/
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout testTimeout = new Timeout(15000);
|
public Timeout testTimeout = new Timeout(15000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rule to provide the method name.
|
* Rule to provide the method name.
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.test;
|
package org.apache.hadoop.test;
|
||||||
|
|
||||||
import org.junit.internal.AssumptionViolatedException;
|
import org.junit.AssumptionViolatedException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JUnit assumptions for the environment (OS).
|
* JUnit assumptions for the environment (OS).
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
import org.junit.rules.TestRule;
|
import org.junit.rules.TestRule;
|
||||||
import org.junit.rules.Timeout;
|
import org.junit.rules.Timeout;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for test units to extend in order that their individual tests will
|
* Class for test units to extend in order that their individual tests will
|
||||||
* be timed out and fail automatically should they run more than 10 seconds.
|
* be timed out and fail automatically should they run more than 10 seconds.
|
||||||
@ -30,5 +32,6 @@
|
|||||||
public class UnitTestcaseTimeLimit {
|
public class UnitTestcaseTimeLimit {
|
||||||
public final int timeOutSecs = 10;
|
public final int timeOutSecs = 10;
|
||||||
|
|
||||||
@Rule public TestRule globalTimeout = new Timeout(timeOutSecs * 1000);
|
@Rule public TestRule globalTimeout =
|
||||||
|
new Timeout(timeOutSecs, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.hadoop.test.LambdaTestUtils;
|
import org.apache.hadoop.test.LambdaTestUtils;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@ -35,7 +36,7 @@
|
|||||||
*/
|
*/
|
||||||
public class TestCrcComposer {
|
public class TestCrcComposer {
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(10000);
|
public Timeout globalTimeout = new Timeout(10000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
private Random rand = new Random(1234);
|
private Random rand = new Random(1234);
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.hadoop.test.LambdaTestUtils;
|
import org.apache.hadoop.test.LambdaTestUtils;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
@ -32,7 +33,7 @@
|
|||||||
*/
|
*/
|
||||||
public class TestCrcUtil {
|
public class TestCrcUtil {
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout globalTimeout = new Timeout(10000);
|
public Timeout globalTimeout = new Timeout(10000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
private Random rand = new Random(1234);
|
private Random rand = new Random(1234);
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.attribute.PosixFilePermission;
|
import java.nio.file.attribute.PosixFilePermission;
|
||||||
import java.nio.file.attribute.PosixFilePermissions;
|
import java.nio.file.attribute.PosixFilePermissions;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@ -44,8 +45,8 @@
|
|||||||
*/
|
*/
|
||||||
public final class TestDiskCheckerWithDiskIo {
|
public final class TestDiskCheckerWithDiskIo {
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout testTimeout = new Timeout(30_000);
|
public Timeout testTimeout = new Timeout(30_000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify DiskChecker ignores at least 2 transient file creation errors.
|
* Verify DiskChecker ignores at least 2 transient file creation errors.
|
||||||
*/
|
*/
|
||||||
|
@ -28,9 +28,7 @@
|
|||||||
import org.apache.hadoop.fs.ChecksumException;
|
import org.apache.hadoop.fs.ChecksumException;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
@ -51,9 +49,6 @@ public class TestNativeCrc32 {
|
|||||||
private ByteBuffer data, checksums;
|
private ByteBuffer data, checksums;
|
||||||
private DataChecksum checksum;
|
private DataChecksum checksum;
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
@Parameters
|
@Parameters
|
||||||
public static Collection<Object[]> data() {
|
public static Collection<Object[]> data() {
|
||||||
Collection<Object[]> params = new ArrayList<Object[]>(2);
|
Collection<Object[]> params = new ArrayList<Object[]>(2);
|
||||||
@ -88,12 +83,12 @@ public void testVerifyChunkedSumsSuccess() throws ChecksumException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVerifyChunkedSumsFail() throws ChecksumException {
|
public void testVerifyChunkedSumsFail() {
|
||||||
allocateDirectByteBuffers();
|
allocateDirectByteBuffers();
|
||||||
fillDataAndInvalidChecksums();
|
fillDataAndInvalidChecksums();
|
||||||
exception.expect(ChecksumException.class);
|
assertThrows(ChecksumException.class,
|
||||||
NativeCrc32.verifyChunkedSums(bytesPerChecksum, checksumType.id,
|
() -> NativeCrc32.verifyChunkedSums(bytesPerChecksum, checksumType.id,
|
||||||
checksums, data, fileName, BASE_POSITION);
|
checksums, data, fileName, BASE_POSITION));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -122,13 +117,14 @@ public void testVerifyChunkedSumsByteArraySuccess() throws ChecksumException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVerifyChunkedSumsByteArrayFail() throws ChecksumException {
|
public void testVerifyChunkedSumsByteArrayFail() {
|
||||||
allocateArrayByteBuffers();
|
allocateArrayByteBuffers();
|
||||||
fillDataAndInvalidChecksums();
|
fillDataAndInvalidChecksums();
|
||||||
exception.expect(ChecksumException.class);
|
assertThrows(ChecksumException.class,
|
||||||
NativeCrc32.verifyChunkedSumsByteArray(bytesPerChecksum, checksumType.id,
|
() -> NativeCrc32.verifyChunkedSumsByteArray(bytesPerChecksum,
|
||||||
checksums.array(), checksums.position(), data.array(), data.position(),
|
checksumType.id, checksums.array(), checksums.position(),
|
||||||
data.remaining(), fileName, BASE_POSITION);
|
data.array(), data.position(), data.remaining(), fileName,
|
||||||
|
BASE_POSITION));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -177,13 +173,13 @@ public void testNativeVerifyChunkedSumsSuccess() throws ChecksumException {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void testNativeVerifyChunkedSumsFail() throws ChecksumException {
|
public void testNativeVerifyChunkedSumsFail() {
|
||||||
allocateDirectByteBuffers();
|
allocateDirectByteBuffers();
|
||||||
fillDataAndInvalidChecksums();
|
fillDataAndInvalidChecksums();
|
||||||
exception.expect(ChecksumException.class);
|
assertThrows(ChecksumException.class,
|
||||||
NativeCrc32.nativeVerifyChunkedSums(bytesPerChecksum, checksumType.id,
|
() -> NativeCrc32.nativeVerifyChunkedSums(bytesPerChecksum,
|
||||||
checksums, checksums.position(), data, data.position(), data.remaining(),
|
checksumType.id, checksums, checksums.position(), data,
|
||||||
fileName, BASE_POSITION);
|
data.position(), data.remaining(), fileName, BASE_POSITION));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,11 +25,11 @@
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.containsString;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.apache.hadoop.test.GenericTestUtils;
|
import org.apache.hadoop.test.GenericTestUtils;
|
||||||
import org.apache.hadoop.test.GenericTestUtils.LogCapturer;
|
import org.apache.hadoop.test.GenericTestUtils.LogCapturer;
|
||||||
|
import org.assertj.core.api.Assertions;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -165,8 +165,8 @@ public void testLogThreadInfo() throws Exception {
|
|||||||
final String title = "title";
|
final String title = "title";
|
||||||
ReflectionUtils.logThreadInfo(logger, title, 0L);
|
ReflectionUtils.logThreadInfo(logger, title, 0L);
|
||||||
|
|
||||||
assertThat(logCapturer.getOutput(),
|
Assertions.assertThat(logCapturer.getOutput())
|
||||||
containsString("Process Thread Dump: " + title));
|
.contains("Process Thread Dump: " + title);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.util;
|
package org.apache.hadoop.util;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.hadoop.security.alias.AbstractJavaKeyStoreProvider;
|
import org.apache.hadoop.security.alias.AbstractJavaKeyStoreProvider;
|
||||||
@ -53,7 +54,7 @@ public class TestShell extends Assert {
|
|||||||
* Set the timeout for every test
|
* Set the timeout for every test
|
||||||
*/
|
*/
|
||||||
@Rule
|
@Rule
|
||||||
public Timeout testTimeout = new Timeout(30000);
|
public Timeout testTimeout = new Timeout(30000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TestName methodName = new TestName();
|
public TestName methodName = new TestName();
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
import static org.apache.hadoop.test.PlatformAssumptions.assumeWindows;
|
import static org.apache.hadoop.test.PlatformAssumptions.assumeWindows;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.matchers.JUnitMatchers.containsString;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@ -31,14 +30,13 @@
|
|||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.hadoop.fs.FileUtil;
|
import org.apache.hadoop.fs.FileUtil;
|
||||||
import org.apache.hadoop.test.GenericTestUtils;
|
import org.apache.hadoop.test.GenericTestUtils;
|
||||||
|
import org.assertj.core.api.Assertions;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test cases for helper Windows winutils.exe utility.
|
* Test cases for helper Windows winutils.exe utility.
|
||||||
*/
|
*/
|
||||||
@ -496,12 +494,12 @@ public void testReadLink() throws IOException {
|
|||||||
String readLinkOutput = Shell.execCommand(winutils,
|
String readLinkOutput = Shell.execCommand(winutils,
|
||||||
"readlink",
|
"readlink",
|
||||||
dirLink.toString());
|
dirLink.toString());
|
||||||
assertThat(readLinkOutput, equalTo(dir1.toString()));
|
Assertions.assertThat(readLinkOutput).isEqualTo(dir1.toString());
|
||||||
|
|
||||||
readLinkOutput = Shell.execCommand(winutils,
|
readLinkOutput = Shell.execCommand(winutils,
|
||||||
"readlink",
|
"readlink",
|
||||||
fileLink.toString());
|
fileLink.toString());
|
||||||
assertThat(readLinkOutput, equalTo(file1.toString()));
|
Assertions.assertThat(readLinkOutput).isEqualTo(file1.toString());
|
||||||
|
|
||||||
// Try a few invalid inputs and verify we get an ExitCodeException for each.
|
// Try a few invalid inputs and verify we get an ExitCodeException for each.
|
||||||
//
|
//
|
||||||
@ -511,7 +509,7 @@ public void testReadLink() throws IOException {
|
|||||||
Shell.execCommand(winutils, "readlink", "");
|
Shell.execCommand(winutils, "readlink", "");
|
||||||
fail("Failed to get Shell.ExitCodeException when reading bad symlink");
|
fail("Failed to get Shell.ExitCodeException when reading bad symlink");
|
||||||
} catch (Shell.ExitCodeException ece) {
|
} catch (Shell.ExitCodeException ece) {
|
||||||
assertThat(ece.getExitCode(), is(1));
|
Assertions.assertThat(ece.getExitCode()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -520,7 +518,7 @@ public void testReadLink() throws IOException {
|
|||||||
Shell.execCommand(winutils, "readlink", "ThereIsNoSuchLink");
|
Shell.execCommand(winutils, "readlink", "ThereIsNoSuchLink");
|
||||||
fail("Failed to get Shell.ExitCodeException when reading bad symlink");
|
fail("Failed to get Shell.ExitCodeException when reading bad symlink");
|
||||||
} catch (Shell.ExitCodeException ece) {
|
} catch (Shell.ExitCodeException ece) {
|
||||||
assertThat(ece.getExitCode(), is(1));
|
Assertions.assertThat(ece.getExitCode()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -529,7 +527,7 @@ public void testReadLink() throws IOException {
|
|||||||
Shell.execCommand(winutils, "readlink", dir1.toString());
|
Shell.execCommand(winutils, "readlink", dir1.toString());
|
||||||
fail("Failed to get Shell.ExitCodeException when reading bad symlink");
|
fail("Failed to get Shell.ExitCodeException when reading bad symlink");
|
||||||
} catch (Shell.ExitCodeException ece) {
|
} catch (Shell.ExitCodeException ece) {
|
||||||
assertThat(ece.getExitCode(), is(1));
|
Assertions.assertThat(ece.getExitCode()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -538,7 +536,7 @@ public void testReadLink() throws IOException {
|
|||||||
Shell.execCommand(winutils, "readlink", file1.toString());
|
Shell.execCommand(winutils, "readlink", file1.toString());
|
||||||
fail("Failed to get Shell.ExitCodeException when reading bad symlink");
|
fail("Failed to get Shell.ExitCodeException when reading bad symlink");
|
||||||
} catch (Shell.ExitCodeException ece) {
|
} catch (Shell.ExitCodeException ece) {
|
||||||
assertThat(ece.getExitCode(), is(1));
|
Assertions.assertThat(ece.getExitCode()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -547,11 +545,10 @@ public void testReadLink() throws IOException {
|
|||||||
Shell.execCommand(winutils, "readlink", "a", "b");
|
Shell.execCommand(winutils, "readlink", "a", "b");
|
||||||
fail("Failed to get Shell.ExitCodeException with bad parameters");
|
fail("Failed to get Shell.ExitCodeException with bad parameters");
|
||||||
} catch (Shell.ExitCodeException ece) {
|
} catch (Shell.ExitCodeException ece) {
|
||||||
assertThat(ece.getExitCode(), is(1));
|
Assertions.assertThat(ece.getExitCode()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Test(timeout=10000)
|
@Test(timeout=10000)
|
||||||
public void testTaskCreate() throws IOException {
|
public void testTaskCreate() throws IOException {
|
||||||
requireWinutils();
|
requireWinutils();
|
||||||
@ -570,8 +567,8 @@ public void testTaskCreate() throws IOException {
|
|||||||
assertTrue(proof.exists());
|
assertTrue(proof.exists());
|
||||||
|
|
||||||
String outNumber = FileUtils.readFileToString(proof);
|
String outNumber = FileUtils.readFileToString(proof);
|
||||||
|
|
||||||
assertThat(outNumber, containsString(testNumber));
|
Assertions.assertThat(outNumber).contains(testNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test (timeout = 30000)
|
@Test (timeout = 30000)
|
||||||
@ -604,7 +601,7 @@ public void testTaskCreateWithLimits() throws IOException {
|
|||||||
+ jobId, "java -Xmx256m -version");
|
+ jobId, "java -Xmx256m -version");
|
||||||
fail("Failed to get Shell.ExitCodeException with insufficient memory");
|
fail("Failed to get Shell.ExitCodeException with insufficient memory");
|
||||||
} catch (Shell.ExitCodeException ece) {
|
} catch (Shell.ExitCodeException ece) {
|
||||||
assertThat(ece.getExitCode(), is(1));
|
Assertions.assertThat(ece.getExitCode()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run tasks with wrong parameters
|
// Run tasks with wrong parameters
|
||||||
@ -615,7 +612,7 @@ public void testTaskCreateWithLimits() throws IOException {
|
|||||||
"-1", "foo", "job" + jobId, "cmd /c echo job" + jobId);
|
"-1", "foo", "job" + jobId, "cmd /c echo job" + jobId);
|
||||||
fail("Failed to get Shell.ExitCodeException with bad parameters");
|
fail("Failed to get Shell.ExitCodeException with bad parameters");
|
||||||
} catch (Shell.ExitCodeException ece) {
|
} catch (Shell.ExitCodeException ece) {
|
||||||
assertThat(ece.getExitCode(), is(1639));
|
Assertions.assertThat(ece.getExitCode()).isEqualTo(1639);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -624,7 +621,7 @@ public void testTaskCreateWithLimits() throws IOException {
|
|||||||
"job" + jobId, "cmd /c echo job" + jobId);
|
"job" + jobId, "cmd /c echo job" + jobId);
|
||||||
fail("Failed to get Shell.ExitCodeException with bad parameters");
|
fail("Failed to get Shell.ExitCodeException with bad parameters");
|
||||||
} catch (Shell.ExitCodeException ece) {
|
} catch (Shell.ExitCodeException ece) {
|
||||||
assertThat(ece.getExitCode(), is(1639));
|
Assertions.assertThat(ece.getExitCode()).isEqualTo(1639);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -633,7 +630,7 @@ public void testTaskCreateWithLimits() throws IOException {
|
|||||||
"job" + jobId, "cmd /c echo job" + jobId);
|
"job" + jobId, "cmd /c echo job" + jobId);
|
||||||
fail("Failed to get Shell.ExitCodeException with bad parameters");
|
fail("Failed to get Shell.ExitCodeException with bad parameters");
|
||||||
} catch (Shell.ExitCodeException ece) {
|
} catch (Shell.ExitCodeException ece) {
|
||||||
assertThat(ece.getExitCode(), is(1639));
|
Assertions.assertThat(ece.getExitCode()).isEqualTo(1639);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user