2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.client
;
20 import static org
.junit
.Assert
.assertEquals
;
21 import static org
.junit
.Assert
.assertNotEquals
;
22 import java
.io
.IOException
;
23 import org
.apache
.hadoop
.conf
.Configuration
;
24 import org
.apache
.hadoop
.hbase
.CellBuilderType
;
25 import org
.apache
.hadoop
.hbase
.ExtendedCellBuilderFactory
;
26 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
27 import org
.apache
.hadoop
.hbase
.HBaseTestingUtility
;
28 import org
.apache
.hadoop
.hbase
.KeyValue
;
29 import org
.apache
.hadoop
.hbase
.TableName
;
30 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
31 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
32 import org
.junit
.AfterClass
;
33 import org
.junit
.BeforeClass
;
34 import org
.junit
.ClassRule
;
35 import org
.junit
.Rule
;
36 import org
.junit
.Test
;
37 import org
.junit
.experimental
.categories
.Category
;
38 import org
.junit
.rules
.TestName
;
41 * Run Append tests that use the HBase clients;
43 @Category(MediumTests
.class)
44 public class TestAppendFromClientSide
{
47 public static final HBaseClassTestRule CLASS_RULE
=
48 HBaseClassTestRule
.forClass(TestAppendFromClientSide
.class);
50 protected final static HBaseTestingUtility TEST_UTIL
= new HBaseTestingUtility();
51 private static byte [] ROW
= Bytes
.toBytes("testRow");
52 private static byte [] FAMILY
= Bytes
.toBytes("testFamily");
53 private static byte [] QUALIFIER
= Bytes
.toBytes("testQualifier");
55 public TestName name
= new TestName();
57 public static void beforeClass() throws Exception
{
58 Configuration conf
= TEST_UTIL
.getConfiguration();
59 TEST_UTIL
.startMiniCluster(3);
63 public static void afterClass() throws Exception
{
64 TEST_UTIL
.shutdownMiniCluster();
68 public void testAppendWithCustomTimestamp() throws IOException
{
69 TableName TABLENAME
= TableName
.valueOf(name
.getMethodName());
70 Table table
= TEST_UTIL
.createTable(TABLENAME
, FAMILY
);
72 Append append
= new Append(ROW
);
73 append
.add(ExtendedCellBuilderFactory
.create(CellBuilderType
.DEEP_COPY
)
76 .setQualifier(QUALIFIER
)
77 .setTimestamp(timestamp
)
78 .setType(KeyValue
.Type
.Put
.getCode())
79 .setValue(Bytes
.toBytes(100L))
81 Result r
= table
.append(append
);
82 assertEquals(1, r
.size());
83 assertEquals(timestamp
, r
.rawCells()[0].getTimestamp());
84 r
= table
.get(new Get(ROW
));
85 assertEquals(1, r
.size());
86 assertEquals(timestamp
, r
.rawCells()[0].getTimestamp());
87 r
= table
.append(append
);
88 assertEquals(1, r
.size());
89 assertNotEquals(timestamp
, r
.rawCells()[0].getTimestamp());
90 r
= table
.get(new Get(ROW
));
91 assertEquals(1, r
.size());
92 assertNotEquals(timestamp
, r
.rawCells()[0].getTimestamp());