1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 }