HBASE-5042 TestReadWriteConsistencyControl should be renamed

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1378804 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2012-08-30 05:27:29 +00:00
parent 8e7185b507
commit e88e87d7fe
1 changed files with 13 additions and 15 deletions

View File

@ -1,6 +1,4 @@
/** /**
* Copyright 2010 The Apache Software Foundation
*
* 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
@ -27,8 +25,12 @@ import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
/**
* This is a hammer test that verifies MultiVersionConsistencyControl in a
* multiple writer single reader scenario.
*/
@Category(SmallTests.class) @Category(SmallTests.class)
public class TestReadWriteConsistencyControl extends TestCase { public class TestMultiVersionConsistencyControl extends TestCase {
static class Writer implements Runnable { static class Writer implements Runnable {
final AtomicBoolean finished; final AtomicBoolean finished;
final MultiVersionConsistencyControl mvcc; final MultiVersionConsistencyControl mvcc;
@ -39,20 +41,20 @@ public class TestReadWriteConsistencyControl extends TestCase {
this.mvcc = mvcc; this.mvcc = mvcc;
this.status = status; this.status = status;
} }
private Random rnd = new Random(); private Random rnd = new Random();
public boolean failed = false; public boolean failed = false;
public void run() { public void run() {
while (!finished.get()) { while (!finished.get()) {
MultiVersionConsistencyControl.WriteEntry e = mvcc.beginMemstoreInsert(); MultiVersionConsistencyControl.WriteEntry e = mvcc.beginMemstoreInsert();
// System.out.println("Begin write: " + e.getWriteNumber()); // System.out.println("Begin write: " + e.getWriteNumber());
// 10 usec - 500usec (including 0) // 10 usec - 500usec (including 0)
int sleepTime = rnd.nextInt(500); int sleepTime = rnd.nextInt(500);
// 500 * 1000 = 500,000ns = 500 usec // 500 * 1000 = 500,000ns = 500 usec
// 1 * 100 = 100ns = 1usec // 1 * 100 = 100ns = 1usec
try { try {
if (sleepTime > 0) if (sleepTime > 0) Thread.sleep(0, sleepTime * 1000);
Thread.sleep(0, sleepTime * 1000);
} catch (InterruptedException e1) { } catch (InterruptedException e1) {
} }
try { try {
@ -84,8 +86,7 @@ public class TestReadWriteConsistencyControl extends TestCase {
long newPrev = mvcc.memstoreReadPoint(); long newPrev = mvcc.memstoreReadPoint();
if (newPrev < prev) { if (newPrev < prev) {
// serious problem. // serious problem.
System.out.println("Reader got out of order, prev: " + System.out.println("Reader got out of order, prev: " + prev + " next was: " + newPrev);
prev + " next was: " + newPrev);
readerFailed.set(true); readerFailed.set(true);
// might as well give up // might as well give up
failedAt.set(newPrev); failedAt.set(newPrev);
@ -97,11 +98,11 @@ public class TestReadWriteConsistencyControl extends TestCase {
// writer thread parallelism. // writer thread parallelism.
int n = 20; int n = 20;
Thread [] writers = new Thread[n]; Thread[] writers = new Thread[n];
AtomicBoolean [] statuses = new AtomicBoolean[n]; AtomicBoolean[] statuses = new AtomicBoolean[n];
Thread readThread = new Thread(reader); Thread readThread = new Thread(reader);
for (int i = 0 ; i < n ; ++i ) { for (int i = 0; i < n; ++i) {
statuses[i] = new AtomicBoolean(true); statuses[i] = new AtomicBoolean(true);
writers[i] = new Thread(new Writer(finished, mvcc, statuses[i])); writers[i] = new Thread(new Writer(finished, mvcc, statuses[i]));
writers[i].start(); writers[i].start();
@ -126,11 +127,8 @@ public class TestReadWriteConsistencyControl extends TestCase {
assertTrue(statuses[i].get()); assertTrue(statuses[i].get());
} }
} }
@org.junit.Rule @org.junit.Rule
public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu = public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu = new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
} }