HBASE-19545 Replace getBytes(StandardCharsets.UTF_8) with Bytes.toBytes

Signed-off-by: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
Peter Somogyi 2017-12-20 21:17:52 +01:00 committed by Chia-Ping Tsai
parent ccc3b2bbc0
commit 15ed748286
18 changed files with 120 additions and 172 deletions

View File

@ -23,7 +23,6 @@ import com.google.protobuf.RpcController;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.EnumSet; import java.util.EnumSet;
@ -1675,8 +1674,8 @@ public class HBaseAdmin implements Admin {
byte[][] encodedNameofRegionsToMerge = new byte[nameofRegionsToMerge.length][]; byte[][] encodedNameofRegionsToMerge = new byte[nameofRegionsToMerge.length][];
for(int i = 0; i < nameofRegionsToMerge.length; i++) { for(int i = 0; i < nameofRegionsToMerge.length; i++) {
encodedNameofRegionsToMerge[i] = HRegionInfo.isEncodedRegionName(nameofRegionsToMerge[i]) ? encodedNameofRegionsToMerge[i] = HRegionInfo.isEncodedRegionName(nameofRegionsToMerge[i]) ?
nameofRegionsToMerge[i] : HRegionInfo.encodeRegionName(nameofRegionsToMerge[i]) nameofRegionsToMerge[i] :
.getBytes(StandardCharsets.UTF_8); Bytes.toBytes(HRegionInfo.encodeRegionName(nameofRegionsToMerge[i]));
} }
TableName tableName = null; TableName tableName = null;
@ -1774,7 +1773,7 @@ public class HBaseAdmin implements Admin {
public Future<Void> splitRegionAsync(byte[] regionName, byte[] splitPoint) public Future<Void> splitRegionAsync(byte[] regionName, byte[] splitPoint)
throws IOException { throws IOException {
byte[] encodedNameofRegionToSplit = HRegionInfo.isEncodedRegionName(regionName) ? byte[] encodedNameofRegionToSplit = HRegionInfo.isEncodedRegionName(regionName) ?
regionName : HRegionInfo.encodeRegionName(regionName).getBytes(StandardCharsets.UTF_8); regionName : Bytes.toBytes(HRegionInfo.encodeRegionName(regionName));
Pair<RegionInfo, ServerName> pair = getRegion(regionName); Pair<RegionInfo, ServerName> pair = getRegion(regionName);
if (pair != null) { if (pair != null) {
if (pair.getFirst() != null && if (pair.getFirst() != null &&

View File

@ -28,6 +28,7 @@ import javax.security.sasl.SaslException;
import javax.security.sasl.SaslServer; import javax.security.sasl.SaslServer;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.yetus.audience.InterfaceAudience; import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -73,7 +74,7 @@ public class SaslUtil {
} }
static byte[] decodeIdentifier(String identifier) { static byte[] decodeIdentifier(String identifier) {
return Base64.decodeBase64(identifier.getBytes(StandardCharsets.UTF_8)); return Base64.decodeBase64(Bytes.toBytes(identifier));
} }
static char[] encodePassword(byte[] password) { static char[] encodePassword(byte[] password) {

View File

@ -20,19 +20,17 @@ package org.apache.hadoop.hbase;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.nio.charset.StandardCharsets;
import org.apache.hadoop.hbase.exceptions.DeserializationException; import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.exceptions.HBaseException; import org.apache.hadoop.hbase.exceptions.HBaseException;
import org.apache.hadoop.hbase.io.compress.Compression; import org.apache.hadoop.hbase.io.compress.Compression;
import org.apache.hadoop.hbase.io.compress.Compression.Algorithm; import org.apache.hadoop.hbase.io.compress.Compression.Algorithm;
import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding; import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
import org.apache.hadoop.hbase.regionserver.BloomType; import org.apache.hadoop.hbase.regionserver.BloomType;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.PrettyPrinter;
import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.BuilderStyleTest; import org.apache.hadoop.hbase.util.BuilderStyleTest;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.PrettyPrinter;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -100,7 +98,7 @@ public class TestHColumnDescriptor {
public void testHColumnDescriptorShouldThrowIAEWhenFamilyNameEmpty() throws Exception { public void testHColumnDescriptorShouldThrowIAEWhenFamilyNameEmpty() throws Exception {
expectedEx.expect(IllegalArgumentException.class); expectedEx.expect(IllegalArgumentException.class);
expectedEx.expectMessage("Column Family name can not be empty"); expectedEx.expectMessage("Column Family name can not be empty");
new HColumnDescriptor("".getBytes(StandardCharsets.UTF_8)); new HColumnDescriptor(Bytes.toBytes(""));
} }
/** /**

View File

@ -24,7 +24,6 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -88,10 +87,10 @@ public class TestAsyncProcess {
private static final Logger LOG = LoggerFactory.getLogger(TestAsyncProcess.class); private static final Logger LOG = LoggerFactory.getLogger(TestAsyncProcess.class);
private static final TableName DUMMY_TABLE = private static final TableName DUMMY_TABLE =
TableName.valueOf("DUMMY_TABLE"); TableName.valueOf("DUMMY_TABLE");
private static final byte[] DUMMY_BYTES_1 = "DUMMY_BYTES_1".getBytes(StandardCharsets.UTF_8); private static final byte[] DUMMY_BYTES_1 = Bytes.toBytes("DUMMY_BYTES_1");
private static final byte[] DUMMY_BYTES_2 = "DUMMY_BYTES_2".getBytes(StandardCharsets.UTF_8); private static final byte[] DUMMY_BYTES_2 = Bytes.toBytes("DUMMY_BYTES_2");
private static final byte[] DUMMY_BYTES_3 = "DUMMY_BYTES_3".getBytes(StandardCharsets.UTF_8); private static final byte[] DUMMY_BYTES_3 = Bytes.toBytes("DUMMY_BYTES_3");
private static final byte[] FAILS = "FAILS".getBytes(StandardCharsets.UTF_8); private static final byte[] FAILS = Bytes.toBytes("FAILS");
private static final Configuration CONF = new Configuration(); private static final Configuration CONF = new Configuration();
private static final ConnectionConfiguration CONNECTION_CONFIG = private static final ConnectionConfiguration CONNECTION_CONFIG =
new ConnectionConfiguration(CONF); new ConnectionConfiguration(CONF);
@ -987,7 +986,7 @@ public class TestAsyncProcess {
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
ap.incTaskCounters(Collections.singleton("dummy".getBytes(StandardCharsets.UTF_8)), sn); ap.incTaskCounters(Collections.singleton(Bytes.toBytes("dummy")), sn);
} }
final Thread myThread = Thread.currentThread(); final Thread myThread = Thread.currentThread();
@ -1018,7 +1017,7 @@ public class TestAsyncProcess {
public void run() { public void run() {
Threads.sleep(sleepTime); Threads.sleep(sleepTime);
while (controller.tasksInProgress.get() > 0) { while (controller.tasksInProgress.get() > 0) {
ap.decTaskCounters(Collections.singleton("dummy".getBytes(StandardCharsets.UTF_8)), sn); ap.decTaskCounters(Collections.singleton(Bytes.toBytes("dummy")), sn);
} }
} }
}; };

View File

@ -30,7 +30,6 @@ import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Iterator; import java.util.Iterator;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -45,6 +44,7 @@ import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.ScannerCallable.MoreResults; import org.apache.hadoop.hbase.client.ScannerCallable.MoreResults;
import org.apache.hadoop.hbase.ipc.RpcControllerFactory; import org.apache.hadoop.hbase.ipc.RpcControllerFactory;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
@ -132,8 +132,7 @@ public class TestClientScanner {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testNoResultsHint() throws IOException { public void testNoResultsHint() throws IOException {
final Result[] results = new Result[1]; final Result[] results = new Result[1];
KeyValue kv1 = new KeyValue("row".getBytes(StandardCharsets.UTF_8), KeyValue kv1 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("cf"), Bytes.toBytes("cq"), 1,
"cf".getBytes(StandardCharsets.UTF_8), "cq".getBytes(StandardCharsets.UTF_8), 1,
Type.Maximum); Type.Maximum);
results[0] = Result.create(new Cell[] {kv1}); results[0] = Result.create(new Cell[] {kv1});
@ -193,8 +192,7 @@ public class TestClientScanner {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testSizeLimit() throws IOException { public void testSizeLimit() throws IOException {
final Result[] results = new Result[1]; final Result[] results = new Result[1];
KeyValue kv1 = new KeyValue("row".getBytes(StandardCharsets.UTF_8), KeyValue kv1 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("cf"), Bytes.toBytes("cq"), 1,
"cf".getBytes(StandardCharsets.UTF_8), "cq".getBytes(StandardCharsets.UTF_8), 1,
Type.Maximum); Type.Maximum);
results[0] = Result.create(new Cell[] {kv1}); results[0] = Result.create(new Cell[] {kv1});
@ -251,14 +249,11 @@ public class TestClientScanner {
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testCacheLimit() throws IOException { public void testCacheLimit() throws IOException {
KeyValue kv1 = new KeyValue("row1".getBytes(StandardCharsets.UTF_8), KeyValue kv1 = new KeyValue(Bytes.toBytes("row1"), Bytes.toBytes("cf"), Bytes.toBytes("cq"), 1,
"cf".getBytes(StandardCharsets.UTF_8), "cq".getBytes(StandardCharsets.UTF_8), 1,
Type.Maximum); Type.Maximum);
KeyValue kv2 = new KeyValue("row2".getBytes(StandardCharsets.UTF_8), KeyValue kv2 = new KeyValue(Bytes.toBytes("row2"), Bytes.toBytes("cf"), Bytes.toBytes("cq"), 1,
"cf".getBytes(StandardCharsets.UTF_8), "cq".getBytes(StandardCharsets.UTF_8), 1,
Type.Maximum); Type.Maximum);
KeyValue kv3 = new KeyValue("row3".getBytes(StandardCharsets.UTF_8), KeyValue kv3 = new KeyValue(Bytes.toBytes("row3"), Bytes.toBytes("cf"), Bytes.toBytes("cq"), 1,
"cf".getBytes(StandardCharsets.UTF_8), "cq".getBytes(StandardCharsets.UTF_8), 1,
Type.Maximum); Type.Maximum);
final Result[] results = new Result[] {Result.create(new Cell[] {kv1}), final Result[] results = new Result[] {Result.create(new Cell[] {kv1}),
Result.create(new Cell[] {kv2}), Result.create(new Cell[] {kv3})}; Result.create(new Cell[] {kv2}), Result.create(new Cell[] {kv3})};
@ -331,8 +326,7 @@ public class TestClientScanner {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testNoMoreResults() throws IOException { public void testNoMoreResults() throws IOException {
final Result[] results = new Result[1]; final Result[] results = new Result[1];
KeyValue kv1 = new KeyValue("row".getBytes(StandardCharsets.UTF_8), KeyValue kv1 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("cf"), Bytes.toBytes("cq"), 1,
"cf".getBytes(StandardCharsets.UTF_8), "cq".getBytes(StandardCharsets.UTF_8), 1,
Type.Maximum); Type.Maximum);
results[0] = Result.create(new Cell[] {kv1}); results[0] = Result.create(new Cell[] {kv1});
@ -390,14 +384,12 @@ public class TestClientScanner {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testMoreResults() throws IOException { public void testMoreResults() throws IOException {
final Result[] results1 = new Result[1]; final Result[] results1 = new Result[1];
KeyValue kv1 = new KeyValue("row".getBytes(StandardCharsets.UTF_8), KeyValue kv1 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("cf"), Bytes.toBytes("cq"), 1,
"cf".getBytes(StandardCharsets.UTF_8), "cq".getBytes(StandardCharsets.UTF_8), 1,
Type.Maximum); Type.Maximum);
results1[0] = Result.create(new Cell[] {kv1}); results1[0] = Result.create(new Cell[] {kv1});
final Result[] results2 = new Result[1]; final Result[] results2 = new Result[1];
KeyValue kv2 = new KeyValue("row2".getBytes(StandardCharsets.UTF_8), KeyValue kv2 = new KeyValue(Bytes.toBytes("row2"), Bytes.toBytes("cf"), Bytes.toBytes("cq"), 1,
"cf".getBytes(StandardCharsets.UTF_8), "cq".getBytes(StandardCharsets.UTF_8), 1,
Type.Maximum); Type.Maximum);
results2[0] = Result.create(new Cell[] {kv2}); results2[0] = Result.create(new Cell[] {kv2});

View File

@ -17,14 +17,15 @@
*/ */
package org.apache.hadoop.hbase.client; package org.apache.hadoop.hbase.client;
import static org.junit.Assert.*; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
@ -34,8 +35,8 @@ public class TestDelayingRunner {
private static final TableName DUMMY_TABLE = private static final TableName DUMMY_TABLE =
TableName.valueOf("DUMMY_TABLE"); TableName.valueOf("DUMMY_TABLE");
private static final byte[] DUMMY_BYTES_1 = "DUMMY_BYTES_1".getBytes(StandardCharsets.UTF_8); private static final byte[] DUMMY_BYTES_1 = Bytes.toBytes("DUMMY_BYTES_1");
private static final byte[] DUMMY_BYTES_2 = "DUMMY_BYTES_2".getBytes(StandardCharsets.UTF_8); private static final byte[] DUMMY_BYTES_2 = Bytes.toBytes("DUMMY_BYTES_2");
private static HRegionInfo hri1 = private static HRegionInfo hri1 =
new HRegionInfo(DUMMY_TABLE, DUMMY_BYTES_1, DUMMY_BYTES_2, false, 1); new HRegionInfo(DUMMY_TABLE, DUMMY_BYTES_1, DUMMY_BYTES_2, false, 1);

View File

@ -21,9 +21,10 @@ package org.apache.hadoop.hbase.client;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -66,7 +67,6 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import com.fasterxml.jackson.databind.ObjectMapper;
/** /**
* Run tests that use the functionality of the Operation superclass for * Run tests that use the functionality of the Operation superclass for
@ -83,66 +83,53 @@ public class TestOperation {
private static List<Long> TS_LIST = Arrays.asList(2L, 3L, 5L); private static List<Long> TS_LIST = Arrays.asList(2L, 3L, 5L);
private static TimestampsFilter TS_FILTER = new TimestampsFilter(TS_LIST); private static TimestampsFilter TS_FILTER = new TimestampsFilter(TS_LIST);
private static String STR_TS_FILTER = private static String STR_TS_FILTER = TS_FILTER.getClass().getSimpleName() + " (3/3): [2, 3, 5]";
TS_FILTER.getClass().getSimpleName() + " (3/3): [2, 3, 5]";
private static List<Long> L_TS_LIST = private static List<Long> L_TS_LIST = Arrays.asList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L);
Arrays.asList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L); private static TimestampsFilter L_TS_FILTER = new TimestampsFilter(L_TS_LIST);
private static TimestampsFilter L_TS_FILTER =
new TimestampsFilter(L_TS_LIST);
private static String STR_L_TS_FILTER = private static String STR_L_TS_FILTER =
L_TS_FILTER.getClass().getSimpleName() + " (5/11): [0, 1, 2, 3, 4]"; L_TS_FILTER.getClass().getSimpleName() + " (5/11): [0, 1, 2, 3, 4]";
private static String COL_NAME_1 = "col1"; private static String COL_NAME_1 = "col1";
private static ColumnPrefixFilter COL_PRE_FILTER = private static ColumnPrefixFilter COL_PRE_FILTER =
new ColumnPrefixFilter(COL_NAME_1.getBytes(StandardCharsets.UTF_8)); new ColumnPrefixFilter(Bytes.toBytes(COL_NAME_1));
private static String STR_COL_PRE_FILTER = private static String STR_COL_PRE_FILTER =
COL_PRE_FILTER.getClass().getSimpleName() + " " + COL_NAME_1; COL_PRE_FILTER.getClass().getSimpleName() + " " + COL_NAME_1;
private static String COL_NAME_2 = "col2"; private static String COL_NAME_2 = "col2";
private static ColumnRangeFilter CR_FILTER = new ColumnRangeFilter( private static ColumnRangeFilter CR_FILTER =
COL_NAME_1.getBytes(StandardCharsets.UTF_8), true, new ColumnRangeFilter(Bytes.toBytes(COL_NAME_1), true, Bytes.toBytes(COL_NAME_2), false);
COL_NAME_2.getBytes(StandardCharsets.UTF_8), false);
private static String STR_CR_FILTER = CR_FILTER.getClass().getSimpleName() private static String STR_CR_FILTER = CR_FILTER.getClass().getSimpleName()
+ " [" + COL_NAME_1 + ", " + COL_NAME_2 + ")"; + " [" + COL_NAME_1 + ", " + COL_NAME_2 + ")";
private static int COL_COUNT = 9; private static int COL_COUNT = 9;
private static ColumnCountGetFilter CCG_FILTER = private static ColumnCountGetFilter CCG_FILTER = new ColumnCountGetFilter(COL_COUNT);
new ColumnCountGetFilter(COL_COUNT); private static String STR_CCG_FILTER = CCG_FILTER.getClass().getSimpleName() + " " + COL_COUNT;
private static String STR_CCG_FILTER =
CCG_FILTER.getClass().getSimpleName() + " " + COL_COUNT;
private static int LIMIT = 3; private static int LIMIT = 3;
private static int OFFSET = 4; private static int OFFSET = 4;
private static ColumnPaginationFilter CP_FILTER = private static ColumnPaginationFilter CP_FILTER = new ColumnPaginationFilter(LIMIT, OFFSET);
new ColumnPaginationFilter(LIMIT, OFFSET);
private static String STR_CP_FILTER = CP_FILTER.getClass().getSimpleName() private static String STR_CP_FILTER = CP_FILTER.getClass().getSimpleName()
+ " (" + LIMIT + ", " + OFFSET + ")"; + " (" + LIMIT + ", " + OFFSET + ")";
private static String STOP_ROW_KEY = "stop"; private static String STOP_ROW_KEY = "stop";
private static InclusiveStopFilter IS_FILTER = private static InclusiveStopFilter IS_FILTER =
new InclusiveStopFilter(STOP_ROW_KEY.getBytes(StandardCharsets.UTF_8)); new InclusiveStopFilter(Bytes.toBytes(STOP_ROW_KEY));
private static String STR_IS_FILTER = private static String STR_IS_FILTER =
IS_FILTER.getClass().getSimpleName() + " " + STOP_ROW_KEY; IS_FILTER.getClass().getSimpleName() + " " + STOP_ROW_KEY;
private static String PREFIX = "prefix"; private static String PREFIX = "prefix";
private static PrefixFilter PREFIX_FILTER = private static PrefixFilter PREFIX_FILTER = new PrefixFilter(Bytes.toBytes(PREFIX));
new PrefixFilter(PREFIX.getBytes(StandardCharsets.UTF_8));
private static String STR_PREFIX_FILTER = "PrefixFilter " + PREFIX; private static String STR_PREFIX_FILTER = "PrefixFilter " + PREFIX;
private static byte[][] PREFIXES = { private static byte[][] PREFIXES = { Bytes.toBytes("0"), Bytes.toBytes("1"), Bytes.toBytes("2") };
"0".getBytes(StandardCharsets.UTF_8), "1".getBytes(StandardCharsets.UTF_8), private static MultipleColumnPrefixFilter MCP_FILTER = new MultipleColumnPrefixFilter(PREFIXES);
"2".getBytes(StandardCharsets.UTF_8)};
private static MultipleColumnPrefixFilter MCP_FILTER =
new MultipleColumnPrefixFilter(PREFIXES);
private static String STR_MCP_FILTER = private static String STR_MCP_FILTER =
MCP_FILTER.getClass().getSimpleName() + " (3/3): [0, 1, 2]"; MCP_FILTER.getClass().getSimpleName() + " (3/3): [0, 1, 2]";
private static byte[][] L_PREFIXES = { private static byte[][] L_PREFIXES = {
"0".getBytes(StandardCharsets.UTF_8), "1".getBytes(StandardCharsets.UTF_8), Bytes.toBytes("0"), Bytes.toBytes("1"), Bytes.toBytes("2"), Bytes.toBytes("3"),
"2".getBytes(StandardCharsets.UTF_8), "3".getBytes(StandardCharsets.UTF_8), Bytes.toBytes("4"), Bytes.toBytes("5"), Bytes.toBytes("6"), Bytes.toBytes("7") };
"4".getBytes(StandardCharsets.UTF_8), "5".getBytes(StandardCharsets.UTF_8),
"6".getBytes(StandardCharsets.UTF_8), "7".getBytes(StandardCharsets.UTF_8)};
private static MultipleColumnPrefixFilter L_MCP_FILTER = private static MultipleColumnPrefixFilter L_MCP_FILTER =
new MultipleColumnPrefixFilter(L_PREFIXES); new MultipleColumnPrefixFilter(L_PREFIXES);
private static String STR_L_MCP_FILTER = private static String STR_L_MCP_FILTER =
@ -150,29 +137,25 @@ public class TestOperation {
private static int PAGE_SIZE = 9; private static int PAGE_SIZE = 9;
private static PageFilter PAGE_FILTER = new PageFilter(PAGE_SIZE); private static PageFilter PAGE_FILTER = new PageFilter(PAGE_SIZE);
private static String STR_PAGE_FILTER = private static String STR_PAGE_FILTER = PAGE_FILTER.getClass().getSimpleName() + " " + PAGE_SIZE;
PAGE_FILTER.getClass().getSimpleName() + " " + PAGE_SIZE;
private static SkipFilter SKIP_FILTER = new SkipFilter(L_TS_FILTER); private static SkipFilter SKIP_FILTER = new SkipFilter(L_TS_FILTER);
private static String STR_SKIP_FILTER = private static String STR_SKIP_FILTER =
SKIP_FILTER.getClass().getSimpleName() + " " + STR_L_TS_FILTER; SKIP_FILTER.getClass().getSimpleName() + " " + STR_L_TS_FILTER;
private static WhileMatchFilter WHILE_FILTER = private static WhileMatchFilter WHILE_FILTER = new WhileMatchFilter(L_TS_FILTER);
new WhileMatchFilter(L_TS_FILTER);
private static String STR_WHILE_FILTER = private static String STR_WHILE_FILTER =
WHILE_FILTER.getClass().getSimpleName() + " " + STR_L_TS_FILTER; WHILE_FILTER.getClass().getSimpleName() + " " + STR_L_TS_FILTER;
private static KeyOnlyFilter KEY_ONLY_FILTER = new KeyOnlyFilter(); private static KeyOnlyFilter KEY_ONLY_FILTER = new KeyOnlyFilter();
private static String STR_KEY_ONLY_FILTER = private static String STR_KEY_ONLY_FILTER = KEY_ONLY_FILTER.getClass().getSimpleName();
KEY_ONLY_FILTER.getClass().getSimpleName();
private static FirstKeyOnlyFilter FIRST_KEY_ONLY_FILTER = private static FirstKeyOnlyFilter FIRST_KEY_ONLY_FILTER = new FirstKeyOnlyFilter();
new FirstKeyOnlyFilter();
private static String STR_FIRST_KEY_ONLY_FILTER = private static String STR_FIRST_KEY_ONLY_FILTER =
FIRST_KEY_ONLY_FILTER.getClass().getSimpleName(); FIRST_KEY_ONLY_FILTER.getClass().getSimpleName();
private static CompareOp CMP_OP = CompareOp.EQUAL; private static CompareOp CMP_OP = CompareOp.EQUAL;
private static byte[] CMP_VALUE = "value".getBytes(StandardCharsets.UTF_8); private static byte[] CMP_VALUE = Bytes.toBytes("value");
private static BinaryComparator BC = new BinaryComparator(CMP_VALUE); private static BinaryComparator BC = new BinaryComparator(CMP_VALUE);
private static DependentColumnFilter DC_FILTER = private static DependentColumnFilter DC_FILTER =
new DependentColumnFilter(FAMILY, QUALIFIER, true, CMP_OP, BC); new DependentColumnFilter(FAMILY, QUALIFIER, true, CMP_OP, BC);
@ -185,14 +168,12 @@ public class TestOperation {
private static String STR_FAMILY_FILTER = private static String STR_FAMILY_FILTER =
FAMILY_FILTER.getClass().getSimpleName() + " (EQUAL, value)"; FAMILY_FILTER.getClass().getSimpleName() + " (EQUAL, value)";
private static QualifierFilter QUALIFIER_FILTER = private static QualifierFilter QUALIFIER_FILTER = new QualifierFilter(CMP_OP, BC);
new QualifierFilter(CMP_OP, BC);
private static String STR_QUALIFIER_FILTER = private static String STR_QUALIFIER_FILTER =
QUALIFIER_FILTER.getClass().getSimpleName() + " (EQUAL, value)"; QUALIFIER_FILTER.getClass().getSimpleName() + " (EQUAL, value)";
private static RowFilter ROW_FILTER = new RowFilter(CMP_OP, BC); private static RowFilter ROW_FILTER = new RowFilter(CMP_OP, BC);
private static String STR_ROW_FILTER = private static String STR_ROW_FILTER = ROW_FILTER.getClass().getSimpleName() + " (EQUAL, value)";
ROW_FILTER.getClass().getSimpleName() + " (EQUAL, value)";
private static ValueFilter VALUE_FILTER = new ValueFilter(CMP_OP, BC); private static ValueFilter VALUE_FILTER = new ValueFilter(CMP_OP, BC);
private static String STR_VALUE_FILTER = private static String STR_VALUE_FILTER =
@ -209,19 +190,16 @@ public class TestOperation {
new SingleColumnValueExcludeFilter(FAMILY, QUALIFIER, CMP_OP, CMP_VALUE); new SingleColumnValueExcludeFilter(FAMILY, QUALIFIER, CMP_OP, CMP_VALUE);
private static String STR_SCVE_FILTER = String.format("%s (%s, %s, %s, %s)", private static String STR_SCVE_FILTER = String.format("%s (%s, %s, %s, %s)",
SCVE_FILTER.getClass().getSimpleName(), Bytes.toStringBinary(FAMILY), SCVE_FILTER.getClass().getSimpleName(), Bytes.toStringBinary(FAMILY),
Bytes.toStringBinary(QUALIFIER), CMP_OP.name(), Bytes.toStringBinary(QUALIFIER), CMP_OP.name(), Bytes.toStringBinary(CMP_VALUE));
Bytes.toStringBinary(CMP_VALUE));
private static FilterList AND_FILTER_LIST = new FilterList( private static FilterList AND_FILTER_LIST = new FilterList(
Operator.MUST_PASS_ALL, Arrays.asList((Filter) TS_FILTER, L_TS_FILTER, Operator.MUST_PASS_ALL, Arrays.asList((Filter) TS_FILTER, L_TS_FILTER, CR_FILTER));
CR_FILTER));
private static String STR_AND_FILTER_LIST = String.format( private static String STR_AND_FILTER_LIST = String.format(
"%s AND (3/3): [%s, %s, %s]", AND_FILTER_LIST.getClass().getSimpleName(), "%s AND (3/3): [%s, %s, %s]", AND_FILTER_LIST.getClass().getSimpleName(),
STR_TS_FILTER, STR_L_TS_FILTER, STR_CR_FILTER); STR_TS_FILTER, STR_L_TS_FILTER, STR_CR_FILTER);
private static FilterList OR_FILTER_LIST = new FilterList( private static FilterList OR_FILTER_LIST = new FilterList(
Operator.MUST_PASS_ONE, Arrays.asList((Filter) TS_FILTER, L_TS_FILTER, Operator.MUST_PASS_ONE, Arrays.asList((Filter) TS_FILTER, L_TS_FILTER, CR_FILTER));
CR_FILTER));
private static String STR_OR_FILTER_LIST = String.format( private static String STR_OR_FILTER_LIST = String.format(
"%s OR (3/3): [%s, %s, %s]", AND_FILTER_LIST.getClass().getSimpleName(), "%s OR (3/3): [%s, %s, %s]", AND_FILTER_LIST.getClass().getSimpleName(),
STR_TS_FILTER, STR_L_TS_FILTER, STR_CR_FILTER); STR_TS_FILTER, STR_L_TS_FILTER, STR_CR_FILTER);

View File

@ -24,7 +24,6 @@ import static org.junit.Assert.fail;
import java.io.IOException; import java.io.IOException;
import java.io.InterruptedIOException; import java.io.InterruptedIOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -53,9 +52,9 @@ public class TestSimpleRequestController {
private static final TableName DUMMY_TABLE private static final TableName DUMMY_TABLE
= TableName.valueOf("DUMMY_TABLE"); = TableName.valueOf("DUMMY_TABLE");
private static final byte[] DUMMY_BYTES_1 = "DUMMY_BYTES_1".getBytes(StandardCharsets.UTF_8); private static final byte[] DUMMY_BYTES_1 = Bytes.toBytes("DUMMY_BYTES_1");
private static final byte[] DUMMY_BYTES_2 = "DUMMY_BYTES_2".getBytes(StandardCharsets.UTF_8); private static final byte[] DUMMY_BYTES_2 = Bytes.toBytes("DUMMY_BYTES_2");
private static final byte[] DUMMY_BYTES_3 = "DUMMY_BYTES_3".getBytes(StandardCharsets.UTF_8); private static final byte[] DUMMY_BYTES_3 = Bytes.toBytes("DUMMY_BYTES_3");
private static final ServerName SN = ServerName.valueOf("s1,1,1"); private static final ServerName SN = ServerName.valueOf("s1,1,1");
private static final ServerName SN2 = ServerName.valueOf("s2,2,2"); private static final ServerName SN2 = ServerName.valueOf("s2,2,2");
private static final HRegionInfo HRI1 private static final HRegionInfo HRI1

View File

@ -27,10 +27,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import org.apache.hadoop.hbase.shaded.com.google.common.base.Strings;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import javax.security.auth.callback.Callback; import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.CallbackHandler;
@ -46,6 +43,7 @@ import javax.security.sasl.SaslClient;
import org.apache.hadoop.hbase.security.AbstractHBaseSaslRpcClient.SaslClientCallbackHandler; import org.apache.hadoop.hbase.security.AbstractHBaseSaslRpcClient.SaslClientCallbackHandler;
import org.apache.hadoop.hbase.testclassification.SecurityTests; import org.apache.hadoop.hbase.testclassification.SecurityTests;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.DataInputBuffer; import org.apache.hadoop.io.DataInputBuffer;
import org.apache.hadoop.io.DataOutputBuffer; import org.apache.hadoop.io.DataOutputBuffer;
import org.apache.hadoop.security.token.Token; import org.apache.hadoop.security.token.Token;
@ -59,6 +57,8 @@ import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.apache.hadoop.hbase.shaded.com.google.common.base.Strings;
@Category({SecurityTests.class, SmallTests.class}) @Category({SecurityTests.class, SmallTests.class})
public class TestHBaseSaslRpcClient { public class TestHBaseSaslRpcClient {
@ -99,18 +99,15 @@ public class TestHBaseSaslRpcClient {
@Test @Test
public void testSaslClientCallbackHandler() throws UnsupportedCallbackException { public void testSaslClientCallbackHandler() throws UnsupportedCallbackException {
final Token<? extends TokenIdentifier> token = createTokenMock(); final Token<? extends TokenIdentifier> token = createTokenMock();
when(token.getIdentifier()) when(token.getIdentifier()).thenReturn(Bytes.toBytes(DEFAULT_USER_NAME));
.thenReturn(DEFAULT_USER_NAME.getBytes(StandardCharsets.UTF_8)); when(token.getPassword()).thenReturn(Bytes.toBytes(DEFAULT_USER_PASSWORD));
when(token.getPassword())
.thenReturn(DEFAULT_USER_PASSWORD.getBytes(StandardCharsets.UTF_8));
final NameCallback nameCallback = mock(NameCallback.class); final NameCallback nameCallback = mock(NameCallback.class);
final PasswordCallback passwordCallback = mock(PasswordCallback.class); final PasswordCallback passwordCallback = mock(PasswordCallback.class);
final RealmCallback realmCallback = mock(RealmCallback.class); final RealmCallback realmCallback = mock(RealmCallback.class);
final RealmChoiceCallback realmChoiceCallback = mock(RealmChoiceCallback.class); final RealmChoiceCallback realmChoiceCallback = mock(RealmChoiceCallback.class);
Callback[] callbackArray = {nameCallback, passwordCallback, Callback[] callbackArray = {nameCallback, passwordCallback, realmCallback, realmChoiceCallback};
realmCallback, realmChoiceCallback};
final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token); final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token);
saslClCallbackHandler.handle(callbackArray); saslClCallbackHandler.handle(callbackArray);
verify(nameCallback).setName(anyString()); verify(nameCallback).setName(anyString());
@ -121,10 +118,8 @@ public class TestHBaseSaslRpcClient {
@Test @Test
public void testSaslClientCallbackHandlerWithException() { public void testSaslClientCallbackHandlerWithException() {
final Token<? extends TokenIdentifier> token = createTokenMock(); final Token<? extends TokenIdentifier> token = createTokenMock();
when(token.getIdentifier()) when(token.getIdentifier()).thenReturn(Bytes.toBytes(DEFAULT_USER_NAME));
.thenReturn(DEFAULT_USER_NAME.getBytes(StandardCharsets.UTF_8)); when(token.getPassword()).thenReturn(Bytes.toBytes(DEFAULT_USER_PASSWORD));
when(token.getPassword())
.thenReturn(DEFAULT_USER_PASSWORD.getBytes(StandardCharsets.UTF_8));
final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token); final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token);
try { try {
saslClCallbackHandler.handle(new Callback[] { mock(TextOutputCallback.class) }); saslClCallbackHandler.handle(new Callback[] { mock(TextOutputCallback.class) });
@ -294,10 +289,8 @@ public class TestHBaseSaslRpcClient {
throws IOException { throws IOException {
Token<? extends TokenIdentifier> token = createTokenMock(); Token<? extends TokenIdentifier> token = createTokenMock();
if (!Strings.isNullOrEmpty(principal) && !Strings.isNullOrEmpty(password)) { if (!Strings.isNullOrEmpty(principal) && !Strings.isNullOrEmpty(password)) {
when(token.getIdentifier()) when(token.getIdentifier()).thenReturn(Bytes.toBytes(DEFAULT_USER_NAME));
.thenReturn(DEFAULT_USER_NAME.getBytes(StandardCharsets.UTF_8)); when(token.getPassword()).thenReturn(Bytes.toBytes(DEFAULT_USER_PASSWORD));
when(token.getPassword())
.thenReturn(DEFAULT_USER_PASSWORD.getBytes(StandardCharsets.UTF_8));
} }
return token; return token;
} }

View File

@ -928,7 +928,7 @@ public class Base64 {
bytes = s.getBytes(PREFERRED_ENCODING); bytes = s.getBytes(PREFERRED_ENCODING);
} catch (UnsupportedEncodingException uee) { } catch (UnsupportedEncodingException uee) {
bytes = s.getBytes(StandardCharsets.UTF_8); bytes = Bytes.toBytes(s);
} // end catch } // end catch
// Decode // Decode

View File

@ -26,7 +26,6 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.NavigableMap; import java.util.NavigableMap;
@ -316,8 +315,8 @@ public class TestCellUtil {
@Test @Test
public void testFindCommonPrefixInFlatKey() { public void testFindCommonPrefixInFlatKey() {
// The whole key matching case // The whole key matching case
KeyValue kv1 = new KeyValue("r1".getBytes(StandardCharsets.UTF_8), KeyValue kv1 = new KeyValue(Bytes.toBytes("r1"), Bytes.toBytes("f1"),
"f1".getBytes(StandardCharsets.UTF_8), "q1".getBytes(StandardCharsets.UTF_8), null); Bytes.toBytes("q1"), null);
Assert.assertEquals(kv1.getKeyLength(), Assert.assertEquals(kv1.getKeyLength(),
PrivateCellUtil.findCommonPrefixInFlatKey(kv1, kv1, true, true)); PrivateCellUtil.findCommonPrefixInFlatKey(kv1, kv1, true, true));
Assert.assertEquals(kv1.getKeyLength(), Assert.assertEquals(kv1.getKeyLength(),
@ -325,35 +324,35 @@ public class TestCellUtil {
Assert.assertEquals(kv1.getKeyLength() - KeyValue.TIMESTAMP_TYPE_SIZE, Assert.assertEquals(kv1.getKeyLength() - KeyValue.TIMESTAMP_TYPE_SIZE,
PrivateCellUtil.findCommonPrefixInFlatKey(kv1, kv1, true, false)); PrivateCellUtil.findCommonPrefixInFlatKey(kv1, kv1, true, false));
// The rk length itself mismatch // The rk length itself mismatch
KeyValue kv2 = new KeyValue("r12".getBytes(StandardCharsets.UTF_8), KeyValue kv2 = new KeyValue(Bytes.toBytes("r12"), Bytes.toBytes("f1"),
"f1".getBytes(StandardCharsets.UTF_8), "q1".getBytes(StandardCharsets.UTF_8), null); Bytes.toBytes("q1"), null);
Assert.assertEquals(1, PrivateCellUtil.findCommonPrefixInFlatKey(kv1, kv2, true, true)); Assert.assertEquals(1, PrivateCellUtil.findCommonPrefixInFlatKey(kv1, kv2, true, true));
// part of rk is same // part of rk is same
KeyValue kv3 = new KeyValue("r14".getBytes(StandardCharsets.UTF_8), KeyValue kv3 = new KeyValue(Bytes.toBytes("r14"), Bytes.toBytes("f1"),
"f1".getBytes(StandardCharsets.UTF_8), "q1".getBytes(StandardCharsets.UTF_8), null); Bytes.toBytes("q1"), null);
Assert.assertEquals(KeyValue.ROW_LENGTH_SIZE + "r1".getBytes(StandardCharsets.UTF_8).length, Assert.assertEquals(KeyValue.ROW_LENGTH_SIZE + Bytes.toBytes("r1").length,
PrivateCellUtil.findCommonPrefixInFlatKey(kv2, kv3, true, true)); PrivateCellUtil.findCommonPrefixInFlatKey(kv2, kv3, true, true));
// entire rk is same but different cf name // entire rk is same but different cf name
KeyValue kv4 = new KeyValue("r14".getBytes(StandardCharsets.UTF_8), KeyValue kv4 = new KeyValue(Bytes.toBytes("r14"), Bytes.toBytes("f2"),
"f2".getBytes(StandardCharsets.UTF_8), "q1".getBytes(StandardCharsets.UTF_8), null); Bytes.toBytes("q1"), null);
Assert.assertEquals(KeyValue.ROW_LENGTH_SIZE + kv3.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE Assert.assertEquals(KeyValue.ROW_LENGTH_SIZE + kv3.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE
+ "f".getBytes(StandardCharsets.UTF_8).length, + Bytes.toBytes("f").length,
PrivateCellUtil.findCommonPrefixInFlatKey(kv3, kv4, false, true)); PrivateCellUtil.findCommonPrefixInFlatKey(kv3, kv4, false, true));
// rk and family are same and part of qualifier // rk and family are same and part of qualifier
KeyValue kv5 = new KeyValue("r14".getBytes(StandardCharsets.UTF_8), KeyValue kv5 = new KeyValue(Bytes.toBytes("r14"), Bytes.toBytes("f2"),
"f2".getBytes(StandardCharsets.UTF_8), "q123".getBytes(StandardCharsets.UTF_8), null); Bytes.toBytes("q123"), null);
Assert.assertEquals(KeyValue.ROW_LENGTH_SIZE + kv3.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE Assert.assertEquals(KeyValue.ROW_LENGTH_SIZE + kv3.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE
+ kv4.getFamilyLength() + kv4.getQualifierLength(), + kv4.getFamilyLength() + kv4.getQualifierLength(),
PrivateCellUtil.findCommonPrefixInFlatKey(kv4, kv5, true, true)); PrivateCellUtil.findCommonPrefixInFlatKey(kv4, kv5, true, true));
// rk, cf and q are same. ts differs // rk, cf and q are same. ts differs
KeyValue kv6 = new KeyValue("rk".getBytes(StandardCharsets.UTF_8), 1234L); KeyValue kv6 = new KeyValue(Bytes.toBytes("rk"), 1234L);
KeyValue kv7 = new KeyValue("rk".getBytes(StandardCharsets.UTF_8), 1235L); KeyValue kv7 = new KeyValue(Bytes.toBytes("rk"), 1235L);
// only last byte out of 8 ts bytes in ts part differs // only last byte out of 8 ts bytes in ts part differs
Assert.assertEquals(KeyValue.ROW_LENGTH_SIZE + kv6.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE Assert.assertEquals(KeyValue.ROW_LENGTH_SIZE + kv6.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE
+ kv6.getFamilyLength() + kv6.getQualifierLength() + 7, + kv6.getFamilyLength() + kv6.getQualifierLength() + 7,
PrivateCellUtil.findCommonPrefixInFlatKey(kv6, kv7, true, true)); PrivateCellUtil.findCommonPrefixInFlatKey(kv6, kv7, true, true));
// rk, cf, q and ts are same. Only type differs // rk, cf, q and ts are same. Only type differs
KeyValue kv8 = new KeyValue("rk".getBytes(StandardCharsets.UTF_8), 1234L, Type.Delete); KeyValue kv8 = new KeyValue(Bytes.toBytes("rk"), 1234L, Type.Delete);
Assert.assertEquals(KeyValue.ROW_LENGTH_SIZE + kv6.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE Assert.assertEquals(KeyValue.ROW_LENGTH_SIZE + kv6.getRowLength() + KeyValue.FAMILY_LENGTH_SIZE
+ kv6.getFamilyLength() + kv6.getQualifierLength() + KeyValue.TIMESTAMP_SIZE, + kv6.getFamilyLength() + kv6.getQualifierLength() + KeyValue.TIMESTAMP_SIZE,
PrivateCellUtil.findCommonPrefixInFlatKey(kv6, kv8, true, true)); PrivateCellUtil.findCommonPrefixInFlatKey(kv6, kv8, true, true));

View File

@ -23,7 +23,6 @@ import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -119,11 +118,11 @@ public class TestTableName extends TestWatcher {
Names(String ns, String tn) { Names(String ns, String tn) {
this.ns = ns; this.ns = ns;
nsb = ns.getBytes(StandardCharsets.UTF_8); nsb = Bytes.toBytes(ns);
this.tn = tn; this.tn = tn;
tnb = tn.getBytes(StandardCharsets.UTF_8); tnb = Bytes.toBytes(tn);
nn = this.ns + ":" + this.tn; nn = this.ns + ":" + this.tn;
nnb = nn.getBytes(StandardCharsets.UTF_8); nnb = Bytes.toBytes(nn);
} }
@Override @Override

View File

@ -22,7 +22,6 @@ import static org.junit.Assert.assertNotNull;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.Key; import java.security.Key;
import java.security.KeyStore; import java.security.KeyStore;
import java.security.MessageDigest; import java.security.MessageDigest;
@ -32,6 +31,7 @@ import javax.crypto.spec.SecretKeySpec;
import org.apache.hadoop.hbase.HBaseCommonTestingUtility; import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
@ -52,7 +52,7 @@ public class TestKeyStoreKeyProvider {
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
KEY = MessageDigest.getInstance("SHA-256").digest(ALIAS.getBytes(StandardCharsets.UTF_8)); KEY = MessageDigest.getInstance("SHA-256").digest(Bytes.toBytes(ALIAS));
// Create a JKECS store containing a test secret key // Create a JKECS store containing a test secret key
KeyStore store = KeyStore.getInstance("JCEKS"); KeyStore store = KeyStore.getInstance("JCEKS");
store.load(null, PASSWORD.toCharArray()); store.load(null, PASSWORD.toCharArray());

View File

@ -21,7 +21,6 @@ import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
@ -70,15 +69,10 @@ public class TestStruct {
}; };
Object[][] pojo2Args = { Object[][] pojo2Args = {
new Object[] { new byte[0], "it".getBytes(StandardCharsets.UTF_8), "was", new Object[] { new byte[0], Bytes.toBytes("it"), "was", Bytes.toBytes("the") },
"the".getBytes(StandardCharsets.UTF_8) }, new Object[] { Bytes.toBytes("best"), new byte[0], "of", Bytes.toBytes("times,") },
new Object[] { "best".getBytes(StandardCharsets.UTF_8), new byte[0], "of", new Object[] { Bytes.toBytes("it"), Bytes.toBytes("was"), "", Bytes.toBytes("the") },
"times,".getBytes(StandardCharsets.UTF_8) }, new Object[] { Bytes.toBytes("worst"), Bytes.toBytes("of"), "times,", new byte[0] },
new Object[] { "it".getBytes(StandardCharsets.UTF_8),
"was".getBytes(StandardCharsets.UTF_8), "",
"the".getBytes(StandardCharsets.UTF_8) },
new Object[] { "worst".getBytes(StandardCharsets.UTF_8),
"of".getBytes(StandardCharsets.UTF_8), "times,", new byte[0] },
new Object[] { new byte[0], new byte[0], "", new byte[0] }, new Object[] { new byte[0], new byte[0], "", new byte[0] },
}; };

View File

@ -19,7 +19,6 @@ package org.apache.hadoop.hbase.util;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.nio.charset.StandardCharsets;
import java.util.HashSet; import java.util.HashSet;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
@ -41,8 +40,8 @@ public class TestLoadTestKVGenerator {
@Test @Test
public void testValueLength() { public void testValueLength() {
for (int i = 0; i < 1000; ++i) { for (int i = 0; i < 1000; ++i) {
byte[] v = gen.generateRandomSizeValue(Integer.toString(i).getBytes(StandardCharsets.UTF_8), byte[] v = gen.generateRandomSizeValue(Bytes.toBytes(Integer.toString(i)),
String.valueOf(rand.nextInt()).getBytes(StandardCharsets.UTF_8)); Bytes.toBytes(String.valueOf(rand.nextInt())));
assertTrue(MIN_LEN <= v.length); assertTrue(MIN_LEN <= v.length);
assertTrue(v.length <= MAX_LEN); assertTrue(v.length <= MAX_LEN);
} }
@ -52,8 +51,8 @@ public class TestLoadTestKVGenerator {
public void testVerification() { public void testVerification() {
for (int i = 0; i < 1000; ++i) { for (int i = 0; i < 1000; ++i) {
for (int qualIndex = 0; qualIndex < 20; ++qualIndex) { for (int qualIndex = 0; qualIndex < 20; ++qualIndex) {
byte[] qual = String.valueOf(qualIndex).getBytes(StandardCharsets.UTF_8); byte[] qual = Bytes.toBytes(String.valueOf(qualIndex));
byte[] rowKey = LoadTestKVGenerator.md5PrefixedKey(i).getBytes(StandardCharsets.UTF_8); byte[] rowKey = Bytes.toBytes(LoadTestKVGenerator.md5PrefixedKey(i));
byte[] v = gen.generateRandomSizeValue(rowKey, qual); byte[] v = gen.generateRandomSizeValue(rowKey, qual);
assertTrue(LoadTestKVGenerator.verify(v, rowKey, qual)); assertTrue(LoadTestKVGenerator.verify(v, rowKey, qual));
v[0]++; v[0]++;

View File

@ -23,7 +23,6 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -874,9 +873,9 @@ public class TestOrderedBytes {
@Test @Test
public void testBlobVar() { public void testBlobVar() {
byte[][] vals = byte[][] vals =
{ "".getBytes(StandardCharsets.UTF_8), { Bytes.toBytes(""),
"foo".getBytes(StandardCharsets.UTF_8), Bytes.toBytes("foo"),
"foobarbazbub".getBytes(StandardCharsets.UTF_8), Bytes.toBytes("foobarbazbub"),
{ (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, { (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa,
(byte) 0xaa, /* 7 bytes of alternating bits; testing around HBASE-9893 */ }, (byte) 0xaa, /* 7 bytes of alternating bits; testing around HBASE-9893 */ },
{ (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, { (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa,
@ -891,14 +890,14 @@ public class TestOrderedBytes {
{ (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, { (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55,
(byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55,
(byte) 0x55, (byte) 0x55, /* 14 bytes of alternating bits; testing around HBASE-9893 */ }, (byte) 0x55, (byte) 0x55, /* 14 bytes of alternating bits; testing around HBASE-9893 */ },
"1".getBytes(StandardCharsets.UTF_8), Bytes.toBytes("1"),
"22".getBytes(StandardCharsets.UTF_8), Bytes.toBytes("22"),
"333".getBytes(StandardCharsets.UTF_8), Bytes.toBytes("333"),
"4444".getBytes(StandardCharsets.UTF_8), Bytes.toBytes("4444"),
"55555".getBytes(StandardCharsets.UTF_8), Bytes.toBytes("55555"),
"666666".getBytes(StandardCharsets.UTF_8), Bytes.toBytes("666666"),
"7777777".getBytes(StandardCharsets.UTF_8), Bytes.toBytes("7777777"),
"88888888".getBytes(StandardCharsets.UTF_8) Bytes.toBytes("88888888")
}; };
/* /*
@ -969,9 +968,9 @@ public class TestOrderedBytes {
@Test @Test
public void testBlobCopy() { public void testBlobCopy() {
byte[][] vals = byte[][] vals =
{ "".getBytes(StandardCharsets.UTF_8), { Bytes.toBytes(""),
"foo".getBytes(StandardCharsets.UTF_8), Bytes.toBytes("foo"),
"foobarbazbub".getBytes(StandardCharsets.UTF_8), Bytes.toBytes("foobarbazbub"),
{ (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, { (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa,
(byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa }, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa },
{ (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, { (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55,
@ -1046,9 +1045,9 @@ public class TestOrderedBytes {
byte[] a = new byte[3 + (Order.ASCENDING == ord ? 1 : 2) + 2]; byte[] a = new byte[3 + (Order.ASCENDING == ord ? 1 : 2) + 2];
PositionedByteRange buf = PositionedByteRange buf =
new SimplePositionedMutableByteRange(a, 1, 3 + (Order.ASCENDING == ord ? 1 : 2)); new SimplePositionedMutableByteRange(a, 1, 3 + (Order.ASCENDING == ord ? 1 : 2));
OrderedBytes.encodeBlobCopy(buf, "foobarbaz".getBytes(StandardCharsets.UTF_8), 3, 3, ord); OrderedBytes.encodeBlobCopy(buf, Bytes.toBytes("foobarbaz"), 3, 3, ord);
buf.setPosition(0); buf.setPosition(0);
assertArrayEquals("bar".getBytes(StandardCharsets.UTF_8), OrderedBytes.decodeBlobCopy(buf)); assertArrayEquals(Bytes.toBytes("bar"), OrderedBytes.decodeBlobCopy(buf));
} }
} }

View File

@ -19,7 +19,6 @@ package org.apache.hadoop.hbase.client.example;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -138,7 +137,7 @@ public class HttpProxyExample {
DefaultFullHttpResponse resp; DefaultFullHttpResponse resp;
if (content.isPresent()) { if (content.isPresent()) {
ByteBuf buf = ByteBuf buf =
ctx.alloc().buffer().writeBytes(content.get().getBytes(StandardCharsets.UTF_8)); ctx.alloc().buffer().writeBytes(Bytes.toBytes(content.get()));
resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, buf); resp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, buf);
resp.headers().set(HttpHeaderNames.CONTENT_LENGTH, buf.readableBytes()); resp.headers().set(HttpHeaderNames.CONTENT_LENGTH, buf.readableBytes());
} else { } else {

View File

@ -27,7 +27,6 @@ import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -49,8 +48,8 @@ import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.PrivateCellUtil;
import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.PrivateCellUtil;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
@ -91,6 +90,7 @@ import org.apache.hadoop.mapreduce.lib.partition.TotalOrderPartitioner;
import org.apache.yetus.audience.InterfaceAudience; import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting; import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting;
/** /**
@ -134,10 +134,9 @@ public class HFileOutputFormat2
} }
} }
protected static final byte[] tableSeparator = ";".getBytes(StandardCharsets.UTF_8); protected static final byte[] tableSeparator = Bytes.toBytes(";");
protected static byte[] combineTableNameSuffix(byte[] tableName, protected static byte[] combineTableNameSuffix(byte[] tableName, byte[] suffix) {
byte[] suffix ) {
return Bytes.add(tableName, tableSeparator, suffix); return Bytes.add(tableName, tableSeparator, suffix);
} }
@ -257,7 +256,7 @@ public class HFileOutputFormat2
"' not" + " expected"); "' not" + " expected");
} }
} else { } else {
tableNameBytes = writeTableNames.getBytes(StandardCharsets.UTF_8); tableNameBytes = Bytes.toBytes(writeTableNames);
} }
byte[] tableAndFamily = getTableNameSuffixedWithFamily(tableNameBytes, family); byte[] tableAndFamily = getTableNameSuffixedWithFamily(tableNameBytes, family);
WriterLength wl = this.writers.get(tableAndFamily); WriterLength wl = this.writers.get(tableAndFamily);
@ -780,7 +779,7 @@ public class HFileOutputFormat2
continue; continue;
} }
try { try {
confValMap.put(URLDecoder.decode(familySplit[0], "UTF-8").getBytes(StandardCharsets.UTF_8), confValMap.put(Bytes.toBytes(URLDecoder.decode(familySplit[0], "UTF-8")),
URLDecoder.decode(familySplit[1], "UTF-8")); URLDecoder.decode(familySplit[1], "UTF-8"));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
// will not happen with UTF-8 encoding // will not happen with UTF-8 encoding