HBASE-24033 Add ut for loading the corrupt recovered hfiles (#1322)
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / client / TestPutWithDelete.java
blobe1ef4725022a52a65667e8a5d00f657eb5f15868
1 /**
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.HBaseClassTestRule;
23 import org.apache.hadoop.hbase.HBaseTestingUtility;
24 import org.apache.hadoop.hbase.HConstants;
25 import org.apache.hadoop.hbase.KeyValue;
26 import org.apache.hadoop.hbase.TableName;
27 import org.apache.hadoop.hbase.testclassification.ClientTests;
28 import org.apache.hadoop.hbase.testclassification.MediumTests;
29 import org.apache.hadoop.hbase.util.Bytes;
30 import org.junit.AfterClass;
31 import org.junit.BeforeClass;
32 import org.junit.ClassRule;
33 import org.junit.Rule;
34 import org.junit.Test;
35 import org.junit.experimental.categories.Category;
36 import org.junit.rules.TestName;
38 @Category({MediumTests.class, ClientTests.class})
39 public class TestPutWithDelete {
41 @ClassRule
42 public static final HBaseClassTestRule CLASS_RULE =
43 HBaseClassTestRule.forClass(TestPutWithDelete.class);
45 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
47 @Rule
48 public TestName name = new TestName();
50 /**
51 * @throws java.lang.Exception
53 @BeforeClass
54 public static void setUpBeforeClass() throws Exception {
55 TEST_UTIL.startMiniCluster();
58 /**
59 * @throws java.lang.Exception
61 @AfterClass
62 public static void tearDownAfterClass() throws Exception {
63 TEST_UTIL.shutdownMiniCluster();
66 @Test
67 public void testHbasePutDeleteCell() throws Exception {
68 final TableName tableName = TableName.valueOf(name.getMethodName());
69 final byte[] rowKey = Bytes.toBytes("12345");
70 final byte[] family = Bytes.toBytes("cf");
71 Table table = TEST_UTIL.createTable(tableName, family);
72 TEST_UTIL.waitTableAvailable(tableName.getName(), 5000);
73 try {
74 // put one row
75 Put put = new Put(rowKey);
76 put.addColumn(family, Bytes.toBytes("A"), Bytes.toBytes("a"));
77 put.addColumn(family, Bytes.toBytes("B"), Bytes.toBytes("b"));
78 put.addColumn(family, Bytes.toBytes("C"), Bytes.toBytes("c"));
79 put.addColumn(family, Bytes.toBytes("D"), Bytes.toBytes("d"));
80 table.put(put);
81 // get row back and assert the values
82 Get get = new Get(rowKey);
83 Result result = table.get(get);
84 assertTrue("Column A value should be a",
85 Bytes.toString(result.getValue(family, Bytes.toBytes("A"))).equals("a"));
86 assertTrue("Column B value should be b",
87 Bytes.toString(result.getValue(family, Bytes.toBytes("B"))).equals("b"));
88 assertTrue("Column C value should be c",
89 Bytes.toString(result.getValue(family, Bytes.toBytes("C"))).equals("c"));
90 assertTrue("Column D value should be d",
91 Bytes.toString(result.getValue(family, Bytes.toBytes("D"))).equals("d"));
92 // put the same row again with C column deleted
93 put = new Put(rowKey);
94 put.addColumn(family, Bytes.toBytes("A"), Bytes.toBytes("a1"));
95 put.addColumn(family, Bytes.toBytes("B"), Bytes.toBytes("b1"));
96 KeyValue marker = new KeyValue(rowKey, family, Bytes.toBytes("C"),
97 HConstants.LATEST_TIMESTAMP, KeyValue.Type.DeleteColumn);
98 put.addColumn(family, Bytes.toBytes("D"), Bytes.toBytes("d1"));
99 put.add(marker);
100 table.put(put);
101 // get row back and assert the values
102 get = new Get(rowKey);
103 result = table.get(get);
104 assertTrue("Column A value should be a1",
105 Bytes.toString(result.getValue(family, Bytes.toBytes("A"))).equals("a1"));
106 assertTrue("Column B value should be b1",
107 Bytes.toString(result.getValue(family, Bytes.toBytes("B"))).equals("b1"));
108 assertTrue("Column C should not exist",
109 result.getValue(family, Bytes.toBytes("C")) == null);
110 assertTrue("Column D value should be d1",
111 Bytes.toString(result.getValue(family, Bytes.toBytes("D"))).equals("d1"));
112 } finally {
113 table.close();