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  package org.apache.omid.committable.hbase;
19  
20  import org.apache.omid.committable.hbase.KeyGeneratorImplementations.BadRandomKeyGenerator;
21  import org.apache.omid.committable.hbase.KeyGeneratorImplementations.BucketKeyGenerator;
22  import org.apache.omid.committable.hbase.KeyGeneratorImplementations.FullRandomKeyGenerator;
23  import org.apache.omid.committable.hbase.KeyGeneratorImplementations.SeqKeyGenerator;
24  import org.testng.annotations.Test;
25  
26  import java.io.IOException;
27  
28  import static java.lang.Long.MAX_VALUE;
29  import static org.testng.Assert.assertEquals;
30  
31  public class TestHBaseCommitTableKey {
32  
33      @Test(timeOut = 10_000)
34      public void testEncodeDecode() throws Exception {
35          testKeyGen(new BucketKeyGenerator());
36          testKeyGen(new BadRandomKeyGenerator());
37          testKeyGen(new FullRandomKeyGenerator());
38          testKeyGen(new SeqKeyGenerator());
39      }
40  
41      @Test(enabled = false, timeOut = 10_000)
42      private void testKeyGen(KeyGenerator keyGen) throws IOException {
43          assertEquals(keyGen.keyToStartTimestamp(keyGen.startTimestampToKey(0)), 0, "Should match");
44          assertEquals(keyGen.keyToStartTimestamp(keyGen.startTimestampToKey(1)), 1, "Should match");
45          assertEquals(keyGen.keyToStartTimestamp(keyGen.startTimestampToKey(8)), 8, "Should match");
46          assertEquals(keyGen.keyToStartTimestamp(keyGen.startTimestampToKey(1024)), 1024, "Should match");
47          assertEquals(keyGen.keyToStartTimestamp(keyGen.startTimestampToKey(1234)), 1234, "Should match");
48          assertEquals(keyGen.keyToStartTimestamp(keyGen.startTimestampToKey(4321)), 4321, "Should match");
49          assertEquals(keyGen.keyToStartTimestamp(keyGen.startTimestampToKey(0xdeadbeefcafeL)), 0xdeadbeefcafeL, "Should match");
50          assertEquals(keyGen.keyToStartTimestamp(keyGen.startTimestampToKey(MAX_VALUE)), MAX_VALUE, "Should match");
51      }
52  
53  }