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
.assertTrue
;
22 import org
.apache
.hadoop
.hbase
.*;
23 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
24 import org
.apache
.hadoop
.hbase
.testclassification
.ClientTests
;
25 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
26 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
27 import org
.junit
.AfterClass
;
28 import org
.junit
.BeforeClass
;
29 import org
.junit
.ClassRule
;
30 import org
.junit
.Rule
;
31 import org
.junit
.Test
;
32 import org
.junit
.experimental
.categories
.Category
;
33 import org
.junit
.rules
.TestName
;
35 @Category({MediumTests
.class, ClientTests
.class})
36 public class TestPutWithDelete
{
39 public static final HBaseClassTestRule CLASS_RULE
=
40 HBaseClassTestRule
.forClass(TestPutWithDelete
.class);
42 private static final HBaseTestingUtility TEST_UTIL
= new HBaseTestingUtility();
45 public TestName name
= new TestName();
48 * @throws java.lang.Exception
51 public static void setUpBeforeClass() throws Exception
{
52 TEST_UTIL
.startMiniCluster();
56 * @throws java.lang.Exception
59 public static void tearDownAfterClass() throws Exception
{
60 TEST_UTIL
.shutdownMiniCluster();
64 public void testHbasePutDeleteCell() throws Exception
{
65 final TableName tableName
= TableName
.valueOf(name
.getMethodName());
66 final byte[] rowKey
= Bytes
.toBytes("12345");
67 final byte[] family
= Bytes
.toBytes("cf");
68 Table table
= TEST_UTIL
.createTable(tableName
, family
);
69 TEST_UTIL
.waitTableAvailable(tableName
.getName(), 5000);
72 Put put
= new Put(rowKey
);
73 put
.addColumn(family
, Bytes
.toBytes("A"), Bytes
.toBytes("a"));
74 put
.addColumn(family
, Bytes
.toBytes("B"), Bytes
.toBytes("b"));
75 put
.addColumn(family
, Bytes
.toBytes("C"), Bytes
.toBytes("c"));
76 put
.addColumn(family
, Bytes
.toBytes("D"), Bytes
.toBytes("d"));
78 // get row back and assert the values
79 Get get
= new Get(rowKey
);
80 Result result
= table
.get(get
);
81 assertTrue("Column A value should be a",
82 Bytes
.toString(result
.getValue(family
, Bytes
.toBytes("A"))).equals("a"));
83 assertTrue("Column B value should be b",
84 Bytes
.toString(result
.getValue(family
, Bytes
.toBytes("B"))).equals("b"));
85 assertTrue("Column C value should be c",
86 Bytes
.toString(result
.getValue(family
, Bytes
.toBytes("C"))).equals("c"));
87 assertTrue("Column D value should be d",
88 Bytes
.toString(result
.getValue(family
, Bytes
.toBytes("D"))).equals("d"));
89 // put the same row again with C column deleted
90 put
= new Put(rowKey
);
91 put
.addColumn(family
, Bytes
.toBytes("A"), Bytes
.toBytes("a1"));
92 put
.addColumn(family
, Bytes
.toBytes("B"), Bytes
.toBytes("b1"));
93 KeyValue marker
= new KeyValue(rowKey
, family
, Bytes
.toBytes("C"),
94 HConstants
.LATEST_TIMESTAMP
, KeyValue
.Type
.DeleteColumn
);
95 put
.addColumn(family
, Bytes
.toBytes("D"), Bytes
.toBytes("d1"));
98 // get row back and assert the values
99 get
= new Get(rowKey
);
100 result
= table
.get(get
);
101 assertTrue("Column A value should be a1",
102 Bytes
.toString(result
.getValue(family
, Bytes
.toBytes("A"))).equals("a1"));
103 assertTrue("Column B value should be b1",
104 Bytes
.toString(result
.getValue(family
, Bytes
.toBytes("B"))).equals("b1"));
105 assertTrue("Column C should not exist",
106 result
.getValue(family
, Bytes
.toBytes("C")) == null);
107 assertTrue("Column D value should be d1",
108 Bytes
.toString(result
.getValue(family
, Bytes
.toBytes("D"))).equals("d1"));