21
21
import com .alipay .oceanbase .hbase .OHTableClient ;
22
22
import com .alipay .oceanbase .hbase .util .ObHTableTestUtil ;
23
23
import com .alipay .oceanbase .hbase .util .TableTemplateManager ;
24
+ import com .google .common .base .Strings ;
24
25
import org .apache .hadoop .hbase .client .*;
25
26
import org .apache .hadoop .hbase .util .Bytes ;
26
27
import org .junit .*;
34
35
35
36
import static com .alipay .oceanbase .hbase .util .ObHTableSecondaryPartUtil .*;
36
37
import static com .alipay .oceanbase .hbase .util .ObHTableTestUtil .FOR_EACH ;
38
+ import static com .alipay .oceanbase .hbase .util .ObHTableTestUtil .getConnection ;
37
39
import static com .alipay .oceanbase .hbase .util .TableTemplateManager .NORMAL_TABLES ;
38
40
import static org .junit .Assert .*;
39
41
@@ -53,7 +55,7 @@ public static void before() throws Exception {
53
55
@ AfterClass
54
56
public static void finish () throws Exception {
55
57
closeDistributedExecute ();
56
- dropTables (tableNames , group2tableNames );
58
+ // dropTables(tableNames, group2tableNames);
57
59
}
58
60
59
61
@ Before
@@ -68,133 +70,139 @@ private static void assertNullResult(Result result) throws Exception {
68
70
private static void testAppend (String tableName ) throws Exception {
69
71
OHTableClient hTable = ObHTableTestUtil .newOHTableClient (getTableName (tableName ));
70
72
hTable .init ();
73
+ try {
74
+ byte [] FAMILY = getColumnFamilyName (tableName ).getBytes ();
75
+ byte [] ROW = "appendKey" .getBytes ();
76
+ byte [] v1 = Bytes .toBytes ("42" );
77
+ byte [] v2 = Bytes .toBytes ("23" );
78
+ byte [][] QUALIFIERS = new byte [][]{Bytes .toBytes ("b" ), Bytes .toBytes ("a" ),
79
+ Bytes .toBytes ("c" )};
80
+ Append a = new Append (ROW );
81
+ a .add (FAMILY , QUALIFIERS [0 ], v1 );
82
+ a .add (FAMILY , QUALIFIERS [1 ], v2 );
83
+ a .setReturnResults (false );
84
+ assertNullResult (hTable .append (a ));
71
85
72
- byte [] FAMILY = getColumnFamilyName (tableName ).getBytes ();
73
- byte [] ROW = "appendKey" .getBytes ();
74
- byte [] v1 = Bytes .toBytes ("42" );
75
- byte [] v2 = Bytes .toBytes ("23" );
76
- byte [][] QUALIFIERS = new byte [][] { Bytes .toBytes ("b" ), Bytes .toBytes ("a" ),
77
- Bytes .toBytes ("c" ) };
78
- Append a = new Append (ROW );
79
- a .add (FAMILY , QUALIFIERS [0 ], v1 );
80
- a .add (FAMILY , QUALIFIERS [1 ], v2 );
81
- a .setReturnResults (false );
82
- assertNullResult (hTable .append (a ));
83
-
84
- a = new Append (ROW );
85
- a .add (FAMILY , QUALIFIERS [0 ], v2 );
86
- a .add (FAMILY , QUALIFIERS [1 ], v1 );
87
- a .add (FAMILY , QUALIFIERS [2 ], v2 );
88
- Result r = hTable .append (a );
89
- assertEquals (0 , Bytes .compareTo (Bytes .add (v1 , v2 ), r .getValue (FAMILY , QUALIFIERS [0 ])));
90
- assertEquals (0 , Bytes .compareTo (Bytes .add (v2 , v1 ), r .getValue (FAMILY , QUALIFIERS [1 ])));
91
- // QUALIFIERS[2] previously not exist, verify both value and timestamp are correct
92
- assertEquals (0 , Bytes .compareTo (v2 , r .getValue (FAMILY , QUALIFIERS [2 ])));
93
- assertEquals (r .getColumnLatest (FAMILY , QUALIFIERS [0 ]).getTimestamp (),
94
- r .getColumnLatest (FAMILY , QUALIFIERS [2 ]).getTimestamp ());
95
-
96
- Get get = new Get (ROW );
97
- get .setMaxVersions (10 );
98
- get .addFamily (FAMILY );
99
- Result result = hTable .get (get );
100
- assertEquals (2 , result .getColumnCells (FAMILY , QUALIFIERS [0 ]).size ());
101
- assertEquals (2 , result .getColumnCells (FAMILY , QUALIFIERS [1 ]).size ());
102
- assertEquals (1 , result .getColumnCells (FAMILY , QUALIFIERS [2 ]).size ());
103
- assertEquals (
104
- 0 ,
105
- Bytes .compareTo (Bytes .add (v1 , v2 ), result .getColumnCells (FAMILY , QUALIFIERS [0 ]).get (0 )
106
- .getValue ()));
107
- assertEquals (0 ,
108
- Bytes .compareTo (v2 , result .getColumnCells (FAMILY , QUALIFIERS [2 ]).get (0 ).getValue ()));
86
+ a = new Append (ROW );
87
+ a .add (FAMILY , QUALIFIERS [0 ], v2 );
88
+ a .add (FAMILY , QUALIFIERS [1 ], v1 );
89
+ a .add (FAMILY , QUALIFIERS [2 ], v2 );
90
+ Result r = hTable .append (a );
91
+ assertEquals (0 , Bytes .compareTo (Bytes .add (v1 , v2 ), r .getValue (FAMILY , QUALIFIERS [0 ])));
92
+ assertEquals (0 , Bytes .compareTo (Bytes .add (v2 , v1 ), r .getValue (FAMILY , QUALIFIERS [1 ])));
93
+ // QUALIFIERS[2] previously not exist, verify both value and timestamp are correct
94
+ assertEquals (0 , Bytes .compareTo (v2 , r .getValue (FAMILY , QUALIFIERS [2 ])));
95
+ assertEquals (r .getColumnLatest (FAMILY , QUALIFIERS [0 ]).getTimestamp (),
96
+ r .getColumnLatest (FAMILY , QUALIFIERS [2 ]).getTimestamp ());
109
97
110
- hTable .close ();
98
+ Get get = new Get (ROW );
99
+ get .setMaxVersions (10 );
100
+ get .addFamily (FAMILY );
101
+ Result result = hTable .get (get );
102
+ assertEquals (2 , result .getColumnCells (FAMILY , QUALIFIERS [0 ]).size ());
103
+ assertEquals (2 , result .getColumnCells (FAMILY , QUALIFIERS [1 ]).size ());
104
+ assertEquals (1 , result .getColumnCells (FAMILY , QUALIFIERS [2 ]).size ());
105
+ assertEquals (
106
+ 0 ,
107
+ Bytes .compareTo (Bytes .add (v1 , v2 ), result .getColumnCells (FAMILY , QUALIFIERS [0 ]).get (0 )
108
+ .getValue ()));
109
+ assertEquals (0 ,
110
+ Bytes .compareTo (v2 , result .getColumnCells (FAMILY , QUALIFIERS [2 ]).get (0 ).getValue ()));
111
+ } finally {
112
+ hTable .close ();
113
+ }
111
114
}
112
115
113
116
private static void testAppendBorder (String tableName ) throws Exception {
114
117
OHTableClient hTable = ObHTableTestUtil .newOHTableClient (getTableName (tableName ));
115
118
hTable .init ();
116
-
117
- byte [] FAMILY = getColumnFamilyName (tableName ).getBytes ();
118
- byte [] ROW = "appendKey" .getBytes ();
119
- byte [] v1 = Bytes .toBytes ("ab" );
120
- byte [][] QUALIFIERS = new byte [][] { Bytes .toBytes ("b" ), Bytes .toBytes ("a" ),
121
- Bytes .toBytes ("c" ) };
122
- Put put = new Put (ROW );
123
- put .addColumn (FAMILY , QUALIFIERS [1 ], v1 );
124
- hTable .put (put );
125
- Append a = new Append (ROW );
126
- a .add (FAMILY , QUALIFIERS [1 ], v1 );
127
- a .add (FAMILY , QUALIFIERS [2 ], "" .getBytes ());
128
- hTable .append (a );
129
- Get get = new Get (ROW );
130
- get .setMaxVersions (10 );
131
- get .addFamily (FAMILY );
132
- Result result = hTable .get (get );
133
- assertEquals (3 , result .size ());
134
-
135
- a = new Append (ROW );
136
- a .add (FAMILY , QUALIFIERS [2 ], v1 );
137
- a .add (FAMILY , QUALIFIERS [2 ], "" .getBytes ());
138
- hTable .append (a );
139
- get = new Get (ROW );
140
- get .setMaxVersions (10 );
141
- get .addFamily (FAMILY );
142
- result = hTable .get (get );
143
- assertEquals (4 , result .size ());
144
-
145
- byte [] randomBytes = new byte [1025 ];
146
- Random random = new Random ();
147
- random .nextBytes (randomBytes );
148
- a = new Append (ROW );
149
- a .add (FAMILY , QUALIFIERS [2 ], randomBytes );
150
119
try {
120
+ byte [] FAMILY = getColumnFamilyName (tableName ).getBytes ();
121
+ byte [] ROW = "appendKey" .getBytes ();
122
+ byte [] v1 = Bytes .toBytes ("ab" );
123
+ byte [][] QUALIFIERS = new byte [][]{Bytes .toBytes ("b" ), Bytes .toBytes ("a" ),
124
+ Bytes .toBytes ("c" )};
125
+ Put put = new Put (ROW );
126
+ put .addColumn (FAMILY , QUALIFIERS [1 ], v1 );
127
+ hTable .put (put );
128
+ Append a = new Append (ROW );
129
+ a .add (FAMILY , QUALIFIERS [1 ], v1 );
130
+ a .add (FAMILY , QUALIFIERS [2 ], "" .getBytes ());
151
131
hTable .append (a );
152
- fail ("unexpect error, too long data should fail" );
153
- } catch (IOException e ) {
154
- assertTrue (e .getCause ().getMessage ().contains ("Data too long for column 'V'" ));
155
- }
132
+ Get get = new Get (ROW );
133
+ get .setMaxVersions (10 );
134
+ get .addFamily (FAMILY );
135
+ Result result = hTable .get (get );
136
+ assertEquals (3 , result .size ());
156
137
157
- hTable .close ();
138
+ a = new Append (ROW );
139
+ a .add (FAMILY , QUALIFIERS [2 ], v1 );
140
+ a .add (FAMILY , QUALIFIERS [2 ], "" .getBytes ());
141
+ hTable .append (a );
142
+ get = new Get (ROW );
143
+ get .setMaxVersions (10 );
144
+ get .addFamily (FAMILY );
145
+ result = hTable .get (get );
146
+ assertEquals (4 , result .size ());
147
+
148
+ byte [] randomBytes = new byte [1025 ];
149
+ Random random = new Random ();
150
+ random .nextBytes (randomBytes );
151
+ a = new Append (ROW );
152
+ a .add (FAMILY , QUALIFIERS [2 ], randomBytes );
153
+ try {
154
+ hTable .append (a );
155
+ fail ("unexpect error, too long data should fail" );
156
+ } catch (IOException e ) {
157
+ assertTrue (e .getCause ().getMessage ().contains ("Data too long for column 'V'" ));
158
+ }
159
+ } finally {
160
+ hTable .close ();
161
+ }
158
162
159
163
}
160
164
161
165
private static void testAppendCon (String tableName ) throws Exception {
162
166
OHTableClient hTable = ObHTableTestUtil .newOHTableClient (getTableName (tableName ));
163
- hTable .init ();
164
- byte [] FAMILY = getColumnFamilyName (tableName ).getBytes ();
165
- String column = "appColumn" ;
166
- byte [] ROW = "appendKey" .getBytes ();
167
- byte [] v = "a" .getBytes ();
168
- byte [] expect = "a" .getBytes ();
169
- ThreadPoolExecutor threadPoolExecutor = OHTable .createDefaultThreadPoolExecutor (1 , 100 ,100 );
170
- AtomicInteger atomicInteger = new AtomicInteger (0 );
171
- CountDownLatch countDownLatch = new CountDownLatch (100 );
172
- for (int i = 0 ; i < 100 ; i ++) {
173
- Append append = new Append (ROW );
174
- append .add (FAMILY , column .getBytes (), v );
175
- threadPoolExecutor .submit (() -> {
176
- try {
177
- hTable .append (append );
178
- atomicInteger .incrementAndGet ();
179
- } catch (Exception e ) {
180
- if (!e .getCause ().getMessage ().contains ("OB_TRY_LOCK_ROW_CONFLICT" ) && !e .getCause ().getMessage ().contains ("OB_TIMEOUT" )) {
181
- throw new RuntimeException (e );
167
+ try {
168
+ hTable .init ();
169
+ byte [] FAMILY = getColumnFamilyName (tableName ).getBytes ();
170
+ String column = "appColumn" ;
171
+ byte [] ROW = "appendKey" .getBytes ();
172
+ byte [] v = "a" .getBytes ();
173
+ ThreadPoolExecutor threadPoolExecutor = OHTable .createDefaultThreadPoolExecutor (1 , 100 , 100 );
174
+ AtomicInteger atomicInteger = new AtomicInteger (0 );
175
+ CountDownLatch countDownLatch = new CountDownLatch (100 );
176
+
177
+ for (int i = 0 ; i < 100 ; i ++) {
178
+ Append append = new Append (ROW );
179
+ append .add (FAMILY , column .getBytes (), v );
180
+ threadPoolExecutor .submit (() -> {
181
+ try {
182
+ hTable .append (append );
183
+ } catch (Exception e ) {
184
+ if (!e .getCause ().getMessage ().contains ("OB_TRY_LOCK_ROW_CONFLICT" )
185
+ && !e .getCause ().getMessage ().contains ("OB_TIMEOUT" )) {
186
+ throw new RuntimeException (e );
187
+ }
188
+ } finally {
189
+ atomicInteger .incrementAndGet ();
190
+ countDownLatch .countDown ();
182
191
}
183
- } finally {
184
- countDownLatch .countDown ();
185
- }
186
- });
187
- }
188
- countDownLatch .await (100000 , TimeUnit .MILLISECONDS );
189
- for (int i = 0 ; i < atomicInteger .get () - 1 ; i ++) {
190
- expect = Bytes .add (expect , v );
192
+ });
193
+ }
194
+ threadPoolExecutor .shutdown ();
195
+ countDownLatch .await (100000 , TimeUnit .MILLISECONDS );
196
+ final byte [] expect = Strings .repeat ("a" , atomicInteger .get ()).getBytes ();
197
+ System .out .println ("atomicInteger: " + atomicInteger .get ());
198
+ Get get = new Get (ROW );
199
+ get .setMaxVersions (1 );
200
+ get .addColumn (FAMILY , column .getBytes ());
201
+ Result result = hTable .get (get );
202
+ ObHTableTestUtil .Assert (tableName , ()-> assertTrue (0 <= Bytes .compareTo (expect , result .getColumnCells (FAMILY , column .getBytes ()).get (0 ).getValue ())));
203
+ } finally {
204
+ hTable .close ();
191
205
}
192
- Get get = new Get (ROW );
193
- get .setMaxVersions (1 );
194
- get .addColumn (FAMILY , column .getBytes ());
195
- Result result = hTable .get (get );
196
- assertEquals (0 , Bytes .compareTo (expect , result .getColumnCells (FAMILY , column .getBytes ()).get (0 ).getValue ()));
197
- hTable .close ();
198
206
}
199
207
200
208
private static void testAppendMultiCF (Map .Entry <String , List <String >> entry ) throws Exception {
@@ -260,8 +268,8 @@ public void testAppendMultiCF() throws Throwable {
260
268
261
269
@ Test
262
270
public void testAppendSeires () throws Throwable {
263
- createTables (TableTemplateManager .TableType .SECONDARY_PARTITIONED_TIME_RANGE_KEY , series_tables , group2tableNames , true );
271
+ createTables (TableTemplateManager .TableType .SECONDARY_PARTITIONED_TIME_RANGE_KEY , series_tables , null , true );
264
272
FOR_EACH (series_tables , OHTableSecondaryPartAppendTest ::testAppendSeires );
265
- dropTables (series_tables , group2tableNames );
273
+ dropTables (series_tables , null );
266
274
}
267
275
}
0 commit comments