You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2015/09/10 06:43:00 UTC
[4/4] hbase git commit: HBASE-14393 Have TestHFileEncryption clean up
after itself so it don't go all zombie on us
HBASE-14393 Have TestHFileEncryption clean up after itself so it don't go all zombie on us
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/41002526
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/41002526
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/41002526
Branch: refs/heads/branch-1.2
Commit: 41002526b3a3efe83a53ebe300c22417cfaea1c3
Parents: 807acca
Author: stack <st...@apache.org>
Authored: Wed Sep 9 21:41:25 2015 -0700
Committer: stack <st...@apache.org>
Committed: Wed Sep 9 21:42:46 2015 -0700
----------------------------------------------------------------------
.../hbase/io/hfile/TestHFileEncryption.java | 42 ++++++++++++--------
1 file changed, 25 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/41002526/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileEncryption.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileEncryption.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileEncryption.java
index 2379df5..83e3ae4 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileEncryption.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/TestHFileEncryption.java
@@ -62,6 +62,8 @@ public class TestHFileEncryption {
@BeforeClass
public static void setUp() throws Exception {
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_MASTERKEY_NAME_CONF_KEY, "hbase");
conf.setInt("hfile.format.version", 3);
@@ -155,32 +157,38 @@ public class TestHFileEncryption {
public void testHFileEncryptionMetadata() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration();
CacheConfig cacheConf = new CacheConfig(conf);
-
HFileContext fileContext = new HFileContextBuilder()
- .withEncryptionContext(cryptoContext)
- .build();
+ .withEncryptionContext(cryptoContext)
+ .build();
// write a simple encrypted hfile
Path path = new Path(TEST_UTIL.getDataTestDir(), "cryptometa.hfile");
FSDataOutputStream out = fs.create(path);
HFile.Writer writer = HFile.getWriterFactory(conf, cacheConf)
- .withOutputStream(out)
- .withFileContext(fileContext)
- .create();
- KeyValue kv = new KeyValue("foo".getBytes(), "f1".getBytes(), null, "value".getBytes());
- writer.append(kv);
- writer.close();
- out.close();
+ .withOutputStream(out)
+ .withFileContext(fileContext)
+ .create();
+ try {
+ KeyValue kv = new KeyValue("foo".getBytes(), "f1".getBytes(), null, "value".getBytes());
+ writer.append(kv);
+ } finally {
+ writer.close();
+ out.close();
+ }
// read it back in and validate correct crypto metadata
HFile.Reader reader = HFile.createReader(fs, path, cacheConf, conf);
- reader.loadFileInfo();
- FixedFileTrailer trailer = reader.getTrailer();
- assertNotNull(trailer.getEncryptionKey());
- Encryption.Context readerContext = reader.getFileContext().getEncryptionContext();
- assertEquals(readerContext.getCipher().getName(), cryptoContext.getCipher().getName());
- assertTrue(Bytes.equals(readerContext.getKeyBytes(),
- cryptoContext.getKeyBytes()));
+ try {
+ reader.loadFileInfo();
+ FixedFileTrailer trailer = reader.getTrailer();
+ assertNotNull(trailer.getEncryptionKey());
+ Encryption.Context readerContext = reader.getFileContext().getEncryptionContext();
+ assertEquals(readerContext.getCipher().getName(), cryptoContext.getCipher().getName());
+ assertTrue(Bytes.equals(readerContext.getKeyBytes(),
+ cryptoContext.getKeyBytes()));
+ } finally {
+ reader.close();
+ }
}
@Test(timeout=6000000)