HADOOP-2321 TestScanner2 does not release resources which sometimes cause the test to time out

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk/src/contrib/hbase@600443 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jim Kellerman 2007-12-03 08:28:32 +00:00
parent 7ac136887a
commit ffe660105a
3 changed files with 102 additions and 82 deletions

View File

@ -48,6 +48,8 @@ Trunk (unreleased changes)
HADOOP-2320 Committed TestGet2 is managled (breaks build). HADOOP-2320 Committed TestGet2 is managled (breaks build).
HADOOP-2322 getRow(row, TS) client interface not properly connected HADOOP-2322 getRow(row, TS) client interface not properly connected
HADOOP-2309 ConcurrentModificationException doing get of all region start keys HADOOP-2309 ConcurrentModificationException doing get of all region start keys
HADOOP-2321 TestScanner2 does not release resources which sometimes cause the
test to time out
IMPROVEMENTS IMPROVEMENTS
HADOOP-2401 Add convenience put method that takes writable HADOOP-2401 Add convenience put method that takes writable

View File

@ -122,11 +122,13 @@ public class HTable implements HConstants {
* other methods will throw an IllegalStateException * other methods will throw an IllegalStateException
*/ */
public synchronized void close() { public synchronized void close() {
if (!closed) {
closed = true; closed = true;
tableServers = null; tableServers = null;
batch.set(null); batch.set(null);
connection.close(tableName); connection.close(tableName);
} }
}
/** /**
* Verifies that no update is in progress * Verifies that no update is in progress
@ -361,6 +363,7 @@ public class HTable implements HConstants {
* Get all the data for the specified row at a specified timestamp * Get all the data for the specified row at a specified timestamp
* *
* @param row row key * @param row row key
* @param ts timestamp
* @return map of colums to values * @return map of colums to values
* @throws IOException * @throws IOException
*/ */

View File

@ -78,6 +78,7 @@ public class TestScanner2 extends HBaseClusterTestCase {
Text tableName = new Text(getName()); Text tableName = new Text(getName());
createTable(new HBaseAdmin(this.conf), tableName); createTable(new HBaseAdmin(this.conf), tableName);
HTable table = new HTable(this.conf, tableName); HTable table = new HTable(this.conf, tableName);
try {
final String lastKey = "aac"; final String lastKey = "aac";
addContent(new HTableIncommon(table), FIRST_COLKEY + ":"); addContent(new HTableIncommon(table), FIRST_COLKEY + ":");
HScannerInterface scanner = HScannerInterface scanner =
@ -87,6 +88,9 @@ public class TestScanner2 extends HBaseClusterTestCase {
LOG.info(e.getKey()); LOG.info(e.getKey());
assertTrue(e.getKey().getRow().toString().compareTo(lastKey) < 0); assertTrue(e.getKey().getRow().toString().compareTo(lastKey) < 0);
} }
} finally {
table.close();
}
} }
/** /**
@ -94,6 +98,7 @@ public class TestScanner2 extends HBaseClusterTestCase {
*/ */
public void testIterator() throws Exception { public void testIterator() throws Exception {
HTable table = new HTable(this.conf, HConstants.ROOT_TABLE_NAME); HTable table = new HTable(this.conf, HConstants.ROOT_TABLE_NAME);
try {
HScannerInterface scanner = HScannerInterface scanner =
table.obtainScanner(HConstants.COLUMN_FAMILY_ARRAY, table.obtainScanner(HConstants.COLUMN_FAMILY_ARRAY,
HConstants.EMPTY_START_ROW); HConstants.EMPTY_START_ROW);
@ -101,6 +106,9 @@ public class TestScanner2 extends HBaseClusterTestCase {
assertNotNull(e.getKey()); assertNotNull(e.getKey());
assertNotNull(e.getValue()); assertNotNull(e.getValue());
} }
} finally {
table.close();
}
} }
/** /**
@ -114,6 +122,7 @@ public class TestScanner2 extends HBaseClusterTestCase {
Text tableName = new Text(getName()); Text tableName = new Text(getName());
createTable(admin, tableName); createTable(admin, tableName);
HTable table = new HTable(this.conf, tableName); HTable table = new HTable(this.conf, tableName);
try {
// Add a row to columns without qualifiers and then two with. Make one // Add a row to columns without qualifiers and then two with. Make one
// numbers only so easy to find w/ a regex. // numbers only so easy to find w/ a regex.
long id = table.startUpdate(new Text(getName())); long id = table.startUpdate(new Text(getName()));
@ -126,6 +135,9 @@ public class TestScanner2 extends HBaseClusterTestCase {
checkRegexingScanner(table, firstColkeyFamily + "\\d+"); checkRegexingScanner(table, firstColkeyFamily + "\\d+");
// Do a new scan that only matches on column family. // Do a new scan that only matches on column family.
checkRegexingScanner(table, firstColkeyFamily + "$"); checkRegexingScanner(table, firstColkeyFamily + "$");
} finally {
table.close();
}
} }
/* /*
@ -170,6 +182,7 @@ public class TestScanner2 extends HBaseClusterTestCase {
// Enter data // Enter data
HTable table = new HTable(conf, tableName); HTable table = new HTable(conf, tableName);
try {
for (char i = FIRST_ROWKEY; i <= LAST_ROWKEY; i++) { for (char i = FIRST_ROWKEY; i <= LAST_ROWKEY; i++) {
Text rowKey = new Text(new String(new char[] { i })); Text rowKey = new Text(new String(new char[] { i }));
long lockID = table.startUpdate(rowKey); long lockID = table.startUpdate(rowKey);
@ -182,6 +195,9 @@ public class TestScanner2 extends HBaseClusterTestCase {
regExpFilterTest(table, colKeys); regExpFilterTest(table, colKeys);
rowFilterSetTest(table, colKeys); rowFilterSetTest(table, colKeys);
} finally {
table.close();
}
} }
/** /**
@ -269,6 +285,7 @@ public class TestScanner2 extends HBaseClusterTestCase {
*/ */
public void testSplitDeleteOneAddTwoRegions() throws IOException { public void testSplitDeleteOneAddTwoRegions() throws IOException {
HTable metaTable = new HTable(conf, HConstants.META_TABLE_NAME); HTable metaTable = new HTable(conf, HConstants.META_TABLE_NAME);
try {
// First add a new table. Its intial region will be added to META region. // First add a new table. Its intial region will be added to META region.
HBaseAdmin admin = new HBaseAdmin(conf); HBaseAdmin admin = new HBaseAdmin(conf);
Text tableName = new Text(getName()); Text tableName = new Text(getName());
@ -280,8 +297,7 @@ public class TestScanner2 extends HBaseClusterTestCase {
region.getRegionName().toString().startsWith(getName())); region.getRegionName().toString().startsWith(getName()));
// Now do what happens at split time; remove old region and then add two // Now do what happens at split time; remove old region and then add two
// new ones in its place. // new ones in its place.
removeRegionFromMETA(new HTable(conf, HConstants.META_TABLE_NAME), removeRegionFromMETA(metaTable, region.getRegionName());
region.getRegionName());
HTableDescriptor desc = region.getTableDesc(); HTableDescriptor desc = region.getTableDesc();
Path homedir = new Path(getName()); Path homedir = new Path(getName());
List<HRegion> newRegions = new ArrayList<HRegion>(2); List<HRegion> newRegions = new ArrayList<HRegion>(2);
@ -304,6 +320,9 @@ public class TestScanner2 extends HBaseClusterTestCase {
r.getLog().closeAndDelete(); r.getLog().closeAndDelete();
} }
} }
} finally {
metaTable.close();
}
} }
private List<HRegionInfo> scan(final HTable t) private List<HRegionInfo> scan(final HTable t)
@ -388,7 +407,6 @@ public class TestScanner2 extends HBaseClusterTestCase {
*/ */
private void removeRegionFromMETA(final HTable t, final Text regionName) private void removeRegionFromMETA(final HTable t, final Text regionName)
throws IOException { throws IOException {
try {
long lockid = t.startUpdate(regionName); long lockid = t.startUpdate(regionName);
t.delete(lockid, HConstants.COL_REGIONINFO); t.delete(lockid, HConstants.COL_REGIONINFO);
t.delete(lockid, HConstants.COL_SERVER); t.delete(lockid, HConstants.COL_SERVER);
@ -397,8 +415,5 @@ public class TestScanner2 extends HBaseClusterTestCase {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("Removed " + regionName + " from table " + t.getTableName()); LOG.debug("Removed " + regionName + " from table " + t.getTableName());
} }
} finally {
t.close();
}
} }
} }