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 2020/05/06 05:06:14 UTC
[hbase] branch branch-2.3 updated: HBASE-23976 Use nio for file
manipulation in TestVerifyBucketCacheFile (#1342)
This is an automated email from the ASF dual-hosted git repository.
stack pushed a commit to branch branch-2.3
in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/branch-2.3 by this push:
new d28b56f HBASE-23976 Use nio for file manipulation in TestVerifyBucketCacheFile (#1342)
d28b56f is described below
commit d28b56f1116dfb0c8f1e72a04e96707f48f9992a
Author: Nick Dimiduk <nd...@apache.org>
AuthorDate: Tue May 5 22:04:26 2020 -0700
HBASE-23976 Use nio for file manipulation in TestVerifyBucketCacheFile (#1342)
Signed-off-by: Wei-Chiu Chuang <we...@apache.org>
---
.../io/hfile/bucket/TestVerifyBucketCacheFile.java | 39 ++++++++++++----------
1 file changed, 22 insertions(+), 17 deletions(-)
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestVerifyBucketCacheFile.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestVerifyBucketCacheFile.java
index c34d315..e257816 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestVerifyBucketCacheFile.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/hfile/bucket/TestVerifyBucketCacheFile.java
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright The Apache Software Foundation
*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -19,14 +19,16 @@
package org.apache.hadoop.hbase.io.hfile.bucket;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
-
import java.io.BufferedWriter;
-import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.attribute.FileTime;
+import java.time.Instant;
import java.util.Arrays;
-
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
@@ -90,7 +92,7 @@ public class TestVerifyBucketCacheFile {
new BucketCache("file:" + testDir + "/bucket.cache", capacitySize, constructedBlockSize,
constructedBlockSizes, writeThreads, writerQLen, testDir + "/bucket.persistence");
long usedSize = bucketCache.getAllocator().getUsedSize();
- assertTrue(usedSize == 0);
+ assertEquals(0, usedSize);
CacheTestUtils.HFileBlockPair[] blocks =
CacheTestUtils.generateHFileBlocks(constructedBlockSize, 1);
// Add blocks
@@ -98,7 +100,7 @@ public class TestVerifyBucketCacheFile {
cacheAndWaitUntilFlushedToBucket(bucketCache, block.getBlockName(), block.getBlock());
}
usedSize = bucketCache.getAllocator().getUsedSize();
- assertTrue(usedSize != 0);
+ assertNotEquals(0, usedSize);
// 1.persist cache to file
bucketCache.shutdown();
// restore cache from file
@@ -110,8 +112,9 @@ public class TestVerifyBucketCacheFile {
bucketCache.shutdown();
// 2.delete bucket cache file
- File cacheFile = new File(testDir + "/bucket.cache");
- assertTrue(cacheFile.delete());
+ final java.nio.file.Path cacheFile =
+ FileSystems.getDefault().getPath(testDir.toString(), "bucket.cache");
+ assertTrue(Files.deleteIfExists(cacheFile));
// can't restore cache from file
bucketCache =
new BucketCache("file:" + testDir + "/bucket.cache", capacitySize, constructedBlockSize,
@@ -123,13 +126,14 @@ public class TestVerifyBucketCacheFile {
cacheAndWaitUntilFlushedToBucket(bucketCache, block.getBlockName(), block.getBlock());
}
usedSize = bucketCache.getAllocator().getUsedSize();
- assertTrue(usedSize != 0);
+ assertNotEquals(0, usedSize);
// persist cache to file
bucketCache.shutdown();
// 3.delete backingMap persistence file
- File mapFile = new File(testDir + "/bucket.persistence");
- assertTrue(mapFile.delete());
+ final java.nio.file.Path mapFile =
+ FileSystems.getDefault().getPath(testDir.toString(), "bucket.persistence");
+ assertTrue(Files.deleteIfExists(mapFile));
// can't restore cache from file
bucketCache =
new BucketCache("file:" + testDir + "/bucket.cache", capacitySize, constructedBlockSize,
@@ -157,7 +161,7 @@ public class TestVerifyBucketCacheFile {
new BucketCache("file:" + testDir + "/bucket.cache", capacitySize, constructedBlockSize,
constructedBlockSizes, writeThreads, writerQLen, testDir + "/bucket.persistence");
long usedSize = bucketCache.getAllocator().getUsedSize();
- assertTrue(usedSize == 0);
+ assertEquals(0, usedSize);
CacheTestUtils.HFileBlockPair[] blocks =
CacheTestUtils.generateHFileBlocks(constructedBlockSize, 1);
@@ -166,7 +170,7 @@ public class TestVerifyBucketCacheFile {
cacheAndWaitUntilFlushedToBucket(bucketCache, block.getBlockName(), block.getBlock());
}
usedSize = bucketCache.getAllocator().getUsedSize();
- assertTrue(usedSize != 0);
+ assertNotEquals(0, usedSize);
// persist cache to file
bucketCache.shutdown();
@@ -204,7 +208,7 @@ public class TestVerifyBucketCacheFile {
new BucketCache("file:" + testDir + "/bucket.cache", capacitySize, constructedBlockSize,
constructedBlockSizes, writeThreads, writerQLen, testDir + "/bucket.persistence");
long usedSize = bucketCache.getAllocator().getUsedSize();
- assertTrue(usedSize == 0);
+ assertEquals(0, usedSize);
CacheTestUtils.HFileBlockPair[] blocks =
CacheTestUtils.generateHFileBlocks(constructedBlockSize, 1);
@@ -213,13 +217,14 @@ public class TestVerifyBucketCacheFile {
cacheAndWaitUntilFlushedToBucket(bucketCache, block.getBlockName(), block.getBlock());
}
usedSize = bucketCache.getAllocator().getUsedSize();
- assertTrue(usedSize != 0);
+ assertNotEquals(0, usedSize);
// persist cache to file
bucketCache.shutdown();
// modified bucket cache file LastModifiedTime
- File file = new File(testDir + "/bucket.cache");
- assertTrue(file.setLastModified(System.currentTimeMillis() + 1000));
+ final java.nio.file.Path file =
+ FileSystems.getDefault().getPath(testDir.toString(), "bucket.cache");
+ Files.setLastModifiedTime(file, FileTime.from(Instant.now().plusMillis(1_000)));
// can't restore cache from file
bucketCache =
new BucketCache("file:" + testDir + "/bucket.cache", capacitySize, constructedBlockSize,