1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.regionserver.querymatcher;
21
22 import static org.junit.Assert.*;
23
24 import org.apache.hadoop.hbase.KeyValue;
25 import org.apache.hadoop.hbase.regionserver.DeleteTracker.DeleteResult;
26 import org.apache.hadoop.hbase.testclassification.RegionServerTests;
27 import org.apache.hadoop.hbase.testclassification.SmallTests;
28 import org.apache.hadoop.hbase.util.Bytes;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.experimental.categories.Category;
32
33 @Category({ RegionServerTests.class, SmallTests.class })
34 public class TestScanDeleteTracker {
35
36 private ScanDeleteTracker sdt;
37
38 private long timestamp = 10L;
39
40 @Before
41 public void setUp() throws Exception {
42 sdt = new ScanDeleteTracker();
43 }
44
45 @Test
46 public void testDeletedByDelete() {
47 KeyValue kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), Bytes.toBytes("qualifier"),
48 timestamp, KeyValue.Type.Delete);
49 sdt.add(kv);
50 DeleteResult ret = sdt.isDeleted(kv);
51 assertEquals(DeleteResult.VERSION_DELETED, ret);
52 }
53
54 @Test
55 public void testDeletedByDeleteColumn() {
56 KeyValue kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), Bytes.toBytes("qualifier"),
57 timestamp, KeyValue.Type.DeleteColumn);
58 sdt.add(kv);
59 timestamp -= 5;
60 kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), Bytes.toBytes("qualifier"),
61 timestamp, KeyValue.Type.DeleteColumn);
62 DeleteResult ret = sdt.isDeleted(kv);
63 assertEquals(DeleteResult.COLUMN_DELETED, ret);
64 }
65
66 @Test
67 public void testDeletedByDeleteFamily() {
68 KeyValue kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), Bytes.toBytes("qualifier"),
69 timestamp, KeyValue.Type.DeleteFamily);
70 sdt.add(kv);
71 timestamp -= 5;
72 kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), Bytes.toBytes("qualifier"),
73 timestamp, KeyValue.Type.DeleteColumn);
74 DeleteResult ret = sdt.isDeleted(kv);
75 assertEquals(DeleteResult.FAMILY_DELETED, ret);
76 }
77
78 @Test
79 public void testDeletedByDeleteFamilyVersion() {
80 byte[] qualifier1 = Bytes.toBytes("qualifier1");
81 byte[] qualifier2 = Bytes.toBytes("qualifier2");
82 byte[] qualifier3 = Bytes.toBytes("qualifier3");
83 byte[] qualifier4 = Bytes.toBytes("qualifier4");
84 KeyValue kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), null, timestamp,
85 KeyValue.Type.DeleteFamilyVersion);
86 sdt.add(kv);
87 kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier1, timestamp,
88 KeyValue.Type.DeleteFamilyVersion);
89 DeleteResult ret = sdt.isDeleted(kv);
90 assertEquals(DeleteResult.FAMILY_VERSION_DELETED, ret);
91 kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier2, timestamp,
92 KeyValue.Type.DeleteFamilyVersion);
93 ret = sdt.isDeleted(kv);
94 assertEquals(DeleteResult.FAMILY_VERSION_DELETED, ret);
95 kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier3, timestamp,
96 KeyValue.Type.DeleteFamilyVersion);
97 ret = sdt.isDeleted(kv);
98 assertEquals(DeleteResult.FAMILY_VERSION_DELETED, ret);
99 kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier4, timestamp,
100 KeyValue.Type.DeleteFamilyVersion);
101 ret = sdt.isDeleted(kv);
102 assertEquals(DeleteResult.FAMILY_VERSION_DELETED, ret);
103 kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier1, timestamp + 3,
104 KeyValue.Type.DeleteFamilyVersion);
105 ret = sdt.isDeleted(kv);
106 assertEquals(DeleteResult.NOT_DELETED, ret);
107 kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier2, timestamp - 2,
108 KeyValue.Type.DeleteFamilyVersion);
109 ret = sdt.isDeleted(kv);
110 assertEquals(DeleteResult.NOT_DELETED, ret);
111 kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier3, timestamp - 5,
112 KeyValue.Type.DeleteFamilyVersion);
113 ret = sdt.isDeleted(kv);
114 assertEquals(DeleteResult.NOT_DELETED, ret);
115 kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier4, timestamp + 8,
116 KeyValue.Type.DeleteFamilyVersion);
117 ret = sdt.isDeleted(kv);
118 assertEquals(DeleteResult.NOT_DELETED, ret);
119 }
120
121 @Test
122 public void testDeleteDeleteColumn() {
123 byte[] qualifier = Bytes.toBytes("qualifier");
124 KeyValue kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier, timestamp,
125 KeyValue.Type.Delete);
126 sdt.add(kv);
127
128 timestamp -= 5;
129 kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier, timestamp,
130 KeyValue.Type.DeleteColumn);
131 sdt.add(kv);
132
133 timestamp -= 5;
134 kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier, timestamp,
135 KeyValue.Type.DeleteColumn);
136 DeleteResult ret = sdt.isDeleted(kv);
137 assertEquals(DeleteResult.COLUMN_DELETED, ret);
138 }
139
140 @Test
141 public void testDeleteColumnDelete() {
142 byte[] qualifier = Bytes.toBytes("qualifier");
143 KeyValue kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier, timestamp,
144 KeyValue.Type.DeleteColumn);
145 sdt.add(kv);
146
147 qualifier = Bytes.toBytes("qualifier1");
148 kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier, timestamp,
149 KeyValue.Type.Delete);
150 sdt.add(kv);
151
152 DeleteResult ret = sdt.isDeleted(kv);
153 assertEquals(DeleteResult.VERSION_DELETED, ret);
154 }
155
156
157
158
159 @Test
160 public void testDeleteKeepDelete() {
161 byte[] qualifier = Bytes.toBytes("qualifier");
162 KeyValue kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier, timestamp,
163 KeyValue.Type.Delete);
164 sdt.add(kv);
165 sdt.isDeleted(kv);
166 assertEquals(false, sdt.isEmpty());
167 }
168
169 @Test
170 public void testDeleteKeepVersionZero() {
171 byte[] qualifier = Bytes.toBytes("qualifier");
172
173 long deleteTimestamp = 10;
174 long valueTimestamp = 0;
175
176 sdt.reset();
177 KeyValue kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier, deleteTimestamp,
178 KeyValue.Type.Delete);
179 sdt.add(kv);
180 kv = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("f"), qualifier, valueTimestamp,
181 KeyValue.Type.Delete);
182 DeleteResult ret = sdt.isDeleted(kv);
183 assertEquals(DeleteResult.NOT_DELETED, ret);
184 }
185 }