HBASE-3098 TestMetaReaderEditor is broken in TRUNK; hangs

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1006107 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2010-10-09 03:46:52 +00:00
parent 9b166c9e33
commit b7f3cfbf05
2 changed files with 34 additions and 24 deletions

View File

@ -380,9 +380,6 @@ public class CatalogTracker {
} }
Throwable t = null; Throwable t = null;
try { try {
// Am expecting only two possible exceptions here; unable
// to connect to the regionserver or NotServingRegionException wrapped
// in the hadoop rpc RemoteException.
return metaServer.getRegionInfo(regionName) != null; return metaServer.getRegionInfo(regionName) != null;
} catch (ConnectException e) { } catch (ConnectException e) {
t = e; t = e;
@ -393,6 +390,13 @@ public class CatalogTracker {
} else { } else {
throw e; throw e;
} }
} catch (IOException e) {
Throwable cause = e.getCause();
if (cause != null && cause instanceof EOFException) {
t = cause;
} else {
throw e;
}
} }
LOG.info("Failed verification of " + Bytes.toString(regionName) + "; " + t); LOG.info("Failed verification of " + Bytes.toString(regionName) + "; " + t);
return false; return false;

View File

@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
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.conf.Configuration;
import org.apache.hadoop.hbase.Abortable; import org.apache.hadoop.hbase.Abortable;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants;
@ -40,6 +41,7 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair; import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -49,8 +51,8 @@ import org.junit.Test;
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 static ZooKeeperWatcher ZKW; private ZooKeeperWatcher zkw;
private static CatalogTracker CT; private 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);
@ -63,12 +65,14 @@ public class TestMetaReaderEditor {
@BeforeClass public static void beforeClass() throws Exception { @BeforeClass public static void beforeClass() throws Exception {
UTIL.startMiniCluster(); UTIL.startMiniCluster();
ZKW = new ZooKeeperWatcher(UTIL.getConfiguration(), }
"TestMetaReaderEditor", ABORTABLE);
HConnection connection = @Before public void setup() throws IOException, InterruptedException {
HConnectionManager.getConnection(UTIL.getConfiguration()); Configuration c = new Configuration(UTIL.getConfiguration());
CT = new CatalogTracker(ZKW, connection, ABORTABLE); zkw = new ZooKeeperWatcher(c, "TestMetaReaderEditor", ABORTABLE);
CT.start(); HConnection connection = HConnectionManager.getConnection(c);
ct = new CatalogTracker(zkw, connection, ABORTABLE);
ct.start();
} }
@AfterClass public static void afterClass() throws IOException { @AfterClass public static void afterClass() throws IOException {
@ -78,50 +82,52 @@ public class TestMetaReaderEditor {
@Test public void testGetRegionsCatalogTables() @Test public void testGetRegionsCatalogTables()
throws IOException, InterruptedException { throws IOException, InterruptedException {
List<HRegionInfo> regions = List<HRegionInfo> regions =
MetaReader.getTableRegions(CT, HConstants.META_TABLE_NAME); MetaReader.getTableRegions(ct, HConstants.META_TABLE_NAME);
assertTrue(regions.size() >= 1); assertTrue(regions.size() >= 1);
assertTrue(MetaReader.getTableRegionsAndLocations(CT, assertTrue(MetaReader.getTableRegionsAndLocations(ct,
Bytes.toString(HConstants.META_TABLE_NAME)).size() >= 1); Bytes.toString(HConstants.META_TABLE_NAME)).size() >= 1);
assertTrue(MetaReader.getTableRegionsAndLocations(CT, assertTrue(MetaReader.getTableRegionsAndLocations(ct,
Bytes.toString(HConstants.ROOT_TABLE_NAME)).size() == 1); Bytes.toString(HConstants.ROOT_TABLE_NAME)).size() == 1);
} }
@Test public void testTableExists() throws IOException { @Test public void testTableExists() throws IOException {
final String name = "testTableExists"; final String name = "testTableExists";
final byte [] nameBytes = Bytes.toBytes(name); final byte [] nameBytes = Bytes.toBytes(name);
assertFalse(MetaReader.tableExists(CT, name)); assertFalse(MetaReader.tableExists(ct, name));
UTIL.createTable(nameBytes, HConstants.CATALOG_FAMILY); UTIL.createTable(nameBytes, HConstants.CATALOG_FAMILY);
assertTrue(MetaReader.tableExists(CT, name)); assertTrue(MetaReader.tableExists(ct, name));
HBaseAdmin admin = UTIL.getHBaseAdmin(); HBaseAdmin admin = UTIL.getHBaseAdmin();
admin.disableTable(name); admin.disableTable(name);
admin.deleteTable(name); admin.deleteTable(name);
assertFalse(MetaReader.tableExists(CT, name)); assertFalse(MetaReader.tableExists(ct, name));
assertTrue(MetaReader.tableExists(CT, assertTrue(MetaReader.tableExists(ct,
Bytes.toString(HConstants.META_TABLE_NAME))); Bytes.toString(HConstants.META_TABLE_NAME)));
assertTrue(MetaReader.tableExists(CT, assertTrue(MetaReader.tableExists(ct,
Bytes.toString(HConstants.ROOT_TABLE_NAME))); Bytes.toString(HConstants.ROOT_TABLE_NAME)));
} }
@Test public void testGetRegion() throws IOException, InterruptedException { @Test public void testGetRegion() throws IOException, InterruptedException {
final String name = "testGetRegion"; final String name = "testGetRegion";
LOG.info("Started " + name);
final byte [] nameBytes = Bytes.toBytes(name); final byte [] nameBytes = Bytes.toBytes(name);
HTable t = UTIL.createTable(nameBytes, HConstants.CATALOG_FAMILY); HTable t = UTIL.createTable(nameBytes, HConstants.CATALOG_FAMILY);
int regionCount = UTIL.createMultiRegions(t, HConstants.CATALOG_FAMILY); int regionCount = UTIL.createMultiRegions(t, HConstants.CATALOG_FAMILY);
// Test it works getting a region from user table. // Test it works getting a region from user table.
List<HRegionInfo> regions = MetaReader.getTableRegions(CT, nameBytes); List<HRegionInfo> regions = MetaReader.getTableRegions(ct, nameBytes);
assertEquals(regionCount, regions.size()); assertEquals(regionCount, regions.size());
Pair<HRegionInfo, HServerAddress> pair = Pair<HRegionInfo, HServerAddress> pair =
MetaReader.getRegion(CT, regions.get(0).getRegionName()); MetaReader.getRegion(ct, regions.get(0).getRegionName());
assertEquals(regions.get(0).getEncodedName(), assertEquals(regions.get(0).getEncodedName(),
pair.getFirst().getEncodedName()); pair.getFirst().getEncodedName());
// Test get on non-existent region. // Test get on non-existent region.
pair = MetaReader.getRegion(CT, Bytes.toBytes("nonexistent-region")); pair = MetaReader.getRegion(ct, Bytes.toBytes("nonexistent-region"));
assertNull(pair); assertNull(pair);
// Test it works getting a region from meta/root. // Test it works getting a region from meta/root.
pair = pair =
MetaReader.getRegion(CT, HRegionInfo.FIRST_META_REGIONINFO.getRegionName()); MetaReader.getRegion(ct, HRegionInfo.FIRST_META_REGIONINFO.getRegionName());
assertEquals(HRegionInfo.FIRST_META_REGIONINFO.getEncodedName(), assertEquals(HRegionInfo.FIRST_META_REGIONINFO.getEncodedName(),
pair.getFirst().getEncodedName()); pair.getFirst().getEncodedName());
LOG.info("Finished " + name);
} }
} }