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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org
.apache
.hadoop
.hbase
.client
;
20 import static org
.apache
.hadoop
.hbase
.HConstants
.RPC_CODEC_CONF_KEY
;
21 import static org
.apache
.hadoop
.hbase
.ipc
.RpcClient
.DEFAULT_CODEC_CLASS
;
22 import static org
.junit
.Assert
.assertEquals
;
23 import static org
.junit
.Assert
.assertNotEquals
;
24 import static org
.junit
.Assert
.assertNotNull
;
25 import static org
.junit
.Assert
.assertTrue
;
26 import static org
.junit
.Assert
.fail
;
28 import java
.io
.IOException
;
29 import java
.util
.ArrayList
;
30 import java
.util
.Collections
;
31 import java
.util
.HashMap
;
32 import java
.util
.List
;
34 import org
.apache
.hadoop
.conf
.Configuration
;
35 import org
.apache
.hadoop
.hbase
.Cell
;
36 import org
.apache
.hadoop
.hbase
.CellBuilderType
;
37 import org
.apache
.hadoop
.hbase
.DoNotRetryIOException
;
38 import org
.apache
.hadoop
.hbase
.ExtendedCellBuilderFactory
;
39 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
40 import org
.apache
.hadoop
.hbase
.HBaseTestingUtil
;
41 import org
.apache
.hadoop
.hbase
.HConstants
;
42 import org
.apache
.hadoop
.hbase
.KeyValue
;
43 import org
.apache
.hadoop
.hbase
.PrivateCellUtil
;
44 import org
.apache
.hadoop
.hbase
.TableName
;
45 import org
.apache
.hadoop
.hbase
.Tag
;
46 import org
.apache
.hadoop
.hbase
.TagType
;
47 import org
.apache
.hadoop
.hbase
.codec
.KeyValueCodecWithTags
;
48 import org
.apache
.hadoop
.hbase
.coprocessor
.CoprocessorHost
;
49 import org
.apache
.hadoop
.hbase
.coprocessor
.MultiRowMutationEndpoint
;
50 import org
.apache
.hadoop
.hbase
.testclassification
.LargeTests
;
51 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
52 import org
.junit
.AfterClass
;
53 import org
.junit
.BeforeClass
;
54 import org
.junit
.ClassRule
;
55 import org
.junit
.Rule
;
56 import org
.junit
.Test
;
57 import org
.junit
.experimental
.categories
.Category
;
58 import org
.junit
.rules
.TestName
;
59 import org
.slf4j
.Logger
;
60 import org
.slf4j
.LoggerFactory
;
63 * Run Increment tests that use the HBase clients; {@link TableBuilder}.
65 * Test is parameterized to run the slow and fast increment code paths. If fast, in the @before, we
66 * do a rolling restart of the single regionserver so that it can pick up the go fast configuration.
67 * Doing it this way should be faster than starting/stopping a cluster per test.
69 * Test takes a long time because spin up a cluster between each run -- ugh.
71 @Category(LargeTests
.class)
72 public class TestIncrementsFromClientSide
{
75 public static final HBaseClassTestRule CLASS_RULE
=
76 HBaseClassTestRule
.forClass(TestIncrementsFromClientSide
.class);
78 final Logger LOG
= LoggerFactory
.getLogger(getClass());
79 protected final static HBaseTestingUtil TEST_UTIL
= new HBaseTestingUtil();
80 private static byte [] ROW
= Bytes
.toBytes("testRow");
81 private static byte [] FAMILY
= Bytes
.toBytes("testFamily");
82 private static byte [] QUALIFIER
= Bytes
.toBytes("testQualifier");
83 // This test depends on there being only one slave running at at a time. See the @Before
84 // method where we do rolling restart.
85 protected static int SLAVES
= 1;
86 @Rule public TestName name
= new TestName();
89 public static void beforeClass() throws Exception
{
90 Configuration conf
= TEST_UTIL
.getConfiguration();
91 conf
.setStrings(CoprocessorHost
.REGION_COPROCESSOR_CONF_KEY
,
92 MultiRowMutationEndpoint
.class.getName());
93 // We need more than one region server in this test
94 TEST_UTIL
.startMiniCluster(SLAVES
);
98 * @throws java.lang.Exception
101 public static void afterClass() throws Exception
{
102 TEST_UTIL
.shutdownMiniCluster();
106 * Test increment result when there are duplicate rpc request.
109 public void testDuplicateIncrement() throws Exception
{
110 TableDescriptorBuilder builder
=
111 TEST_UTIL
.createModifyableTableDescriptor(name
.getMethodName());
112 Map
<String
, String
> kvs
= new HashMap
<>();
113 kvs
.put(SleepAtFirstRpcCall
.SLEEP_TIME_CONF_KEY
, "2000");
114 builder
.setCoprocessor(CoprocessorDescriptorBuilder
115 .newBuilder(SleepAtFirstRpcCall
.class.getName())
119 TEST_UTIL
.createTable(builder
.build(), new byte[][] { ROW
}).close();
121 Configuration c
= new Configuration(TEST_UTIL
.getConfiguration());
122 c
.setInt(HConstants
.HBASE_CLIENT_PAUSE
, 50);
123 // Client will retry beacuse rpc timeout is small than the sleep time of first rpc call
124 c
.setInt(HConstants
.HBASE_RPC_TIMEOUT_KEY
, 1500);
126 try (Connection connection
= ConnectionFactory
.createConnection(c
);
127 Table table
= connection
.getTableBuilder(TableName
.valueOf(name
.getMethodName()), null)
128 .setOperationTimeout(3 * 1000).build()) {
129 Increment inc
= new Increment(ROW
);
130 inc
.addColumn(HBaseTestingUtil
.fam1
, QUALIFIER
, 1);
131 Result result
= table
.increment(inc
);
133 Cell
[] cells
= result
.rawCells();
134 assertEquals(1, cells
.length
);
135 assertIncrementKey(cells
[0], ROW
, HBaseTestingUtil
.fam1
, QUALIFIER
, 1);
137 // Verify expected result
138 Result readResult
= table
.get(new Get(ROW
));
139 cells
= readResult
.rawCells();
140 assertEquals(1, cells
.length
);
141 assertIncrementKey(cells
[0], ROW
, HBaseTestingUtil
.fam1
, QUALIFIER
, 1);
146 * Test batch increment result when there are duplicate rpc request.
149 public void testDuplicateBatchIncrement() throws Exception
{
150 TableDescriptorBuilder builder
=
151 TEST_UTIL
.createModifyableTableDescriptor(name
.getMethodName());
152 Map
<String
, String
> kvs
= new HashMap
<>();
153 kvs
.put(SleepAtFirstRpcCall
.SLEEP_TIME_CONF_KEY
, "2000");
154 builder
.setCoprocessor(CoprocessorDescriptorBuilder
155 .newBuilder(SleepAtFirstRpcCall
.class.getName())
159 TEST_UTIL
.createTable(builder
.build(), new byte[][] { ROW
}).close();
161 Configuration c
= new Configuration(TEST_UTIL
.getConfiguration());
162 c
.setInt(HConstants
.HBASE_CLIENT_PAUSE
, 50);
163 // Client will retry beacuse rpc timeout is small than the sleep time of first rpc call
164 c
.setInt(HConstants
.HBASE_RPC_TIMEOUT_KEY
, 1500);
166 try (Connection connection
= ConnectionFactory
.createConnection(c
);
167 Table table
= connection
.getTableBuilder(TableName
.valueOf(name
.getMethodName()), null)
168 .setOperationTimeout(3 * 1000).build()) {
169 Increment inc
= new Increment(ROW
);
170 inc
.addColumn(HBaseTestingUtil
.fam1
, QUALIFIER
, 1);
173 Object
[] results
= new Object
[1];
174 table
.batch(Collections
.singletonList(inc
), results
);
176 Cell
[] cells
= ((Result
) results
[0]).rawCells();
177 assertEquals(1, cells
.length
);
178 assertIncrementKey(cells
[0], ROW
, HBaseTestingUtil
.fam1
, QUALIFIER
, 1);
180 // Verify expected result
181 Result readResult
= table
.get(new Get(ROW
));
182 cells
= readResult
.rawCells();
183 assertEquals(1, cells
.length
);
184 assertIncrementKey(cells
[0], ROW
, HBaseTestingUtil
.fam1
, QUALIFIER
, 1);
189 public void testIncrementWithDeletes() throws Exception
{
190 LOG
.info("Starting " + this.name
.getMethodName());
191 final TableName TABLENAME
=
192 TableName
.valueOf(filterStringSoTableNameSafe(this.name
.getMethodName()));
193 Table ht
= TEST_UTIL
.createTable(TABLENAME
, FAMILY
);
194 final byte[] COLUMN
= Bytes
.toBytes("column");
196 ht
.incrementColumnValue(ROW
, FAMILY
, COLUMN
, 5);
197 TEST_UTIL
.flush(TABLENAME
);
199 Delete del
= new Delete(ROW
);
202 ht
.incrementColumnValue(ROW
, FAMILY
, COLUMN
, 5);
204 Get get
= new Get(ROW
);
205 Result r
= ht
.get(get
);
206 assertEquals(1, r
.size());
207 assertEquals(5, Bytes
.toLong(r
.getValue(FAMILY
, COLUMN
)));
211 public void testIncrementingInvalidValue() throws Exception
{
212 LOG
.info("Starting " + this.name
.getMethodName());
213 final TableName TABLENAME
=
214 TableName
.valueOf(filterStringSoTableNameSafe(this.name
.getMethodName()));
215 Table ht
= TEST_UTIL
.createTable(TABLENAME
, FAMILY
);
216 final byte[] COLUMN
= Bytes
.toBytes("column");
217 Put p
= new Put(ROW
);
218 // write an integer here (not a Long)
219 p
.addColumn(FAMILY
, COLUMN
, Bytes
.toBytes(5));
222 ht
.incrementColumnValue(ROW
, FAMILY
, COLUMN
, 5);
223 fail("Should have thrown DoNotRetryIOException");
224 } catch (DoNotRetryIOException iox
) {
227 Increment inc
= new Increment(ROW
);
228 inc
.addColumn(FAMILY
, COLUMN
, 5);
231 fail("Should have thrown DoNotRetryIOException");
232 } catch (DoNotRetryIOException iox
) {
238 public void testBatchIncrementsWithReturnResultFalse() throws Exception
{
239 LOG
.info("Starting testBatchIncrementsWithReturnResultFalse");
240 final TableName tableName
= TableName
.valueOf(name
.getMethodName());
241 Table table
= TEST_UTIL
.createTable(tableName
, FAMILY
);
242 Increment inc1
= new Increment(Bytes
.toBytes("row2"));
243 inc1
.setReturnResults(false);
244 inc1
.addColumn(FAMILY
, Bytes
.toBytes("f1"), 1);
245 Increment inc2
= new Increment(Bytes
.toBytes("row2"));
246 inc2
.setReturnResults(false);
247 inc2
.addColumn(FAMILY
, Bytes
.toBytes("f1"), 1);
248 List
<Increment
> incs
= new ArrayList
<>();
251 Object
[] results
= new Object
[2];
252 table
.batch(incs
, results
);
253 assertTrue(results
.length
== 2);
254 for(Object r
: results
) {
255 Result result
= (Result
)r
;
256 assertTrue(result
.isEmpty());
262 public void testIncrementInvalidArguments() throws Exception
{
263 LOG
.info("Starting " + this.name
.getMethodName());
264 final TableName TABLENAME
=
265 TableName
.valueOf(filterStringSoTableNameSafe(this.name
.getMethodName()));
266 Table ht
= TEST_UTIL
.createTable(TABLENAME
, FAMILY
);
267 final byte[] COLUMN
= Bytes
.toBytes("column");
270 ht
.incrementColumnValue(null, FAMILY
, COLUMN
, 5);
271 fail("Should have thrown NPE/IOE");
272 } catch (NullPointerException
| IOException error
) {
277 ht
.incrementColumnValue(ROW
, null, COLUMN
, 5);
278 fail("Should have thrown NPE/IOE");
279 } catch (NullPointerException
| IOException error
) {
284 Increment incNoRow
= new Increment((byte[]) null);
285 incNoRow
.addColumn(FAMILY
, COLUMN
, 5);
286 fail("Should have thrown IAE/NPE");
287 } catch (IllegalArgumentException
| NullPointerException error
) {
292 Increment incNoFamily
= new Increment(ROW
);
293 incNoFamily
.addColumn(null, COLUMN
, 5);
294 fail("Should have thrown IAE");
295 } catch (IllegalArgumentException iax
) {
301 public void testIncrementOutOfOrder() throws Exception
{
302 LOG
.info("Starting " + this.name
.getMethodName());
303 final TableName TABLENAME
=
304 TableName
.valueOf(filterStringSoTableNameSafe(this.name
.getMethodName()));
305 Table ht
= TEST_UTIL
.createTable(TABLENAME
, FAMILY
);
307 byte [][] QUALIFIERS
= new byte [][] {
308 Bytes
.toBytes("B"), Bytes
.toBytes("A"), Bytes
.toBytes("C")
311 Increment inc
= new Increment(ROW
);
312 for (int i
=0; i
<QUALIFIERS
.length
; i
++) {
313 inc
.addColumn(FAMILY
, QUALIFIERS
[i
], 1);
317 // Verify expected results
318 Get get
= new Get(ROW
);
319 Result r
= ht
.get(get
);
320 Cell
[] kvs
= r
.rawCells();
321 assertEquals(3, kvs
.length
);
322 assertIncrementKey(kvs
[0], ROW
, FAMILY
, QUALIFIERS
[1], 1);
323 assertIncrementKey(kvs
[1], ROW
, FAMILY
, QUALIFIERS
[0], 1);
324 assertIncrementKey(kvs
[2], ROW
, FAMILY
, QUALIFIERS
[2], 1);
326 // Now try multiple columns again
327 inc
= new Increment(ROW
);
328 for (int i
=0; i
<QUALIFIERS
.length
; i
++) {
329 inc
.addColumn(FAMILY
, QUALIFIERS
[i
], 1);
336 assertEquals(3, kvs
.length
);
337 assertIncrementKey(kvs
[0], ROW
, FAMILY
, QUALIFIERS
[1], 2);
338 assertIncrementKey(kvs
[1], ROW
, FAMILY
, QUALIFIERS
[0], 2);
339 assertIncrementKey(kvs
[2], ROW
, FAMILY
, QUALIFIERS
[2], 2);
343 public void testIncrementOnSameColumn() throws Exception
{
344 LOG
.info("Starting " + this.name
.getMethodName());
345 final byte[] TABLENAME
= Bytes
.toBytes(filterStringSoTableNameSafe(this.name
.getMethodName()));
346 Table ht
= TEST_UTIL
.createTable(TableName
.valueOf(TABLENAME
), FAMILY
);
348 byte[][] QUALIFIERS
=
349 new byte[][] { Bytes
.toBytes("A"), Bytes
.toBytes("B"), Bytes
.toBytes("C") };
351 Increment inc
= new Increment(ROW
);
352 for (int i
= 0; i
< QUALIFIERS
.length
; i
++) {
353 inc
.addColumn(FAMILY
, QUALIFIERS
[i
], 1);
354 inc
.addColumn(FAMILY
, QUALIFIERS
[i
], 1);
358 // Verify expected results
359 Get get
= new Get(ROW
);
360 Result r
= ht
.get(get
);
361 Cell
[] kvs
= r
.rawCells();
362 assertEquals(3, kvs
.length
);
363 assertIncrementKey(kvs
[0], ROW
, FAMILY
, QUALIFIERS
[0], 1);
364 assertIncrementKey(kvs
[1], ROW
, FAMILY
, QUALIFIERS
[1], 1);
365 assertIncrementKey(kvs
[2], ROW
, FAMILY
, QUALIFIERS
[2], 1);
367 // Now try multiple columns again
368 inc
= new Increment(ROW
);
369 for (int i
= 0; i
< QUALIFIERS
.length
; i
++) {
370 inc
.addColumn(FAMILY
, QUALIFIERS
[i
], 1);
371 inc
.addColumn(FAMILY
, QUALIFIERS
[i
], 1);
378 assertEquals(3, kvs
.length
);
379 assertIncrementKey(kvs
[0], ROW
, FAMILY
, QUALIFIERS
[0], 2);
380 assertIncrementKey(kvs
[1], ROW
, FAMILY
, QUALIFIERS
[1], 2);
381 assertIncrementKey(kvs
[2], ROW
, FAMILY
, QUALIFIERS
[2], 2);
387 public void testIncrementIncrZeroAtFirst() throws Exception
{
388 LOG
.info("Starting " + this.name
.getMethodName());
389 final TableName TABLENAME
=
390 TableName
.valueOf(filterStringSoTableNameSafe(this.name
.getMethodName()));
391 Table ht
= TEST_UTIL
.createTable(TABLENAME
, FAMILY
);
393 byte[] col1
= Bytes
.toBytes("col1");
394 byte[] col2
= Bytes
.toBytes("col2");
395 byte[] col3
= Bytes
.toBytes("col3");
397 // Now increment zero at first time incr
398 Increment inc
= new Increment(ROW
);
399 inc
.addColumn(FAMILY
, col1
, 0);
402 // Verify expected results
403 Get get
= new Get(ROW
);
404 Result r
= ht
.get(get
);
405 Cell
[] kvs
= r
.rawCells();
406 assertEquals(1, kvs
.length
);
407 assertNotNull(kvs
[0]);
408 assertIncrementKey(kvs
[0], ROW
, FAMILY
, col1
, 0);
410 // Now try multiple columns by different amounts
411 inc
= new Increment(ROW
);
412 inc
.addColumn(FAMILY
, col1
, 1);
413 inc
.addColumn(FAMILY
, col2
, 0);
414 inc
.addColumn(FAMILY
, col3
, 2);
420 assertEquals(3, kvs
.length
);
421 assertNotNull(kvs
[0]);
422 assertNotNull(kvs
[1]);
423 assertNotNull(kvs
[2]);
424 assertIncrementKey(kvs
[0], ROW
, FAMILY
, col1
, 1);
425 assertIncrementKey(kvs
[1], ROW
, FAMILY
, col2
, 0);
426 assertIncrementKey(kvs
[2], ROW
, FAMILY
, col3
, 2);
430 public void testIncrement() throws Exception
{
431 LOG
.info("Starting " + this.name
.getMethodName());
432 final TableName TABLENAME
=
433 TableName
.valueOf(filterStringSoTableNameSafe(this.name
.getMethodName()));
434 Table ht
= TEST_UTIL
.createTable(TABLENAME
, FAMILY
);
436 byte [][] ROWS
= new byte [][] {
437 Bytes
.toBytes("a"), Bytes
.toBytes("b"), Bytes
.toBytes("c"),
438 Bytes
.toBytes("d"), Bytes
.toBytes("e"), Bytes
.toBytes("f"),
439 Bytes
.toBytes("g"), Bytes
.toBytes("h"), Bytes
.toBytes("i")
441 byte [][] QUALIFIERS
= new byte [][] {
442 Bytes
.toBytes("a"), Bytes
.toBytes("b"), Bytes
.toBytes("c"),
443 Bytes
.toBytes("d"), Bytes
.toBytes("e"), Bytes
.toBytes("f"),
444 Bytes
.toBytes("g"), Bytes
.toBytes("h"), Bytes
.toBytes("i")
447 // Do some simple single-column increments
449 // First with old API
450 ht
.incrementColumnValue(ROW
, FAMILY
, QUALIFIERS
[0], 1);
451 ht
.incrementColumnValue(ROW
, FAMILY
, QUALIFIERS
[1], 2);
452 ht
.incrementColumnValue(ROW
, FAMILY
, QUALIFIERS
[2], 3);
453 ht
.incrementColumnValue(ROW
, FAMILY
, QUALIFIERS
[3], 4);
455 // Now increment things incremented with old and do some new
456 Increment inc
= new Increment(ROW
);
457 inc
.addColumn(FAMILY
, QUALIFIERS
[1], 1);
458 inc
.addColumn(FAMILY
, QUALIFIERS
[3], 1);
459 inc
.addColumn(FAMILY
, QUALIFIERS
[4], 1);
462 // Verify expected results
463 Get get
= new Get(ROW
);
464 Result r
= ht
.get(get
);
465 Cell
[] kvs
= r
.rawCells();
466 assertEquals(5, kvs
.length
);
467 assertIncrementKey(kvs
[0], ROW
, FAMILY
, QUALIFIERS
[0], 1);
468 assertIncrementKey(kvs
[1], ROW
, FAMILY
, QUALIFIERS
[1], 3);
469 assertIncrementKey(kvs
[2], ROW
, FAMILY
, QUALIFIERS
[2], 3);
470 assertIncrementKey(kvs
[3], ROW
, FAMILY
, QUALIFIERS
[3], 5);
471 assertIncrementKey(kvs
[4], ROW
, FAMILY
, QUALIFIERS
[4], 1);
473 // Now try multiple columns by different amounts
474 inc
= new Increment(ROWS
[0]);
475 for (int i
=0;i
<QUALIFIERS
.length
;i
++) {
476 inc
.addColumn(FAMILY
, QUALIFIERS
[i
], i
+1);
480 get
= new Get(ROWS
[0]);
483 assertEquals(QUALIFIERS
.length
, kvs
.length
);
484 for (int i
=0;i
<QUALIFIERS
.length
;i
++) {
485 assertIncrementKey(kvs
[i
], ROWS
[0], FAMILY
, QUALIFIERS
[i
], i
+1);
489 inc
= new Increment(ROWS
[0]);
490 for (int i
=0;i
<QUALIFIERS
.length
;i
++) {
491 inc
.addColumn(FAMILY
, QUALIFIERS
[i
], i
+1);
497 assertEquals(QUALIFIERS
.length
, kvs
.length
);
498 for (int i
=0;i
<QUALIFIERS
.length
;i
++) {
499 assertIncrementKey(kvs
[i
], ROWS
[0], FAMILY
, QUALIFIERS
[i
], 2*(i
+1));
502 // Verify that an Increment of an amount of zero, returns current count; i.e. same as for above
503 // test, that is: 2 * (i + 1).
504 inc
= new Increment(ROWS
[0]);
505 for (int i
= 0; i
< QUALIFIERS
.length
; i
++) {
506 inc
.addColumn(FAMILY
, QUALIFIERS
[i
], 0);
511 assertEquals(QUALIFIERS
.length
, kvs
.length
);
512 for (int i
= 0; i
< QUALIFIERS
.length
; i
++) {
513 assertIncrementKey(kvs
[i
], ROWS
[0], FAMILY
, QUALIFIERS
[i
], 2*(i
+1));
518 public void testIncrementWithCustomTimestamp() throws IOException
{
519 TableName TABLENAME
= TableName
.valueOf(name
.getMethodName());
520 Table table
= TEST_UTIL
.createTable(TABLENAME
, FAMILY
);
521 long timestamp
= 999;
522 Increment increment
= new Increment(ROW
);
523 increment
.add(ExtendedCellBuilderFactory
.create(CellBuilderType
.DEEP_COPY
)
526 .setQualifier(QUALIFIER
)
527 .setTimestamp(timestamp
)
528 .setType(KeyValue
.Type
.Put
.getCode())
529 .setValue(Bytes
.toBytes(100L))
531 Result r
= table
.increment(increment
);
532 assertEquals(1, r
.size());
533 assertEquals(timestamp
, r
.rawCells()[0].getTimestamp());
534 r
= table
.get(new Get(ROW
));
535 assertEquals(1, r
.size());
536 assertEquals(timestamp
, r
.rawCells()[0].getTimestamp());
537 r
= table
.increment(increment
);
538 assertEquals(1, r
.size());
539 assertNotEquals(timestamp
, r
.rawCells()[0].getTimestamp());
540 r
= table
.get(new Get(ROW
));
541 assertEquals(1, r
.size());
542 assertNotEquals(timestamp
, r
.rawCells()[0].getTimestamp());
546 * Call over to the adjacent class's method of same name.
548 static void assertIncrementKey(Cell key
, byte [] row
, byte [] family
,
549 byte [] qualifier
, long value
) throws Exception
{
550 TestFromClientSide
.assertIncrementKey(key
, row
, family
, qualifier
, value
);
553 public static String
filterStringSoTableNameSafe(final String str
) {
554 return str
.replaceAll("\\[fast\\=(.*)\\]", ".FAST.is.$1");
558 Test that we have only 1 ttl tag with increment mutation.
561 public void testIncrementWithTtlTags() throws Exception
{
562 LOG
.info("Starting " + this.name
.getMethodName());
563 final TableName tableName
=
564 TableName
.valueOf(filterStringSoTableNameSafe(this.name
.getMethodName()));
565 Table ht
= TEST_UTIL
.createTable(tableName
, FAMILY
);
566 final byte[] COLUMN
= Bytes
.toBytes("column");
568 Configuration conf
= new Configuration(TEST_UTIL
.getConfiguration());
569 // Set RPC_CODEC_CONF_KEY to KeyValueCodecWithTags so that scan will return tags.
570 conf
.set(RPC_CODEC_CONF_KEY
, KeyValueCodecWithTags
.class.getName());
571 conf
.set(DEFAULT_CODEC_CLASS
, "");
572 try (Connection connection
= ConnectionFactory
.createConnection(conf
);
573 Table table
= connection
.getTable(tableName
)) {
574 for (int i
= 0; i
< 10; i
++) {
575 Increment inc
= new Increment(ROW
);
576 inc
.addColumn(FAMILY
, COLUMN
, 1);
577 long ttl
= i
+ 3600000 ;
581 Scan scan
= new Scan().withStartRow(ROW
);
582 ResultScanner scanner
= table
.getScanner(scan
);
585 while ((result
= scanner
.next()) != null) {
586 Cell
[] cells
= result
.rawCells();
587 for (Cell cell
: cells
) {
588 List
<Tag
> tags
= PrivateCellUtil
.getTags(cell
);
589 // Make sure there is only 1 tag.
590 assertEquals(1, tags
.size());
591 Tag tag
= tags
.get(0);
592 assertEquals(TagType
.TTL_TAG_TYPE
, tag
.getType());
593 long ttlTagValue
= Bytes
.toLong(tag
.getValueArray(), tag
.getValueOffset());
594 assertEquals(ttl
, ttlTagValue
);
598 // Make sure there is only 1 result.
599 assertEquals(1, count
);