View Javadoc

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
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
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.
17   */
18  
19  package org.apache.hadoop.hbase.codec.prefixtree.row.data;
20  
21  import java.util.List;
22  
23  import org.apache.hadoop.hbase.KeyValue;
24  import org.apache.hadoop.hbase.codec.prefixtree.PrefixTreeBlockMeta;
25  import org.apache.hadoop.hbase.codec.prefixtree.row.BaseTestRowData;
26  import org.apache.hadoop.hbase.util.Bytes;
27  import org.junit.Assert;
28  
29  import com.google.common.collect.Lists;
30  
31  /*
32   * test different timestamps
33   */
34  public class TestRowDataDifferentTimestamps extends BaseTestRowData{
35  
36    static byte[]
37      Arow = Bytes.toBytes("Arow"),
38      Brow = Bytes.toBytes("Brow"),
39      cf = Bytes.toBytes("fammy"),
40      cq0 = Bytes.toBytes("cq0"),
41      cq1 = Bytes.toBytes("cq1"),
42      v0 = Bytes.toBytes("v0");
43  
44    static List<KeyValue> d = Lists.newArrayList();
45    static{
46      KeyValue kv0 = new KeyValue(Arow, cf, cq0, 0L, v0);
47      kv0.setSequenceId(123456789L);
48      d.add(kv0);
49  
50      KeyValue kv1 = new KeyValue(Arow, cf, cq1, 1L, v0);
51      kv1.setSequenceId(3L);
52      d.add(kv1);
53  
54      KeyValue kv2 = new KeyValue(Brow, cf, cq0, 12345678L, v0);
55      kv2.setSequenceId(65537L);
56      d.add(kv2);
57  
58      //watch out... Long.MAX_VALUE comes back as 1332221664203, even with other encoders
59      //d.add(new KeyValue(Brow, cf, cq1, Long.MAX_VALUE, v0));
60      KeyValue kv3 = new KeyValue(Brow, cf, cq1, Long.MAX_VALUE-1, v0);
61      kv3.setSequenceId(1L);
62      d.add(kv3);
63  
64      KeyValue kv4 = new KeyValue(Brow, cf, cq1, 999999999, v0);
65      //don't set memstoreTS
66      d.add(kv4);
67  
68      KeyValue kv5 = new KeyValue(Brow, cf, cq1, 12345, v0);
69      kv5.setSequenceId(0L);
70      d.add(kv5);
71    }
72  
73    @Override
74    public List<KeyValue> getInputs() {
75      return d;
76    }
77  
78    @Override
79    public void individualBlockMetaAssertions(PrefixTreeBlockMeta blockMeta) {
80      Assert.assertTrue(blockMeta.getNumMvccVersionBytes() > 0);
81      Assert.assertEquals(12, blockMeta.getNumValueBytes());
82  
83      Assert.assertFalse(blockMeta.isAllSameTimestamp());
84      Assert.assertNotNull(blockMeta.getMinTimestamp());
85      Assert.assertTrue(blockMeta.getTimestampIndexWidth() > 0);
86      Assert.assertTrue(blockMeta.getTimestampDeltaWidth() > 0);
87  
88      Assert.assertFalse(blockMeta.isAllSameMvccVersion());
89      Assert.assertNotNull(blockMeta.getMinMvccVersion());
90      Assert.assertTrue(blockMeta.getMvccVersionIndexWidth() > 0);
91      Assert.assertTrue(blockMeta.getMvccVersionDeltaWidth() > 0);
92    }
93  
94  }