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

View File

@ -1305,36 +1305,6 @@ public class TestAdmin {
admin.createTable(htd, null); 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 * For HBASE-2556
* @throws IOException * @throws IOException