HBASE-14393 Have TestHFileEncryption clean up after itself so it don't go all zombie on us
This commit is contained in:
parent
0bcaa165ad
commit
28afeebf76
@ -62,6 +62,8 @@ public class TestHFileEncryption {
|
|||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
Configuration conf = TEST_UTIL.getConfiguration();
|
Configuration conf = TEST_UTIL.getConfiguration();
|
||||||
|
// Disable block cache in this test.
|
||||||
|
conf.setFloat(HConstants.HFILE_BLOCK_CACHE_SIZE_KEY, 0.0f);
|
||||||
conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
|
conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());
|
||||||
conf.set(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, "hbase");
|
conf.set(HConstants.CRYPTO_MASTERKEY_NAME_CONF_KEY, "hbase");
|
||||||
conf.setInt("hfile.format.version", 3);
|
conf.setInt("hfile.format.version", 3);
|
||||||
@ -155,32 +157,38 @@ public class TestHFileEncryption {
|
|||||||
public void testHFileEncryptionMetadata() throws Exception {
|
public void testHFileEncryptionMetadata() throws Exception {
|
||||||
Configuration conf = TEST_UTIL.getConfiguration();
|
Configuration conf = TEST_UTIL.getConfiguration();
|
||||||
CacheConfig cacheConf = new CacheConfig(conf);
|
CacheConfig cacheConf = new CacheConfig(conf);
|
||||||
|
|
||||||
HFileContext fileContext = new HFileContextBuilder()
|
HFileContext fileContext = new HFileContextBuilder()
|
||||||
.withEncryptionContext(cryptoContext)
|
.withEncryptionContext(cryptoContext)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// write a simple encrypted hfile
|
// write a simple encrypted hfile
|
||||||
Path path = new Path(TEST_UTIL.getDataTestDir(), "cryptometa.hfile");
|
Path path = new Path(TEST_UTIL.getDataTestDir(), "cryptometa.hfile");
|
||||||
FSDataOutputStream out = fs.create(path);
|
FSDataOutputStream out = fs.create(path);
|
||||||
HFile.Writer writer = HFile.getWriterFactory(conf, cacheConf)
|
HFile.Writer writer = HFile.getWriterFactory(conf, cacheConf)
|
||||||
.withOutputStream(out)
|
.withOutputStream(out)
|
||||||
.withFileContext(fileContext)
|
.withFileContext(fileContext)
|
||||||
.create();
|
.create();
|
||||||
KeyValue kv = new KeyValue("foo".getBytes(), "f1".getBytes(), null, "value".getBytes());
|
try {
|
||||||
writer.append(kv);
|
KeyValue kv = new KeyValue("foo".getBytes(), "f1".getBytes(), null, "value".getBytes());
|
||||||
writer.close();
|
writer.append(kv);
|
||||||
out.close();
|
} finally {
|
||||||
|
writer.close();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
// read it back in and validate correct crypto metadata
|
// read it back in and validate correct crypto metadata
|
||||||
HFile.Reader reader = HFile.createReader(fs, path, cacheConf, conf);
|
HFile.Reader reader = HFile.createReader(fs, path, cacheConf, conf);
|
||||||
reader.loadFileInfo();
|
try {
|
||||||
FixedFileTrailer trailer = reader.getTrailer();
|
reader.loadFileInfo();
|
||||||
assertNotNull(trailer.getEncryptionKey());
|
FixedFileTrailer trailer = reader.getTrailer();
|
||||||
Encryption.Context readerContext = reader.getFileContext().getEncryptionContext();
|
assertNotNull(trailer.getEncryptionKey());
|
||||||
assertEquals(readerContext.getCipher().getName(), cryptoContext.getCipher().getName());
|
Encryption.Context readerContext = reader.getFileContext().getEncryptionContext();
|
||||||
assertTrue(Bytes.equals(readerContext.getKeyBytes(),
|
assertEquals(readerContext.getCipher().getName(), cryptoContext.getCipher().getName());
|
||||||
cryptoContext.getKeyBytes()));
|
assertTrue(Bytes.equals(readerContext.getKeyBytes(),
|
||||||
|
cryptoContext.getKeyBytes()));
|
||||||
|
} finally {
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout=6000000)
|
@Test(timeout=6000000)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user