HBASE-14637 Loosen TestChoreService assert AND have TestDataBlockEncoders do less work (and add timeouts)

This commit is contained in:
stack 2015-10-17 16:14:45 -07:00
parent 9bdb88a572
commit 836afcc901
2 changed files with 22 additions and 6 deletions

View File

@ -38,8 +38,6 @@ import org.junit.experimental.categories.Category;
@Category(SmallTests.class)
public class TestChoreService {
private static final Log LOG = LogFactory.getLog(TestChoreService.class);
/**
* A few ScheduledChore samples that are useful for testing with ChoreService
*/
@ -373,7 +371,7 @@ public class TestChoreService {
final int period = 100;
final int delta = 5;
ChoreService service = ChoreService.getInstance("testForceTrigger");
CountingChore chore = new CountingChore("countingChore", period);
final CountingChore chore = new CountingChore("countingChore", period);
try {
service.scheduleChore(chore);
Thread.sleep(10 * period + delta);
@ -393,11 +391,12 @@ public class TestChoreService {
chore.triggerNow();
Thread.sleep(delta);
assertTrue(chore.getCountOfChoreCalls() == 16);
assertTrue("" + chore.getCountOfChoreCalls(), chore.getCountOfChoreCalls() == 16);
Thread.sleep(10 * period + delta);
assertTrue(chore.getCountOfChoreCalls() == 26);
// Be loosey-goosey. It used to be '26' but it was a big flakey relying on timing.
assertTrue("" + chore.getCountOfChoreCalls(), chore.getCountOfChoreCalls() > 16);
} finally {
shutdownService(service);
}

View File

@ -30,6 +30,10 @@ import java.util.Collection;
import java.util.List;
import java.util.Random;
import org.apache.hadoop.hbase.CategoryBasedTimeout;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellComparator;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@ -43,11 +47,14 @@ import org.apache.hadoop.hbase.io.hfile.HFileContext;
import org.apache.hadoop.hbase.io.hfile.HFileContextBuilder;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.test.RedundantKVGenerator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.mortbay.log.Log;
/**
* Test all of the data block encoding algorithms for correctness. Most of the
@ -56,9 +63,11 @@ import org.junit.runners.Parameterized.Parameters;
@Category(LargeTests.class)
@RunWith(Parameterized.class)
public class TestDataBlockEncoders {
@Rule public final TestRule timeout = CategoryBasedTimeout.builder().
withTimeout(this.getClass()).withLookingForStuckThread(true).build();
private static int NUMBER_OF_KV = 10000;
private static int NUM_RANDOM_SEEKS = 10000;
private static int NUM_RANDOM_SEEKS = 1000;
private static int ENCODED_DATA_OFFSET = HConstants.HFILEBLOCK_HEADER_SIZE
+ DataBlockEncoding.ID_SIZE;
@ -172,10 +181,15 @@ public class TestDataBlockEncoders {
List<DataBlockEncoder.EncodedSeeker> encodedSeekers =
new ArrayList<DataBlockEncoder.EncodedSeeker>();
for (DataBlockEncoding encoding : DataBlockEncoding.values()) {
Log.info("Encoding: " + encoding);
// Off heap block data support not added for PREFIX_TREE DBE yet.
// TODO remove this once support is added. HBASE-12298
if (encoding == DataBlockEncoding.PREFIX_TREE) continue;
DataBlockEncoder encoder = encoding.getEncoder();
if (encoder == null) {
continue;
}
Log.info("Encoder: " + encoder);
ByteBuffer encodedBuffer = encodeKeyValues(encoding, sampleKv,
getEncodingContext(Compression.Algorithm.NONE, encoding));
HFileContext meta = new HFileContextBuilder()
@ -189,6 +203,7 @@ public class TestDataBlockEncoders {
seeker.setCurrentBuffer(encodedBuffer);
encodedSeekers.add(seeker);
}
Log.info("Testing it!");
// test it!
// try a few random seeks
for (boolean seekBefore : new boolean[] { false, true }) {
@ -206,6 +221,7 @@ public class TestDataBlockEncoders {
}
// check edge cases
Log.info("Checking edge cases");
checkSeekingConsistency(encodedSeekers, false, sampleKv.get(0));
for (boolean seekBefore : new boolean[] { false, true }) {
checkSeekingConsistency(encodedSeekers, seekBefore, sampleKv.get(sampleKv.size() - 1));
@ -213,6 +229,7 @@ public class TestDataBlockEncoders {
KeyValue lastMidKv =KeyValueUtil.createLastOnRowCol(midKv);
checkSeekingConsistency(encodedSeekers, seekBefore, lastMidKv);
}
Log.info("Done");
}
static ByteBuffer encodeKeyValues(DataBlockEncoding encoding, List<KeyValue> kvs,