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
.hamcrest
.CoreMatchers
.instanceOf
;
21 import static org
.hamcrest
.MatcherAssert
.assertThat
;
22 import static org
.junit
.Assert
.assertEquals
;
23 import static org
.junit
.Assert
.assertFalse
;
24 import static org
.junit
.Assert
.assertNull
;
25 import static org
.junit
.Assert
.assertTrue
;
26 import static org
.junit
.Assert
.fail
;
27 import java
.io
.IOException
;
28 import java
.util
.Arrays
;
29 import java
.util
.Collections
;
30 import java
.util
.List
;
31 import org
.apache
.hadoop
.hbase
.CompareOperator
;
32 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
33 import org
.apache
.hadoop
.hbase
.HBaseTestingUtil
;
34 import org
.apache
.hadoop
.hbase
.TableName
;
35 import org
.apache
.hadoop
.hbase
.filter
.BinaryComparator
;
36 import org
.apache
.hadoop
.hbase
.filter
.FamilyFilter
;
37 import org
.apache
.hadoop
.hbase
.filter
.FilterList
;
38 import org
.apache
.hadoop
.hbase
.filter
.QualifierFilter
;
39 import org
.apache
.hadoop
.hbase
.filter
.SingleColumnValueFilter
;
40 import org
.apache
.hadoop
.hbase
.filter
.TimestampsFilter
;
41 import org
.apache
.hadoop
.hbase
.io
.TimeRange
;
42 import org
.apache
.hadoop
.hbase
.regionserver
.NoSuchColumnFamilyException
;
43 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
44 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
45 import org
.junit
.AfterClass
;
46 import org
.junit
.BeforeClass
;
47 import org
.junit
.ClassRule
;
48 import org
.junit
.Rule
;
49 import org
.junit
.Test
;
50 import org
.junit
.experimental
.categories
.Category
;
51 import org
.junit
.rules
.TestName
;
53 @Category(MediumTests
.class)
54 public class TestCheckAndMutate
{
57 public static final HBaseClassTestRule CLASS_RULE
=
58 HBaseClassTestRule
.forClass(TestCheckAndMutate
.class);
60 private static final HBaseTestingUtil TEST_UTIL
= new HBaseTestingUtil();
61 private static final byte[] ROWKEY
= Bytes
.toBytes("12345");
62 private static final byte[] ROWKEY2
= Bytes
.toBytes("67890");
63 private static final byte[] ROWKEY3
= Bytes
.toBytes("abcde");
64 private static final byte[] ROWKEY4
= Bytes
.toBytes("fghij");
65 private static final byte[] FAMILY
= Bytes
.toBytes("cf");
68 public TestName name
= new TestName();
71 public static void setUpBeforeClass() throws Exception
{
72 TEST_UTIL
.startMiniCluster();
76 public static void tearDownAfterClass() throws Exception
{
77 TEST_UTIL
.shutdownMiniCluster();
80 private Table
createTable()
81 throws IOException
, InterruptedException
{
82 final TableName tableName
= TableName
.valueOf(name
.getMethodName());
83 Table table
= TEST_UTIL
.createTable(tableName
, FAMILY
);
84 TEST_UTIL
.waitTableAvailable(tableName
.getName(), 5000);
88 private void putOneRow(Table table
) throws IOException
{
89 Put put
= new Put(ROWKEY
);
90 put
.addColumn(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a"));
91 put
.addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("b"));
92 put
.addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("c"));
96 private void getOneRowAndAssertAllExist(final Table table
) throws IOException
{
97 Get get
= new Get(ROWKEY
);
98 Result result
= table
.get(get
);
99 assertTrue("Column A value should be a",
100 Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("A"))).equals("a"));
101 assertTrue("Column B value should be b",
102 Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("B"))).equals("b"));
103 assertTrue("Column C value should be c",
104 Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("C"))).equals("c"));
107 private void getOneRowAndAssertAllButCExist(final Table table
) throws IOException
{
108 Get get
= new Get(ROWKEY
);
109 Result result
= table
.get(get
);
110 assertTrue("Column A value should be a",
111 Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("A"))).equals("a"));
112 assertTrue("Column B value should be b",
113 Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("B"))).equals("b"));
114 assertTrue("Column C should not exist",
115 result
.getValue(FAMILY
, Bytes
.toBytes("C")) == null);
118 private RowMutations
makeRowMutationsWithColumnCDeleted() throws IOException
{
119 RowMutations rm
= new RowMutations(ROWKEY
, 2);
120 Put put
= new Put(ROWKEY
);
121 put
.addColumn(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a"));
122 put
.addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("b"));
124 Delete del
= new Delete(ROWKEY
);
125 del
.addColumn(FAMILY
, Bytes
.toBytes("C"));
130 private RowMutations
getBogusRowMutations() throws IOException
{
131 Put p
= new Put(ROWKEY
);
132 byte[] value
= new byte[0];
133 p
.addColumn(new byte[]{'b', 'o', 'g', 'u', 's'}, new byte[]{'A'}, value
);
134 RowMutations rm
= new RowMutations(ROWKEY
);
139 // Tests for old checkAndMutate API
143 public void testCheckAndMutateForOldApi() throws Throwable
{
144 try (Table table
= createTable()) {
147 // get row back and assert the values
148 getOneRowAndAssertAllExist(table
);
150 // put the same row again with C column deleted
151 RowMutations rm
= makeRowMutationsWithColumnCDeleted();
152 boolean res
= table
.checkAndMutate(ROWKEY
, FAMILY
).qualifier(Bytes
.toBytes("A"))
153 .ifEquals(Bytes
.toBytes("a")).thenMutate(rm
);
156 // get row back and assert the values
157 getOneRowAndAssertAllButCExist(table
);
159 // Test that we get a region level exception
161 rm
= getBogusRowMutations();
162 table
.checkAndMutate(ROWKEY
, FAMILY
).qualifier(Bytes
.toBytes("A"))
163 .ifEquals(Bytes
.toBytes("a")).thenMutate(rm
);
164 fail("Expected NoSuchColumnFamilyException");
165 } catch (NoSuchColumnFamilyException e
) {
167 } catch (RetriesExhaustedException e
) {
168 assertThat(e
.getCause(), instanceOf(NoSuchColumnFamilyException
.class));
175 public void testCheckAndMutateWithSingleFilterForOldApi() throws Throwable
{
176 try (Table table
= createTable()) {
179 // get row back and assert the values
180 getOneRowAndAssertAllExist(table
);
183 boolean ok
= table
.checkAndMutate(ROWKEY
, new SingleColumnValueFilter(FAMILY
,
184 Bytes
.toBytes("A"), CompareOperator
.EQUAL
, Bytes
.toBytes("a")))
185 .thenPut(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d")));
188 Result result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D")));
189 assertEquals("d", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("D"))));
192 ok
= table
.checkAndMutate(ROWKEY
, new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"),
193 CompareOperator
.EQUAL
, Bytes
.toBytes("b")))
194 .thenPut(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("E"), Bytes
.toBytes("e")));
197 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("E"))));
199 // Delete with success
200 ok
= table
.checkAndMutate(ROWKEY
, new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"),
201 CompareOperator
.EQUAL
, Bytes
.toBytes("a")))
202 .thenDelete(new Delete(ROWKEY
).addColumns(FAMILY
, Bytes
.toBytes("D")));
205 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D"))));
207 // Mutate with success
208 ok
= table
.checkAndMutate(ROWKEY
, new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("B"),
209 CompareOperator
.EQUAL
, Bytes
.toBytes("b")))
210 .thenMutate(new RowMutations(ROWKEY
)
211 .add((Mutation
) new Put(ROWKEY
)
212 .addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d")))
213 .add((Mutation
) new Delete(ROWKEY
).addColumns(FAMILY
, Bytes
.toBytes("A"))));
216 result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D")));
217 assertEquals("d", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("D"))));
219 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"))));
225 public void testCheckAndMutateWithMultipleFiltersForOldApi() throws Throwable
{
226 try (Table table
= createTable()) {
229 // get row back and assert the values
230 getOneRowAndAssertAllExist(table
);
233 boolean ok
= table
.checkAndMutate(ROWKEY
, new FilterList(
234 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
236 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("B"), CompareOperator
.EQUAL
,
239 .thenPut(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d")));
242 Result result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D")));
243 assertEquals("d", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("D"))));
246 ok
= table
.checkAndMutate(ROWKEY
, new FilterList(
247 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
249 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("B"), CompareOperator
.EQUAL
,
252 .thenPut(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("E"), Bytes
.toBytes("e")));
255 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("E"))));
257 // Delete with success
258 ok
= table
.checkAndMutate(ROWKEY
, new FilterList(
259 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
261 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("B"), CompareOperator
.EQUAL
,
264 .thenDelete(new Delete(ROWKEY
).addColumns(FAMILY
, Bytes
.toBytes("D")));
267 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D"))));
269 // Mutate with success
270 ok
= table
.checkAndMutate(ROWKEY
, new FilterList(
271 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
273 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("B"), CompareOperator
.EQUAL
,
276 .thenMutate(new RowMutations(ROWKEY
)
277 .add((Mutation
) new Put(ROWKEY
)
278 .addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d")))
279 .add((Mutation
) new Delete(ROWKEY
).addColumns(FAMILY
, Bytes
.toBytes("A"))));
282 result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D")));
283 assertEquals("d", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("D"))));
285 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"))));
291 public void testCheckAndMutateWithTimestampFilterForOldApi() throws Throwable
{
292 try (Table table
= createTable()) {
293 // Put with specifying the timestamp
294 table
.put(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"), 100, Bytes
.toBytes("a")));
297 boolean ok
= table
.checkAndMutate(ROWKEY
, new FilterList(
298 new FamilyFilter(CompareOperator
.EQUAL
, new BinaryComparator(FAMILY
)),
299 new QualifierFilter(CompareOperator
.EQUAL
, new BinaryComparator(Bytes
.toBytes("A"))),
300 new TimestampsFilter(Collections
.singletonList(100L))
302 .thenPut(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("b")));
305 Result result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B")));
306 assertEquals("b", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
309 ok
= table
.checkAndMutate(ROWKEY
, new FilterList(
310 new FamilyFilter(CompareOperator
.EQUAL
, new BinaryComparator(FAMILY
)),
311 new QualifierFilter(CompareOperator
.EQUAL
, new BinaryComparator(Bytes
.toBytes("A"))),
312 new TimestampsFilter(Collections
.singletonList(101L))
314 .thenPut(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("c")));
317 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C"))));
323 public void testCheckAndMutateWithFilterAndTimeRangeForOldApi() throws Throwable
{
324 try (Table table
= createTable()) {
325 // Put with specifying the timestamp
326 table
.put(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"), 100, Bytes
.toBytes("a")));
329 boolean ok
= table
.checkAndMutate(ROWKEY
, new SingleColumnValueFilter(FAMILY
,
330 Bytes
.toBytes("A"), CompareOperator
.EQUAL
, Bytes
.toBytes("a")))
331 .timeRange(TimeRange
.between(0, 101))
332 .thenPut(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("b")));
335 Result result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B")));
336 assertEquals("b", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
339 ok
= table
.checkAndMutate(ROWKEY
, new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"),
340 CompareOperator
.EQUAL
, Bytes
.toBytes("a")))
341 .timeRange(TimeRange
.between(0, 100))
342 .thenPut(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("c")));
345 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C"))));
349 @Test(expected
= NullPointerException
.class)
351 public void testCheckAndMutateWithoutConditionForOldApi() throws Throwable
{
352 try (Table table
= createTable()) {
353 table
.checkAndMutate(ROWKEY
, FAMILY
)
354 .thenPut(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d")));
358 // Tests for new CheckAndMutate API
361 public void testCheckAndMutate() throws Throwable
{
362 try (Table table
= createTable()) {
365 // get row back and assert the values
366 getOneRowAndAssertAllExist(table
);
368 // put the same row again with C column deleted
369 RowMutations rm
= makeRowMutationsWithColumnCDeleted();
370 CheckAndMutateResult res
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
371 .ifEquals(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a"))
373 assertTrue(res
.isSuccess());
374 assertNull(res
.getResult());
376 // get row back and assert the values
377 getOneRowAndAssertAllButCExist(table
);
379 // Test that we get a region level exception
381 rm
= getBogusRowMutations();
382 table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
383 .ifEquals(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a"))
385 fail("Expected NoSuchColumnFamilyException");
386 } catch (NoSuchColumnFamilyException e
) {
388 } catch (RetriesExhaustedException e
) {
389 assertThat(e
.getCause(), instanceOf(NoSuchColumnFamilyException
.class));
395 public void testCheckAndMutateWithSingleFilter() throws Throwable
{
396 try (Table table
= createTable()) {
399 // get row back and assert the values
400 getOneRowAndAssertAllExist(table
);
403 CheckAndMutateResult result
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
404 .ifMatches(new SingleColumnValueFilter(FAMILY
,
405 Bytes
.toBytes("A"), CompareOperator
.EQUAL
, Bytes
.toBytes("a")))
406 .build(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d"))));
407 assertTrue(result
.isSuccess());
408 assertNull(result
.getResult());
410 Result r
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D")));
411 assertEquals("d", Bytes
.toString(r
.getValue(FAMILY
, Bytes
.toBytes("D"))));
414 result
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
415 .ifMatches(new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"),
416 CompareOperator
.EQUAL
, Bytes
.toBytes("b")))
417 .build(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("E"), Bytes
.toBytes("e"))));
418 assertFalse(result
.isSuccess());
419 assertNull(result
.getResult());
421 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("E"))));
423 // Delete with success
424 result
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
425 .ifMatches(new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"),
426 CompareOperator
.EQUAL
, Bytes
.toBytes("a")))
427 .build(new Delete(ROWKEY
).addColumns(FAMILY
, Bytes
.toBytes("D"))));
428 assertTrue(result
.isSuccess());
429 assertNull(result
.getResult());
431 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D"))));
433 // Mutate with success
434 result
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
435 .ifMatches(new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("B"),
436 CompareOperator
.EQUAL
, Bytes
.toBytes("b")))
437 .build(new RowMutations(ROWKEY
)
438 .add((Mutation
) new Put(ROWKEY
)
439 .addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d")))
440 .add((Mutation
) new Delete(ROWKEY
).addColumns(FAMILY
, Bytes
.toBytes("A")))));
441 assertTrue(result
.isSuccess());
442 assertNull(result
.getResult());
444 r
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D")));
445 assertEquals("d", Bytes
.toString(r
.getValue(FAMILY
, Bytes
.toBytes("D"))));
447 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"))));
452 public void testCheckAndMutateWithMultipleFilters() throws Throwable
{
453 try (Table table
= createTable()) {
456 // get row back and assert the values
457 getOneRowAndAssertAllExist(table
);
460 CheckAndMutateResult result
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
461 .ifMatches(new FilterList(
462 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
464 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("B"), CompareOperator
.EQUAL
,
465 Bytes
.toBytes("b"))))
466 .build(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d"))));
467 assertTrue(result
.isSuccess());
468 assertNull(result
.getResult());
470 Result r
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D")));
471 assertEquals("d", Bytes
.toString(r
.getValue(FAMILY
, Bytes
.toBytes("D"))));
474 result
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
475 .ifMatches(new FilterList(
476 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
478 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("B"), CompareOperator
.EQUAL
,
479 Bytes
.toBytes("c"))))
480 .build(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("E"), Bytes
.toBytes("e"))));
481 assertFalse(result
.isSuccess());
482 assertNull(result
.getResult());
484 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("E"))));
486 // Delete with success
487 result
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
488 .ifMatches(new FilterList(
489 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
491 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("B"), CompareOperator
.EQUAL
,
492 Bytes
.toBytes("b"))))
493 .build(new Delete(ROWKEY
).addColumns(FAMILY
, Bytes
.toBytes("D"))));
494 assertTrue(result
.isSuccess());
495 assertNull(result
.getResult());
497 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D"))));
499 // Mutate with success
500 result
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
501 .ifMatches(new FilterList(
502 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
504 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("B"), CompareOperator
.EQUAL
,
505 Bytes
.toBytes("b"))))
506 .build(new RowMutations(ROWKEY
)
507 .add((Mutation
) new Put(ROWKEY
)
508 .addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d")))
509 .add((Mutation
) new Delete(ROWKEY
).addColumns(FAMILY
, Bytes
.toBytes("A")))));
510 assertTrue(result
.isSuccess());
511 assertNull(result
.getResult());
513 r
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D")));
514 assertEquals("d", Bytes
.toString(r
.getValue(FAMILY
, Bytes
.toBytes("D"))));
516 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"))));
521 public void testCheckAndMutateWithTimestampFilter() throws Throwable
{
522 try (Table table
= createTable()) {
523 // Put with specifying the timestamp
524 table
.put(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"), 100, Bytes
.toBytes("a")));
527 CheckAndMutateResult result
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
528 .ifMatches(new FilterList(
529 new FamilyFilter(CompareOperator
.EQUAL
, new BinaryComparator(FAMILY
)),
530 new QualifierFilter(CompareOperator
.EQUAL
, new BinaryComparator(Bytes
.toBytes("A"))),
531 new TimestampsFilter(Collections
.singletonList(100L))))
532 .build(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("b"))));
533 assertTrue(result
.isSuccess());
534 assertNull(result
.getResult());
536 Result r
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B")));
537 assertEquals("b", Bytes
.toString(r
.getValue(FAMILY
, Bytes
.toBytes("B"))));
540 result
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
541 .ifMatches(new FilterList(
542 new FamilyFilter(CompareOperator
.EQUAL
, new BinaryComparator(FAMILY
)),
543 new QualifierFilter(CompareOperator
.EQUAL
, new BinaryComparator(Bytes
.toBytes("A"))),
544 new TimestampsFilter(Collections
.singletonList(101L))))
545 .build(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("c"))));
546 assertFalse(result
.isSuccess());
547 assertNull(result
.getResult());
549 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C"))));
554 public void testCheckAndMutateWithFilterAndTimeRange() throws Throwable
{
555 try (Table table
= createTable()) {
556 // Put with specifying the timestamp
557 table
.put(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"), 100, Bytes
.toBytes("a")));
560 CheckAndMutateResult result
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
561 .ifMatches(new SingleColumnValueFilter(FAMILY
,
562 Bytes
.toBytes("A"), CompareOperator
.EQUAL
, Bytes
.toBytes("a")))
563 .timeRange(TimeRange
.between(0, 101))
564 .build(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("b"))));
565 assertTrue(result
.isSuccess());
566 assertNull(result
.getResult());
568 Result r
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B")));
569 assertEquals("b", Bytes
.toString(r
.getValue(FAMILY
, Bytes
.toBytes("B"))));
572 result
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
573 .ifMatches(new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"),
574 CompareOperator
.EQUAL
, Bytes
.toBytes("a")))
575 .timeRange(TimeRange
.between(0, 100))
576 .build(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("c"))));
577 assertFalse(result
.isSuccess());
578 assertNull(result
.getResult());
580 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C"))));
584 @Test(expected
= IllegalStateException
.class)
585 public void testCheckAndMutateBuilderWithoutCondition() {
586 CheckAndMutate
.newBuilder(ROWKEY
)
587 .build(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d")));
591 public void testCheckAndIncrement() throws Throwable
{
592 try (Table table
= createTable()) {
593 table
.put(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a")));
595 // CheckAndIncrement with correct value
596 CheckAndMutateResult res
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
597 .ifEquals(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a"))
598 .build(new Increment(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B"), 1)));
599 assertTrue(res
.isSuccess());
600 assertEquals(1, Bytes
.toLong(res
.getResult().getValue(FAMILY
, Bytes
.toBytes("B"))));
602 Result result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B")));
603 assertEquals(1, Bytes
.toLong(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
605 // CheckAndIncrement with wrong value
606 res
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
607 .ifEquals(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("b"))
608 .build(new Increment(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B"), 1)));
609 assertFalse(res
.isSuccess());
610 assertNull(res
.getResult());
612 result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B")));
613 assertEquals(1, Bytes
.toLong(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
615 table
.put(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("c")));
617 // CheckAndIncrement with a filter and correct value
618 res
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
619 .ifMatches(new FilterList(
620 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
622 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("C"), CompareOperator
.EQUAL
,
623 Bytes
.toBytes("c"))))
624 .build(new Increment(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B"), 2)));
625 assertTrue(res
.isSuccess());
626 assertEquals(3, Bytes
.toLong(res
.getResult().getValue(FAMILY
, Bytes
.toBytes("B"))));
628 result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B")));
629 assertEquals(3, Bytes
.toLong(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
631 // CheckAndIncrement with a filter and correct value
632 res
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
633 .ifMatches(new FilterList(
634 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
636 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("C"), CompareOperator
.EQUAL
,
637 Bytes
.toBytes("d"))))
638 .build(new Increment(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B"), 2)));
639 assertFalse(res
.isSuccess());
640 assertNull(res
.getResult());
642 result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B")));
643 assertEquals(3, Bytes
.toLong(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
648 public void testCheckAndAppend() throws Throwable
{
649 try (Table table
= createTable()) {
650 table
.put(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a")));
652 // CheckAndAppend with correct value
653 CheckAndMutateResult res
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
654 .ifEquals(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a"))
655 .build(new Append(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("b"))));
656 assertTrue(res
.isSuccess());
657 assertEquals("b", Bytes
.toString(res
.getResult().getValue(FAMILY
, Bytes
.toBytes("B"))));
659 Result result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B")));
660 assertEquals("b", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
662 // CheckAndAppend with correct value
663 res
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
664 .ifEquals(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("b"))
665 .build(new Append(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("b"))));
666 assertFalse(res
.isSuccess());
667 assertNull(res
.getResult());
669 result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B")));
670 assertEquals("b", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
672 table
.put(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("c")));
674 // CheckAndAppend with a filter and correct value
675 res
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
676 .ifMatches(new FilterList(
677 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
679 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("C"), CompareOperator
.EQUAL
,
680 Bytes
.toBytes("c"))))
681 .build(new Append(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("bb"))));
682 assertTrue(res
.isSuccess());
683 assertEquals("bbb", Bytes
.toString(res
.getResult().getValue(FAMILY
, Bytes
.toBytes("B"))));
685 result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B")));
686 assertEquals("bbb", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
688 // CheckAndAppend with a filter and wrong value
689 res
= table
.checkAndMutate(CheckAndMutate
.newBuilder(ROWKEY
)
690 .ifMatches(new FilterList(
691 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
693 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("C"), CompareOperator
.EQUAL
,
694 Bytes
.toBytes("d"))))
695 .build(new Append(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("bb"))));
696 assertFalse(res
.isSuccess());
697 assertNull(res
.getResult());
699 result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B")));
700 assertEquals("bbb", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
705 public void testCheckAndRowMutations() throws Throwable
{
706 final byte[] q1
= Bytes
.toBytes("q1");
707 final byte[] q2
= Bytes
.toBytes("q2");
708 final byte[] q3
= Bytes
.toBytes("q3");
709 final byte[] q4
= Bytes
.toBytes("q4");
710 final String v1
= "v1";
712 try (Table table
= createTable()) {
714 table
.put(Arrays
.asList(
715 new Put(ROWKEY
).addColumn(FAMILY
, q2
, Bytes
.toBytes("toBeDeleted")),
716 new Put(ROWKEY
).addColumn(FAMILY
, q3
, Bytes
.toBytes(5L)),
717 new Put(ROWKEY
).addColumn(FAMILY
, q4
, Bytes
.toBytes("a"))));
719 // Do CheckAndRowMutations
720 CheckAndMutate checkAndMutate
= CheckAndMutate
.newBuilder(ROWKEY
)
721 .ifNotExists(FAMILY
, q1
)
722 .build(new RowMutations(ROWKEY
).add(Arrays
.asList(
723 new Put(ROWKEY
).addColumn(FAMILY
, q1
, Bytes
.toBytes(v1
)),
724 new Delete(ROWKEY
).addColumns(FAMILY
, q2
),
725 new Increment(ROWKEY
).addColumn(FAMILY
, q3
, 1),
726 new Append(ROWKEY
).addColumn(FAMILY
, q4
, Bytes
.toBytes("b"))))
729 CheckAndMutateResult result
= table
.checkAndMutate(checkAndMutate
);
730 assertTrue(result
.isSuccess());
731 assertEquals(6L, Bytes
.toLong(result
.getResult().getValue(FAMILY
, q3
)));
732 assertEquals("ab", Bytes
.toString(result
.getResult().getValue(FAMILY
, q4
)));
735 Result r
= table
.get(new Get(ROWKEY
));
736 assertEquals(v1
, Bytes
.toString(r
.getValue(FAMILY
, q1
)));
737 assertNull(r
.getValue(FAMILY
, q2
));
738 assertEquals(6L, Bytes
.toLong(r
.getValue(FAMILY
, q3
)));
739 assertEquals("ab", Bytes
.toString(r
.getValue(FAMILY
, q4
)));
741 // Do CheckAndRowMutations again
742 checkAndMutate
= CheckAndMutate
.newBuilder(ROWKEY
)
743 .ifNotExists(FAMILY
, q1
)
744 .build(new RowMutations(ROWKEY
).add(Arrays
.asList(
745 new Delete(ROWKEY
).addColumns(FAMILY
, q1
),
746 new Put(ROWKEY
).addColumn(FAMILY
, q2
, Bytes
.toBytes(v1
)),
747 new Increment(ROWKEY
).addColumn(FAMILY
, q3
, 1),
748 new Append(ROWKEY
).addColumn(FAMILY
, q4
, Bytes
.toBytes("b"))))
751 result
= table
.checkAndMutate(checkAndMutate
);
752 assertFalse(result
.isSuccess());
753 assertNull(result
.getResult());
756 r
= table
.get(new Get(ROWKEY
));
757 assertEquals(v1
, Bytes
.toString(r
.getValue(FAMILY
, q1
)));
758 assertNull(r
.getValue(FAMILY
, q2
));
759 assertEquals(6L, Bytes
.toLong(r
.getValue(FAMILY
, q3
)));
760 assertEquals("ab", Bytes
.toString(r
.getValue(FAMILY
, q4
)));
764 // Tests for batch version of checkAndMutate
767 public void testCheckAndMutateBatch() throws Throwable
{
768 try (Table table
= createTable()) {
769 table
.put(Arrays
.asList(
770 new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a")),
771 new Put(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("b")),
772 new Put(ROWKEY3
).addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("c")),
773 new Put(ROWKEY4
).addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d"))));
776 CheckAndMutate checkAndMutate1
= CheckAndMutate
.newBuilder(ROWKEY
)
777 .ifEquals(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a"))
778 .build(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("e")));
780 CheckAndMutate checkAndMutate2
= CheckAndMutate
.newBuilder(ROWKEY2
)
781 .ifEquals(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("a"))
782 .build(new Put(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("f")));
784 List
<CheckAndMutateResult
> results
=
785 table
.checkAndMutate(Arrays
.asList(checkAndMutate1
, checkAndMutate2
));
787 assertTrue(results
.get(0).isSuccess());
788 assertNull(results
.get(0).getResult());
789 assertFalse(results
.get(1).isSuccess());
790 assertNull(results
.get(1).getResult());
792 Result result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A")));
793 assertEquals("e", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("A"))));
795 result
= table
.get(new Get(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("B")));
796 assertEquals("b", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
799 checkAndMutate1
= CheckAndMutate
.newBuilder(ROWKEY
)
800 .ifEquals(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("e"))
801 .build(new Delete(ROWKEY
));
803 checkAndMutate2
= CheckAndMutate
.newBuilder(ROWKEY2
)
804 .ifEquals(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("a"))
805 .build(new Delete(ROWKEY2
));
807 results
= table
.checkAndMutate(Arrays
.asList(checkAndMutate1
, checkAndMutate2
));
809 assertTrue(results
.get(0).isSuccess());
810 assertNull(results
.get(0).getResult());
811 assertFalse(results
.get(1).isSuccess());
812 assertNull(results
.get(1).getResult());
814 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"))));
816 result
= table
.get(new Get(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("B")));
817 assertEquals("b", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
819 // Test for RowMutations
820 checkAndMutate1
= CheckAndMutate
.newBuilder(ROWKEY3
)
821 .ifEquals(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("c"))
822 .build(new RowMutations(ROWKEY3
)
823 .add((Mutation
) new Put(ROWKEY3
)
824 .addColumn(FAMILY
, Bytes
.toBytes("F"), Bytes
.toBytes("f")))
825 .add((Mutation
) new Delete(ROWKEY3
).addColumns(FAMILY
, Bytes
.toBytes("C"))));
827 checkAndMutate2
= CheckAndMutate
.newBuilder(ROWKEY4
)
828 .ifEquals(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("f"))
829 .build(new RowMutations(ROWKEY4
)
830 .add((Mutation
) new Put(ROWKEY4
)
831 .addColumn(FAMILY
, Bytes
.toBytes("F"), Bytes
.toBytes("f")))
832 .add((Mutation
) new Delete(ROWKEY4
).addColumns(FAMILY
, Bytes
.toBytes("D"))));
834 results
= table
.checkAndMutate(Arrays
.asList(checkAndMutate1
, checkAndMutate2
));
836 assertTrue(results
.get(0).isSuccess());
837 assertNull(results
.get(0).getResult());
838 assertFalse(results
.get(1).isSuccess());
839 assertNull(results
.get(1).getResult());
841 result
= table
.get(new Get(ROWKEY3
));
842 assertEquals("f", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("F"))));
843 assertNull(result
.getValue(FAMILY
, Bytes
.toBytes("D")));
845 result
= table
.get(new Get(ROWKEY4
));
846 assertNull(result
.getValue(FAMILY
, Bytes
.toBytes("F")));
847 assertEquals("d", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("D"))));
852 public void testCheckAndMutateBatch2() throws Throwable
{
853 try (Table table
= createTable()) {
854 table
.put(Arrays
.asList(
855 new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a")),
856 new Put(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("b")),
857 new Put(ROWKEY3
).addColumn(FAMILY
, Bytes
.toBytes("C"), 100, Bytes
.toBytes("c")),
858 new Put(ROWKEY4
).addColumn(FAMILY
, Bytes
.toBytes("D"), 100, Bytes
.toBytes("d"))));
860 // Test for ifNotExists()
861 CheckAndMutate checkAndMutate1
= CheckAndMutate
.newBuilder(ROWKEY
)
862 .ifNotExists(FAMILY
, Bytes
.toBytes("B"))
863 .build(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("e")));
865 CheckAndMutate checkAndMutate2
= CheckAndMutate
.newBuilder(ROWKEY2
)
866 .ifNotExists(FAMILY
, Bytes
.toBytes("B"))
867 .build(new Put(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("f")));
869 List
<CheckAndMutateResult
> results
=
870 table
.checkAndMutate(Arrays
.asList(checkAndMutate1
, checkAndMutate2
));
872 assertTrue(results
.get(0).isSuccess());
873 assertNull(results
.get(0).getResult());
874 assertFalse(results
.get(1).isSuccess());
875 assertNull(results
.get(1).getResult());
877 Result result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A")));
878 assertEquals("e", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("A"))));
880 result
= table
.get(new Get(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("B")));
881 assertEquals("b", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
883 // Test for ifMatches()
884 checkAndMutate1
= CheckAndMutate
.newBuilder(ROWKEY
)
885 .ifMatches(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.NOT_EQUAL
, Bytes
.toBytes("a"))
886 .build(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a")));
888 checkAndMutate2
= CheckAndMutate
.newBuilder(ROWKEY2
)
889 .ifMatches(FAMILY
, Bytes
.toBytes("B"), CompareOperator
.GREATER
, Bytes
.toBytes("b"))
890 .build(new Put(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("f")));
892 results
= table
.checkAndMutate(Arrays
.asList(checkAndMutate1
, checkAndMutate2
));
894 assertTrue(results
.get(0).isSuccess());
895 assertNull(results
.get(0).getResult());
896 assertFalse(results
.get(1).isSuccess());
897 assertNull(results
.get(1).getResult());
899 result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A")));
900 assertEquals("a", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("A"))));
902 result
= table
.get(new Get(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("B")));
903 assertEquals("b", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
905 // Test for timeRange()
906 checkAndMutate1
= CheckAndMutate
.newBuilder(ROWKEY3
)
907 .ifEquals(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("c"))
908 .timeRange(TimeRange
.between(0, 101))
909 .build(new Put(ROWKEY3
).addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("e")));
911 checkAndMutate2
= CheckAndMutate
.newBuilder(ROWKEY4
)
912 .ifEquals(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d"))
913 .timeRange(TimeRange
.between(0, 100))
914 .build(new Put(ROWKEY4
).addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("f")));
916 results
= table
.checkAndMutate(Arrays
.asList(checkAndMutate1
, checkAndMutate2
));
918 assertTrue(results
.get(0).isSuccess());
919 assertNull(results
.get(0).getResult());
920 assertFalse(results
.get(1).isSuccess());
921 assertNull(results
.get(1).getResult());
923 result
= table
.get(new Get(ROWKEY3
).addColumn(FAMILY
, Bytes
.toBytes("C")));
924 assertEquals("e", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("C"))));
926 result
= table
.get(new Get(ROWKEY4
).addColumn(FAMILY
, Bytes
.toBytes("D")));
927 assertEquals("d", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("D"))));
932 public void testCheckAndMutateBatchWithFilter() throws Throwable
{
933 try (Table table
= createTable()) {
934 table
.put(Arrays
.asList(
936 .addColumn(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a"))
937 .addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("b"))
938 .addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("c")),
940 .addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d"))
941 .addColumn(FAMILY
, Bytes
.toBytes("E"), Bytes
.toBytes("e"))
942 .addColumn(FAMILY
, Bytes
.toBytes("F"), Bytes
.toBytes("f"))));
945 CheckAndMutate checkAndMutate1
= CheckAndMutate
.newBuilder(ROWKEY
)
946 .ifMatches(new FilterList(
947 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
949 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("B"), CompareOperator
.EQUAL
,
950 Bytes
.toBytes("b"))))
951 .build(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("g")));
953 CheckAndMutate checkAndMutate2
= CheckAndMutate
.newBuilder(ROWKEY2
)
954 .ifMatches(new FilterList(
955 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("D"), CompareOperator
.EQUAL
,
957 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("E"), CompareOperator
.EQUAL
,
958 Bytes
.toBytes("b"))))
959 .build(new Put(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("F"), Bytes
.toBytes("h")));
961 List
<CheckAndMutateResult
> results
=
962 table
.checkAndMutate(Arrays
.asList(checkAndMutate1
, checkAndMutate2
));
964 assertTrue(results
.get(0).isSuccess());
965 assertNull(results
.get(0).getResult());
966 assertFalse(results
.get(1).isSuccess());
967 assertNull(results
.get(1).getResult());
969 Result result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C")));
970 assertEquals("g", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("C"))));
972 result
= table
.get(new Get(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("F")));
973 assertEquals("f", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("F"))));
976 checkAndMutate1
= CheckAndMutate
.newBuilder(ROWKEY
)
977 .ifMatches(new FilterList(
978 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
980 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("B"), CompareOperator
.EQUAL
,
981 Bytes
.toBytes("b"))))
982 .build(new Delete(ROWKEY
).addColumns(FAMILY
, Bytes
.toBytes("C")));
984 checkAndMutate2
= CheckAndMutate
.newBuilder(ROWKEY2
)
985 .ifMatches(new FilterList(
986 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("D"), CompareOperator
.EQUAL
,
988 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("E"), CompareOperator
.EQUAL
,
989 Bytes
.toBytes("b"))))
990 .build(new Delete(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("F")));
992 results
= table
.checkAndMutate(Arrays
.asList(checkAndMutate1
, checkAndMutate2
));
994 assertTrue(results
.get(0).isSuccess());
995 assertNull(results
.get(0).getResult());
996 assertFalse(results
.get(1).isSuccess());
997 assertNull(results
.get(1).getResult());
999 assertFalse(table
.exists(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C"))));
1001 result
= table
.get(new Get(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("F")));
1002 assertEquals("f", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("F"))));
1004 // Test for RowMutations
1005 checkAndMutate1
= CheckAndMutate
.newBuilder(ROWKEY
)
1006 .ifMatches(new FilterList(
1007 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
1008 Bytes
.toBytes("a")),
1009 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("B"), CompareOperator
.EQUAL
,
1010 Bytes
.toBytes("b"))))
1011 .build(new RowMutations(ROWKEY
)
1012 .add((Mutation
) new Put(ROWKEY
)
1013 .addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("c")))
1014 .add((Mutation
) new Delete(ROWKEY
).addColumns(FAMILY
, Bytes
.toBytes("A"))));
1016 checkAndMutate2
= CheckAndMutate
.newBuilder(ROWKEY2
)
1017 .ifMatches(new FilterList(
1018 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("D"), CompareOperator
.EQUAL
,
1019 Bytes
.toBytes("a")),
1020 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("E"), CompareOperator
.EQUAL
,
1021 Bytes
.toBytes("b"))))
1022 .build(new RowMutations(ROWKEY2
)
1023 .add((Mutation
) new Put(ROWKEY2
)
1024 .addColumn(FAMILY
, Bytes
.toBytes("F"), Bytes
.toBytes("g")))
1025 .add((Mutation
) new Delete(ROWKEY2
).addColumns(FAMILY
, Bytes
.toBytes("D"))));
1027 results
= table
.checkAndMutate(Arrays
.asList(checkAndMutate1
, checkAndMutate2
));
1029 assertTrue(results
.get(0).isSuccess());
1030 assertNull(results
.get(0).getResult());
1031 assertFalse(results
.get(1).isSuccess());
1032 assertNull(results
.get(1).getResult());
1034 result
= table
.get(new Get(ROWKEY
));
1035 assertNull(result
.getValue(FAMILY
, Bytes
.toBytes("A")));
1036 assertEquals("c", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("C"))));
1038 result
= table
.get(new Get(ROWKEY2
));
1039 assertEquals("d", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("D"))));
1040 assertEquals("f", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("F"))));
1045 public void testCheckAndMutateBatchWithFilterAndTimeRange() throws Throwable
{
1046 try (Table table
= createTable()) {
1047 table
.put(Arrays
.asList(
1048 new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"), 100, Bytes
.toBytes("a"))
1049 .addColumn(FAMILY
, Bytes
.toBytes("B"), 100, Bytes
.toBytes("b"))
1050 .addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("c")),
1051 new Put(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("D"), 100, Bytes
.toBytes("d"))
1052 .addColumn(FAMILY
, Bytes
.toBytes("E"), 100, Bytes
.toBytes("e"))
1053 .addColumn(FAMILY
, Bytes
.toBytes("F"), Bytes
.toBytes("f"))));
1055 CheckAndMutate checkAndMutate1
= CheckAndMutate
.newBuilder(ROWKEY
)
1056 .ifMatches(new FilterList(
1057 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("A"), CompareOperator
.EQUAL
,
1058 Bytes
.toBytes("a")),
1059 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("B"), CompareOperator
.EQUAL
,
1060 Bytes
.toBytes("b"))))
1061 .timeRange(TimeRange
.between(0, 101))
1062 .build(new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("g")));
1064 CheckAndMutate checkAndMutate2
= CheckAndMutate
.newBuilder(ROWKEY2
)
1065 .ifMatches(new FilterList(
1066 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("D"), CompareOperator
.EQUAL
,
1067 Bytes
.toBytes("d")),
1068 new SingleColumnValueFilter(FAMILY
, Bytes
.toBytes("E"), CompareOperator
.EQUAL
,
1069 Bytes
.toBytes("e"))))
1070 .timeRange(TimeRange
.between(0, 100))
1071 .build(new Put(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("F"), Bytes
.toBytes("h")));
1073 List
<CheckAndMutateResult
> results
=
1074 table
.checkAndMutate(Arrays
.asList(checkAndMutate1
, checkAndMutate2
));
1076 assertTrue(results
.get(0).isSuccess());
1077 assertNull(results
.get(0).getResult());
1078 assertFalse(results
.get(1).isSuccess());
1079 assertNull(results
.get(1).getResult());
1081 Result result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C")));
1082 assertEquals("g", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("C"))));
1084 result
= table
.get(new Get(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("F")));
1085 assertEquals("f", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("F"))));
1090 public void testCheckAndIncrementBatch() throws Throwable
{
1091 try (Table table
= createTable()) {
1092 table
.put(Arrays
.asList(
1093 new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a"))
1094 .addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes(0L)),
1095 new Put(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("c"))
1096 .addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes(0L))));
1098 // CheckAndIncrement with correct value
1099 CheckAndMutate checkAndMutate1
= CheckAndMutate
.newBuilder(ROWKEY
)
1100 .ifEquals(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a"))
1101 .build(new Increment(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B"), 1));
1103 // CheckAndIncrement with wrong value
1104 CheckAndMutate checkAndMutate2
= CheckAndMutate
.newBuilder(ROWKEY2
)
1105 .ifEquals(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("d"))
1106 .build(new Increment(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("D"), 1));
1108 List
<CheckAndMutateResult
> results
=
1109 table
.checkAndMutate(Arrays
.asList(checkAndMutate1
, checkAndMutate2
));
1111 assertTrue(results
.get(0).isSuccess());
1112 assertEquals(1, Bytes
.toLong(results
.get(0).getResult()
1113 .getValue(FAMILY
, Bytes
.toBytes("B"))));
1114 assertFalse(results
.get(1).isSuccess());
1115 assertNull(results
.get(1).getResult());
1117 Result result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B")));
1118 assertEquals(1, Bytes
.toLong(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
1120 result
= table
.get(new Get(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("D")));
1121 assertEquals(0, Bytes
.toLong(result
.getValue(FAMILY
, Bytes
.toBytes("D"))));
1126 public void testCheckAndAppendBatch() throws Throwable
{
1127 try (Table table
= createTable()) {
1128 table
.put(Arrays
.asList(
1129 new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a"))
1130 .addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("b")),
1131 new Put(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("c"))
1132 .addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d"))));
1134 // CheckAndAppend with correct value
1135 CheckAndMutate checkAndMutate1
= CheckAndMutate
.newBuilder(ROWKEY
)
1136 .ifEquals(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a"))
1137 .build(new Append(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("b")));
1139 // CheckAndAppend with wrong value
1140 CheckAndMutate checkAndMutate2
= CheckAndMutate
.newBuilder(ROWKEY2
)
1141 .ifEquals(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes("d"))
1142 .build(new Append(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d")));
1144 List
<CheckAndMutateResult
> results
=
1145 table
.checkAndMutate(Arrays
.asList(checkAndMutate1
, checkAndMutate2
));
1147 assertTrue(results
.get(0).isSuccess());
1148 assertEquals("bb", Bytes
.toString(results
.get(0).getResult()
1149 .getValue(FAMILY
, Bytes
.toBytes("B"))));
1150 assertFalse(results
.get(1).isSuccess());
1151 assertNull(results
.get(1).getResult());
1153 Result result
= table
.get(new Get(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B")));
1154 assertEquals("bb", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("B"))));
1156 result
= table
.get(new Get(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("D")));
1157 assertEquals("d", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("D"))));
1162 public void testCheckAndRowMutationsBatch() throws Throwable
{
1163 try (Table table
= createTable()) {
1164 table
.put(Arrays
.asList(
1165 new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("b"))
1166 .addColumn(FAMILY
, Bytes
.toBytes("C"), Bytes
.toBytes(1L))
1167 .addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d")),
1168 new Put(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("F"), Bytes
.toBytes("f"))
1169 .addColumn(FAMILY
, Bytes
.toBytes("G"), Bytes
.toBytes(1L))
1170 .addColumn(FAMILY
, Bytes
.toBytes("H"), Bytes
.toBytes("h")))
1173 // CheckAndIncrement with correct value
1174 CheckAndMutate checkAndMutate1
= CheckAndMutate
.newBuilder(ROWKEY
)
1175 .ifEquals(FAMILY
, Bytes
.toBytes("B"), Bytes
.toBytes("b"))
1176 .build(new RowMutations(ROWKEY
).add(Arrays
.asList(
1177 new Put(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("A"), Bytes
.toBytes("a")),
1178 new Delete(ROWKEY
).addColumns(FAMILY
, Bytes
.toBytes("B")),
1179 new Increment(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("C"), 1L),
1180 new Append(ROWKEY
).addColumn(FAMILY
, Bytes
.toBytes("D"), Bytes
.toBytes("d"))
1183 // CheckAndIncrement with wrong value
1184 CheckAndMutate checkAndMutate2
= CheckAndMutate
.newBuilder(ROWKEY2
)
1185 .ifEquals(FAMILY
, Bytes
.toBytes("F"), Bytes
.toBytes("a"))
1186 .build(new RowMutations(ROWKEY2
).add(Arrays
.asList(
1187 new Put(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("E"), Bytes
.toBytes("e")),
1188 new Delete(ROWKEY2
).addColumns(FAMILY
, Bytes
.toBytes("F")),
1189 new Increment(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("G"), 1L),
1190 new Append(ROWKEY2
).addColumn(FAMILY
, Bytes
.toBytes("H"), Bytes
.toBytes("h"))
1193 List
<CheckAndMutateResult
> results
=
1194 table
.checkAndMutate(Arrays
.asList(checkAndMutate1
, checkAndMutate2
));
1196 assertTrue(results
.get(0).isSuccess());
1197 assertEquals(2, Bytes
.toLong(results
.get(0).getResult()
1198 .getValue(FAMILY
, Bytes
.toBytes("C"))));
1199 assertEquals("dd", Bytes
.toString(results
.get(0).getResult()
1200 .getValue(FAMILY
, Bytes
.toBytes("D"))));
1202 assertFalse(results
.get(1).isSuccess());
1203 assertNull(results
.get(1).getResult());
1205 Result result
= table
.get(new Get(ROWKEY
));
1206 assertEquals("a", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("A"))));
1207 assertNull(result
.getValue(FAMILY
, Bytes
.toBytes("B")));
1208 assertEquals(2, Bytes
.toLong(result
.getValue(FAMILY
, Bytes
.toBytes("C"))));
1209 assertEquals("dd", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("D"))));
1211 result
= table
.get(new Get(ROWKEY2
));
1212 assertNull(result
.getValue(FAMILY
, Bytes
.toBytes("E")));
1213 assertEquals("f", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("F"))));
1214 assertEquals(1, Bytes
.toLong(result
.getValue(FAMILY
, Bytes
.toBytes("G"))));
1215 assertEquals("h", Bytes
.toString(result
.getValue(FAMILY
, Bytes
.toBytes("H"))));
1220 public void testCheckAndMutateForNull() throws Exception
{
1221 byte[] qualifier
= Bytes
.toBytes("Q");
1222 try (Table table
= createTable()) {
1223 byte [] row1
= Bytes
.toBytes("testRow1");
1224 Put put
= new Put(row1
);
1225 put
.addColumn(FAMILY
, qualifier
, Bytes
.toBytes("v0"));
1227 assertEquals("v0", Bytes
.toString(
1228 table
.get(new Get(row1
).addColumn(FAMILY
, qualifier
)).getValue(FAMILY
, qualifier
)));
1230 CheckAndMutate checkAndMutate1
= CheckAndMutate
.newBuilder(row1
)
1231 .ifMatches(FAMILY
, qualifier
, CompareOperator
.NOT_EQUAL
, new byte[] {})
1232 .build(new Put(row1
).addColumn(FAMILY
, qualifier
, Bytes
.toBytes("v1")));
1233 table
.checkAndMutate(checkAndMutate1
);
1234 assertEquals("v1", Bytes
.toString(
1235 table
.get(new Get(row1
).addColumn(FAMILY
, qualifier
)).getValue(FAMILY
, qualifier
)));
1237 byte [] row2
= Bytes
.toBytes("testRow2");
1238 put
= new Put(row2
);
1239 put
.addColumn(FAMILY
, qualifier
, new byte[] {});
1242 table
.get(new Get(row2
).addColumn(FAMILY
, qualifier
)).getValue(FAMILY
, qualifier
).length
);
1244 CheckAndMutate checkAndMutate2
= CheckAndMutate
.newBuilder(row2
)
1245 .ifMatches(FAMILY
, qualifier
, CompareOperator
.EQUAL
, new byte[] {})
1246 .build(new Put(row2
).addColumn(FAMILY
, qualifier
, Bytes
.toBytes("v2")));
1247 table
.checkAndMutate(checkAndMutate2
);
1248 assertEquals("v2", Bytes
.toString(
1249 table
.get(new Get(row2
).addColumn(FAMILY
, qualifier
)).getValue(FAMILY
, qualifier
)));
1251 byte [] row3
= Bytes
.toBytes("testRow3");
1252 put
= new Put(row3
).addColumn(FAMILY
, qualifier
, Bytes
.toBytes("v0"));
1253 assertNull(table
.get(new Get(row3
).addColumn(FAMILY
, qualifier
)).getValue(FAMILY
, qualifier
));
1254 CheckAndMutate checkAndMutate3
= CheckAndMutate
.newBuilder(row3
)
1255 .ifMatches(FAMILY
, qualifier
, CompareOperator
.NOT_EQUAL
, new byte[] {})
1257 table
.checkAndMutate(checkAndMutate3
);
1258 assertNull(table
.get(new Get(row3
).addColumn(FAMILY
, qualifier
)).getValue(FAMILY
, qualifier
));
1260 CheckAndMutate checkAndMutate4
= CheckAndMutate
.newBuilder(row3
)
1261 .ifMatches(FAMILY
, qualifier
, CompareOperator
.EQUAL
, new byte[] {})
1263 table
.checkAndMutate(checkAndMutate4
);
1264 assertEquals("v0", Bytes
.toString(
1265 table
.get(new Get(row3
).addColumn(FAMILY
, qualifier
)).getValue(FAMILY
, qualifier
)));