1   /*
2    * Copyright 2009 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package org.apache.hadoop.hbase.regionserver;
22  
23  import org.apache.hadoop.hbase.HBaseTestCase;
24  import org.apache.hadoop.hbase.HConstants;
25  import org.apache.hadoop.hbase.KeyValue;
26  import org.apache.hadoop.hbase.util.Bytes;
27  
28  
29  public class TestScanDeleteTracker extends HBaseTestCase {
30  
31    private ScanDeleteTracker sdt;
32    private long timestamp = 10L;
33    private byte deleteType = 0;
34  
35    public void setUp() throws Exception {
36      super.setUp();
37      sdt = new ScanDeleteTracker();
38    }
39  
40    public void testDeletedBy_Delete() {
41      byte [] qualifier = Bytes.toBytes("qualifier");
42      deleteType = KeyValue.Type.Delete.getCode();
43  
44      sdt.add(qualifier, 0, qualifier.length, timestamp, deleteType);
45      boolean ret = sdt.isDeleted(qualifier, 0, qualifier.length, timestamp);
46      assertEquals(true, ret);
47    }
48  
49    public void testDeletedBy_DeleteColumn() {
50      byte [] qualifier = Bytes.toBytes("qualifier");
51      deleteType = KeyValue.Type.DeleteColumn.getCode();
52  
53      sdt.add(qualifier, 0, qualifier.length, timestamp, deleteType);
54      timestamp -= 5;
55      boolean ret = sdt.isDeleted(qualifier, 0, qualifier.length, timestamp);
56      assertEquals(true, ret);
57    }
58  
59    public void testDeletedBy_DeleteFamily() {
60      byte [] qualifier = Bytes.toBytes("qualifier");
61      deleteType = KeyValue.Type.DeleteFamily.getCode();
62  
63      sdt.add(qualifier, 0, qualifier.length, timestamp, deleteType);
64  
65      timestamp -= 5;
66      boolean ret = sdt.isDeleted(qualifier, 0, qualifier.length, timestamp);
67      assertEquals(true, ret);
68    }
69  
70    public void testDelete_DeleteColumn() {
71      byte [] qualifier = Bytes.toBytes("qualifier");
72      deleteType = KeyValue.Type.Delete.getCode();
73  
74      sdt.add(qualifier, 0, qualifier.length, timestamp, deleteType);
75  
76      timestamp -= 5;
77      deleteType = KeyValue.Type.DeleteColumn.getCode();
78      sdt.add(qualifier, 0, qualifier.length, timestamp, deleteType);
79  
80      timestamp -= 5;
81      boolean ret = sdt.isDeleted(qualifier, 0, qualifier.length, timestamp);
82      assertEquals(true, ret);
83    }
84  
85  
86    public void testDeleteColumn_Delete() {
87      byte [] qualifier = Bytes.toBytes("qualifier");
88      deleteType = KeyValue.Type.DeleteColumn.getCode();
89  
90      sdt.add(qualifier, 0, qualifier.length, timestamp, deleteType);
91  
92      qualifier = Bytes.toBytes("qualifier1");
93      deleteType = KeyValue.Type.Delete.getCode();
94      sdt.add(qualifier, 0, qualifier.length, timestamp, deleteType);
95  
96      boolean ret = sdt.isDeleted(qualifier, 0, qualifier.length, timestamp);
97      assertEquals(true, ret);
98    }
99  
100   //Testing new way where we save the Delete in case of a Delete for specific
101   //ts, could have just added the last line to the first test, but rather keep
102   //them separated
103   public void testDelete_KeepDelete(){
104     byte [] qualifier = Bytes.toBytes("qualifier");
105     deleteType = KeyValue.Type.Delete.getCode();
106 
107     sdt.add(qualifier, 0, qualifier.length, timestamp, deleteType);
108     sdt.isDeleted(qualifier, 0, qualifier.length, timestamp);
109     assertEquals(false ,sdt.isEmpty());
110   }
111 
112 
113 }