HBASE-13181 TestHRegionReplayEvents.testReplayBulkLoadEvent fails frequently

This commit is contained in:
Matteo Bertozzi 2015-03-10 17:21:34 +00:00
parent 78d6a3402c
commit c4369d9a90
2 changed files with 36 additions and 22 deletions

View File

@ -90,7 +90,7 @@ public class TestBulkLoad {
private final Expectations callOnce; private final Expectations callOnce;
@Rule @Rule
public TestName name = new TestName(); public TestName name = new TestName();
public TestBulkLoad() throws IOException { public TestBulkLoad() throws IOException {
callOnce = new Expectations() { callOnce = new Expectations() {
{ {
@ -233,17 +233,24 @@ public class TestBulkLoad {
HFile.WriterFactory hFileFactory = HFile.getWriterFactoryNoCache(conf); HFile.WriterFactory hFileFactory = HFile.getWriterFactoryNoCache(conf);
// TODO We need a way to do this without creating files // TODO We need a way to do this without creating files
File hFileLocation = testFolder.newFile(); File hFileLocation = testFolder.newFile();
hFileFactory.withOutputStream(new FSDataOutputStream(new FileOutputStream(hFileLocation))); FSDataOutputStream out = new FSDataOutputStream(new FileOutputStream(hFileLocation));
hFileFactory.withFileContext(new HFileContext()); try {
HFile.Writer writer = hFileFactory.create(); hFileFactory.withOutputStream(out);
hFileFactory.withFileContext(new HFileContext());
writer.append(new KeyValue(CellUtil.createCell(randomBytes, HFile.Writer writer = hFileFactory.create();
family, try {
randomBytes, writer.append(new KeyValue(CellUtil.createCell(randomBytes,
0l, family,
KeyValue.Type.Put.getCode(), randomBytes,
randomBytes))); 0l,
writer.close(); KeyValue.Type.Put.getCode(),
randomBytes)));
} finally {
writer.close();
}
} finally {
out.close();
}
return hFileLocation.getAbsoluteFile().getAbsolutePath(); return hFileLocation.getAbsoluteFile().getAbsolutePath();
} }
@ -286,7 +293,7 @@ public class TestBulkLoad {
assertNotNull(desc); assertNotNull(desc);
if (tableName != null) { if (tableName != null) {
assertTrue(Bytes.equals(ProtobufUtil.toTableName(desc.getTableName()).getName(), assertTrue(Bytes.equals(ProtobufUtil.toTableName(desc.getTableName()).getName(),
tableName)); tableName));
} }
@ -297,7 +304,7 @@ public class TestBulkLoad {
assertTrue(Bytes.equals(Bytes.toBytes(store.getStoreHomeDir()), familyName)); assertTrue(Bytes.equals(Bytes.toBytes(store.getStoreHomeDir()), familyName));
assertEquals(storeFileNames.size(), store.getStoreFileCount()); assertEquals(storeFileNames.size(), store.getStoreFileCount());
} }
return true; return true;
} }

View File

@ -1452,7 +1452,7 @@ public class TestHRegionReplayEvents {
// close the region and open again. // close the region and open again.
primaryRegion.close(); primaryRegion.close();
primaryRegion = HRegion.openHRegion(rootDir, primaryHri, htd, walPrimary, CONF, rss, null); primaryRegion = HRegion.openHRegion(rootDir, primaryHri, htd, walPrimary, CONF, rss, null);
// bulk load a file into primary region // bulk load a file into primary region
Random random = new Random(); Random random = new Random();
byte[] randomValues = new byte[20]; byte[] randomValues = new byte[20];
@ -1515,13 +1515,20 @@ public class TestHRegionReplayEvents {
HFile.WriterFactory hFileFactory = HFile.getWriterFactoryNoCache(TEST_UTIL.getConfiguration()); HFile.WriterFactory hFileFactory = HFile.getWriterFactoryNoCache(TEST_UTIL.getConfiguration());
// TODO We need a way to do this without creating files // TODO We need a way to do this without creating files
Path testFile = new Path(testPath, UUID.randomUUID().toString()); Path testFile = new Path(testPath, UUID.randomUUID().toString());
hFileFactory.withOutputStream(TEST_UTIL.getTestFileSystem().create(testFile)); FSDataOutputStream out = TEST_UTIL.getTestFileSystem().create(testFile);
hFileFactory.withFileContext(new HFileContext()); try {
HFile.Writer writer = hFileFactory.create(); hFileFactory.withOutputStream(out);
hFileFactory.withFileContext(new HFileContext());
writer.append(new KeyValue(CellUtil.createCell(valueBytes, family, valueBytes, 0l, HFile.Writer writer = hFileFactory.create();
KeyValue.Type.Put.getCode(), valueBytes))); try {
writer.close(); writer.append(new KeyValue(CellUtil.createCell(valueBytes, family, valueBytes, 0l,
KeyValue.Type.Put.getCode(), valueBytes)));
} finally {
writer.close();
}
} finally {
out.close();
}
return testFile.toString(); return testFile.toString();
} }