HBASE-5114 TestMetaReaderEditor can timeout during test execution

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1226269 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Zhihong Yu 2012-01-01 17:46:53 +00:00
parent c0c6500436
commit b549283c78
2 changed files with 46 additions and 66 deletions

View File

@ -50,8 +50,8 @@ import org.junit.experimental.categories.Category;
public class TestMetaReaderEditor {
private static final Log LOG = LogFactory.getLog(TestMetaReaderEditor.class);
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
private ZooKeeperWatcher zkw;
private CatalogTracker ct;
private static ZooKeeperWatcher zkw;
private static CatalogTracker ct;
private final static Abortable ABORTABLE = new Abortable() {
private final AtomicBoolean abort = new AtomicBoolean(false);
@ -70,9 +70,7 @@ public class TestMetaReaderEditor {
@BeforeClass public static void beforeClass() throws Exception {
UTIL.startMiniCluster(3);
}
@Before public void setup() throws IOException, InterruptedException {
Configuration c = new Configuration(UTIL.getConfiguration());
// Tests to 4 retries every 5 seconds. Make it try every 1 second so more
// responsive. 1 second is default as is ten retries.
@ -84,6 +82,7 @@ public class TestMetaReaderEditor {
}
@AfterClass public static void afterClass() throws Exception {
ABORTABLE.abort("test ending", null);
UTIL.shutdownMiniCluster();
}
@ -94,7 +93,7 @@ public class TestMetaReaderEditor {
* @throws IOException
* @throws InterruptedException
*/
@Test (timeout = 180000) public void testRetrying()
@Test public void testRetrying()
throws IOException, InterruptedException {
final String name = "testRetrying";
LOG.info("Started " + name);
@ -120,9 +119,18 @@ public class TestMetaReaderEditor {
};
reader.start();
writer.start();
// We're gonna check how it takes. If it takes too long, we will consider
// it as a fail. We can't put that in the @Test tag as we want to close
// the threads nicely
final long timeOut = 180000;
long startTime = System.currentTimeMillis();
try {
// Make sure reader and writer are working.
assertTrue(reader.isProgressing());
assertTrue(writer.isProgressing());
// Kill server hosting meta -- twice . See if our reader/writer ride over the
// meta moves. They'll need to retry.
for (int i = 0; i < 2; i++) {
@ -131,18 +139,29 @@ public class TestMetaReaderEditor {
int index = -1;
do {
index = UTIL.getMiniHBaseCluster().getServerWithMeta();
} while (index == -1);
}while (index == -1 &&
startTime + timeOut < System.currentTimeMillis());
if (index != -1){
UTIL.getMiniHBaseCluster().abortRegionServer(index);
UTIL.getMiniHBaseCluster().waitOnRegionServer(index);
}
assertTrue(reader.toString(), reader.isProgressing());
assertTrue(writer.toString(), writer.isProgressing());
}
assertTrue("reader: "+reader.toString(), reader.isProgressing());
assertTrue("writer: "+writer.toString(), writer.isProgressing());
} catch (IOException e) {
throw e;
} finally {
reader.stop = true;
writer.stop = true;
reader.join();
writer.join();
t.close();
}
long exeTime = System.currentTimeMillis() - startTime;
assertTrue("Timeout: test took " + exeTime / 1000 + " sec", exeTime < timeOut);
}
/**
* Thread that runs a MetaReader/MetaEditor task until asked stop.
@ -241,18 +260,12 @@ public class TestMetaReaderEditor {
final String name = "testScanMetaForTable";
LOG.info("Started " + name);
/** Create 5 tables
/** Create 2 tables
- testScanMetaForTable
- testScanMetaForTable0
- testScanMetaForTable1
- testScanMetaForTable2
- testScanMetaForTablf
**/
UTIL.createTable(Bytes.toBytes(name), HConstants.CATALOG_FAMILY);
for (int i = 3; i < 3; i ++) {
UTIL.createTable(Bytes.toBytes(name+i), HConstants.CATALOG_FAMILY);
}
// name that is +1 greater than the first one (e+1=f)
byte[] greaterName = Bytes.toBytes("testScanMetaForTablf");
UTIL.createTable(greaterName, HConstants.CATALOG_FAMILY);
@ -260,9 +273,6 @@ public class TestMetaReaderEditor {
// Now make sure we only get the regions from 1 of the tables at a time
assertEquals(1, MetaReader.getTableRegions(ct, Bytes.toBytes(name)).size());
for (int i = 3; i < 3; i ++) {
assertEquals(1, MetaReader.getTableRegions(ct, Bytes.toBytes(name+i)).size());
}
assertEquals(1, MetaReader.getTableRegions(ct, greaterName).size());
}

View File

@ -1305,36 +1305,6 @@ public class TestAdmin {
admin.createTable(htd, null);
}
@Test
public void testHundredsOfTable() throws IOException{
final int times = 100;
HColumnDescriptor fam1 = new HColumnDescriptor("fam1");
HColumnDescriptor fam2 = new HColumnDescriptor("fam2");
HColumnDescriptor fam3 = new HColumnDescriptor("fam3");
for(int i = 0; i < times; i++) {
HTableDescriptor htd = new HTableDescriptor("table"+i);
htd.addFamily(fam1);
htd.addFamily(fam2);
htd.addFamily(fam3);
this.admin.createTable(htd);
}
for(int i = 0; i < times; i++) {
String tableName = "table"+i;
this.admin.disableTable(tableName);
byte [] tableNameBytes = Bytes.toBytes(tableName);
assertTrue(this.admin.isTableDisabled(tableNameBytes));
this.admin.enableTable(tableName);
assertFalse(this.admin.isTableDisabled(tableNameBytes));
this.admin.disableTable(tableName);
assertTrue(this.admin.isTableDisabled(tableNameBytes));
this.admin.deleteTable(tableName);
}
}
/**
* For HBASE-2556
* @throws IOException