1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.omid.transaction;
19
20 import static org.testng.Assert.fail;
21
22 import org.apache.hadoop.hbase.client.Delete;
23 import org.apache.hadoop.hbase.client.Get;
24 import org.apache.hadoop.hbase.client.Put;
25 import org.apache.hadoop.hbase.client.Scan;
26 import org.apache.hadoop.hbase.client.Table;
27 import org.apache.hadoop.hbase.util.Bytes;
28 import org.mockito.Mockito;
29 import org.testng.annotations.Test;
30
31 import org.apache.phoenix.thirdparty.com.google.common.base.Charsets;
32
33 @Test(groups = "noHBase")
34 public class TestTTableBehaviour {
35
36 private byte[] row = Bytes.toBytes("1row");
37 private byte[] famName = Bytes.toBytes("tf");
38 private byte[] colName = Bytes.toBytes("tc");
39 private byte[] dataValue = Bytes.toBytes("test-data");
40
41 @Test(timeOut = 10_000)
42 public void testUserOperationsDontAllowTimestampSpecification() throws Exception {
43
44
45 TTable tt = new TTable(Mockito.mock(Table.class), false, false);
46
47 long randomTimestampValue = Bytes.toLong("deadbeef".getBytes());
48
49 Transaction tx = Mockito.mock(Transaction.class);
50
51
52 Put put = new Put(row, randomTimestampValue);
53 put.addColumn(famName, colName, dataValue);
54 try {
55 tt.put(tx, put);
56 fail("Should have thrown an IllegalArgumentException due to timestamp specification");
57 } catch (IllegalArgumentException e) {
58
59 }
60
61
62 put = new Put(row);
63 put.addColumn(famName, colName, randomTimestampValue, dataValue);
64 try {
65 tt.put(tx, put);
66 fail("Should have thrown an IllegalArgumentException due to timestamp specification");
67 } catch (IllegalArgumentException e) {
68
69 }
70
71
72 Get get = new Get(row);
73 get.setTimeStamp(randomTimestampValue);
74 try {
75 tt.get(tx, get);
76 fail("Should have thrown an IllegalArgumentException due to timestamp specification");
77 } catch (IllegalArgumentException e) {
78
79 }
80
81
82 Scan scan = new Scan(get);
83 try {
84 tt.getScanner(tx, scan);
85 fail("Should have thrown an IllegalArgumentException due to timestamp specification");
86 } catch (IllegalArgumentException e) {
87
88 }
89
90
91 Delete delete = new Delete(row);
92 delete.setTimestamp(randomTimestampValue);
93 try {
94 tt.delete(tx, delete);
95 fail("Should have thrown an IllegalArgumentException due to timestamp specification");
96 } catch (IllegalArgumentException e) {
97
98 }
99
100
101 delete = new Delete(row);
102 delete.addColumn(famName, colName, randomTimestampValue);
103 try {
104 tt.delete(tx, delete);
105 fail("Should have thrown an IllegalArgumentException due to timestamp specification");
106 } catch (IllegalArgumentException e) {
107
108 }
109
110 }
111
112
113
114
115 @Test(timeOut = 10_000)
116 public void testReservedNamesForShadowCellsCanNotBeUsedAsQualifiersInUserOperations() throws Exception {
117 byte[] nonValidQualifier1 = "blahblah\u0080".getBytes(Charsets.UTF_8);
118 byte[] validQualifierIncludingOldShadowCellSuffix = "blahblah:OMID_CTS".getBytes(Charsets.UTF_8);
119
120 TTable table = new TTable(Mockito.mock(Table.class), false, false);
121
122 HBaseTransaction t1 = Mockito.mock(HBaseTransaction.class);
123 Put put = new Put(row);
124 put.addColumn(famName, nonValidQualifier1, dataValue);
125 try {
126 table.put(t1, put);
127 fail("Shouldn't be able to put this");
128 } catch (IllegalArgumentException iae) {
129
130 }
131 Delete del = new Delete(row);
132 del.addColumn(famName, nonValidQualifier1);
133 try {
134 table.delete(t1, del);
135 fail("Shouldn't be able to delete this");
136 } catch (IllegalArgumentException iae) {
137
138 }
139
140 put = new Put(row);
141 put.addColumn(famName, validQualifierIncludingOldShadowCellSuffix, dataValue);
142 try {
143 table.put(t1, put);
144 } catch (IllegalArgumentException iae) {
145 fail("Qualifier shouldn't be rejected anymore");
146 }
147 del = new Delete(row);
148 del.addColumn(famName, validQualifierIncludingOldShadowCellSuffix);
149 try {
150 table.delete(t1, del);
151 } catch (IllegalArgumentException iae) {
152 fail("Qualifier shouldn't be rejected anymore");
153 }
154 }
155
156 }