HBASE-23645 Fixed remaining Checkstyle violations in hbase-common tests
Signed-off-by: stack <stack@apache.org>
This commit is contained in:
parent
99d26e884b
commit
9d4ea24db5
|
@ -36,6 +36,8 @@
|
||||||
<suppress checks="MagicNumberCheck" files=".*Test\.java"/>
|
<suppress checks="MagicNumberCheck" files=".*Test\.java"/>
|
||||||
<!-- Will not have a private constructor, because it is InterfaceAudience.Public -->
|
<!-- Will not have a private constructor, because it is InterfaceAudience.Public -->
|
||||||
<suppress checks="HideUtilityClassConstructor" files="org.apache.hadoop.hbase.util.ByteRangeUtils"/>
|
<suppress checks="HideUtilityClassConstructor" files="org.apache.hadoop.hbase.util.ByteRangeUtils"/>
|
||||||
|
<suppress checks="InnerAssignment" files="org.apache.hadoop.hbase.Waiter"/>
|
||||||
|
<suppress checks="EmptyBlock" files="org.apache.hadoop.hbase.TestTimeout"/>
|
||||||
<suppress checks="InnerAssignment" files="org.apache.hadoop.hbase.rest.PerformanceEvaluation"/>
|
<suppress checks="InnerAssignment" files="org.apache.hadoop.hbase.rest.PerformanceEvaluation"/>
|
||||||
<suppress checks="EmptyBlock" files="org.apache.hadoop.hbase.rest.PerformanceEvaluation"/>
|
<suppress checks="EmptyBlock" files="org.apache.hadoop.hbase.rest.PerformanceEvaluation"/>
|
||||||
</suppressions>
|
</suppressions>
|
||||||
|
|
|
@ -25,7 +25,6 @@ import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -49,12 +48,12 @@ import org.junit.experimental.categories.Category;
|
||||||
public class TestKeyValue extends TestCase {
|
public class TestKeyValue extends TestCase {
|
||||||
private static final Log LOG = LogFactory.getLog(TestKeyValue.class);
|
private static final Log LOG = LogFactory.getLog(TestKeyValue.class);
|
||||||
|
|
||||||
public void testColumnCompare() throws Exception {
|
public void testColumnCompare() {
|
||||||
final byte [] a = Bytes.toBytes("aaa");
|
final byte[] a = Bytes.toBytes("aaa");
|
||||||
byte [] family1 = Bytes.toBytes("abc");
|
byte[] family1 = Bytes.toBytes("abc");
|
||||||
byte [] qualifier1 = Bytes.toBytes("def");
|
byte[] qualifier1 = Bytes.toBytes("def");
|
||||||
byte [] family2 = Bytes.toBytes("abcd");
|
byte[] family2 = Bytes.toBytes("abcd");
|
||||||
byte [] qualifier2 = Bytes.toBytes("ef");
|
byte[] qualifier2 = Bytes.toBytes("ef");
|
||||||
|
|
||||||
KeyValue aaa = new KeyValue(a, family1, qualifier1, 0L, KeyValue.Type.Put, a);
|
KeyValue aaa = new KeyValue(a, family1, qualifier1, 0L, KeyValue.Type.Put, a);
|
||||||
assertFalse(CellUtil.matchingColumn(aaa, family2, qualifier2));
|
assertFalse(CellUtil.matchingColumn(aaa, family2, qualifier2));
|
||||||
|
@ -62,28 +61,27 @@ public class TestKeyValue extends TestCase {
|
||||||
aaa = new KeyValue(a, family2, qualifier2, 0L, KeyValue.Type.Put, a);
|
aaa = new KeyValue(a, family2, qualifier2, 0L, KeyValue.Type.Put, a);
|
||||||
assertFalse(CellUtil.matchingColumn(aaa, family1, qualifier1));
|
assertFalse(CellUtil.matchingColumn(aaa, family1, qualifier1));
|
||||||
assertTrue(CellUtil.matchingColumn(aaa, family2,qualifier2));
|
assertTrue(CellUtil.matchingColumn(aaa, family2,qualifier2));
|
||||||
byte [] nullQualifier = new byte[0];
|
byte[] nullQualifier = new byte[0];
|
||||||
aaa = new KeyValue(a, family1, nullQualifier, 0L, KeyValue.Type.Put, a);
|
aaa = new KeyValue(a, family1, nullQualifier, 0L, KeyValue.Type.Put, a);
|
||||||
assertTrue(CellUtil.matchingColumn(aaa, family1,null));
|
assertTrue(CellUtil.matchingColumn(aaa, family1,null));
|
||||||
assertFalse(CellUtil.matchingColumn(aaa, family2,qualifier2));
|
assertFalse(CellUtil.matchingColumn(aaa, family2,qualifier2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test a corner case when the family qualifier is a prefix of the
|
* Test a corner case when the family qualifier is a prefix of the column qualifier.
|
||||||
* column qualifier.
|
|
||||||
*/
|
*/
|
||||||
public void testColumnCompare_prefix() throws Exception {
|
public void testColumnCompare_prefix() {
|
||||||
final byte [] a = Bytes.toBytes("aaa");
|
final byte[] a = Bytes.toBytes("aaa");
|
||||||
byte [] family1 = Bytes.toBytes("abc");
|
byte[] family1 = Bytes.toBytes("abc");
|
||||||
byte [] qualifier1 = Bytes.toBytes("def");
|
byte[] qualifier1 = Bytes.toBytes("def");
|
||||||
byte [] family2 = Bytes.toBytes("ab");
|
byte[] family2 = Bytes.toBytes("ab");
|
||||||
byte [] qualifier2 = Bytes.toBytes("def");
|
byte[] qualifier2 = Bytes.toBytes("def");
|
||||||
|
|
||||||
KeyValue aaa = new KeyValue(a, family1, qualifier1, 0L, KeyValue.Type.Put, a);
|
KeyValue aaa = new KeyValue(a, family1, qualifier1, 0L, KeyValue.Type.Put, a);
|
||||||
assertFalse(CellUtil.matchingColumn(aaa, family2, qualifier2));
|
assertFalse(CellUtil.matchingColumn(aaa, family2, qualifier2));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBasics() throws Exception {
|
public void testBasics() {
|
||||||
LOG.info("LOWKEY: " + KeyValue.LOWESTKEY.toString());
|
LOG.info("LOWKEY: " + KeyValue.LOWESTKEY.toString());
|
||||||
check(Bytes.toBytes(getName()),
|
check(Bytes.toBytes(getName()),
|
||||||
Bytes.toBytes(getName()), Bytes.toBytes(getName()), 1,
|
Bytes.toBytes(getName()), Bytes.toBytes(getName()), 1,
|
||||||
|
@ -108,11 +106,11 @@ public class TestKeyValue extends TestCase {
|
||||||
LOG.info(kv.toString());
|
LOG.info(kv.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPlainCompare() throws Exception {
|
public void testPlainCompare() {
|
||||||
final byte [] a = Bytes.toBytes("aaa");
|
final byte[] a = Bytes.toBytes("aaa");
|
||||||
final byte [] b = Bytes.toBytes("bbb");
|
final byte[] b = Bytes.toBytes("bbb");
|
||||||
final byte [] fam = Bytes.toBytes("col");
|
final byte[] fam = Bytes.toBytes("col");
|
||||||
final byte [] qf = Bytes.toBytes("umn");
|
final byte[] qf = Bytes.toBytes("umn");
|
||||||
KeyValue aaa = new KeyValue(a, fam, qf, a);
|
KeyValue aaa = new KeyValue(a, fam, qf, a);
|
||||||
KeyValue bbb = new KeyValue(b, fam, qf, b);
|
KeyValue bbb = new KeyValue(b, fam, qf, b);
|
||||||
assertTrue(KeyValue.COMPARATOR.compare(aaa, bbb) < 0);
|
assertTrue(KeyValue.COMPARATOR.compare(aaa, bbb) < 0);
|
||||||
|
@ -135,7 +133,7 @@ public class TestKeyValue extends TestCase {
|
||||||
assertTrue(KeyValue.COMPARATOR.compare(aaa, aaa) == 0);
|
assertTrue(KeyValue.COMPARATOR.compare(aaa, aaa) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMoreComparisons() throws Exception {
|
public void testMoreComparisons() {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
|
|
||||||
// Meta compares
|
// Meta compares
|
||||||
|
@ -176,9 +174,8 @@ public class TestKeyValue extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Tests cases where rows keys have characters below the ','.
|
* Tests cases where rows keys have characters below the ','.
|
||||||
* See HBASE-832
|
* See HBASE-832
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
public void testKeyValueBorderCases() throws IOException {
|
public void testKeyValueBorderCases() {
|
||||||
// % sorts before , so if we don't do special comparator, rowB would
|
// % sorts before , so if we don't do special comparator, rowB would
|
||||||
// come before rowA.
|
// come before rowA.
|
||||||
KeyValue rowA = new KeyValue(Bytes.toBytes("testtable,www.hbase.org/,1234"),
|
KeyValue rowA = new KeyValue(Bytes.toBytes("testtable,www.hbase.org/,1234"),
|
||||||
|
@ -192,7 +189,6 @@ public class TestKeyValue extends TestCase {
|
||||||
rowB = new KeyValue(Bytes.toBytes("testtable,$www.hbase.org/,99999"),
|
rowB = new KeyValue(Bytes.toBytes("testtable,$www.hbase.org/,99999"),
|
||||||
Bytes.toBytes("fam"), Bytes.toBytes(""), Long.MAX_VALUE, (byte[])null);
|
Bytes.toBytes("fam"), Bytes.toBytes(""), Long.MAX_VALUE, (byte[])null);
|
||||||
assertTrue(KeyValue.META_COMPARATOR.compare(rowA, rowB) < 0);
|
assertTrue(KeyValue.META_COMPARATOR.compare(rowA, rowB) < 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void metacomparisons(final KeyValue.MetaComparator c) {
|
private void metacomparisons(final KeyValue.MetaComparator c) {
|
||||||
|
@ -228,12 +224,12 @@ public class TestKeyValue extends TestCase {
|
||||||
Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,1"), now)) > 0);
|
Bytes.toBytes(TableName.META_TABLE_NAME.getNameAsString()+",,1"), now)) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBinaryKeys() throws Exception {
|
public void testBinaryKeys() {
|
||||||
Set<KeyValue> set = new TreeSet<KeyValue>(KeyValue.COMPARATOR);
|
Set<KeyValue> set = new TreeSet<>(KeyValue.COMPARATOR);
|
||||||
final byte [] fam = Bytes.toBytes("col");
|
final byte[] fam = Bytes.toBytes("col");
|
||||||
final byte [] qf = Bytes.toBytes("umn");
|
final byte[] qf = Bytes.toBytes("umn");
|
||||||
final byte [] nb = new byte[0];
|
final byte[] nb = new byte[0];
|
||||||
KeyValue [] keys = {new KeyValue(Bytes.toBytes("aaaaa,\u0000\u0000,2"), fam, qf, 2, nb),
|
KeyValue[] keys = {new KeyValue(Bytes.toBytes("aaaaa,\u0000\u0000,2"), fam, qf, 2, nb),
|
||||||
new KeyValue(Bytes.toBytes("aaaaa,\u0001,3"), fam, qf, 3, nb),
|
new KeyValue(Bytes.toBytes("aaaaa,\u0001,3"), fam, qf, 3, nb),
|
||||||
new KeyValue(Bytes.toBytes("aaaaa,,1"), fam, qf, 1, nb),
|
new KeyValue(Bytes.toBytes("aaaaa,,1"), fam, qf, 1, nb),
|
||||||
new KeyValue(Bytes.toBytes("aaaaa,\u1000,5"), fam, qf, 5, nb),
|
new KeyValue(Bytes.toBytes("aaaaa,\u1000,5"), fam, qf, 5, nb),
|
||||||
|
@ -246,8 +242,8 @@ public class TestKeyValue extends TestCase {
|
||||||
boolean assertion = false;
|
boolean assertion = false;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
try {
|
try {
|
||||||
for (KeyValue k: set) {
|
for (KeyValue k : set) {
|
||||||
assertTrue(count++ == k.getTimestamp());
|
assertEquals(count++, k.getTimestamp());
|
||||||
}
|
}
|
||||||
} catch (junit.framework.AssertionFailedError e) {
|
} catch (junit.framework.AssertionFailedError e) {
|
||||||
// Expected
|
// Expected
|
||||||
|
@ -255,11 +251,11 @@ public class TestKeyValue extends TestCase {
|
||||||
}
|
}
|
||||||
assertTrue(assertion);
|
assertTrue(assertion);
|
||||||
// Make set with good comparator
|
// Make set with good comparator
|
||||||
set = new TreeSet<KeyValue>(new KeyValue.MetaComparator());
|
set = new TreeSet<>(new KeyValue.MetaComparator());
|
||||||
Collections.addAll(set, keys);
|
Collections.addAll(set, keys);
|
||||||
count = 0;
|
count = 0;
|
||||||
for (KeyValue k: set) {
|
for (KeyValue k : set) {
|
||||||
assertTrue(count++ == k.getTimestamp());
|
assertEquals(count++, k.getTimestamp());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,11 +264,8 @@ public class TestKeyValue extends TestCase {
|
||||||
|
|
||||||
private final byte[] family = Bytes.toBytes("family");
|
private final byte[] family = Bytes.toBytes("family");
|
||||||
private final byte[] qualA = Bytes.toBytes("qfA");
|
private final byte[] qualA = Bytes.toBytes("qfA");
|
||||||
private final byte[] qualB = Bytes.toBytes("qfB");
|
|
||||||
|
|
||||||
private void assertKVLess(KeyValue.KVComparator c,
|
private void assertKVLess(KeyValue.KVComparator c, KeyValue less, KeyValue greater) {
|
||||||
KeyValue less,
|
|
||||||
KeyValue greater) {
|
|
||||||
int cmp = c.compare(less,greater);
|
int cmp = c.compare(less,greater);
|
||||||
assertTrue(cmp < 0);
|
assertTrue(cmp < 0);
|
||||||
cmp = c.compare(greater,less);
|
cmp = c.compare(greater,less);
|
||||||
|
@ -317,7 +310,7 @@ public class TestKeyValue extends TestCase {
|
||||||
assertKVLessWithoutRow(c, 0, kv0_1, kv1_0);
|
assertKVLessWithoutRow(c, 0, kv0_1, kv1_0);
|
||||||
|
|
||||||
// Test comparison by skipping the same prefix bytes.
|
// Test comparison by skipping the same prefix bytes.
|
||||||
/***
|
/*
|
||||||
* KeyValue Format and commonLength:
|
* KeyValue Format and commonLength:
|
||||||
* |_keyLen_|_valLen_|_rowLen_|_rowKey_|_famiLen_|_fami_|_Quali_|....
|
* |_keyLen_|_valLen_|_rowLen_|_rowKey_|_famiLen_|_fami_|_Quali_|....
|
||||||
* ------------------|-------commonLength--------|--------------
|
* ------------------|-------commonLength--------|--------------
|
||||||
|
@ -380,12 +373,12 @@ public class TestKeyValue extends TestCase {
|
||||||
assertKVLess(c, firstOnRowABufferFamQual, lastOnRowA);
|
assertKVLess(c, firstOnRowABufferFamQual, lastOnRowA);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCreateKeyOnly() throws Exception {
|
public void testCreateKeyOnly() {
|
||||||
long ts = 1;
|
long ts = 1;
|
||||||
byte [] value = Bytes.toBytes("a real value");
|
byte[] value = Bytes.toBytes("a real value");
|
||||||
byte [] evalue = new byte[0]; // empty value
|
byte[] evalue = new byte[0]; // empty value
|
||||||
|
|
||||||
for (byte[] val : new byte[][]{value, evalue}) {
|
for (byte[] val : new byte[][] { value, evalue }) {
|
||||||
for (boolean useLen : new boolean[]{false,true}) {
|
for (boolean useLen : new boolean[]{false,true}) {
|
||||||
KeyValue kv1 = new KeyValue(rowA, family, qualA, ts, val);
|
KeyValue kv1 = new KeyValue(rowA, family, qualA, ts, val);
|
||||||
KeyValue kv1ko = kv1.createKeyOnly(useLen);
|
KeyValue kv1ko = kv1.createKeyOnly(useLen);
|
||||||
|
@ -443,7 +436,8 @@ public class TestKeyValue extends TestCase {
|
||||||
byte[] metaValue1 = Bytes.toBytes("metaValue1");
|
byte[] metaValue1 = Bytes.toBytes("metaValue1");
|
||||||
byte[] metaValue2 = Bytes.toBytes("metaValue2");
|
byte[] metaValue2 = Bytes.toBytes("metaValue2");
|
||||||
KeyValue kv = new KeyValue(row, cf, q, HConstants.LATEST_TIMESTAMP, value, new Tag[] {
|
KeyValue kv = new KeyValue(row, cf, q, HConstants.LATEST_TIMESTAMP, value, new Tag[] {
|
||||||
new Tag((byte) 1, metaValue1), new Tag((byte) 2, metaValue2) });
|
new Tag((byte) 1, metaValue1), new Tag((byte) 2, metaValue2)
|
||||||
|
});
|
||||||
assertTrue(kv.getTagsLength() > 0);
|
assertTrue(kv.getTagsLength() > 0);
|
||||||
assertTrue(Bytes.equals(kv.getRowArray(), kv.getRowOffset(), kv.getRowLength(), row, 0,
|
assertTrue(Bytes.equals(kv.getRowArray(), kv.getRowOffset(), kv.getRowLength(), row, 0,
|
||||||
row.length));
|
row.length));
|
||||||
|
@ -544,7 +538,7 @@ public class TestKeyValue extends TestCase {
|
||||||
assertTrue(c.compare(a, b) < 0);
|
assertTrue(c.compare(a, b) < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEqualsAndHashCode() throws Exception {
|
public void testEqualsAndHashCode() {
|
||||||
KeyValue kvA1 = new KeyValue(Bytes.toBytes("key"), Bytes.toBytes("cf"),
|
KeyValue kvA1 = new KeyValue(Bytes.toBytes("key"), Bytes.toBytes("cf"),
|
||||||
Bytes.toBytes("qualA"), Bytes.toBytes("1"));
|
Bytes.toBytes("qualA"), Bytes.toBytes("1"));
|
||||||
KeyValue kvA2 = new KeyValue(Bytes.toBytes("key"), Bytes.toBytes("cf"),
|
KeyValue kvA2 = new KeyValue(Bytes.toBytes("key"), Bytes.toBytes("cf"),
|
||||||
|
@ -559,7 +553,6 @@ public class TestKeyValue extends TestCase {
|
||||||
assertNotEquals(kvA1, kvB);
|
assertNotEquals(kvA1, kvB);
|
||||||
assertEquals(kvA1.hashCode(), kvA2.hashCode());
|
assertEquals(kvA1.hashCode(), kvA2.hashCode());
|
||||||
assertNotEquals(kvA1.hashCode(), kvB.hashCode());
|
assertNotEquals(kvA1.hashCode(), kvB.hashCode());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKeyValueSerialization() throws Exception {
|
public void testKeyValueSerialization() throws Exception {
|
||||||
|
@ -570,8 +563,9 @@ public class TestKeyValue extends TestCase {
|
||||||
Bytes.toBytes("2")),
|
Bytes.toBytes("2")),
|
||||||
new KeyValue(Bytes.toBytes("key"), Bytes.toBytes("cf"), Bytes.toBytes("qualA"),
|
new KeyValue(Bytes.toBytes("key"), Bytes.toBytes("cf"), Bytes.toBytes("qualA"),
|
||||||
System.currentTimeMillis(), Bytes.toBytes("2"),
|
System.currentTimeMillis(), Bytes.toBytes("2"),
|
||||||
new Tag[] { new Tag((byte) 120, "tagA"),
|
new Tag[] {
|
||||||
new Tag((byte) 121, Bytes.toBytes("tagB")) }),
|
new Tag((byte) 120, "tagA"),
|
||||||
|
new Tag((byte) 121, Bytes.toBytes("tagB")) }),
|
||||||
new KeyValue(Bytes.toBytes("key"), Bytes.toBytes("cf"), Bytes.toBytes("qualA"),
|
new KeyValue(Bytes.toBytes("key"), Bytes.toBytes("cf"), Bytes.toBytes("qualA"),
|
||||||
System.currentTimeMillis(), Bytes.toBytes("2"),
|
System.currentTimeMillis(), Bytes.toBytes("2"),
|
||||||
new Tag[] { new Tag((byte) 0, "tagA") }),
|
new Tag[] { new Tag((byte) 0, "tagA") }),
|
||||||
|
@ -595,11 +589,11 @@ public class TestKeyValue extends TestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNullByteArrayKeyValueFailure() {
|
public void testNullByteArrayKeyValueFailure() {
|
||||||
//can't add to testCheckKeyValueBytesFailureCase because it
|
// can't add to testCheckKeyValueBytesFailureCase because it
|
||||||
//goes through the InputStream KeyValue API which can't produce a null buffer
|
// goes through the InputStream KeyValue API which can't produce a null buffer
|
||||||
try {
|
try {
|
||||||
KeyValue kv = new KeyValue(null, 0, 0);
|
new KeyValue(null, 0, 0);
|
||||||
} catch (IllegalArgumentException iae){
|
} catch (IllegalArgumentException iae) {
|
||||||
assertEquals("Invalid to have null byte array in KeyValue.", iae.getMessage());
|
assertEquals("Invalid to have null byte array in KeyValue.", iae.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -638,22 +632,22 @@ public class TestKeyValue extends TestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testCheckKeyValueBytesFailureCase() throws Exception {
|
public void testCheckKeyValueBytesFailureCase() throws Exception {
|
||||||
byte[][] inputs = new byte[][] { HConstants.EMPTY_BYTE_ARRAY, // case.0
|
byte[][] inputs = new byte[][] { HConstants.EMPTY_BYTE_ARRAY, // case.0
|
||||||
Bytes.toBytesBinary("a"), // case.1
|
Bytes.toBytesBinary("a"), // case.1
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x01"), // case.2
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x01"), // case.2
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x01\\x00"), // case.3
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x01\\x00"), // case.3
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x01"), // case.4
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x01"), // case.4
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x01\\x00"), // case.5
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x01\\x00"), // case.5
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x01\\x00\\x01"), // case.6
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x01\\x00\\x01"), // case.6
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x01\\x00\\x03ROW"), // case.7
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x01\\x00\\x03ROW"), // case.7
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01"), // case.8
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x01\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01"), // case.8
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\xFF"
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\xFF"
|
||||||
+ "\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF\\x03"), // case.9
|
+ "\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF\\x03"), // case.9
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
||||||
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x03"), // case.10
|
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x03"), // case.10
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
||||||
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04"), // case.11
|
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04"), // case.11
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
||||||
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04VALUE"), // case.12
|
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04VALUE"), // case.12
|
||||||
};
|
};
|
||||||
String[] outputs = new String[] { "Overflow when reading key length at position=0",
|
String[] outputs = new String[] { "Overflow when reading key length at position=0",
|
||||||
"Overflow when reading key length at position=0",
|
"Overflow when reading key length at position=0",
|
||||||
|
@ -668,32 +662,34 @@ public class TestKeyValue extends TestCase {
|
||||||
"Invalid tags length in KeyValue at position=26"};
|
"Invalid tags length in KeyValue at position=26"};
|
||||||
byte[][] withTagsInputs = new byte[][] {
|
byte[][] withTagsInputs = new byte[][] {
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
||||||
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x01"), // case.13
|
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x01"), // case.13
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
||||||
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x00\\x01"), // case.14
|
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x00\\x01"), // case.14
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
||||||
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x00\\x04\\x00\\x03\\x00A"), // case.15
|
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x00\\x04\\x00\\x03\\x00A"), // case.15
|
||||||
|
// case.16
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
||||||
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x00\\x0A\\x00\\x04\\x00TAG\\x00\\x04"
|
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x00\\x0A\\x00\\x04\\x00TAG\\x00\\x04"
|
||||||
+ "\\xFFT"), // case.16
|
+ "\\xFFT"),
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
||||||
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x00\\x0C\\x00\\x04\\x00TAG\\x00\\x05"
|
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x00\\x0C\\x00\\x04\\x00TAG\\x00\\x05"
|
||||||
+ "\\xF0COME\\x00"), // case.17
|
+ "\\xF0COME\\x00"), // case.17
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
||||||
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x00\\x0C\\x00\\x04\\x00TAG\\x00\\x05"
|
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x00\\x0C\\x00\\x04\\x00TAG\\x00\\x05"
|
||||||
+ "\\xF0COME"), // case.18
|
+ "\\xF0COME"), // case.18
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
||||||
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x00\\x00"), // case.19
|
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x00\\x00"), // case.19
|
||||||
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
Bytes.toBytesBinary("\\x00\\x00\\x00\\x11\\x00\\x00\\x00\\x01\\x00\\x03ROW\\x01FQ\\x00"
|
||||||
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x00\\x1B\\x00\\x05\\x01TAG1\\x00\\x05"
|
+ "\\x00\\x00\\x00\\x00\\x00\\x00\\x01\\x04V\\x00\\x1B\\x00\\x05\\x01TAG1\\x00\\x05"
|
||||||
+ "\\x02TAG2\\x00\\x05\\x03TAG3\\x00\\x05\\x04TAG4"), // case.20
|
+ "\\x02TAG2\\x00\\x05\\x03TAG3\\x00\\x05\\x04TAG4"), // case.20
|
||||||
};
|
};
|
||||||
String[] withTagsOutputs = new String[] { "Overflow when reading tags length at position=26",
|
String[] withTagsOutputs = new String[] { "Overflow when reading tags length at position=26",
|
||||||
"Invalid tags length in KeyValue at position=26",
|
"Invalid tags length in KeyValue at position=26",
|
||||||
"Invalid tag length at position=28, tagLength=3",
|
"Invalid tag length at position=28, tagLength=3",
|
||||||
"Invalid tag length at position=34, tagLength=4",
|
"Invalid tag length at position=34, tagLength=4",
|
||||||
"Some redundant bytes in KeyValue's buffer, startOffset=41, endOffset=42", null, null,
|
"Some redundant bytes in KeyValue's buffer, startOffset=41, endOffset=42", null, null,
|
||||||
null, };
|
null,
|
||||||
|
};
|
||||||
assertEquals(inputs.length, outputs.length);
|
assertEquals(inputs.length, outputs.length);
|
||||||
assertEquals(withTagsInputs.length, withTagsOutputs.length);
|
assertEquals(withTagsInputs.length, withTagsOutputs.length);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/**
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
* distributed with this work for additional information
|
* distributed with this work for additional information
|
||||||
|
@ -18,31 +18,33 @@
|
||||||
package org.apache.hadoop.hbase;
|
package org.apache.hadoop.hbase;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
import org.junit.rules.TestRule;
|
import org.junit.rules.TestRule;
|
||||||
import org.junit.rules.Timeout;
|
|
||||||
|
|
||||||
@Category({SmallTests.class})
|
@Category({SmallTests.class})
|
||||||
public class TestTimeout {
|
public class TestTimeout {
|
||||||
@Rule public final TestRule timeout = CategoryBasedTimeout.builder()
|
@Rule
|
||||||
|
public final TestRule timeout = CategoryBasedTimeout.builder()
|
||||||
.withTimeout(this.getClass())
|
.withTimeout(this.getClass())
|
||||||
.withLookingForStuckThread(true)
|
.withLookingForStuckThread(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void run1() throws InterruptedException {
|
public void run1() throws InterruptedException {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable to check if timeout works.
|
* Enable to check if timeout works.
|
||||||
* Can't enable as it waits 30seconds and expected doesn't do Exception catching
|
* Can't enable as it waits 30seconds and expected doesn't do Exception catching
|
||||||
*/
|
*/
|
||||||
@Ignore @Test
|
@Ignore
|
||||||
public void infiniteLoop() {
|
@Test
|
||||||
while (true) {}
|
public void infiniteLoop() {
|
||||||
}
|
while (true) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.hadoop.hbase;
|
package org.apache.hadoop.hbase;
|
||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
@ -25,8 +24,8 @@ import junit.framework.Assert;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.hbase.classification.InterfaceAudience;
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
import org.apache.hadoop.hbase.classification.InterfaceAudience;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that provides a standard waitFor pattern
|
* A class that provides a standard waitFor pattern
|
||||||
|
@ -34,7 +33,6 @@ import org.apache.hadoop.conf.Configuration;
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public final class Waiter {
|
public final class Waiter {
|
||||||
|
|
||||||
private static final Log LOG = LogFactory.getLog(Waiter.class);
|
private static final Log LOG = LogFactory.getLog(Waiter.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,18 +81,16 @@ public final class Waiter {
|
||||||
/**
|
/**
|
||||||
* A predicate 'closure' used by the {@link Waiter#waitFor(Configuration, long, Predicate)} and
|
* A predicate 'closure' used by the {@link Waiter#waitFor(Configuration, long, Predicate)} and
|
||||||
* {@link Waiter#waitFor(Configuration, long, Predicate)} and
|
* {@link Waiter#waitFor(Configuration, long, Predicate)} and
|
||||||
* {@link Waiter#waitFor(Configuration, long, long, boolean, Predicate) methods.
|
* {@link Waiter#waitFor(Configuration, long, long, boolean, Predicate)} methods.
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public interface Predicate<E extends Exception> {
|
public interface Predicate<E extends Exception> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a predicate evaluation.
|
* Perform a predicate evaluation.
|
||||||
* @return the boolean result of the evaluation.
|
* @return the boolean result of the evaluation.
|
||||||
* @throws Exception thrown if the predicate evaluation could not evaluate.
|
* @throws E thrown if the predicate evaluation could not evaluate.
|
||||||
*/
|
*/
|
||||||
boolean evaluate() throws E;
|
boolean evaluate() throws E;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,14 +98,12 @@ public final class Waiter {
|
||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public interface ExplainingPredicate<E extends Exception> extends Predicate<E> {
|
public interface ExplainingPredicate<E extends Exception> extends Predicate<E> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform a predicate evaluation.
|
* Perform a predicate evaluation.
|
||||||
*
|
*
|
||||||
* @return explanation of failed state
|
* @return explanation of failed state
|
||||||
*/
|
*/
|
||||||
String explainFailure() throws E;
|
String explainFailure() throws E;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -139,7 +133,7 @@ public final class Waiter {
|
||||||
* wait is interrupted otherwise <code>-1</code> when times out
|
* wait is interrupted otherwise <code>-1</code> when times out
|
||||||
*/
|
*/
|
||||||
public static <E extends Exception> long waitFor(Configuration conf, long timeout,
|
public static <E extends Exception> long waitFor(Configuration conf, long timeout,
|
||||||
Predicate<E> predicate) throws E {
|
Predicate<E> predicate) {
|
||||||
return waitFor(conf, timeout, 100, true, predicate);
|
return waitFor(conf, timeout, 100, true, predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +151,7 @@ public final class Waiter {
|
||||||
* wait is interrupted otherwise <code>-1</code> when times out
|
* wait is interrupted otherwise <code>-1</code> when times out
|
||||||
*/
|
*/
|
||||||
public static <E extends Exception> long waitFor(Configuration conf, long timeout, long interval,
|
public static <E extends Exception> long waitFor(Configuration conf, long timeout, long interval,
|
||||||
Predicate<E> predicate) throws E {
|
Predicate<E> predicate) {
|
||||||
return waitFor(conf, timeout, interval, true, predicate);
|
return waitFor(conf, timeout, interval, true, predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,14 +170,14 @@ public final class Waiter {
|
||||||
* wait is interrupted otherwise <code>-1</code> when times out
|
* wait is interrupted otherwise <code>-1</code> when times out
|
||||||
*/
|
*/
|
||||||
public static <E extends Exception> long waitFor(Configuration conf, long timeout, long interval,
|
public static <E extends Exception> long waitFor(Configuration conf, long timeout, long interval,
|
||||||
boolean failIfTimeout, Predicate<E> predicate) throws E {
|
boolean failIfTimeout, Predicate<E> predicate) {
|
||||||
long started = System.currentTimeMillis();
|
long started = System.currentTimeMillis();
|
||||||
long adjustedTimeout = (long) (getWaitForRatio(conf) * timeout);
|
long adjustedTimeout = (long) (getWaitForRatio(conf) * timeout);
|
||||||
long mustEnd = started + adjustedTimeout;
|
long mustEnd = started + adjustedTimeout;
|
||||||
long remainderWait = 0;
|
long remainderWait;
|
||||||
long sleepInterval = 0;
|
long sleepInterval;
|
||||||
Boolean eval = false;
|
boolean eval;
|
||||||
Boolean interrupted = false;
|
boolean interrupted = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LOG.info(MessageFormat.format("Waiting up to [{0}] milli-secs(wait.for.ratio=[{1}])",
|
LOG.info(MessageFormat.format("Waiting up to [{0}] milli-secs(wait.for.ratio=[{1}])",
|
||||||
|
@ -192,7 +186,7 @@ public final class Waiter {
|
||||||
&& (remainderWait = mustEnd - System.currentTimeMillis()) > 0) {
|
&& (remainderWait = mustEnd - System.currentTimeMillis()) > 0) {
|
||||||
try {
|
try {
|
||||||
// handle tail case when remainder wait is less than one interval
|
// handle tail case when remainder wait is less than one interval
|
||||||
sleepInterval = (remainderWait > interval) ? interval : remainderWait;
|
sleepInterval = Math.min(remainderWait, interval);
|
||||||
Thread.sleep(sleepInterval);
|
Thread.sleep(sleepInterval);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
eval = predicate.evaluate();
|
eval = predicate.evaluate();
|
||||||
|
@ -232,5 +226,4 @@ public final class Waiter {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,24 +15,26 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.hadoop.hbase.types;
|
package org.apache.hadoop.hbase.types;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.junit.Before;
|
import static org.junit.Assert.assertFalse;
|
||||||
import org.junit.Test;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import org.junit.experimental.categories.Category;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentNavigableMap;
|
import java.util.concurrent.ConcurrentNavigableMap;
|
||||||
import java.util.concurrent.ConcurrentSkipListMap;
|
import java.util.concurrent.ConcurrentSkipListMap;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.experimental.categories.Category;
|
||||||
|
|
||||||
@Category(SmallTests.class)
|
@Category(SmallTests.class)
|
||||||
public class TestCopyOnWriteMaps {
|
public class TestCopyOnWriteMaps {
|
||||||
|
|
||||||
private static final int MAX_RAND = 10 * 1000 * 1000;
|
private static final int MAX_RAND = 10 * 1000 * 1000;
|
||||||
private ConcurrentNavigableMap<Long, Long> m;
|
private ConcurrentNavigableMap<Long, Long> m;
|
||||||
private ConcurrentSkipListMap<Long, Long> csm;
|
private ConcurrentSkipListMap<Long, Long> csm;
|
||||||
|
@ -42,7 +44,7 @@ public class TestCopyOnWriteMaps {
|
||||||
m = new CopyOnWriteArrayMap<>();
|
m = new CopyOnWriteArrayMap<>();
|
||||||
csm = new ConcurrentSkipListMap<>();
|
csm = new ConcurrentSkipListMap<>();
|
||||||
|
|
||||||
for ( long i = 0 ; i < 10000; i++ ) {
|
for (long i = 0 ; i < 10000; i++) {
|
||||||
long o = ThreadLocalRandom.current().nextLong(MAX_RAND);
|
long o = ThreadLocalRandom.current().nextLong(MAX_RAND);
|
||||||
m.put(i, o);
|
m.put(i, o);
|
||||||
csm.put(i,o);
|
csm.put(i,o);
|
||||||
|
@ -53,12 +55,12 @@ public class TestCopyOnWriteMaps {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSize() throws Exception {
|
public void testSize() {
|
||||||
assertEquals("Size should always be equal", m.size(), csm.size());
|
assertEquals("Size should always be equal", m.size(), csm.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsEmpty() throws Exception {
|
public void testIsEmpty() {
|
||||||
m.clear();
|
m.clear();
|
||||||
assertTrue(m.isEmpty());
|
assertTrue(m.isEmpty());
|
||||||
m.put(100L, 100L);
|
m.put(100L, 100L);
|
||||||
|
@ -68,7 +70,7 @@ public class TestCopyOnWriteMaps {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindOnEmpty() throws Exception {
|
public void testFindOnEmpty() {
|
||||||
m.clear();
|
m.clear();
|
||||||
assertTrue(m.isEmpty());
|
assertTrue(m.isEmpty());
|
||||||
assertNull(m.get(100L));
|
assertNull(m.get(100L));
|
||||||
|
@ -76,81 +78,77 @@ public class TestCopyOnWriteMaps {
|
||||||
assertEquals(0, m.tailMap(100L).entrySet().size());
|
assertEquals(0, m.tailMap(100L).entrySet().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLowerKey() throws Exception {
|
public void testLowerKey() {
|
||||||
|
|
||||||
assertEquals(csm.lowerKey(400L), m.lowerKey(400L));
|
assertEquals(csm.lowerKey(400L), m.lowerKey(400L));
|
||||||
assertEquals(csm.lowerKey(-1L), m.lowerKey(-1L));
|
assertEquals(csm.lowerKey(-1L), m.lowerKey(-1L));
|
||||||
|
|
||||||
for ( int i =0 ; i < 100; i ++) {
|
for (int i = 0 ; i < 100; i++) {
|
||||||
Long key = ThreadLocalRandom.current().nextLong();
|
Long key = ThreadLocalRandom.current().nextLong();
|
||||||
assertEquals(csm.lowerKey(key), m.lowerKey(key));
|
assertEquals(csm.lowerKey(key), m.lowerKey(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFloorEntry() throws Exception {
|
public void testFloorEntry() {
|
||||||
for ( int i =0 ; i < 100; i ++) {
|
for (int i = 0 ; i < 100; i++) {
|
||||||
Long key = ThreadLocalRandom.current().nextLong();
|
Long key = ThreadLocalRandom.current().nextLong();
|
||||||
assertEquals(csm.floorEntry(key), m.floorEntry(key));
|
assertEquals(csm.floorEntry(key), m.floorEntry(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFloorKey() throws Exception {
|
public void testFloorKey() {
|
||||||
for ( int i =0 ; i < 100; i ++) {
|
for (int i = 0 ; i < 100; i++) {
|
||||||
Long key = ThreadLocalRandom.current().nextLong();
|
Long key = ThreadLocalRandom.current().nextLong();
|
||||||
assertEquals(csm.floorKey(key), m.floorKey(key));
|
assertEquals(csm.floorKey(key), m.floorKey(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCeilingKey() throws Exception {
|
public void testCeilingKey() {
|
||||||
|
|
||||||
assertEquals(csm.ceilingKey(4000L), m.ceilingKey(4000L));
|
assertEquals(csm.ceilingKey(4000L), m.ceilingKey(4000L));
|
||||||
assertEquals(csm.ceilingKey(400L), m.ceilingKey(400L));
|
assertEquals(csm.ceilingKey(400L), m.ceilingKey(400L));
|
||||||
assertEquals(csm.ceilingKey(-1L), m.ceilingKey(-1L));
|
assertEquals(csm.ceilingKey(-1L), m.ceilingKey(-1L));
|
||||||
|
|
||||||
for ( int i =0 ; i < 100; i ++) {
|
for (int i = 0 ; i < 100; i++) {
|
||||||
Long key = ThreadLocalRandom.current().nextLong();
|
Long key = ThreadLocalRandom.current().nextLong();
|
||||||
assertEquals(csm.ceilingKey(key), m.ceilingKey(key));
|
assertEquals(csm.ceilingKey(key), m.ceilingKey(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHigherKey() throws Exception {
|
public void testHigherKey() {
|
||||||
|
|
||||||
assertEquals(csm.higherKey(4000L), m.higherKey(4000L));
|
assertEquals(csm.higherKey(4000L), m.higherKey(4000L));
|
||||||
assertEquals(csm.higherKey(400L), m.higherKey(400L));
|
assertEquals(csm.higherKey(400L), m.higherKey(400L));
|
||||||
assertEquals(csm.higherKey(-1L), m.higherKey(-1L));
|
assertEquals(csm.higherKey(-1L), m.higherKey(-1L));
|
||||||
|
|
||||||
for ( int i =0 ; i < 100; i ++) {
|
for (int i = 0 ; i < 100; i++) {
|
||||||
Long key = ThreadLocalRandom.current().nextLong();
|
Long key = ThreadLocalRandom.current().nextLong();
|
||||||
assertEquals(csm.higherKey(key), m.higherKey(key));
|
assertEquals(csm.higherKey(key), m.higherKey(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemove() throws Exception {
|
public void testRemove() {
|
||||||
for (Map.Entry<Long, Long> e:csm.entrySet()) {
|
for (Map.Entry<Long, Long> e : csm.entrySet()) {
|
||||||
assertEquals(csm.remove(e.getKey()), m.remove(e.getKey()));
|
assertEquals(csm.remove(e.getKey()), m.remove(e.getKey()));
|
||||||
assertEquals(null, m.remove(e.getKey()));
|
assertNull(m.remove(e.getKey()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReplace() throws Exception {
|
public void testReplace() {
|
||||||
for (Map.Entry<Long, Long> e:csm.entrySet()) {
|
for (Map.Entry<Long, Long> e : csm.entrySet()) {
|
||||||
Long newValue = ThreadLocalRandom.current().nextLong();
|
Long newValue = ThreadLocalRandom.current().nextLong();
|
||||||
assertEquals(csm.replace(e.getKey(), newValue), m.replace(e.getKey(), newValue));
|
assertEquals(csm.replace(e.getKey(), newValue), m.replace(e.getKey(), newValue));
|
||||||
}
|
}
|
||||||
assertEquals(null, m.replace(MAX_RAND + 100L, ThreadLocalRandom.current().nextLong()));
|
assertNull(m.replace(MAX_RAND + 100L, ThreadLocalRandom.current().nextLong()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReplace1() throws Exception {
|
public void testReplace1() {
|
||||||
for (Map.Entry<Long, Long> e: csm.entrySet()) {
|
for (Map.Entry<Long, Long> e : csm.entrySet()) {
|
||||||
Long newValue = ThreadLocalRandom.current().nextLong();
|
Long newValue = ThreadLocalRandom.current().nextLong();
|
||||||
assertEquals(csm.replace(e.getKey(), e.getValue() + 1, newValue),
|
assertEquals(csm.replace(e.getKey(), e.getValue() + 1, newValue),
|
||||||
m.replace(e.getKey(), e.getValue() + 1, newValue));
|
m.replace(e.getKey(), e.getValue() + 1, newValue));
|
||||||
|
@ -159,18 +157,17 @@ public class TestCopyOnWriteMaps {
|
||||||
assertEquals(newValue, m.get(e.getKey()));
|
assertEquals(newValue, m.get(e.getKey()));
|
||||||
assertEquals(csm.get(e.getKey()), m.get(e.getKey()));
|
assertEquals(csm.get(e.getKey()), m.get(e.getKey()));
|
||||||
}
|
}
|
||||||
assertEquals(null, m.replace(MAX_RAND + 100L, ThreadLocalRandom.current().nextLong()));
|
assertNull(m.replace(MAX_RAND + 100L, ThreadLocalRandom.current().nextLong()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultiAdd() throws InterruptedException {
|
public void testMultiAdd() throws InterruptedException {
|
||||||
|
|
||||||
Thread[] threads = new Thread[10];
|
Thread[] threads = new Thread[10];
|
||||||
for ( int i =0 ; i<threads.length; i++) {
|
for (int i = 0 ; i < threads.length; i++) {
|
||||||
threads[i] = new Thread(new Runnable() {
|
threads[i] = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for ( int j = 0; j < 5000; j++) {
|
for (int j = 0; j < 5000; j++) {
|
||||||
m.put(ThreadLocalRandom.current().nextLong(),
|
m.put(ThreadLocalRandom.current().nextLong(),
|
||||||
ThreadLocalRandom.current().nextLong());
|
ThreadLocalRandom.current().nextLong());
|
||||||
}
|
}
|
||||||
|
@ -188,33 +185,32 @@ public class TestCopyOnWriteMaps {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFirstKey() throws Exception {
|
public void testFirstKey() {
|
||||||
assertEquals(csm.firstKey(), m.firstKey());
|
assertEquals(csm.firstKey(), m.firstKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLastKey() throws Exception {
|
public void testLastKey() {
|
||||||
assertEquals(csm.lastKey(), m.lastKey());
|
assertEquals(csm.lastKey(), m.lastKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFirstEntry() throws Exception {
|
public void testFirstEntry() {
|
||||||
assertEquals(csm.firstEntry().getKey(), m.firstEntry().getKey());
|
assertEquals(csm.firstEntry().getKey(), m.firstEntry().getKey());
|
||||||
assertEquals(csm.firstEntry().getValue(), m.firstEntry().getValue());
|
assertEquals(csm.firstEntry().getValue(), m.firstEntry().getValue());
|
||||||
assertEquals(csm.firstEntry(), m.firstEntry());
|
assertEquals(csm.firstEntry(), m.firstEntry());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLastEntry() throws Exception {
|
public void testLastEntry() {
|
||||||
assertEquals(csm.lastEntry().getKey(), m.lastEntry().getKey());
|
assertEquals(csm.lastEntry().getKey(), m.lastEntry().getKey());
|
||||||
assertEquals(csm.lastEntry().getValue(), m.lastEntry().getValue());
|
assertEquals(csm.lastEntry().getValue(), m.lastEntry().getValue());
|
||||||
assertEquals(csm.lastEntry(), m.lastEntry());
|
assertEquals(csm.lastEntry(), m.lastEntry());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKeys() throws Exception {
|
public void testKeys() {
|
||||||
for (Long key:csm.keySet()) {
|
for (Long key : csm.keySet()) {
|
||||||
//assertTrue(m.containsKey(key));
|
|
||||||
assertNotNull(m.get(key));
|
assertNotNull(m.get(key));
|
||||||
assertNotNull(m.remove(key));
|
assertNotNull(m.remove(key));
|
||||||
assertNull(m.get(key));
|
assertNull(m.get(key));
|
||||||
|
@ -222,30 +218,30 @@ public class TestCopyOnWriteMaps {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValues() throws Exception {
|
public void testValues() {
|
||||||
for (Long value:m.values()) {
|
for (Long value : m.values()) {
|
||||||
assertTrue(csm.values().contains(value));
|
assertTrue(csm.containsValue(value));
|
||||||
assertTrue(m.containsValue(value));
|
assertTrue(m.containsValue(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTailMap() throws Exception {
|
public void testTailMap() {
|
||||||
Map<Long, Long> fromCsm = csm.tailMap(50L);
|
Map<Long, Long> fromCsm = csm.tailMap(50L);
|
||||||
Map<Long, Long> fromM = m.tailMap(50L);
|
Map<Long, Long> fromM = m.tailMap(50L);
|
||||||
assertEquals(fromCsm, fromM);
|
assertEquals(fromCsm, fromM);
|
||||||
for (Long value:m.keySet()) {
|
for (Long value : m.keySet()) {
|
||||||
assertEquals(csm.tailMap(value), m.tailMap(value));
|
assertEquals(csm.tailMap(value), m.tailMap(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( long i = 0 ; i < 100; i++ ) {
|
for (long i = 0; i < 100; i++) {
|
||||||
long o = ThreadLocalRandom.current().nextLong(MAX_RAND);
|
long o = ThreadLocalRandom.current().nextLong(MAX_RAND);
|
||||||
assertEquals(csm.tailMap(o), m.tailMap(o));
|
assertEquals(csm.tailMap(o), m.tailMap(o));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTailMapExclusive() throws Exception {
|
public void testTailMapExclusive() {
|
||||||
m.clear();
|
m.clear();
|
||||||
m.put(100L, 100L);
|
m.put(100L, 100L);
|
||||||
m.put(101L, 101L);
|
m.put(101L, 101L);
|
||||||
|
@ -256,7 +252,7 @@ public class TestCopyOnWriteMaps {
|
||||||
|
|
||||||
long n = 100L;
|
long n = 100L;
|
||||||
CopyOnWriteArrayMap<Long,Long> tm99 = (CopyOnWriteArrayMap<Long, Long>) m.tailMap(99L, false);
|
CopyOnWriteArrayMap<Long,Long> tm99 = (CopyOnWriteArrayMap<Long, Long>) m.tailMap(99L, false);
|
||||||
for (Map.Entry<Long,Long> e:tm99.entrySet()) {
|
for (Map.Entry<Long,Long> e : tm99.entrySet()) {
|
||||||
assertEquals(new Long(n), e.getKey());
|
assertEquals(new Long(n), e.getKey());
|
||||||
assertEquals(new Long(n), e.getValue());
|
assertEquals(new Long(n), e.getValue());
|
||||||
n++;
|
n++;
|
||||||
|
@ -264,7 +260,7 @@ public class TestCopyOnWriteMaps {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTailMapInclusive() throws Exception {
|
public void testTailMapInclusive() {
|
||||||
m.clear();
|
m.clear();
|
||||||
m.put(100L, 100L);
|
m.put(100L, 100L);
|
||||||
m.put(101L, 101L);
|
m.put(101L, 101L);
|
||||||
|
@ -275,14 +271,14 @@ public class TestCopyOnWriteMaps {
|
||||||
|
|
||||||
long n = 102;
|
long n = 102;
|
||||||
CopyOnWriteArrayMap<Long,Long> tm102 = (CopyOnWriteArrayMap<Long, Long>) m.tailMap(102L, true);
|
CopyOnWriteArrayMap<Long,Long> tm102 = (CopyOnWriteArrayMap<Long, Long>) m.tailMap(102L, true);
|
||||||
for (Map.Entry<Long,Long> e:tm102.entrySet()) {
|
for (Map.Entry<Long,Long> e : tm102.entrySet()) {
|
||||||
assertEquals(new Long(n), e.getKey());
|
assertEquals(new Long(n), e.getKey());
|
||||||
assertEquals(new Long(n), e.getValue());
|
assertEquals(new Long(n), e.getValue());
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
n = 99;
|
n = 99;
|
||||||
CopyOnWriteArrayMap<Long,Long> tm98 = (CopyOnWriteArrayMap<Long, Long>) m.tailMap(98L, true);
|
CopyOnWriteArrayMap<Long,Long> tm98 = (CopyOnWriteArrayMap<Long, Long>) m.tailMap(98L, true);
|
||||||
for (Map.Entry<Long,Long> e:tm98.entrySet()) {
|
for (Map.Entry<Long,Long> e : tm98.entrySet()) {
|
||||||
assertEquals(new Long(n), e.getKey());
|
assertEquals(new Long(n), e.getKey());
|
||||||
assertEquals(new Long(n), e.getValue());
|
assertEquals(new Long(n), e.getValue());
|
||||||
n++;
|
n++;
|
||||||
|
@ -290,7 +286,7 @@ public class TestCopyOnWriteMaps {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPut() throws Exception {
|
public void testPut() {
|
||||||
m.clear();
|
m.clear();
|
||||||
m.put(100L, 100L);
|
m.put(100L, 100L);
|
||||||
m.put(101L, 101L);
|
m.put(101L, 101L);
|
||||||
|
@ -300,12 +296,12 @@ public class TestCopyOnWriteMaps {
|
||||||
m.put(102L, 102L);
|
m.put(102L, 102L);
|
||||||
long n = 99;
|
long n = 99;
|
||||||
|
|
||||||
for (Map.Entry<Long, Long> e:m.entrySet()) {
|
for (Map.Entry<Long, Long> e : m.entrySet()) {
|
||||||
assertEquals(new Long(n), e.getKey());
|
assertEquals(new Long(n), e.getKey());
|
||||||
assertEquals(new Long(n), e.getValue());
|
assertEquals(new Long(n), e.getValue());
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
assertEquals(5, m.size());
|
assertEquals(5, m.size());
|
||||||
assertEquals(false, m.isEmpty());
|
assertFalse(m.isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue