HADOOP-16510. [hadoop-common] Fix order of actual and expected expression in assert statements. Contributed by Adam Antal
This commit is contained in:
parent
e6137d0e50
commit
8c9173c87c
@ -2437,7 +2437,7 @@ public class TestConfiguration {
|
|||||||
}
|
}
|
||||||
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.");
|
||||||
assertEquals(prefixedProps.size(), 10);
|
assertThat(prefixedProps.size(), is(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));
|
||||||
}
|
}
|
||||||
@ -2448,7 +2448,7 @@ public class TestConfiguration {
|
|||||||
conf.set("subprefix." + "subname" + i, "value_${foo}" + i);
|
conf.set("subprefix." + "subname" + i, "value_${foo}" + i);
|
||||||
}
|
}
|
||||||
prefixedProps = conf.getPropsWithPrefix("subprefix.");
|
prefixedProps = conf.getPropsWithPrefix("subprefix.");
|
||||||
assertEquals(prefixedProps.size(), 10);
|
assertThat(prefixedProps.size(), is(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));
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,8 @@ import org.junit.Test;
|
|||||||
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 abstract class CryptoStreamsTestBase {
|
public abstract class CryptoStreamsTestBase {
|
||||||
protected static final Logger LOG = LoggerFactory.getLogger(
|
protected static final Logger LOG = LoggerFactory.getLogger(
|
||||||
CryptoStreamsTestBase.class);
|
CryptoStreamsTestBase.class);
|
||||||
@ -198,7 +200,7 @@ public abstract class CryptoStreamsTestBase {
|
|||||||
|
|
||||||
// EOF
|
// EOF
|
||||||
n = in.read(result, 0, dataLen);
|
n = in.read(result, 0, dataLen);
|
||||||
Assert.assertEquals(n, -1);
|
assertThat(n).isEqualTo(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test crypto writing with different buffer size. */
|
/** Test crypto writing with different buffer size. */
|
||||||
@ -612,7 +614,7 @@ public abstract class CryptoStreamsTestBase {
|
|||||||
|
|
||||||
// Skip after EOF
|
// Skip after EOF
|
||||||
skipped = in.skip(3);
|
skipped = in.skip(3);
|
||||||
Assert.assertEquals(skipped, 0);
|
assertThat(skipped).isZero();
|
||||||
|
|
||||||
in.close();
|
in.close();
|
||||||
}
|
}
|
||||||
@ -844,7 +846,7 @@ public abstract class CryptoStreamsTestBase {
|
|||||||
((Seekable) in).seek(dataLen);
|
((Seekable) in).seek(dataLen);
|
||||||
buf.clear();
|
buf.clear();
|
||||||
n = ((ByteBufferReadable) in).read(buf);
|
n = ((ByteBufferReadable) in).read(buf);
|
||||||
Assert.assertEquals(n, -1);
|
assertThat(n).isEqualTo(-1);
|
||||||
|
|
||||||
in.close();
|
in.close();
|
||||||
}
|
}
|
||||||
|
@ -19,20 +19,21 @@ package org.apache.hadoop.crypto;
|
|||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class TestCryptoStreamsWithJceAesCtrCryptoCodec extends
|
public class TestCryptoStreamsWithJceAesCtrCryptoCodec extends
|
||||||
TestCryptoStreams {
|
TestCryptoStreams {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void init() throws Exception {
|
public static void init() {
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
conf.set(
|
conf.set(
|
||||||
CommonConfigurationKeysPublic.HADOOP_SECURITY_CRYPTO_CODEC_CLASSES_AES_CTR_NOPADDING_KEY,
|
CommonConfigurationKeysPublic.HADOOP_SECURITY_CRYPTO_CODEC_CLASSES_AES_CTR_NOPADDING_KEY,
|
||||||
JceAesCtrCryptoCodec.class.getName());
|
JceAesCtrCryptoCodec.class.getName());
|
||||||
codec = CryptoCodec.getInstance(conf);
|
codec = CryptoCodec.getInstance(conf);
|
||||||
Assert.assertEquals(JceAesCtrCryptoCodec.class.getCanonicalName(),
|
assertThat(JceAesCtrCryptoCodec.class.getCanonicalName())
|
||||||
codec.getClass().getCanonicalName());
|
.isEqualTo(codec.getClass().getCanonicalName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,7 @@ import java.util.concurrent.CompletableFuture;
|
|||||||
import static org.apache.hadoop.fs.Options.ChecksumOpt;
|
import static org.apache.hadoop.fs.Options.ChecksumOpt;
|
||||||
import static org.apache.hadoop.fs.Options.CreateOpts;
|
import static org.apache.hadoop.fs.Options.CreateOpts;
|
||||||
import static org.apache.hadoop.fs.Options.Rename;
|
import static org.apache.hadoop.fs.Options.Rename;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class TestHarFileSystem {
|
public class TestHarFileSystem {
|
||||||
@ -279,13 +278,8 @@ public class TestHarFileSystem {
|
|||||||
@Test
|
@Test
|
||||||
public void testFileChecksum() throws Exception {
|
public void testFileChecksum() throws Exception {
|
||||||
final Path p = new Path("har://file-localhost/foo.har/file1");
|
final Path p = new Path("har://file-localhost/foo.har/file1");
|
||||||
final HarFileSystem harfs = new HarFileSystem();
|
try (HarFileSystem harfs = new HarFileSystem()) {
|
||||||
try {
|
assertThat(harfs.getFileChecksum(p)).isNull();
|
||||||
Assert.assertEquals(null, harfs.getFileChecksum(p));
|
|
||||||
} finally {
|
|
||||||
if (harfs != null) {
|
|
||||||
harfs.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,30 +293,30 @@ public class TestHarFileSystem {
|
|||||||
// case 1: range starts before current har block and ends after
|
// case 1: range starts before current har block and ends after
|
||||||
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
||||||
HarFileSystem.fixBlockLocations(b, 0, 20, 5);
|
HarFileSystem.fixBlockLocations(b, 0, 20, 5);
|
||||||
assertEquals(b[0].getOffset(), 5);
|
assertThat(b[0].getOffset()).isEqualTo(5);
|
||||||
assertEquals(b[0].getLength(), 10);
|
assertThat(b[0].getLength()).isEqualTo(10);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// case 2: range starts in current har block and ends after
|
// case 2: range starts in current har block and ends after
|
||||||
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
||||||
HarFileSystem.fixBlockLocations(b, 0, 20, 15);
|
HarFileSystem.fixBlockLocations(b, 0, 20, 15);
|
||||||
assertEquals(b[0].getOffset(), 0);
|
assertThat(b[0].getOffset()).isZero();
|
||||||
assertEquals(b[0].getLength(), 5);
|
assertThat(b[0].getLength()).isEqualTo(5);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// case 3: range starts before current har block and ends in
|
// case 3: range starts before current har block and ends in
|
||||||
// current har block
|
// current har block
|
||||||
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
||||||
HarFileSystem.fixBlockLocations(b, 0, 10, 5);
|
HarFileSystem.fixBlockLocations(b, 0, 10, 5);
|
||||||
assertEquals(b[0].getOffset(), 5);
|
assertThat(b[0].getOffset()).isEqualTo(5);
|
||||||
assertEquals(b[0].getLength(), 5);
|
assertThat(b[0].getLength()).isEqualTo(5);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// case 4: range starts and ends in current har block
|
// case 4: range starts and ends in current har block
|
||||||
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
||||||
HarFileSystem.fixBlockLocations(b, 0, 6, 12);
|
HarFileSystem.fixBlockLocations(b, 0, 6, 12);
|
||||||
assertEquals(b[0].getOffset(), 0);
|
assertThat(b[0].getOffset()).isZero();
|
||||||
assertEquals(b[0].getLength(), 6);
|
assertThat(b[0].getLength()).isEqualTo(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
// now try a range where start == 3
|
// now try a range where start == 3
|
||||||
@ -330,30 +324,30 @@ public class TestHarFileSystem {
|
|||||||
// case 5: range starts before current har block and ends after
|
// case 5: range starts before current har block and ends after
|
||||||
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
||||||
HarFileSystem.fixBlockLocations(b, 3, 20, 5);
|
HarFileSystem.fixBlockLocations(b, 3, 20, 5);
|
||||||
assertEquals(b[0].getOffset(), 5);
|
assertThat(b[0].getOffset()).isEqualTo(5);
|
||||||
assertEquals(b[0].getLength(), 10);
|
assertThat(b[0].getLength()).isEqualTo(10);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// case 6: range starts in current har block and ends after
|
// case 6: range starts in current har block and ends after
|
||||||
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
||||||
HarFileSystem.fixBlockLocations(b, 3, 20, 15);
|
HarFileSystem.fixBlockLocations(b, 3, 20, 15);
|
||||||
assertEquals(b[0].getOffset(), 3);
|
assertThat(b[0].getOffset()).isEqualTo(3);
|
||||||
assertEquals(b[0].getLength(), 2);
|
assertThat(b[0].getLength()).isEqualTo(2);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// case 7: range starts before current har block and ends in
|
// case 7: range starts before current har block and ends in
|
||||||
// current har block
|
// current har block
|
||||||
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
||||||
HarFileSystem.fixBlockLocations(b, 3, 7, 5);
|
HarFileSystem.fixBlockLocations(b, 3, 7, 5);
|
||||||
assertEquals(b[0].getOffset(), 5);
|
assertThat(b[0].getOffset()).isEqualTo(5);
|
||||||
assertEquals(b[0].getLength(), 5);
|
assertThat(b[0].getLength()).isEqualTo(5);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
// case 8: range starts and ends in current har block
|
// case 8: range starts and ends in current har block
|
||||||
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
BlockLocation[] b = { new BlockLocation(null, null, 10, 10) };
|
||||||
HarFileSystem.fixBlockLocations(b, 3, 3, 12);
|
HarFileSystem.fixBlockLocations(b, 3, 3, 12);
|
||||||
assertEquals(b[0].getOffset(), 3);
|
assertThat(b[0].getOffset()).isEqualTo(3);
|
||||||
assertEquals(b[0].getLength(), 3);
|
assertThat(b[0].getLength()).isEqualTo(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// test case from JIRA MAPREDUCE-1752
|
// test case from JIRA MAPREDUCE-1752
|
||||||
@ -361,10 +355,10 @@ public class TestHarFileSystem {
|
|||||||
BlockLocation[] b = { new BlockLocation(null, null, 512, 512),
|
BlockLocation[] b = { new BlockLocation(null, null, 512, 512),
|
||||||
new BlockLocation(null, null, 1024, 512) };
|
new BlockLocation(null, null, 1024, 512) };
|
||||||
HarFileSystem.fixBlockLocations(b, 0, 512, 896);
|
HarFileSystem.fixBlockLocations(b, 0, 512, 896);
|
||||||
assertEquals(b[0].getOffset(), 0);
|
assertThat(b[0].getOffset()).isZero();
|
||||||
assertEquals(b[0].getLength(), 128);
|
assertThat(b[0].getLength()).isEqualTo(128);
|
||||||
assertEquals(b[1].getOffset(), 128);
|
assertThat(b[1].getOffset()).isEqualTo(128);
|
||||||
assertEquals(b[1].getLength(), 384);
|
assertThat(b[1].getLength()).isEqualTo(384);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,7 +390,9 @@ public class TestHarFileSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertTrue((errors + " methods were not overridden correctly - see log"),
|
assertThat(errors)
|
||||||
errors <= 0);
|
.withFailMessage(errors +
|
||||||
|
" methods were not overridden correctly - see log")
|
||||||
|
.isLessThanOrEqualTo(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,11 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
|
import static org.apache.hadoop.test.PlatformAssumptions.assumeNotWindows;
|
||||||
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.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
@ -56,6 +60,7 @@ import org.junit.rules.Timeout;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class tests the local file system via the FileSystem abstraction.
|
* This class tests the local file system via the FileSystem abstraction.
|
||||||
@ -692,27 +697,33 @@ public class TestLocalFileSystem {
|
|||||||
FSDataOutputStreamBuilder builder =
|
FSDataOutputStreamBuilder builder =
|
||||||
fileSys.createFile(path);
|
fileSys.createFile(path);
|
||||||
try (FSDataOutputStream stream = builder.build()) {
|
try (FSDataOutputStream stream = builder.build()) {
|
||||||
Assert.assertEquals("Should be default block size",
|
assertThat(builder.getBlockSize())
|
||||||
builder.getBlockSize(), fileSys.getDefaultBlockSize());
|
.withFailMessage("Should be default block size")
|
||||||
Assert.assertEquals("Should be default replication factor",
|
.isEqualTo(fileSys.getDefaultBlockSize());
|
||||||
builder.getReplication(), fileSys.getDefaultReplication());
|
assertThat(builder.getReplication())
|
||||||
Assert.assertEquals("Should be default buffer size",
|
.withFailMessage("Should be default replication factor")
|
||||||
builder.getBufferSize(),
|
.isEqualTo(fileSys.getDefaultReplication());
|
||||||
fileSys.getConf().getInt(IO_FILE_BUFFER_SIZE_KEY,
|
assertThat(builder.getBufferSize())
|
||||||
|
.withFailMessage("Should be default buffer size")
|
||||||
|
.isEqualTo(fileSys.getConf().getInt(IO_FILE_BUFFER_SIZE_KEY,
|
||||||
IO_FILE_BUFFER_SIZE_DEFAULT));
|
IO_FILE_BUFFER_SIZE_DEFAULT));
|
||||||
Assert.assertEquals("Should be default permission",
|
assertThat(builder.getPermission())
|
||||||
builder.getPermission(), FsPermission.getFileDefault());
|
.withFailMessage("Should be default permission")
|
||||||
|
.isEqualTo(FsPermission.getFileDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test set 0 to replication, block size and buffer size
|
// Test set 0 to replication, block size and buffer size
|
||||||
builder = fileSys.createFile(path);
|
builder = fileSys.createFile(path);
|
||||||
builder.bufferSize(0).blockSize(0).replication((short) 0);
|
builder.bufferSize(0).blockSize(0).replication((short) 0);
|
||||||
Assert.assertEquals("Block size should be 0",
|
assertThat(builder.getBlockSize())
|
||||||
builder.getBlockSize(), 0);
|
.withFailMessage("Block size should be 0")
|
||||||
Assert.assertEquals("Replication factor should be 0",
|
.isZero();
|
||||||
builder.getReplication(), 0);
|
assertThat(builder.getReplication())
|
||||||
Assert.assertEquals("Buffer size should be 0",
|
.withFailMessage("Replication factor should be 0")
|
||||||
builder.getBufferSize(), 0);
|
.isZero();
|
||||||
|
assertThat(builder.getBufferSize())
|
||||||
|
.withFailMessage("Buffer size should be 0")
|
||||||
|
.isZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,9 +69,9 @@ 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.containsString;
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* A collection of tests for the {@link ViewFileSystem}.
|
* A collection of tests for the {@link ViewFileSystem}.
|
||||||
@ -477,9 +477,9 @@ abstract public class ViewFileSystemBaseTest {
|
|||||||
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) {
|
||||||
Assert.assertEquals(vbl.toString(), targetBL[i].toString());
|
assertThat(vbl.toString(), equalTo(targetBL[i].toString()));
|
||||||
Assert.assertEquals(targetBL[i].getOffset(), vbl.getOffset());
|
assertThat(vbl.getOffset(), equalTo(targetBL[i].getOffset()));
|
||||||
Assert.assertEquals(targetBL[i].getLength(), vbl.getLength());
|
assertThat(vbl.getLength(), equalTo(targetBL[i].getLength()));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.fs.viewfs;
|
package org.apache.hadoop.fs.viewfs;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.apache.hadoop.fs.FileContextTestHelper.checkFileLinkStatus;
|
import static org.apache.hadoop.fs.FileContextTestHelper.checkFileLinkStatus;
|
||||||
import static org.apache.hadoop.fs.FileContextTestHelper.checkFileStatus;
|
import static org.apache.hadoop.fs.FileContextTestHelper.checkFileStatus;
|
||||||
import static org.apache.hadoop.fs.FileContextTestHelper.exists;
|
import static org.apache.hadoop.fs.FileContextTestHelper.exists;
|
||||||
@ -459,9 +460,9 @@ abstract public class ViewFsBaseTest {
|
|||||||
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) {
|
||||||
Assert.assertEquals(vbl.toString(), targetBL[i].toString());
|
assertThat(vbl.toString()).isEqualTo(targetBL[i].toString());
|
||||||
Assert.assertEquals(targetBL[i].getOffset(), vbl.getOffset());
|
assertThat(vbl.getOffset()).isEqualTo(targetBL[i].getOffset());
|
||||||
Assert.assertEquals(targetBL[i].getLength(), vbl.getLength());
|
assertThat(vbl.getLength()).isEqualTo(targetBL[i].getLength());
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,9 @@ import org.junit.Test;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
@ -146,15 +146,16 @@ public class TestArrayFile {
|
|||||||
|
|
||||||
for (int i = 0; i < SIZE; i++) {
|
for (int i = 0; i < SIZE; i++) {
|
||||||
nextWritable = (LongWritable)reader.next(nextWritable);
|
nextWritable = (LongWritable)reader.next(nextWritable);
|
||||||
assertEquals(nextWritable.get(), i);
|
assertThat(nextWritable.get()).isEqualTo(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue("testArrayFileIteration seek error !!!",
|
assertTrue("testArrayFileIteration seek error !!!",
|
||||||
reader.seek(new LongWritable(6)));
|
reader.seek(new LongWritable(6)));
|
||||||
nextWritable = (LongWritable) reader.next(nextWritable);
|
nextWritable = (LongWritable) reader.next(nextWritable);
|
||||||
assertTrue("testArrayFileIteration error !!!", reader.key() == 7);
|
assertThat(reader.key()).withFailMessage(
|
||||||
assertTrue("testArrayFileIteration error !!!",
|
"testArrayFileIteration error !!!").isEqualTo(7);
|
||||||
nextWritable.equals(new LongWritable(7)));
|
assertThat(nextWritable).withFailMessage(
|
||||||
|
"testArrayFileIteration error !!!").isEqualTo(new LongWritable(7));
|
||||||
assertFalse("testArrayFileIteration error !!!",
|
assertFalse("testArrayFileIteration error !!!",
|
||||||
reader.seek(new LongWritable(SIZE + 5)));
|
reader.seek(new LongWritable(SIZE + 5)));
|
||||||
reader.close();
|
reader.close();
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
|
|
||||||
package org.apache.hadoop.io;
|
package org.apache.hadoop.io;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
@ -31,6 +29,8 @@ import org.apache.hadoop.io.SequenceFile.CompressionType;
|
|||||||
import org.apache.hadoop.test.GenericTestUtils;
|
import org.apache.hadoop.test.GenericTestUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/** Tests sync based seek reads/write intervals inside SequenceFiles. */
|
/** Tests sync based seek reads/write intervals inside SequenceFiles. */
|
||||||
public class TestSequenceFileSync {
|
public class TestSequenceFileSync {
|
||||||
private static final int NUMRECORDS = 2000;
|
private static final int NUMRECORDS = 2000;
|
||||||
@ -46,12 +46,10 @@ public class TestSequenceFileSync {
|
|||||||
val.clear();
|
val.clear();
|
||||||
reader.sync(off);
|
reader.sync(off);
|
||||||
reader.next(key, val);
|
reader.next(key, val);
|
||||||
assertEquals(key.get(), expectedRecord);
|
assertThat(key.get()).isEqualTo(expectedRecord);
|
||||||
final String test = String.format(REC_FMT, expectedRecord, expectedRecord);
|
final String test = String.format(REC_FMT, expectedRecord, expectedRecord);
|
||||||
assertEquals(
|
assertThat(val.find(test, 0)).withFailMessage(
|
||||||
"Invalid value in iter " + iter + ": " + val,
|
"Invalid value in iter " + iter + ": " + val).isZero();
|
||||||
0,
|
|
||||||
val.find(test, 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -124,7 +122,7 @@ public class TestSequenceFileSync {
|
|||||||
SequenceFile.Writer.syncInterval(20*100)
|
SequenceFile.Writer.syncInterval(20*100)
|
||||||
);
|
);
|
||||||
// Ensure the custom sync interval value is set
|
// Ensure the custom sync interval value is set
|
||||||
assertEquals(writer.syncInterval, 20*100);
|
assertThat(writer.syncInterval).isEqualTo(20*100);
|
||||||
try {
|
try {
|
||||||
writeSequenceFile(writer, NUMRECORDS);
|
writeSequenceFile(writer, NUMRECORDS);
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
|
@ -26,6 +26,8 @@ import java.util.Random;
|
|||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.primitives.Bytes;
|
import com.google.common.primitives.Bytes;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
@ -232,10 +234,10 @@ public class TestText {
|
|||||||
@Test
|
@Test
|
||||||
public void testFind() throws Exception {
|
public void testFind() throws Exception {
|
||||||
Text text = new Text("abcd\u20acbdcd\u20ac");
|
Text text = new Text("abcd\u20acbdcd\u20ac");
|
||||||
assertTrue(text.find("abd")==-1);
|
assertThat(text.find("abd")).isEqualTo(-1);
|
||||||
assertTrue(text.find("ac") ==-1);
|
assertThat(text.find("ac")).isEqualTo(-1);
|
||||||
assertTrue(text.find("\u20ac") == 4);
|
assertThat(text.find("\u20ac")).isEqualTo(4);
|
||||||
assertTrue(text.find("\u20ac", 5)==11);
|
assertThat(text.find("\u20ac", 5)).isEqualTo(11);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -20,7 +20,6 @@ package org.apache.hadoop.io.file.tfile;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.FSDataOutputStream;
|
import org.apache.hadoop.fs.FSDataOutputStream;
|
||||||
@ -33,6 +32,9 @@ import org.apache.hadoop.test.GenericTestUtils;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public class TestTFileUnsortedByteArrays {
|
public class TestTFileUnsortedByteArrays {
|
||||||
private static String ROOT = GenericTestUtils.getTestDir().getAbsolutePath();
|
private static String ROOT = GenericTestUtils.getTestDir().getAbsolutePath();
|
||||||
|
|
||||||
@ -84,46 +86,36 @@ public class TestTFileUnsortedByteArrays {
|
|||||||
// we still can scan records in an unsorted TFile
|
// we still can scan records in an unsorted TFile
|
||||||
@Test
|
@Test
|
||||||
public void testFailureScannerWithKeys() throws IOException {
|
public void testFailureScannerWithKeys() throws IOException {
|
||||||
Reader reader =
|
try (Reader reader =
|
||||||
new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf);
|
new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf)) {
|
||||||
Assert.assertFalse(reader.isSorted());
|
assertThat(reader.isSorted()).isFalse();
|
||||||
Assert.assertEquals((int) reader.getEntryCount(), 4);
|
assertThat(reader.getEntryCount()).isEqualTo(4);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Scanner scanner =
|
|
||||||
reader.createScannerByKey("aaa".getBytes(), "zzz".getBytes());
|
reader.createScannerByKey("aaa".getBytes(), "zzz".getBytes());
|
||||||
Assert
|
fail("Failed to catch creating scanner with keys on unsorted file.");
|
||||||
.fail("Failed to catch creating scanner with keys on unsorted file.");
|
} catch (RuntimeException expected) {
|
||||||
}
|
}
|
||||||
catch (RuntimeException e) {
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
reader.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we still can scan records in an unsorted TFile
|
// we still can scan records in an unsorted TFile
|
||||||
@Test
|
@Test
|
||||||
public void testScan() throws IOException {
|
public void testScan() throws IOException {
|
||||||
Reader reader =
|
try (Reader reader =
|
||||||
new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf);
|
new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf)) {
|
||||||
Assert.assertFalse(reader.isSorted());
|
assertThat(reader.isSorted()).isFalse();
|
||||||
Assert.assertEquals((int) reader.getEntryCount(), 4);
|
assertThat(reader.getEntryCount()).isEqualTo(4);
|
||||||
|
try (Scanner scanner = reader.createScanner()) {
|
||||||
Scanner scanner = reader.createScanner();
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
// read key and value
|
// read key and value
|
||||||
byte[] kbuf = new byte[BUF_SIZE];
|
byte[] kbuf = new byte[BUF_SIZE];
|
||||||
int klen = scanner.entry().getKeyLength();
|
int klen = scanner.entry().getKeyLength();
|
||||||
scanner.entry().getKey(kbuf);
|
scanner.entry().getKey(kbuf);
|
||||||
Assert.assertEquals(new String(kbuf, 0, klen), "keyZ");
|
assertThat(new String(kbuf, 0, klen)).isEqualTo("keyZ");
|
||||||
|
|
||||||
byte[] vbuf = new byte[BUF_SIZE];
|
byte[] vbuf = new byte[BUF_SIZE];
|
||||||
int vlen = scanner.entry().getValueLength();
|
int vlen = scanner.entry().getValueLength();
|
||||||
scanner.entry().getValue(vbuf);
|
scanner.entry().getValue(vbuf);
|
||||||
Assert.assertEquals(new String(vbuf, 0, vlen), "valueZ");
|
assertThat(new String(vbuf, 0, vlen)).isEqualTo("valueZ");
|
||||||
|
|
||||||
scanner.advance();
|
scanner.advance();
|
||||||
|
|
||||||
@ -131,41 +123,36 @@ public class TestTFileUnsortedByteArrays {
|
|||||||
vbuf = new byte[BUF_SIZE];
|
vbuf = new byte[BUF_SIZE];
|
||||||
vlen = scanner.entry().getValueLength();
|
vlen = scanner.entry().getValueLength();
|
||||||
scanner.entry().getValue(vbuf);
|
scanner.entry().getValue(vbuf);
|
||||||
Assert.assertEquals(new String(vbuf, 0, vlen), "valueM");
|
assertThat(new String(vbuf, 0, vlen)).isEqualTo("valueM");
|
||||||
|
|
||||||
kbuf = new byte[BUF_SIZE];
|
kbuf = new byte[BUF_SIZE];
|
||||||
klen = scanner.entry().getKeyLength();
|
klen = scanner.entry().getKeyLength();
|
||||||
scanner.entry().getKey(kbuf);
|
scanner.entry().getKey(kbuf);
|
||||||
Assert.assertEquals(new String(kbuf, 0, klen), "keyM");
|
assertThat(new String(kbuf, 0, klen)).isEqualTo("keyM");
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
scanner.close();
|
|
||||||
reader.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we still can scan records in an unsorted TFile
|
// we still can scan records in an unsorted TFile
|
||||||
@Test
|
@Test
|
||||||
public void testScanRange() throws IOException {
|
public void testScanRange() throws IOException {
|
||||||
Reader reader =
|
try (Reader reader =
|
||||||
new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf);
|
new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf)) {
|
||||||
Assert.assertFalse(reader.isSorted());
|
assertThat(reader.isSorted()).isFalse();
|
||||||
Assert.assertEquals((int) reader.getEntryCount(), 4);
|
assertThat(reader.getEntryCount()).isEqualTo(4);
|
||||||
|
|
||||||
Scanner scanner = reader.createScanner();
|
try (Scanner scanner = reader.createScanner()) {
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
// read key and value
|
// read key and value
|
||||||
byte[] kbuf = new byte[BUF_SIZE];
|
byte[] kbuf = new byte[BUF_SIZE];
|
||||||
int klen = scanner.entry().getKeyLength();
|
int klen = scanner.entry().getKeyLength();
|
||||||
scanner.entry().getKey(kbuf);
|
scanner.entry().getKey(kbuf);
|
||||||
Assert.assertEquals(new String(kbuf, 0, klen), "keyZ");
|
assertThat(new String(kbuf, 0, klen)).isEqualTo("keyZ");
|
||||||
|
|
||||||
byte[] vbuf = new byte[BUF_SIZE];
|
byte[] vbuf = new byte[BUF_SIZE];
|
||||||
int vlen = scanner.entry().getValueLength();
|
int vlen = scanner.entry().getValueLength();
|
||||||
scanner.entry().getValue(vbuf);
|
scanner.entry().getValue(vbuf);
|
||||||
Assert.assertEquals(new String(vbuf, 0, vlen), "valueZ");
|
assertThat(new String(vbuf, 0, vlen)).isEqualTo("valueZ");
|
||||||
|
|
||||||
scanner.advance();
|
scanner.advance();
|
||||||
|
|
||||||
@ -173,62 +160,44 @@ public class TestTFileUnsortedByteArrays {
|
|||||||
vbuf = new byte[BUF_SIZE];
|
vbuf = new byte[BUF_SIZE];
|
||||||
vlen = scanner.entry().getValueLength();
|
vlen = scanner.entry().getValueLength();
|
||||||
scanner.entry().getValue(vbuf);
|
scanner.entry().getValue(vbuf);
|
||||||
Assert.assertEquals(new String(vbuf, 0, vlen), "valueM");
|
assertThat(new String(vbuf, 0, vlen)).isEqualTo("valueM");
|
||||||
|
|
||||||
kbuf = new byte[BUF_SIZE];
|
kbuf = new byte[BUF_SIZE];
|
||||||
klen = scanner.entry().getKeyLength();
|
klen = scanner.entry().getKeyLength();
|
||||||
scanner.entry().getKey(kbuf);
|
scanner.entry().getKey(kbuf);
|
||||||
Assert.assertEquals(new String(kbuf, 0, klen), "keyM");
|
assertThat(new String(kbuf, 0, klen)).isEqualTo("keyM");
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
scanner.close();
|
|
||||||
reader.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailureSeek() throws IOException {
|
public void testFailureSeek() throws IOException {
|
||||||
Reader reader =
|
try (Reader reader = new Reader(fs.open(path),
|
||||||
new Reader(fs.open(path), fs.getFileStatus(path).getLen(), conf);
|
fs.getFileStatus(path).getLen(), conf);
|
||||||
Scanner scanner = reader.createScanner();
|
Scanner scanner = reader.createScanner()) {
|
||||||
|
|
||||||
try {
|
|
||||||
// can't find ceil
|
// can't find ceil
|
||||||
try {
|
try {
|
||||||
scanner.lowerBound("keyN".getBytes());
|
scanner.lowerBound("keyN".getBytes());
|
||||||
Assert.fail("Cannot search in a unsorted TFile!");
|
fail("Cannot search in a unsorted TFile!");
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception expected) {
|
||||||
// noop, expecting excetions
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// can't find higher
|
// can't find higher
|
||||||
try {
|
try {
|
||||||
scanner.upperBound("keyA".getBytes());
|
scanner.upperBound("keyA".getBytes());
|
||||||
Assert.fail("Cannot search higher in a unsorted TFile!");
|
fail("Cannot search higher in a unsorted TFile!");
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception expected) {
|
||||||
// noop, expecting excetions
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// can't seek
|
// can't seek
|
||||||
try {
|
try {
|
||||||
scanner.seekTo("keyM".getBytes());
|
scanner.seekTo("keyM".getBytes());
|
||||||
Assert.fail("Cannot search a unsorted TFile!");
|
fail("Cannot search a unsorted TFile!");
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception expected) {
|
||||||
// noop, expecting excetions
|
|
||||||
}
|
}
|
||||||
finally {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
scanner.close();
|
|
||||||
reader.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ import org.apache.hadoop.test.GenericTestUtils;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class TestVLong {
|
public class TestVLong {
|
||||||
private static String ROOT = GenericTestUtils.getTestDir().getAbsolutePath();
|
private static String ROOT = GenericTestUtils.getTestDir().getAbsolutePath();
|
||||||
private Configuration conf;
|
private Configuration conf;
|
||||||
@ -70,8 +72,7 @@ public class TestVLong {
|
|||||||
|
|
||||||
FSDataInputStream in = fs.open(path);
|
FSDataInputStream in = fs.open(path);
|
||||||
for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; ++i) {
|
for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; ++i) {
|
||||||
long n = Utils.readVLong(in);
|
assertThat(Utils.readVLong(in)).isEqualTo(i);
|
||||||
Assert.assertEquals(n, i);
|
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
fs.delete(path, false);
|
fs.delete(path, false);
|
||||||
@ -85,8 +86,7 @@ public class TestVLong {
|
|||||||
out.close();
|
out.close();
|
||||||
FSDataInputStream in = fs.open(path);
|
FSDataInputStream in = fs.open(path);
|
||||||
for (int i = Short.MIN_VALUE; i <= Short.MAX_VALUE; ++i) {
|
for (int i = Short.MIN_VALUE; i <= Short.MAX_VALUE; ++i) {
|
||||||
long n = Utils.readVLong(in);
|
assertThat(Utils.readVLong(in)).isEqualTo(((long) i) << shift);
|
||||||
Assert.assertEquals(n, ((long) i) << shift);
|
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
long ret = fs.getFileStatus(path).getLen();
|
long ret = fs.getFileStatus(path).getLen();
|
||||||
@ -165,7 +165,7 @@ public class TestVLong {
|
|||||||
|
|
||||||
FSDataInputStream in = fs.open(path);
|
FSDataInputStream in = fs.open(path);
|
||||||
for (int i = 0; i < data.length; ++i) {
|
for (int i = 0; i < data.length; ++i) {
|
||||||
Assert.assertEquals(Utils.readVLong(in), data[i]);
|
assertThat(Utils.readVLong(in)).isEqualTo(data[i]);
|
||||||
}
|
}
|
||||||
in.close();
|
in.close();
|
||||||
fs.delete(path, false);
|
fs.delete(path, false);
|
||||||
|
@ -31,7 +31,13 @@ import static org.mockito.Mockito.times;
|
|||||||
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
import org.apache.hadoop.fs.CommonConfigurationKeys;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
@ -50,6 +56,8 @@ import org.apache.hadoop.conf.Configuration;
|
|||||||
import org.apache.hadoop.ipc.CallQueueManager.CallQueueOverflowException;
|
import org.apache.hadoop.ipc.CallQueueManager.CallQueueOverflowException;
|
||||||
import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcResponseHeaderProto.RpcStatusProto;
|
import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcResponseHeaderProto.RpcStatusProto;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class TestFairCallQueue {
|
public class TestFairCallQueue {
|
||||||
private FairCallQueue<Schedulable> fcq;
|
private FairCallQueue<Schedulable> fcq;
|
||||||
|
|
||||||
@ -85,17 +93,17 @@ public class TestFairCallQueue {
|
|||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
FairCallQueue<Schedulable> fairCallQueue;
|
FairCallQueue<Schedulable> fairCallQueue;
|
||||||
fairCallQueue = new FairCallQueue<Schedulable>(1, 1000, "ns", conf);
|
fairCallQueue = new FairCallQueue<Schedulable>(1, 1000, "ns", conf);
|
||||||
assertEquals(fairCallQueue.remainingCapacity(), 1000);
|
assertThat(fairCallQueue.remainingCapacity()).isEqualTo(1000);
|
||||||
fairCallQueue = new FairCallQueue<Schedulable>(4, 1000, "ns", conf);
|
fairCallQueue = new FairCallQueue<Schedulable>(4, 1000, "ns", conf);
|
||||||
assertEquals(fairCallQueue.remainingCapacity(), 1000);
|
assertThat(fairCallQueue.remainingCapacity()).isEqualTo(1000);
|
||||||
fairCallQueue = new FairCallQueue<Schedulable>(7, 1000, "ns", conf);
|
fairCallQueue = new FairCallQueue<Schedulable>(7, 1000, "ns", conf);
|
||||||
assertEquals(fairCallQueue.remainingCapacity(), 1000);
|
assertThat(fairCallQueue.remainingCapacity()).isEqualTo(1000);
|
||||||
fairCallQueue = new FairCallQueue<Schedulable>(1, 1025, "ns", conf);
|
fairCallQueue = new FairCallQueue<Schedulable>(1, 1025, "ns", conf);
|
||||||
assertEquals(fairCallQueue.remainingCapacity(), 1025);
|
assertThat(fairCallQueue.remainingCapacity()).isEqualTo(1025);
|
||||||
fairCallQueue = new FairCallQueue<Schedulable>(4, 1025, "ns", conf);
|
fairCallQueue = new FairCallQueue<Schedulable>(4, 1025, "ns", conf);
|
||||||
assertEquals(fairCallQueue.remainingCapacity(), 1025);
|
assertThat(fairCallQueue.remainingCapacity()).isEqualTo(1025);
|
||||||
fairCallQueue = new FairCallQueue<Schedulable>(7, 1025, "ns", conf);
|
fairCallQueue = new FairCallQueue<Schedulable>(7, 1025, "ns", conf);
|
||||||
assertEquals(fairCallQueue.remainingCapacity(), 1025);
|
assertThat(fairCallQueue.remainingCapacity()).isEqualTo(1025);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -24,7 +24,6 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
@ -106,6 +105,8 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.slf4j.event.Level;
|
import org.slf4j.event.Level;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/** Unit tests for IPC. */
|
/** Unit tests for IPC. */
|
||||||
public class TestIPC {
|
public class TestIPC {
|
||||||
public static final Logger LOG = LoggerFactory.getLogger(TestIPC.class);
|
public static final Logger LOG = LoggerFactory.getLogger(TestIPC.class);
|
||||||
@ -1274,7 +1275,7 @@ public class TestIPC {
|
|||||||
retryProxy.dummyRun();
|
retryProxy.dummyRun();
|
||||||
} finally {
|
} finally {
|
||||||
// Check if dummyRun called only once
|
// Check if dummyRun called only once
|
||||||
Assert.assertEquals(handler.invocations, 1);
|
assertThat(handler.invocations).isOne();
|
||||||
Client.setCallIdAndRetryCount(0, 0, null);
|
Client.setCallIdAndRetryCount(0, 0, null);
|
||||||
client.stop();
|
client.stop();
|
||||||
server.stop();
|
server.stop();
|
||||||
@ -1455,7 +1456,7 @@ public class TestIPC {
|
|||||||
@Test
|
@Test
|
||||||
public void testClientGetTimeout() throws IOException {
|
public void testClientGetTimeout() throws IOException {
|
||||||
Configuration config = new Configuration();
|
Configuration config = new Configuration();
|
||||||
assertEquals(Client.getTimeout(config), -1);
|
assertThat(Client.getTimeout(config)).isEqualTo(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout=60000)
|
@Test(timeout=60000)
|
||||||
|
@ -36,7 +36,6 @@ import org.apache.hadoop.metrics2.MetricsRecordBuilder;
|
|||||||
import org.apache.hadoop.net.NetUtils;
|
import org.apache.hadoop.net.NetUtils;
|
||||||
import org.apache.hadoop.test.GenericTestUtils;
|
import org.apache.hadoop.test.GenericTestUtils;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -44,10 +43,10 @@ import java.io.IOException;
|
|||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.apache.hadoop.test.MetricsAsserts.assertCounterGt;
|
import static org.apache.hadoop.test.MetricsAsserts.assertCounterGt;
|
||||||
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
|
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.fail;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for testing protocol buffer based RPC mechanism.
|
* Test for testing protocol buffer based RPC mechanism.
|
||||||
@ -143,19 +142,19 @@ public class TestProtoBufRpc extends TestRpcBase {
|
|||||||
EchoRequestProto echoRequest = EchoRequestProto.newBuilder()
|
EchoRequestProto echoRequest = EchoRequestProto.newBuilder()
|
||||||
.setMessage("hello").build();
|
.setMessage("hello").build();
|
||||||
EchoResponseProto echoResponse = client.echo(null, echoRequest);
|
EchoResponseProto echoResponse = client.echo(null, echoRequest);
|
||||||
Assert.assertEquals(echoResponse.getMessage(), "hello");
|
assertThat(echoResponse.getMessage()).isEqualTo("hello");
|
||||||
|
|
||||||
// Test error method - error should be thrown as RemoteException
|
// Test error method - error should be thrown as RemoteException
|
||||||
try {
|
try {
|
||||||
client.error(null, newEmptyRequest());
|
client.error(null, newEmptyRequest());
|
||||||
Assert.fail("Expected exception is not thrown");
|
fail("Expected exception is not thrown");
|
||||||
} catch (ServiceException e) {
|
} catch (ServiceException e) {
|
||||||
RemoteException re = (RemoteException)e.getCause();
|
RemoteException re = (RemoteException)e.getCause();
|
||||||
RpcServerException rse = (RpcServerException) re
|
RpcServerException rse = (RpcServerException) re
|
||||||
.unwrapRemoteException(RpcServerException.class);
|
.unwrapRemoteException(RpcServerException.class);
|
||||||
Assert.assertNotNull(rse);
|
assertThat(rse).isNotNull();
|
||||||
Assert.assertTrue(re.getErrorCode().equals(
|
assertThat(re.getErrorCode())
|
||||||
RpcErrorCodeProto.ERROR_RPC_SERVER));
|
.isEqualTo(RpcErrorCodeProto.ERROR_RPC_SERVER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +168,7 @@ public class TestProtoBufRpc extends TestRpcBase {
|
|||||||
// Test echo method
|
// Test echo method
|
||||||
EchoResponseProto echoResponse = client.echo2(null,
|
EchoResponseProto echoResponse = client.echo2(null,
|
||||||
newEchoRequest("hello"));
|
newEchoRequest("hello"));
|
||||||
Assert.assertEquals(echoResponse.getMessage(), "hello");
|
assertThat(echoResponse.getMessage()).isEqualTo("hello");
|
||||||
|
|
||||||
// Ensure RPC metrics are updated
|
// Ensure RPC metrics are updated
|
||||||
MetricsRecordBuilder rpcMetrics = getMetrics(server.getRpcMetrics().name());
|
MetricsRecordBuilder rpcMetrics = getMetrics(server.getRpcMetrics().name());
|
||||||
@ -188,13 +187,13 @@ public class TestProtoBufRpc extends TestRpcBase {
|
|||||||
try {
|
try {
|
||||||
client.error2(null, newEmptyRequest());
|
client.error2(null, newEmptyRequest());
|
||||||
} catch (ServiceException se) {
|
} catch (ServiceException se) {
|
||||||
Assert.assertTrue(se.getCause() instanceof RemoteException);
|
assertThat(se.getCause()).isInstanceOf(RemoteException.class);
|
||||||
RemoteException re = (RemoteException) se.getCause();
|
RemoteException re = (RemoteException) se.getCause();
|
||||||
Assert.assertTrue(re.getClassName().equals(
|
assertThat(re.getClassName())
|
||||||
URISyntaxException.class.getName()));
|
.isEqualTo(URISyntaxException.class.getName());
|
||||||
Assert.assertTrue(re.getMessage().contains("testException"));
|
assertThat(re.getMessage()).contains("testException");
|
||||||
Assert.assertTrue(
|
assertThat(re.getErrorCode())
|
||||||
re.getErrorCode().equals(RpcErrorCodeProto.ERROR_APPLICATION));
|
.isEqualTo(RpcErrorCodeProto.ERROR_APPLICATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,12 +204,12 @@ public class TestProtoBufRpc extends TestRpcBase {
|
|||||||
// short message goes through
|
// short message goes through
|
||||||
EchoResponseProto echoResponse = client.echo2(null,
|
EchoResponseProto echoResponse = client.echo2(null,
|
||||||
newEchoRequest(shortString));
|
newEchoRequest(shortString));
|
||||||
Assert.assertEquals(shortString, echoResponse.getMessage());
|
assertThat(echoResponse.getMessage()).isEqualTo(shortString);
|
||||||
|
|
||||||
final String longString = StringUtils.repeat("X", 4096);
|
final String longString = StringUtils.repeat("X", 4096);
|
||||||
try {
|
try {
|
||||||
client.echo2(null, newEchoRequest(longString));
|
client.echo2(null, newEchoRequest(longString));
|
||||||
Assert.fail("expected extra-long RPC to fail");
|
fail("expected extra-long RPC to fail");
|
||||||
} catch (ServiceException se) {
|
} catch (ServiceException se) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
@ -231,7 +230,7 @@ public class TestProtoBufRpc extends TestRpcBase {
|
|||||||
|
|
||||||
// Ensure RPC metrics are updated
|
// Ensure RPC metrics are updated
|
||||||
RpcMetrics rpcMetrics = server.getRpcMetrics();
|
RpcMetrics rpcMetrics = server.getRpcMetrics();
|
||||||
assertTrue(rpcMetrics.getProcessingSampleCount() > 999L);
|
assertThat(rpcMetrics.getProcessingSampleCount()).isGreaterThan(999L);
|
||||||
long before = rpcMetrics.getRpcSlowCalls();
|
long before = rpcMetrics.getRpcSlowCalls();
|
||||||
|
|
||||||
// make a really slow call. Sleep sleeps for 1000ms
|
// make a really slow call. Sleep sleeps for 1000ms
|
||||||
@ -255,7 +254,7 @@ public class TestProtoBufRpc extends TestRpcBase {
|
|||||||
|
|
||||||
// Ensure RPC metrics are updated
|
// Ensure RPC metrics are updated
|
||||||
RpcMetrics rpcMetrics = server.getRpcMetrics();
|
RpcMetrics rpcMetrics = server.getRpcMetrics();
|
||||||
assertTrue(rpcMetrics.getProcessingSampleCount() > 999L);
|
assertThat(rpcMetrics.getProcessingSampleCount()).isGreaterThan(999L);
|
||||||
long before = rpcMetrics.getRpcSlowCalls();
|
long before = rpcMetrics.getRpcSlowCalls();
|
||||||
|
|
||||||
// make a really slow call. Sleep sleeps for 1000ms
|
// make a really slow call. Sleep sleeps for 1000ms
|
||||||
@ -264,6 +263,6 @@ public class TestProtoBufRpc extends TestRpcBase {
|
|||||||
long after = rpcMetrics.getRpcSlowCalls();
|
long after = rpcMetrics.getRpcSlowCalls();
|
||||||
|
|
||||||
// make sure we never called into Log slow RPC routine.
|
// make sure we never called into Log slow RPC routine.
|
||||||
assertEquals(before, after);
|
assertThat(before).isEqualTo(after);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.apache.hadoop.test.MetricsAsserts.assertCounter;
|
import static org.apache.hadoop.test.MetricsAsserts.assertCounter;
|
||||||
import static org.apache.hadoop.test.MetricsAsserts.assertCounterGt;
|
import static org.apache.hadoop.test.MetricsAsserts.assertCounterGt;
|
||||||
import static org.apache.hadoop.test.MetricsAsserts.assertGauge;
|
import static org.apache.hadoop.test.MetricsAsserts.assertGauge;
|
||||||
@ -486,14 +487,14 @@ public class TestRPC extends TestRpcBase {
|
|||||||
.setParam2(2).build();
|
.setParam2(2).build();
|
||||||
TestProtos.AddResponseProto addResponse =
|
TestProtos.AddResponseProto addResponse =
|
||||||
proxy.add(null, addRequest);
|
proxy.add(null, addRequest);
|
||||||
assertEquals(addResponse.getResult(), 3);
|
assertThat(addResponse.getResult()).isEqualTo(3);
|
||||||
|
|
||||||
Integer[] integers = new Integer[] {1, 2};
|
Integer[] integers = new Integer[] {1, 2};
|
||||||
TestProtos.AddRequestProto2 addRequest2 =
|
TestProtos.AddRequestProto2 addRequest2 =
|
||||||
TestProtos.AddRequestProto2.newBuilder().addAllParams(
|
TestProtos.AddRequestProto2.newBuilder().addAllParams(
|
||||||
Arrays.asList(integers)).build();
|
Arrays.asList(integers)).build();
|
||||||
addResponse = proxy.add2(null, addRequest2);
|
addResponse = proxy.add2(null, addRequest2);
|
||||||
assertEquals(addResponse.getResult(), 3);
|
assertThat(addResponse.getResult()).isEqualTo(3);
|
||||||
|
|
||||||
boolean caught = false;
|
boolean caught = false;
|
||||||
try {
|
try {
|
||||||
|
@ -33,23 +33,20 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.net.SocketFactory;
|
import javax.net.SocketFactory;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
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.apache.hadoop.net.NetUtils;
|
import org.apache.hadoop.net.NetUtils;
|
||||||
import org.apache.hadoop.net.SocksSocketFactory;
|
import org.apache.hadoop.net.SocksSocketFactory;
|
||||||
import org.apache.hadoop.net.StandardSocketFactory;
|
import org.apache.hadoop.net.StandardSocketFactory;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test StandardSocketFactory and SocksSocketFactory NetUtils
|
* test StandardSocketFactory and SocksSocketFactory NetUtils
|
||||||
*
|
*
|
||||||
@ -111,10 +108,12 @@ public class TestSocketFactory {
|
|||||||
.getDefaultSocketFactory(conf);
|
.getDefaultSocketFactory(conf);
|
||||||
dummyCache.put(defaultSocketFactory, toBeCached2);
|
dummyCache.put(defaultSocketFactory, toBeCached2);
|
||||||
|
|
||||||
Assert
|
assertThat(dummyCache.size())
|
||||||
.assertEquals("The cache contains two elements", 2, dummyCache.size());
|
.withFailMessage("The cache contains two elements")
|
||||||
Assert.assertEquals("Equals of both socket factory shouldn't be same",
|
.isEqualTo(2);
|
||||||
defaultSocketFactory.equals(dummySocketFactory), false);
|
assertThat(defaultSocketFactory)
|
||||||
|
.withFailMessage("Equals of both socket factory shouldn't be same")
|
||||||
|
.isNotEqualTo(dummySocketFactory);
|
||||||
|
|
||||||
assertSame(toBeCached2, dummyCache.remove(defaultSocketFactory));
|
assertSame(toBeCached2, dummyCache.remove(defaultSocketFactory));
|
||||||
dummyCache.put(defaultSocketFactory, toBeCached2);
|
dummyCache.put(defaultSocketFactory, toBeCached2);
|
||||||
@ -184,14 +183,13 @@ public class TestSocketFactory {
|
|||||||
"localhost", 0));
|
"localhost", 0));
|
||||||
|
|
||||||
SocksSocketFactory templateWithProxy = new SocksSocketFactory(proxy);
|
SocksSocketFactory templateWithProxy = new SocksSocketFactory(proxy);
|
||||||
assertFalse(templateWithoutProxy.equals(templateWithProxy));
|
assertThat(templateWithoutProxy).isNotEqualTo(templateWithProxy);
|
||||||
|
|
||||||
Configuration configuration = new Configuration();
|
Configuration configuration = new Configuration();
|
||||||
configuration.set("hadoop.socks.server", "localhost:0");
|
configuration.set("hadoop.socks.server", "localhost:0");
|
||||||
|
|
||||||
templateWithoutProxy.setConf(configuration);
|
templateWithoutProxy.setConf(configuration);
|
||||||
assertTrue(templateWithoutProxy.equals(templateWithProxy));
|
assertThat(templateWithoutProxy).isEqualTo(templateWithProxy);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkSocket(Socket socket) throws Exception {
|
private void checkSocket(Socket socket) throws Exception {
|
||||||
@ -200,8 +198,7 @@ public class TestSocketFactory {
|
|||||||
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
|
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
|
||||||
out.writeBytes("test\n");
|
out.writeBytes("test\n");
|
||||||
String answer = input.readLine();
|
String answer = input.readLine();
|
||||||
assertEquals("TEST", answer);
|
assertThat(answer).isEqualTo("TEST");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
package org.apache.hadoop.ipc;
|
package org.apache.hadoop.ipc;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
@ -68,47 +69,47 @@ public class TestWeightedRoundRobinMultiplexer {
|
|||||||
// Mux of size 1: 0 0 0 0 0, etc
|
// Mux of size 1: 0 0 0 0 0, etc
|
||||||
mux = new WeightedRoundRobinMultiplexer(1, "", new Configuration());
|
mux = new WeightedRoundRobinMultiplexer(1, "", new Configuration());
|
||||||
for(int i = 0; i < 10; i++) {
|
for(int i = 0; i < 10; i++) {
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mux of size 2: 0 0 1 0 0 1 0 0 1, etc
|
// Mux of size 2: 0 0 1 0 0 1 0 0 1, etc
|
||||||
mux = new WeightedRoundRobinMultiplexer(2, "", new Configuration());
|
mux = new WeightedRoundRobinMultiplexer(2, "", new Configuration());
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isOne();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isOne();
|
||||||
|
|
||||||
// Size 3: 4x0 2x1 1x2, etc
|
// Size 3: 4x0 2x1 1x2, etc
|
||||||
mux = new WeightedRoundRobinMultiplexer(3, "", new Configuration());
|
mux = new WeightedRoundRobinMultiplexer(3, "", new Configuration());
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isOne();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isOne();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 2);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isEqualTo(2);
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
|
|
||||||
// Size 4: 8x0 4x1 2x2 1x3
|
// Size 4: 8x0 4x1 2x2 1x3
|
||||||
mux = new WeightedRoundRobinMultiplexer(4, "", new Configuration());
|
mux = new WeightedRoundRobinMultiplexer(4, "", new Configuration());
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isOne();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isOne();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isOne();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isOne();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 2);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isEqualTo(2);
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 2);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isEqualTo(2);
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 3);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isEqualTo(3);
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -119,10 +120,10 @@ public class TestWeightedRoundRobinMultiplexer {
|
|||||||
"1", "1");
|
"1", "1");
|
||||||
|
|
||||||
mux = new WeightedRoundRobinMultiplexer(2, "test.custom", conf);
|
mux = new WeightedRoundRobinMultiplexer(2, "test.custom", conf);
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isOne();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isOne();
|
||||||
|
|
||||||
// 1x0 3x1 2x2
|
// 1x0 3x1 2x2
|
||||||
conf.setStrings("test.custom." + IPC_CALLQUEUE_WRRMUX_WEIGHTS_KEY,
|
conf.setStrings("test.custom." + IPC_CALLQUEUE_WRRMUX_WEIGHTS_KEY,
|
||||||
@ -131,12 +132,12 @@ public class TestWeightedRoundRobinMultiplexer {
|
|||||||
mux = new WeightedRoundRobinMultiplexer(3, "test.custom", conf);
|
mux = new WeightedRoundRobinMultiplexer(3, "test.custom", conf);
|
||||||
|
|
||||||
for(int i = 0; i < 5; i++) {
|
for(int i = 0; i < 5; i++) {
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 0);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isZero();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isOne();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isOne();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 1);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isOne();
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 2);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isEqualTo(2);
|
||||||
assertEquals(mux.getAndAdvanceCurrentIndex(), 2);
|
assertThat(mux.getAndAdvanceCurrentIndex()).isEqualTo(2);
|
||||||
} // Ensure pattern repeats
|
} // Ensure pattern repeats
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
|
|
||||||
package org.apache.hadoop.metrics2.util;
|
package org.apache.hadoop.metrics2.util;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -29,6 +27,8 @@ import java.util.Random;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class TestSampleQuantiles {
|
public class TestSampleQuantiles {
|
||||||
|
|
||||||
static final Quantile[] quantiles = { new Quantile(0.50, 0.050),
|
static final Quantile[] quantiles = { new Quantile(0.50, 0.050),
|
||||||
@ -49,24 +49,24 @@ public class TestSampleQuantiles {
|
|||||||
@Test
|
@Test
|
||||||
public void testCount() throws IOException {
|
public void testCount() throws IOException {
|
||||||
// Counts start off zero
|
// Counts start off zero
|
||||||
assertEquals(estimator.getCount(), 0);
|
assertThat(estimator.getCount()).isZero();
|
||||||
assertEquals(estimator.getSampleCount(), 0);
|
assertThat(estimator.getSampleCount()).isZero();
|
||||||
|
|
||||||
// Snapshot should be null if there are no entries.
|
// Snapshot should be null if there are no entries.
|
||||||
assertNull(estimator.snapshot());
|
assertThat(estimator.snapshot()).isNull();
|
||||||
|
|
||||||
// Count increment correctly by 1
|
// Count increment correctly by 1
|
||||||
estimator.insert(1337);
|
estimator.insert(1337);
|
||||||
assertEquals(estimator.getCount(), 1);
|
assertThat(estimator.getCount()).isOne();
|
||||||
estimator.snapshot();
|
estimator.snapshot();
|
||||||
assertEquals(estimator.getSampleCount(), 1);
|
assertThat(estimator.getSampleCount()).isOne();
|
||||||
|
|
||||||
assertEquals(
|
assertThat(estimator.toString()).isEqualTo(
|
||||||
"50.00 %ile +/- 5.00%: 1337\n" +
|
"50.00 %ile +/- 5.00%: 1337\n" +
|
||||||
"75.00 %ile +/- 2.50%: 1337\n" +
|
"75.00 %ile +/- 2.50%: 1337\n" +
|
||||||
"90.00 %ile +/- 1.00%: 1337\n" +
|
"90.00 %ile +/- 1.00%: 1337\n" +
|
||||||
"95.00 %ile +/- 0.50%: 1337\n" +
|
"95.00 %ile +/- 0.50%: 1337\n" +
|
||||||
"99.00 %ile +/- 0.10%: 1337", estimator.toString());
|
"99.00 %ile +/- 0.10%: 1337");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,9 +79,9 @@ public class TestSampleQuantiles {
|
|||||||
estimator.insert(i);
|
estimator.insert(i);
|
||||||
}
|
}
|
||||||
estimator.clear();
|
estimator.clear();
|
||||||
assertEquals(estimator.getCount(), 0);
|
assertThat(estimator.getCount()).isZero();
|
||||||
assertEquals(estimator.getSampleCount(), 0);
|
assertThat(estimator.getSampleCount()).isZero();
|
||||||
assertNull(estimator.snapshot());
|
assertThat(estimator.snapshot()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,8 +113,8 @@ public class TestSampleQuantiles {
|
|||||||
System.out
|
System.out
|
||||||
.println(String.format("Expected %d with error %d, estimated %d",
|
.println(String.format("Expected %d with error %d, estimated %d",
|
||||||
actual, error, estimate));
|
actual, error, estimate));
|
||||||
assertTrue(estimate <= actual + error);
|
assertThat(estimate <= actual + error).isTrue();
|
||||||
assertTrue(estimate >= actual - error);
|
assertThat(estimate >= actual - error).isTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,11 +42,10 @@ import static org.junit.Assert.fail;
|
|||||||
|
|
||||||
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.apache.hadoop.security.Groups;
|
|
||||||
import org.apache.hadoop.security.ShellBasedUnixGroupsMapping;
|
|
||||||
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 TestGroupsCaching {
|
public class TestGroupsCaching {
|
||||||
public static final Logger TESTLOG =
|
public static final Logger TESTLOG =
|
||||||
@ -494,7 +493,7 @@ public class TestGroupsCaching {
|
|||||||
// Now get the cache entry - it should return immediately
|
// Now get the cache entry - it should return immediately
|
||||||
// with the old value and the cache will not have completed
|
// with the old value and the cache will not have completed
|
||||||
// a request to getGroups yet.
|
// a request to getGroups yet.
|
||||||
assertEquals(groups.getGroups("me").size(), 2);
|
assertThat(groups.getGroups("me").size()).isEqualTo(2);
|
||||||
assertEquals(startingRequestCount, FakeGroupMapping.getRequestCount());
|
assertEquals(startingRequestCount, FakeGroupMapping.getRequestCount());
|
||||||
|
|
||||||
// Now sleep for over the delay time and the request count should
|
// Now sleep for over the delay time and the request count should
|
||||||
@ -502,7 +501,7 @@ public class TestGroupsCaching {
|
|||||||
Thread.sleep(110);
|
Thread.sleep(110);
|
||||||
assertEquals(startingRequestCount + 1, FakeGroupMapping.getRequestCount());
|
assertEquals(startingRequestCount + 1, FakeGroupMapping.getRequestCount());
|
||||||
// Another call to get groups should give 3 groups instead of 2
|
// Another call to get groups should give 3 groups instead of 2
|
||||||
assertEquals(groups.getGroups("me").size(), 3);
|
assertThat(groups.getGroups("me").size()).isEqualTo(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -532,7 +531,7 @@ public class TestGroupsCaching {
|
|||||||
|
|
||||||
// Now get the cache entry - it should block and return the new
|
// Now get the cache entry - it should block and return the new
|
||||||
// 3 group value
|
// 3 group value
|
||||||
assertEquals(groups.getGroups("me").size(), 3);
|
assertThat(groups.getGroups("me").size()).isEqualTo(3);
|
||||||
assertEquals(startingRequestCount + 1, FakeGroupMapping.getRequestCount());
|
assertEquals(startingRequestCount + 1, FakeGroupMapping.getRequestCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -567,7 +566,7 @@ public class TestGroupsCaching {
|
|||||||
// Now get the cache entry - it should return immediately
|
// Now get the cache entry - it should return immediately
|
||||||
// with the old value and the cache will not have completed
|
// with the old value and the cache will not have completed
|
||||||
// a request to getGroups yet.
|
// a request to getGroups yet.
|
||||||
assertEquals(groups.getGroups("me").size(), 2);
|
assertThat(groups.getGroups("me").size()).isEqualTo(2);
|
||||||
assertEquals(startingRequestCount, FakeGroupMapping.getRequestCount());
|
assertEquals(startingRequestCount, FakeGroupMapping.getRequestCount());
|
||||||
// Resume the getGroups operation and the cache can get refreshed
|
// Resume the getGroups operation and the cache can get refreshed
|
||||||
FakeGroupMapping.resume();
|
FakeGroupMapping.resume();
|
||||||
@ -577,14 +576,14 @@ public class TestGroupsCaching {
|
|||||||
waitForGroupCounters(groups, 0, 0, 0, 1);
|
waitForGroupCounters(groups, 0, 0, 0, 1);
|
||||||
FakeGroupMapping.setThrowException(false);
|
FakeGroupMapping.setThrowException(false);
|
||||||
assertEquals(startingRequestCount + 1, FakeGroupMapping.getRequestCount());
|
assertEquals(startingRequestCount + 1, FakeGroupMapping.getRequestCount());
|
||||||
assertEquals(groups.getGroups("me").size(), 2);
|
assertThat(groups.getGroups("me").size()).isEqualTo(2);
|
||||||
|
|
||||||
// Now the 3rd call to getGroups above will have kicked off
|
// Now the 3rd call to getGroups above will have kicked off
|
||||||
// another refresh that updates the cache, since it no longer gives
|
// another refresh that updates the cache, since it no longer gives
|
||||||
// exception, we now expect the counter for success is 1.
|
// exception, we now expect the counter for success is 1.
|
||||||
waitForGroupCounters(groups, 0, 0, 1, 1);
|
waitForGroupCounters(groups, 0, 0, 1, 1);
|
||||||
assertEquals(startingRequestCount + 2, FakeGroupMapping.getRequestCount());
|
assertEquals(startingRequestCount + 2, FakeGroupMapping.getRequestCount());
|
||||||
assertEquals(groups.getGroups("me").size(), 3);
|
assertThat(groups.getGroups("me").size()).isEqualTo(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -613,7 +612,7 @@ public class TestGroupsCaching {
|
|||||||
// be triggered which will fail to update the key, but the keys old value
|
// be triggered which will fail to update the key, but the keys old value
|
||||||
// will be retrievable until it is evicted after about 10 seconds.
|
// will be retrievable until it is evicted after about 10 seconds.
|
||||||
for(int i=0; i<9; i++) {
|
for(int i=0; i<9; i++) {
|
||||||
assertEquals(groups.getGroups("me").size(), 2);
|
assertThat(groups.getGroups("me").size()).isEqualTo(2);
|
||||||
timer.advance(1 * 1000);
|
timer.advance(1 * 1000);
|
||||||
}
|
}
|
||||||
// Wait until the 11th second. The call to getGroups should throw
|
// Wait until the 11th second. The call to getGroups should throw
|
||||||
@ -631,7 +630,7 @@ public class TestGroupsCaching {
|
|||||||
// Finally check groups are retrieve again after FakeGroupMapping
|
// Finally check groups are retrieve again after FakeGroupMapping
|
||||||
// stops throw exceptions
|
// stops throw exceptions
|
||||||
FakeGroupMapping.setThrowException(false);
|
FakeGroupMapping.setThrowException(false);
|
||||||
assertEquals(groups.getGroups("me").size(), 2);
|
assertThat(groups.getGroups("me").size()).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -725,14 +724,14 @@ public class TestGroupsCaching {
|
|||||||
FakeGroupMapping.clearBlackList();
|
FakeGroupMapping.clearBlackList();
|
||||||
|
|
||||||
// First populate the cash
|
// First populate the cash
|
||||||
assertEquals(groups.getGroups("me").size(), 2);
|
assertThat(groups.getGroups("me").size()).isEqualTo(2);
|
||||||
|
|
||||||
// Advance the timer so a refresh is required
|
// Advance the timer so a refresh is required
|
||||||
timer.advance(2 * 1000);
|
timer.advance(2 * 1000);
|
||||||
|
|
||||||
// This call should throw an exception
|
// This call should throw an exception
|
||||||
FakeGroupMapping.setThrowException(true);
|
FakeGroupMapping.setThrowException(true);
|
||||||
assertEquals(groups.getGroups("me").size(), 2);
|
assertThat(groups.getGroups("me").size()).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -35,6 +35,8 @@ import org.junit.Test;
|
|||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class TestShellBasedIdMapping {
|
public class TestShellBasedIdMapping {
|
||||||
|
|
||||||
private static final Map<Integer, Integer> EMPTY_PASS_THROUGH_MAP =
|
private static final Map<Integer, Integer> EMPTY_PASS_THROUGH_MAP =
|
||||||
@ -295,18 +297,19 @@ public class TestShellBasedIdMapping {
|
|||||||
@Test
|
@Test
|
||||||
public void testUserUpdateSetting() throws IOException {
|
public void testUserUpdateSetting() throws IOException {
|
||||||
ShellBasedIdMapping iug = new ShellBasedIdMapping(new Configuration());
|
ShellBasedIdMapping iug = new ShellBasedIdMapping(new Configuration());
|
||||||
assertEquals(iug.getTimeout(),
|
assertThat(iug.getTimeout()).isEqualTo(
|
||||||
IdMappingConstant.USERGROUPID_UPDATE_MILLIS_DEFAULT);
|
IdMappingConstant.USERGROUPID_UPDATE_MILLIS_DEFAULT);
|
||||||
|
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
conf.setLong(IdMappingConstant.USERGROUPID_UPDATE_MILLIS_KEY, 0);
|
conf.setLong(IdMappingConstant.USERGROUPID_UPDATE_MILLIS_KEY, 0);
|
||||||
iug = new ShellBasedIdMapping(conf);
|
iug = new ShellBasedIdMapping(conf);
|
||||||
assertEquals(iug.getTimeout(), IdMappingConstant.USERGROUPID_UPDATE_MILLIS_MIN);
|
assertThat(iug.getTimeout()).isEqualTo(
|
||||||
|
IdMappingConstant.USERGROUPID_UPDATE_MILLIS_MIN);
|
||||||
|
|
||||||
conf.setLong(IdMappingConstant.USERGROUPID_UPDATE_MILLIS_KEY,
|
conf.setLong(IdMappingConstant.USERGROUPID_UPDATE_MILLIS_KEY,
|
||||||
IdMappingConstant.USERGROUPID_UPDATE_MILLIS_DEFAULT * 2);
|
IdMappingConstant.USERGROUPID_UPDATE_MILLIS_DEFAULT * 2);
|
||||||
iug = new ShellBasedIdMapping(conf);
|
iug = new ShellBasedIdMapping(conf);
|
||||||
assertEquals(iug.getTimeout(),
|
assertThat(iug.getTimeout()).isEqualTo(
|
||||||
IdMappingConstant.USERGROUPID_UPDATE_MILLIS_DEFAULT * 2);
|
IdMappingConstant.USERGROUPID_UPDATE_MILLIS_DEFAULT * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,9 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.security.authorize;
|
package org.apache.hadoop.security.authorize;
|
||||||
|
|
||||||
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.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -37,6 +35,7 @@ import org.junit.Test;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@ -187,29 +186,29 @@ public class TestAccessControlList {
|
|||||||
AccessControlList acl;
|
AccessControlList acl;
|
||||||
|
|
||||||
acl = new AccessControlList("*");
|
acl = new AccessControlList("*");
|
||||||
assertEquals("All users are allowed", acl.toString());
|
assertThat(acl.toString()).isEqualTo("All users are allowed");
|
||||||
validateGetAclString(acl);
|
validateGetAclString(acl);
|
||||||
|
|
||||||
acl = new AccessControlList(" ");
|
acl = new AccessControlList(" ");
|
||||||
assertEquals("No users are allowed", acl.toString());
|
assertThat(acl.toString()).isEqualTo("No users are allowed");
|
||||||
|
|
||||||
acl = new AccessControlList("user1,user2");
|
acl = new AccessControlList("user1,user2");
|
||||||
assertEquals("Users [user1, user2] are allowed", acl.toString());
|
assertThat(acl.toString()).isEqualTo("Users [user1, user2] are allowed");
|
||||||
validateGetAclString(acl);
|
validateGetAclString(acl);
|
||||||
|
|
||||||
acl = new AccessControlList("user1,user2 ");// with space
|
acl = new AccessControlList("user1,user2 ");// with space
|
||||||
assertEquals("Users [user1, user2] are allowed", acl.toString());
|
assertThat(acl.toString()).isEqualTo("Users [user1, user2] are allowed");
|
||||||
validateGetAclString(acl);
|
validateGetAclString(acl);
|
||||||
|
|
||||||
acl = new AccessControlList(" group1,group2");
|
acl = new AccessControlList(" group1,group2");
|
||||||
assertTrue(acl.toString().equals(
|
assertThat(acl.toString()).isEqualTo(
|
||||||
"Members of the groups [group1, group2] are allowed"));
|
"Members of the groups [group1, group2] are allowed");
|
||||||
validateGetAclString(acl);
|
validateGetAclString(acl);
|
||||||
|
|
||||||
acl = new AccessControlList("user1,user2 group1,group2");
|
acl = new AccessControlList("user1,user2 group1,group2");
|
||||||
assertTrue(acl.toString().equals(
|
assertThat(acl.toString()).isEqualTo(
|
||||||
"Users [user1, user2] and " +
|
"Users [user1, user2] and " +
|
||||||
"members of the groups [group1, group2] are allowed"));
|
"members of the groups [group1, group2] are allowed");
|
||||||
validateGetAclString(acl);
|
validateGetAclString(acl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,45 +227,45 @@ public class TestAccessControlList {
|
|||||||
|
|
||||||
acl = new AccessControlList("drwho tardis");
|
acl = new AccessControlList("drwho tardis");
|
||||||
users = acl.getUsers();
|
users = acl.getUsers();
|
||||||
assertEquals(users.size(), 1);
|
assertThat(users.size()).isOne();
|
||||||
assertEquals(users.iterator().next(), "drwho");
|
assertThat(users.iterator().next()).isEqualTo("drwho");
|
||||||
groups = acl.getGroups();
|
groups = acl.getGroups();
|
||||||
assertEquals(groups.size(), 1);
|
assertThat(groups.size()).isOne();
|
||||||
assertEquals(groups.iterator().next(), "tardis");
|
assertThat(groups.iterator().next()).isEqualTo("tardis");
|
||||||
|
|
||||||
acl = new AccessControlList("drwho");
|
acl = new AccessControlList("drwho");
|
||||||
users = acl.getUsers();
|
users = acl.getUsers();
|
||||||
assertEquals(users.size(), 1);
|
assertThat(users.size()).isOne();
|
||||||
assertEquals(users.iterator().next(), "drwho");
|
assertThat(users.iterator().next()).isEqualTo("drwho");
|
||||||
groups = acl.getGroups();
|
groups = acl.getGroups();
|
||||||
assertEquals(groups.size(), 0);
|
assertThat(groups.size()).isZero();
|
||||||
|
|
||||||
acl = new AccessControlList("drwho ");
|
acl = new AccessControlList("drwho ");
|
||||||
users = acl.getUsers();
|
users = acl.getUsers();
|
||||||
assertEquals(users.size(), 1);
|
assertThat(users.size()).isOne();
|
||||||
assertEquals(users.iterator().next(), "drwho");
|
assertThat(users.iterator().next()).isEqualTo("drwho");
|
||||||
groups = acl.getGroups();
|
groups = acl.getGroups();
|
||||||
assertEquals(groups.size(), 0);
|
assertThat(groups.size()).isZero();
|
||||||
|
|
||||||
acl = new AccessControlList(" tardis");
|
acl = new AccessControlList(" tardis");
|
||||||
users = acl.getUsers();
|
users = acl.getUsers();
|
||||||
assertEquals(users.size(), 0);
|
assertThat(users.size()).isZero();
|
||||||
groups = acl.getGroups();
|
groups = acl.getGroups();
|
||||||
assertEquals(groups.size(), 1);
|
assertThat(groups.size()).isOne();
|
||||||
assertEquals(groups.iterator().next(), "tardis");
|
assertThat(groups.iterator().next()).isEqualTo("tardis");
|
||||||
|
|
||||||
Iterator<String> iter;
|
Iterator<String> iter;
|
||||||
acl = new AccessControlList("drwho,joe tardis, users");
|
acl = new AccessControlList("drwho,joe tardis, users");
|
||||||
users = acl.getUsers();
|
users = acl.getUsers();
|
||||||
assertEquals(users.size(), 2);
|
assertThat(users.size()).isEqualTo(2);
|
||||||
iter = users.iterator();
|
iter = users.iterator();
|
||||||
assertEquals(iter.next(), "drwho");
|
assertThat(iter.next()).isEqualTo("drwho");
|
||||||
assertEquals(iter.next(), "joe");
|
assertThat(iter.next()).isEqualTo("joe");
|
||||||
groups = acl.getGroups();
|
groups = acl.getGroups();
|
||||||
assertEquals(groups.size(), 2);
|
assertThat(groups.size()).isEqualTo(2);
|
||||||
iter = groups.iterator();
|
iter = groups.iterator();
|
||||||
assertEquals(iter.next(), "tardis");
|
assertThat(iter.next()).isEqualTo("tardis");
|
||||||
assertEquals(iter.next(), "users");
|
assertThat(iter.next()).isEqualTo("users");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -278,58 +277,58 @@ public class TestAccessControlList {
|
|||||||
Collection<String> users;
|
Collection<String> users;
|
||||||
Collection<String> groups;
|
Collection<String> groups;
|
||||||
acl = new AccessControlList(" ");
|
acl = new AccessControlList(" ");
|
||||||
assertEquals(0, acl.getUsers().size());
|
assertThat(acl.getUsers().size()).isZero();
|
||||||
assertEquals(0, acl.getGroups().size());
|
assertThat(acl.getGroups().size()).isZero();
|
||||||
assertEquals(" ", acl.getAclString());
|
assertThat(acl.getAclString()).isEqualTo(" ");
|
||||||
|
|
||||||
acl.addUser("drwho");
|
acl.addUser("drwho");
|
||||||
users = acl.getUsers();
|
users = acl.getUsers();
|
||||||
assertEquals(users.size(), 1);
|
assertThat(users.size()).isOne();
|
||||||
assertEquals(users.iterator().next(), "drwho");
|
assertThat(users.iterator().next()).isEqualTo("drwho");
|
||||||
assertEquals("drwho ", acl.getAclString());
|
assertThat(acl.getAclString()).isEqualTo("drwho ");
|
||||||
|
|
||||||
acl.addGroup("tardis");
|
acl.addGroup("tardis");
|
||||||
groups = acl.getGroups();
|
groups = acl.getGroups();
|
||||||
assertEquals(groups.size(), 1);
|
assertThat(groups.size()).isOne();
|
||||||
assertEquals(groups.iterator().next(), "tardis");
|
assertThat(groups.iterator().next()).isEqualTo("tardis");
|
||||||
assertEquals("drwho tardis", acl.getAclString());
|
assertThat(acl.getAclString()).isEqualTo("drwho tardis");
|
||||||
|
|
||||||
acl.addUser("joe");
|
acl.addUser("joe");
|
||||||
acl.addGroup("users");
|
acl.addGroup("users");
|
||||||
users = acl.getUsers();
|
users = acl.getUsers();
|
||||||
assertEquals(users.size(), 2);
|
assertThat(users.size()).isEqualTo(2);
|
||||||
Iterator<String> iter = users.iterator();
|
Iterator<String> iter = users.iterator();
|
||||||
assertEquals(iter.next(), "drwho");
|
assertThat(iter.next()).isEqualTo("drwho");
|
||||||
assertEquals(iter.next(), "joe");
|
assertThat(iter.next()).isEqualTo("joe");
|
||||||
groups = acl.getGroups();
|
groups = acl.getGroups();
|
||||||
assertEquals(groups.size(), 2);
|
assertThat(groups.size()).isEqualTo(2);
|
||||||
iter = groups.iterator();
|
iter = groups.iterator();
|
||||||
assertEquals(iter.next(), "tardis");
|
assertThat(iter.next()).isEqualTo("tardis");
|
||||||
assertEquals(iter.next(), "users");
|
assertThat(iter.next()).isEqualTo("users");
|
||||||
assertEquals("drwho,joe tardis,users", acl.getAclString());
|
assertThat(acl.getAclString()).isEqualTo("drwho,joe tardis,users");
|
||||||
|
|
||||||
acl.removeUser("joe");
|
acl.removeUser("joe");
|
||||||
acl.removeGroup("users");
|
acl.removeGroup("users");
|
||||||
users = acl.getUsers();
|
users = acl.getUsers();
|
||||||
assertEquals(users.size(), 1);
|
assertThat(users.size()).isOne();
|
||||||
assertFalse(users.contains("joe"));
|
assertFalse(users.contains("joe"));
|
||||||
groups = acl.getGroups();
|
groups = acl.getGroups();
|
||||||
assertEquals(groups.size(), 1);
|
assertThat(groups.size()).isOne();
|
||||||
assertFalse(groups.contains("users"));
|
assertFalse(groups.contains("users"));
|
||||||
assertEquals("drwho tardis", acl.getAclString());
|
assertThat(acl.getAclString()).isEqualTo("drwho tardis");
|
||||||
|
|
||||||
acl.removeGroup("tardis");
|
acl.removeGroup("tardis");
|
||||||
groups = acl.getGroups();
|
groups = acl.getGroups();
|
||||||
assertEquals(0, groups.size());
|
assertThat(groups.size()).isZero();
|
||||||
assertFalse(groups.contains("tardis"));
|
assertFalse(groups.contains("tardis"));
|
||||||
assertEquals("drwho ", acl.getAclString());
|
assertThat(acl.getAclString()).isEqualTo("drwho ");
|
||||||
|
|
||||||
acl.removeUser("drwho");
|
acl.removeUser("drwho");
|
||||||
assertEquals(0, users.size());
|
assertThat(users.size()).isZero();
|
||||||
assertFalse(users.contains("drwho"));
|
assertFalse(users.contains("drwho"));
|
||||||
assertEquals(0, acl.getGroups().size());
|
assertThat(acl.getGroups().size()).isZero();
|
||||||
assertEquals(0, acl.getUsers().size());
|
assertThat(acl.getUsers().size()).isZero();
|
||||||
assertEquals(" ", acl.getAclString());
|
assertThat(acl.getAclString()).isEqualTo(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -345,8 +344,8 @@ public class TestAccessControlList {
|
|||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
th = t;
|
th = t;
|
||||||
}
|
}
|
||||||
assertNotNull(th);
|
assertThat(th).isNotNull();
|
||||||
assertTrue(th instanceof IllegalArgumentException);
|
assertThat(th).isInstanceOf(IllegalArgumentException.class);
|
||||||
|
|
||||||
th = null;
|
th = null;
|
||||||
try {
|
try {
|
||||||
@ -354,24 +353,24 @@ public class TestAccessControlList {
|
|||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
th = t;
|
th = t;
|
||||||
}
|
}
|
||||||
assertNotNull(th);
|
assertThat(th).isNotNull();
|
||||||
assertTrue(th instanceof IllegalArgumentException);
|
assertThat(th).isInstanceOf(IllegalArgumentException.class);
|
||||||
th = null;
|
th = null;
|
||||||
try {
|
try {
|
||||||
acl.removeUser(" * ");
|
acl.removeUser(" * ");
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
th = t;
|
th = t;
|
||||||
}
|
}
|
||||||
assertNotNull(th);
|
assertThat(th).isNotNull();
|
||||||
assertTrue(th instanceof IllegalArgumentException);
|
assertThat(th).isInstanceOf(IllegalArgumentException.class);
|
||||||
th = null;
|
th = null;
|
||||||
try {
|
try {
|
||||||
acl.removeGroup(" * ");
|
acl.removeGroup(" * ");
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
th = t;
|
th = t;
|
||||||
}
|
}
|
||||||
assertNotNull(th);
|
assertThat(th).isNotNull();
|
||||||
assertTrue(th instanceof IllegalArgumentException);
|
assertThat(th).isInstanceOf(IllegalArgumentException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,6 +31,7 @@ import org.mockito.Mockito;
|
|||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,8 +85,9 @@ public class TestXFrameOptionsFilter {
|
|||||||
|
|
||||||
filter.doFilter(request, response, chain);
|
filter.doFilter(request, response, chain);
|
||||||
|
|
||||||
Assert.assertEquals("X-Frame-Options count not equal to 1.",
|
assertThat(headers.size())
|
||||||
headers.size(), 1);
|
.withFailMessage("X-Frame-Options count not equal to 1.")
|
||||||
|
.isOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -138,10 +140,12 @@ public class TestXFrameOptionsFilter {
|
|||||||
|
|
||||||
filter.doFilter(request, response, chain);
|
filter.doFilter(request, response, chain);
|
||||||
|
|
||||||
Assert.assertEquals("X-Frame-Options count not equal to 1.",
|
assertThat(headers.size())
|
||||||
headers.size(), 1);
|
.withFailMessage("X-Frame-Options count not equal to 1.")
|
||||||
|
.isOne();
|
||||||
|
|
||||||
Assert.assertEquals("X-Frame-Options count not equal to 1.",
|
assertThat(headers.toArray()[0])
|
||||||
headers.toArray()[0], "SAMEORIGIN");
|
.withFailMessage("X-Frame-Options count not equal to 1.")
|
||||||
|
.isEqualTo("SAMEORIGIN");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ import org.junit.Test;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class TestDelegationToken {
|
public class TestDelegationToken {
|
||||||
@ -266,17 +267,17 @@ public class TestDelegationToken {
|
|||||||
3*1000, 1*1000, 3600000);
|
3*1000, 1*1000, 3600000);
|
||||||
try {
|
try {
|
||||||
dtSecretManager.startThreads();
|
dtSecretManager.startThreads();
|
||||||
Assert.assertEquals(dtSecretManager.getCurrentTokensSize(), 0);
|
assertThat(dtSecretManager.getCurrentTokensSize()).isZero();
|
||||||
final Token<TestDelegationTokenIdentifier> token1 =
|
final Token<TestDelegationTokenIdentifier> token1 =
|
||||||
generateDelegationToken(dtSecretManager, "SomeUser", "JobTracker");
|
generateDelegationToken(dtSecretManager, "SomeUser", "JobTracker");
|
||||||
Assert.assertEquals(dtSecretManager.getCurrentTokensSize(), 1);
|
assertThat(dtSecretManager.getCurrentTokensSize()).isOne();
|
||||||
final Token<TestDelegationTokenIdentifier> token2 =
|
final Token<TestDelegationTokenIdentifier> token2 =
|
||||||
generateDelegationToken(dtSecretManager, "SomeUser", "JobTracker");
|
generateDelegationToken(dtSecretManager, "SomeUser", "JobTracker");
|
||||||
Assert.assertEquals(dtSecretManager.getCurrentTokensSize(), 2);
|
assertThat(dtSecretManager.getCurrentTokensSize()).isEqualTo(2);
|
||||||
dtSecretManager.cancelToken(token1, "JobTracker");
|
dtSecretManager.cancelToken(token1, "JobTracker");
|
||||||
Assert.assertEquals(dtSecretManager.getCurrentTokensSize(), 1);
|
assertThat(dtSecretManager.getCurrentTokensSize()).isOne();
|
||||||
dtSecretManager.cancelToken(token2, "JobTracker");
|
dtSecretManager.cancelToken(token2, "JobTracker");
|
||||||
Assert.assertEquals(dtSecretManager.getCurrentTokensSize(), 0);
|
assertThat(dtSecretManager.getCurrentTokensSize()).isZero();
|
||||||
} finally {
|
} finally {
|
||||||
dtSecretManager.stopThreads();
|
dtSecretManager.stopThreads();
|
||||||
}
|
}
|
||||||
@ -386,7 +387,7 @@ public class TestDelegationToken {
|
|||||||
|
|
||||||
//after rolling, the length of the keys list must increase
|
//after rolling, the length of the keys list must increase
|
||||||
int currNumKeys = dtSecretManager.getAllKeys().length;
|
int currNumKeys = dtSecretManager.getAllKeys().length;
|
||||||
Assert.assertEquals((currNumKeys - prevNumKeys) >= 1, true);
|
assertThat(currNumKeys - prevNumKeys).isGreaterThanOrEqualTo(1);
|
||||||
|
|
||||||
//after rolling, the token that was generated earlier must
|
//after rolling, the token that was generated earlier must
|
||||||
//still be valid (retrievePassword will fail if the token
|
//still be valid (retrievePassword will fail if the token
|
||||||
|
@ -27,7 +27,7 @@ import org.junit.Test;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/** Testing {@link LightWeightResizableGSet} */
|
/** Testing {@link LightWeightResizableGSet} */
|
||||||
public class TestLightWeightResizableGSet {
|
public class TestLightWeightResizableGSet {
|
||||||
@ -132,23 +132,23 @@ public class TestLightWeightResizableGSet {
|
|||||||
final LightWeightResizableGSet<TestKey, TestElement> set =
|
final LightWeightResizableGSet<TestKey, TestElement> set =
|
||||||
new LightWeightResizableGSet<TestKey, TestElement>();
|
new LightWeightResizableGSet<TestKey, TestElement>();
|
||||||
|
|
||||||
assertEquals(set.size(), 0);
|
assertThat(set.size()).isZero();
|
||||||
|
|
||||||
// put all elements
|
// put all elements
|
||||||
for (int i = 0; i < elements.length; i++) {
|
for (int i = 0; i < elements.length; i++) {
|
||||||
TestElement element = set.put(elements[i]);
|
TestElement element = set.put(elements[i]);
|
||||||
assertTrue(element == null);
|
assertThat(element).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the set size
|
// check the set size
|
||||||
assertEquals(set.size(), elements.length);
|
assertThat(set.size()).isEqualTo(elements.length);
|
||||||
|
|
||||||
// check all elements exist in the set and the data is correct
|
// check all elements exist in the set and the data is correct
|
||||||
for (int i = 0; i < elements.length; i++) {
|
for (int i = 0; i < elements.length; i++) {
|
||||||
assertTrue(set.contains(elements[i]));
|
assertThat(set.contains(elements[i])).isTrue();
|
||||||
|
|
||||||
TestElement element = set.get(elements[i]);
|
TestElement element = set.get(elements[i]);
|
||||||
assertEquals(elements[i].getData(), element.getData());
|
assertThat(elements[i].getData()).isEqualTo(element.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
TestKey[] keys = getKeys(elements);
|
TestKey[] keys = getKeys(elements);
|
||||||
@ -157,39 +157,38 @@ public class TestLightWeightResizableGSet {
|
|||||||
// update the set
|
// update the set
|
||||||
for (int i = 0; i < newElements.length; i++) {
|
for (int i = 0; i < newElements.length; i++) {
|
||||||
TestElement element = set.put(newElements[i]);
|
TestElement element = set.put(newElements[i]);
|
||||||
assertTrue(element != null);
|
assertThat(element).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the set size
|
// check the set size
|
||||||
assertEquals(set.size(), elements.length);
|
assertThat(set.size()).isEqualTo(elements.length);
|
||||||
|
|
||||||
// check all elements exist in the set and the data is updated to new value
|
// check all elements exist in the set and the data is updated to new value
|
||||||
for (int i = 0; i < keys.length; i++) {
|
for (int i = 0; i < keys.length; i++) {
|
||||||
assertTrue(set.contains(keys[i]));
|
assertThat(set.contains(keys[i])).isTrue();
|
||||||
|
|
||||||
TestElement element = set.get(keys[i]);
|
TestElement element = set.get(keys[i]);
|
||||||
assertEquals(newElements[i].getData(), element.getData());
|
assertThat(newElements[i].getData()).isEqualTo(element.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
// test LightWeightHashGSet#values
|
// test LightWeightHashGSet#values
|
||||||
Collection<TestElement> cElements = set.values();
|
Collection<TestElement> cElements = set.values();
|
||||||
assertEquals(cElements.size(), elements.length);
|
assertThat(cElements.size()).isEqualTo(elements.length);
|
||||||
for (TestElement element : cElements) {
|
for (TestElement element : cElements) {
|
||||||
assertTrue(set.contains(element));
|
assertThat(set.contains(element)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove elements
|
// remove elements
|
||||||
for (int i = 0; i < keys.length; i++) {
|
for (int i = 0; i < keys.length; i++) {
|
||||||
TestElement element = set.remove(keys[i]);
|
TestElement element = set.remove(keys[i]);
|
||||||
|
assertThat(element).isNotNull();
|
||||||
assertTrue(element != null);
|
|
||||||
|
|
||||||
// the element should not exist after remove
|
// the element should not exist after remove
|
||||||
assertFalse(set.contains(keys[i]));
|
assertThat(set.contains(keys[i])).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the set size
|
// check the set size
|
||||||
assertEquals(set.size(), 0);
|
assertThat(set.size()).isZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout = 60000)
|
@Test(timeout = 60000)
|
||||||
@ -198,33 +197,33 @@ public class TestLightWeightResizableGSet {
|
|||||||
final LightWeightResizableGSet<TestKey, TestElement> set =
|
final LightWeightResizableGSet<TestKey, TestElement> set =
|
||||||
new LightWeightResizableGSet<TestKey, TestElement>();
|
new LightWeightResizableGSet<TestKey, TestElement>();
|
||||||
|
|
||||||
assertEquals(set.size(), 0);
|
assertThat(set.size()).isZero();
|
||||||
|
|
||||||
// put all elements
|
// put all elements
|
||||||
for (int i = 0; i < elements.length; i++) {
|
for (int i = 0; i < elements.length; i++) {
|
||||||
TestElement element = set.put(elements[i]);
|
TestElement element = set.put(elements[i]);
|
||||||
assertTrue(element == null);
|
assertThat(element).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the set size
|
// check the set size
|
||||||
assertEquals(set.size(), elements.length);
|
assertThat(set.size()).isEqualTo(elements.length);
|
||||||
|
|
||||||
// remove all through clear
|
// remove all through clear
|
||||||
{
|
{
|
||||||
set.clear();
|
set.clear();
|
||||||
assertEquals(set.size(), 0);
|
assertThat(set.size()).isZero();
|
||||||
|
|
||||||
// check all elements removed
|
// check all elements removed
|
||||||
for (int i = 0; i < elements.length; i++) {
|
for (int i = 0; i < elements.length; i++) {
|
||||||
assertFalse(set.contains(elements[i]));
|
assertThat(set.contains(elements[i])).isFalse();
|
||||||
}
|
}
|
||||||
assertFalse(set.iterator().hasNext());
|
assertThat(set.iterator().hasNext()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
// put all elements back
|
// put all elements back
|
||||||
for (int i = 0; i < elements.length; i++) {
|
for (int i = 0; i < elements.length; i++) {
|
||||||
TestElement element = set.put(elements[i]);
|
TestElement element = set.put(elements[i]);
|
||||||
assertTrue(element == null);
|
assertThat(element).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove all through iterator
|
// remove all through iterator
|
||||||
@ -232,22 +231,22 @@ public class TestLightWeightResizableGSet {
|
|||||||
for (Iterator<TestElement> iter = set.iterator(); iter.hasNext(); ) {
|
for (Iterator<TestElement> iter = set.iterator(); iter.hasNext(); ) {
|
||||||
TestElement element = iter.next();
|
TestElement element = iter.next();
|
||||||
// element should be there before removing
|
// element should be there before removing
|
||||||
assertTrue(set.contains(element));
|
assertThat(set.contains(element)).isTrue();
|
||||||
iter.remove();
|
iter.remove();
|
||||||
// element should not be there now
|
// element should not be there now
|
||||||
assertFalse(set.contains(element));
|
assertThat(set.contains(element)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
// the deleted elements should not be there
|
// the deleted elements should not be there
|
||||||
for (int i = 0; i < elements.length; i++) {
|
for (int i = 0; i < elements.length; i++) {
|
||||||
assertFalse(set.contains(elements[i]));
|
assertThat(set.contains(elements[i])).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterator should not have next
|
// iterator should not have next
|
||||||
assertFalse(set.iterator().hasNext());
|
assertThat(set.iterator().hasNext()).isFalse();
|
||||||
|
|
||||||
// check the set size
|
// check the set size
|
||||||
assertEquals(set.size(), 0);
|
assertThat(set.size()).isZero();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,14 @@ import org.apache.curator.retry.RetryOneTime;
|
|||||||
import org.apache.curator.test.Timing;
|
import org.apache.curator.test.Timing;
|
||||||
import org.apache.zookeeper.data.Stat;
|
import org.apache.zookeeper.data.Stat;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.net.BindException;
|
import java.net.BindException;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a copy of Curator 2.7.1's TestChildReaper class, with minor
|
* This is a copy of Curator 2.7.1's TestChildReaper class, with minor
|
||||||
* modifications to make it work with JUnit (some setup code taken from
|
* modifications to make it work with JUnit (some setup code taken from
|
||||||
@ -90,7 +91,7 @@ public class TestChildReaper
|
|||||||
timing.forWaiting().sleepABit();
|
timing.forWaiting().sleepABit();
|
||||||
|
|
||||||
Stat stat = client.checkExists().forPath("/test");
|
Stat stat = client.checkExists().forPath("/test");
|
||||||
Assert.assertEquals(stat.getNumChildren(), nonEmptyNodes);
|
assertThat(stat.getNumChildren()).isEqualTo(nonEmptyNodes);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -120,7 +121,7 @@ public class TestChildReaper
|
|||||||
timing.forWaiting().sleepABit();
|
timing.forWaiting().sleepABit();
|
||||||
|
|
||||||
Stat stat = client.checkExists().forPath("/test");
|
Stat stat = client.checkExists().forPath("/test");
|
||||||
Assert.assertEquals(stat.getNumChildren(), 0);
|
assertThat(stat.getNumChildren()).isZero();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -153,11 +154,11 @@ public class TestChildReaper
|
|||||||
timing.forWaiting().sleepABit();
|
timing.forWaiting().sleepABit();
|
||||||
|
|
||||||
Stat stat = client.checkExists().forPath("/test1");
|
Stat stat = client.checkExists().forPath("/test1");
|
||||||
Assert.assertEquals(stat.getNumChildren(), 0);
|
assertThat(stat.getNumChildren()).isZero();
|
||||||
stat = client.checkExists().forPath("/test2");
|
stat = client.checkExists().forPath("/test2");
|
||||||
Assert.assertEquals(stat.getNumChildren(), 0);
|
assertThat(stat.getNumChildren()).isZero();
|
||||||
stat = client.checkExists().forPath("/test3");
|
stat = client.checkExists().forPath("/test3");
|
||||||
Assert.assertEquals(stat.getNumChildren(), 10);
|
assertThat(stat.getNumChildren()).isEqualTo(10);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -193,11 +194,11 @@ public class TestChildReaper
|
|||||||
timing.forWaiting().sleepABit();
|
timing.forWaiting().sleepABit();
|
||||||
|
|
||||||
Stat stat = client.checkExists().forPath("/test");
|
Stat stat = client.checkExists().forPath("/test");
|
||||||
Assert.assertEquals(stat.getNumChildren(), 0);
|
assertThat(stat.getNumChildren()).isZero();
|
||||||
|
|
||||||
stat = client.usingNamespace(null).checkExists().forPath("/foo/test");
|
stat = client.usingNamespace(null).checkExists().forPath("/foo/test");
|
||||||
Assert.assertNotNull(stat);
|
assertThat(stat).isNotNull();
|
||||||
Assert.assertEquals(stat.getNumChildren(), 0);
|
assertThat(stat.getNumChildren()).isZero();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -97,6 +97,11 @@
|
|||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-core</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -17,24 +17,23 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.hadoop.nfs.nfs3;
|
package org.apache.hadoop.nfs.nfs3;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
|
|
||||||
import org.apache.hadoop.nfs.nfs3.FileHandle;
|
|
||||||
import org.apache.hadoop.oncrpc.XDR;
|
import org.apache.hadoop.oncrpc.XDR;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class TestFileHandle {
|
public class TestFileHandle {
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor() {
|
public void testConstructor() {
|
||||||
FileHandle handle = new FileHandle(1024);
|
FileHandle handle = new FileHandle(1024);
|
||||||
XDR xdr = new XDR();
|
XDR xdr = new XDR();
|
||||||
handle.serialize(xdr);
|
handle.serialize(xdr);
|
||||||
Assert.assertEquals(handle.getFileId(), 1024);
|
assertThat(handle.getFileId()).isEqualTo(1024);
|
||||||
|
|
||||||
// Deserialize it back
|
// Deserialize it back
|
||||||
FileHandle handle2 = new FileHandle();
|
FileHandle handle2 = new FileHandle();
|
||||||
handle2.deserialize(xdr.asReadOnlyWrap());
|
handle2.deserialize(xdr.asReadOnlyWrap());
|
||||||
Assert.assertEquals("Failed: Assert 1024 is id ", 1024,
|
assertThat(handle.getFileId())
|
||||||
handle.getFileId());
|
.withFailMessage("Failed: Assert 1024 is id ").isEqualTo(1024);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user