1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with this
4 * work for additional information regarding copyright ownership. The ASF
5 * licenses this file to you under the Apache License, Version 2.0 (the
6 * "License"); you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations
15 * under the License.
16 */
17 package org.apache.hadoop.hbase.io.encoding;
18
19 import static org.junit.Assert.assertEquals;
20
21 import org.apache.hadoop.hbase.MediumTests;
22 import org.junit.Test;
23 import org.junit.experimental.categories.Category;
24
25 @Category(MediumTests.class)
26 public class TestBufferedDataBlockEncoder {
27
28 @Test
29 public void testEnsureSpaceForKey() {
30 BufferedDataBlockEncoder.SeekerState state =
31 new BufferedDataBlockEncoder.SeekerState();
32 for (int i = 1; i <= 65536; ++i) {
33 state.keyLength = i;
34 state.ensureSpaceForKey();
35 state.keyBuffer[state.keyLength - 1] = (byte) ((i - 1) % 0xff);
36 for (int j = 0; j < i - 1; ++j) {
37 // Check that earlier bytes were preserved as the buffer grew.
38 assertEquals((byte) (j % 0xff), state.keyBuffer[j]);
39 }
40 }
41 }
42
43 }