| <!DOCTYPE HTML> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc (17) --> |
| <title>Source code</title> |
| <meta name="viewport" content="width=device-width, initial-scale=1"> |
| <meta name="description" content="source: package: org.apache.hadoop.hbase.client, class: TestAsyncTable"> |
| <meta name="generator" content="javadoc/SourceToHTMLConverter"> |
| <link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style"> |
| </head> |
| <body class="source-page"> |
| <main role="main"> |
| <div class="source-container"> |
| <pre><span class="source-line-no">001</span><span id="line-1">/*</span> |
| <span class="source-line-no">002</span><span id="line-2"> * Licensed to the Apache Software Foundation (ASF) under one</span> |
| <span class="source-line-no">003</span><span id="line-3"> * or more contributor license agreements. See the NOTICE file</span> |
| <span class="source-line-no">004</span><span id="line-4"> * distributed with this work for additional information</span> |
| <span class="source-line-no">005</span><span id="line-5"> * regarding copyright ownership. The ASF licenses this file</span> |
| <span class="source-line-no">006</span><span id="line-6"> * to you under the Apache License, Version 2.0 (the</span> |
| <span class="source-line-no">007</span><span id="line-7"> * "License"); you may not use this file except in compliance</span> |
| <span class="source-line-no">008</span><span id="line-8"> * with the License. You may obtain a copy of the License at</span> |
| <span class="source-line-no">009</span><span id="line-9"> *</span> |
| <span class="source-line-no">010</span><span id="line-10"> * http://www.apache.org/licenses/LICENSE-2.0</span> |
| <span class="source-line-no">011</span><span id="line-11"> *</span> |
| <span class="source-line-no">012</span><span id="line-12"> * Unless required by applicable law or agreed to in writing, software</span> |
| <span class="source-line-no">013</span><span id="line-13"> * distributed under the License is distributed on an "AS IS" BASIS,</span> |
| <span class="source-line-no">014</span><span id="line-14"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span> |
| <span class="source-line-no">015</span><span id="line-15"> * See the License for the specific language governing permissions and</span> |
| <span class="source-line-no">016</span><span id="line-16"> * limitations under the License.</span> |
| <span class="source-line-no">017</span><span id="line-17"> */</span> |
| <span class="source-line-no">018</span><span id="line-18">package org.apache.hadoop.hbase.client;</span> |
| <span class="source-line-no">019</span><span id="line-19"></span> |
| <span class="source-line-no">020</span><span id="line-20">import static org.hamcrest.CoreMatchers.containsString;</span> |
| <span class="source-line-no">021</span><span id="line-21">import static org.hamcrest.CoreMatchers.instanceOf;</span> |
| <span class="source-line-no">022</span><span id="line-22">import static org.hamcrest.MatcherAssert.assertThat;</span> |
| <span class="source-line-no">023</span><span id="line-23">import static org.junit.Assert.assertArrayEquals;</span> |
| <span class="source-line-no">024</span><span id="line-24">import static org.junit.Assert.assertEquals;</span> |
| <span class="source-line-no">025</span><span id="line-25">import static org.junit.Assert.assertFalse;</span> |
| <span class="source-line-no">026</span><span id="line-26">import static org.junit.Assert.assertNull;</span> |
| <span class="source-line-no">027</span><span id="line-27">import static org.junit.Assert.assertTrue;</span> |
| <span class="source-line-no">028</span><span id="line-28">import static org.junit.Assert.fail;</span> |
| <span class="source-line-no">029</span><span id="line-29"></span> |
| <span class="source-line-no">030</span><span id="line-30">import java.io.IOException;</span> |
| <span class="source-line-no">031</span><span id="line-31">import java.io.UncheckedIOException;</span> |
| <span class="source-line-no">032</span><span id="line-32">import java.util.Arrays;</span> |
| <span class="source-line-no">033</span><span id="line-33">import java.util.Collections;</span> |
| <span class="source-line-no">034</span><span id="line-34">import java.util.List;</span> |
| <span class="source-line-no">035</span><span id="line-35">import java.util.concurrent.ArrayBlockingQueue;</span> |
| <span class="source-line-no">036</span><span id="line-36">import java.util.concurrent.BlockingQueue;</span> |
| <span class="source-line-no">037</span><span id="line-37">import java.util.concurrent.CountDownLatch;</span> |
| <span class="source-line-no">038</span><span id="line-38">import java.util.concurrent.ExecutionException;</span> |
| <span class="source-line-no">039</span><span id="line-39">import java.util.concurrent.ForkJoinPool;</span> |
| <span class="source-line-no">040</span><span id="line-40">import java.util.concurrent.atomic.AtomicInteger;</span> |
| <span class="source-line-no">041</span><span id="line-41">import java.util.concurrent.atomic.AtomicLong;</span> |
| <span class="source-line-no">042</span><span id="line-42">import java.util.function.Supplier;</span> |
| <span class="source-line-no">043</span><span id="line-43">import java.util.stream.IntStream;</span> |
| <span class="source-line-no">044</span><span id="line-44">import org.apache.hadoop.hbase.CompareOperator;</span> |
| <span class="source-line-no">045</span><span id="line-45">import org.apache.hadoop.hbase.HBaseClassTestRule;</span> |
| <span class="source-line-no">046</span><span id="line-46">import org.apache.hadoop.hbase.HBaseTestingUtil;</span> |
| <span class="source-line-no">047</span><span id="line-47">import org.apache.hadoop.hbase.TableName;</span> |
| <span class="source-line-no">048</span><span id="line-48">import org.apache.hadoop.hbase.TableNotEnabledException;</span> |
| <span class="source-line-no">049</span><span id="line-49">import org.apache.hadoop.hbase.filter.BinaryComparator;</span> |
| <span class="source-line-no">050</span><span id="line-50">import org.apache.hadoop.hbase.filter.FamilyFilter;</span> |
| <span class="source-line-no">051</span><span id="line-51">import org.apache.hadoop.hbase.filter.FilterList;</span> |
| <span class="source-line-no">052</span><span id="line-52">import org.apache.hadoop.hbase.filter.QualifierFilter;</span> |
| <span class="source-line-no">053</span><span id="line-53">import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;</span> |
| <span class="source-line-no">054</span><span id="line-54">import org.apache.hadoop.hbase.filter.TimestampsFilter;</span> |
| <span class="source-line-no">055</span><span id="line-55">import org.apache.hadoop.hbase.io.TimeRange;</span> |
| <span class="source-line-no">056</span><span id="line-56">import org.apache.hadoop.hbase.testclassification.ClientTests;</span> |
| <span class="source-line-no">057</span><span id="line-57">import org.apache.hadoop.hbase.testclassification.MediumTests;</span> |
| <span class="source-line-no">058</span><span id="line-58">import org.apache.hadoop.hbase.util.Bytes;</span> |
| <span class="source-line-no">059</span><span id="line-59">import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;</span> |
| <span class="source-line-no">060</span><span id="line-60">import org.apache.hadoop.hbase.util.Pair;</span> |
| <span class="source-line-no">061</span><span id="line-61">import org.junit.AfterClass;</span> |
| <span class="source-line-no">062</span><span id="line-62">import org.junit.Before;</span> |
| <span class="source-line-no">063</span><span id="line-63">import org.junit.BeforeClass;</span> |
| <span class="source-line-no">064</span><span id="line-64">import org.junit.ClassRule;</span> |
| <span class="source-line-no">065</span><span id="line-65">import org.junit.Rule;</span> |
| <span class="source-line-no">066</span><span id="line-66">import org.junit.Test;</span> |
| <span class="source-line-no">067</span><span id="line-67">import org.junit.experimental.categories.Category;</span> |
| <span class="source-line-no">068</span><span id="line-68">import org.junit.rules.TestName;</span> |
| <span class="source-line-no">069</span><span id="line-69">import org.junit.runner.RunWith;</span> |
| <span class="source-line-no">070</span><span id="line-70">import org.junit.runners.Parameterized;</span> |
| <span class="source-line-no">071</span><span id="line-71">import org.junit.runners.Parameterized.Parameter;</span> |
| <span class="source-line-no">072</span><span id="line-72">import org.junit.runners.Parameterized.Parameters;</span> |
| <span class="source-line-no">073</span><span id="line-73"></span> |
| <span class="source-line-no">074</span><span id="line-74">import org.apache.hbase.thirdparty.com.google.common.io.Closeables;</span> |
| <span class="source-line-no">075</span><span id="line-75"></span> |
| <span class="source-line-no">076</span><span id="line-76">@RunWith(Parameterized.class)</span> |
| <span class="source-line-no">077</span><span id="line-77">@Category({ MediumTests.class, ClientTests.class })</span> |
| <span class="source-line-no">078</span><span id="line-78">public class TestAsyncTable {</span> |
| <span class="source-line-no">079</span><span id="line-79"></span> |
| <span class="source-line-no">080</span><span id="line-80"> @ClassRule</span> |
| <span class="source-line-no">081</span><span id="line-81"> public static final HBaseClassTestRule CLASS_RULE =</span> |
| <span class="source-line-no">082</span><span id="line-82"> HBaseClassTestRule.forClass(TestAsyncTable.class);</span> |
| <span class="source-line-no">083</span><span id="line-83"></span> |
| <span class="source-line-no">084</span><span id="line-84"> private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();</span> |
| <span class="source-line-no">085</span><span id="line-85"></span> |
| <span class="source-line-no">086</span><span id="line-86"> private static TableName TABLE_NAME = TableName.valueOf("async");</span> |
| <span class="source-line-no">087</span><span id="line-87"></span> |
| <span class="source-line-no">088</span><span id="line-88"> private static byte[] FAMILY = Bytes.toBytes("cf");</span> |
| <span class="source-line-no">089</span><span id="line-89"></span> |
| <span class="source-line-no">090</span><span id="line-90"> private static byte[] QUALIFIER = Bytes.toBytes("cq");</span> |
| <span class="source-line-no">091</span><span id="line-91"></span> |
| <span class="source-line-no">092</span><span id="line-92"> private static byte[] VALUE = Bytes.toBytes("value");</span> |
| <span class="source-line-no">093</span><span id="line-93"></span> |
| <span class="source-line-no">094</span><span id="line-94"> private static int MAX_KEY_VALUE_SIZE = 64 * 1024;</span> |
| <span class="source-line-no">095</span><span id="line-95"></span> |
| <span class="source-line-no">096</span><span id="line-96"> private static AsyncConnection ASYNC_CONN;</span> |
| <span class="source-line-no">097</span><span id="line-97"></span> |
| <span class="source-line-no">098</span><span id="line-98"> @Rule</span> |
| <span class="source-line-no">099</span><span id="line-99"> public TestName testName = new TestName();</span> |
| <span class="source-line-no">100</span><span id="line-100"></span> |
| <span class="source-line-no">101</span><span id="line-101"> private byte[] row;</span> |
| <span class="source-line-no">102</span><span id="line-102"></span> |
| <span class="source-line-no">103</span><span id="line-103"> @Parameter</span> |
| <span class="source-line-no">104</span><span id="line-104"> public Supplier<AsyncTable<?>> getTable;</span> |
| <span class="source-line-no">105</span><span id="line-105"></span> |
| <span class="source-line-no">106</span><span id="line-106"> private static AsyncTable<?> getRawTable() {</span> |
| <span class="source-line-no">107</span><span id="line-107"> return ASYNC_CONN.getTable(TABLE_NAME);</span> |
| <span class="source-line-no">108</span><span id="line-108"> }</span> |
| <span class="source-line-no">109</span><span id="line-109"></span> |
| <span class="source-line-no">110</span><span id="line-110"> private static AsyncTable<?> getTable() {</span> |
| <span class="source-line-no">111</span><span id="line-111"> return ASYNC_CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool());</span> |
| <span class="source-line-no">112</span><span id="line-112"> }</span> |
| <span class="source-line-no">113</span><span id="line-113"></span> |
| <span class="source-line-no">114</span><span id="line-114"> @Parameters</span> |
| <span class="source-line-no">115</span><span id="line-115"> public static List<Object[]> params() {</span> |
| <span class="source-line-no">116</span><span id="line-116"> return Arrays.asList(new Supplier<?>[] { TestAsyncTable::getRawTable },</span> |
| <span class="source-line-no">117</span><span id="line-117"> new Supplier<?>[] { TestAsyncTable::getTable });</span> |
| <span class="source-line-no">118</span><span id="line-118"> }</span> |
| <span class="source-line-no">119</span><span id="line-119"></span> |
| <span class="source-line-no">120</span><span id="line-120"> @BeforeClass</span> |
| <span class="source-line-no">121</span><span id="line-121"> public static void setUpBeforeClass() throws Exception {</span> |
| <span class="source-line-no">122</span><span id="line-122"> TEST_UTIL.getConfiguration().setInt(ConnectionConfiguration.MAX_KEYVALUE_SIZE_KEY,</span> |
| <span class="source-line-no">123</span><span id="line-123"> MAX_KEY_VALUE_SIZE);</span> |
| <span class="source-line-no">124</span><span id="line-124"> TEST_UTIL.startMiniCluster(1);</span> |
| <span class="source-line-no">125</span><span id="line-125"> TEST_UTIL.createTable(TABLE_NAME, FAMILY);</span> |
| <span class="source-line-no">126</span><span id="line-126"> TEST_UTIL.waitTableAvailable(TABLE_NAME);</span> |
| <span class="source-line-no">127</span><span id="line-127"> ASYNC_CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get();</span> |
| <span class="source-line-no">128</span><span id="line-128"> assertFalse(ASYNC_CONN.isClosed());</span> |
| <span class="source-line-no">129</span><span id="line-129"> }</span> |
| <span class="source-line-no">130</span><span id="line-130"></span> |
| <span class="source-line-no">131</span><span id="line-131"> @AfterClass</span> |
| <span class="source-line-no">132</span><span id="line-132"> public static void tearDownAfterClass() throws Exception {</span> |
| <span class="source-line-no">133</span><span id="line-133"> Closeables.close(ASYNC_CONN, true);</span> |
| <span class="source-line-no">134</span><span id="line-134"> assertTrue(ASYNC_CONN.isClosed());</span> |
| <span class="source-line-no">135</span><span id="line-135"> TEST_UTIL.shutdownMiniCluster();</span> |
| <span class="source-line-no">136</span><span id="line-136"> }</span> |
| <span class="source-line-no">137</span><span id="line-137"></span> |
| <span class="source-line-no">138</span><span id="line-138"> @Before</span> |
| <span class="source-line-no">139</span><span id="line-139"> public void setUp() throws IOException, InterruptedException, ExecutionException {</span> |
| <span class="source-line-no">140</span><span id="line-140"> row = Bytes.toBytes(testName.getMethodName().replaceAll("[^0-9A-Za-z]", "_"));</span> |
| <span class="source-line-no">141</span><span id="line-141"> if (ASYNC_CONN.getAdmin().isTableDisabled(TABLE_NAME).get()) {</span> |
| <span class="source-line-no">142</span><span id="line-142"> ASYNC_CONN.getAdmin().enableTable(TABLE_NAME).get();</span> |
| <span class="source-line-no">143</span><span id="line-143"> }</span> |
| <span class="source-line-no">144</span><span id="line-144"> }</span> |
| <span class="source-line-no">145</span><span id="line-145"></span> |
| <span class="source-line-no">146</span><span id="line-146"> @Test</span> |
| <span class="source-line-no">147</span><span id="line-147"> public void testSimple() throws Exception {</span> |
| <span class="source-line-no">148</span><span id="line-148"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">149</span><span id="line-149"> table.put(new Put(row).addColumn(FAMILY, QUALIFIER, VALUE)).get();</span> |
| <span class="source-line-no">150</span><span id="line-150"> assertTrue(table.exists(new Get(row).addColumn(FAMILY, QUALIFIER)).get());</span> |
| <span class="source-line-no">151</span><span id="line-151"> Result result = table.get(new Get(row).addColumn(FAMILY, QUALIFIER)).get();</span> |
| <span class="source-line-no">152</span><span id="line-152"> assertArrayEquals(VALUE, result.getValue(FAMILY, QUALIFIER));</span> |
| <span class="source-line-no">153</span><span id="line-153"> table.delete(new Delete(row)).get();</span> |
| <span class="source-line-no">154</span><span id="line-154"> result = table.get(new Get(row).addColumn(FAMILY, QUALIFIER)).get();</span> |
| <span class="source-line-no">155</span><span id="line-155"> assertTrue(result.isEmpty());</span> |
| <span class="source-line-no">156</span><span id="line-156"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, QUALIFIER)).get());</span> |
| <span class="source-line-no">157</span><span id="line-157"> }</span> |
| <span class="source-line-no">158</span><span id="line-158"></span> |
| <span class="source-line-no">159</span><span id="line-159"> private byte[] concat(byte[] base, int index) {</span> |
| <span class="source-line-no">160</span><span id="line-160"> return Bytes.toBytes(Bytes.toString(base) + "-" + index);</span> |
| <span class="source-line-no">161</span><span id="line-161"> }</span> |
| <span class="source-line-no">162</span><span id="line-162"></span> |
| <span class="source-line-no">163</span><span id="line-163"> @SuppressWarnings("FutureReturnValueIgnored")</span> |
| <span class="source-line-no">164</span><span id="line-164"> @Test</span> |
| <span class="source-line-no">165</span><span id="line-165"> public void testSimpleMultiple() throws Exception {</span> |
| <span class="source-line-no">166</span><span id="line-166"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">167</span><span id="line-167"> int count = 100;</span> |
| <span class="source-line-no">168</span><span id="line-168"> CountDownLatch putLatch = new CountDownLatch(count);</span> |
| <span class="source-line-no">169</span><span id="line-169"> IntStream.range(0, count).forEach(</span> |
| <span class="source-line-no">170</span><span id="line-170"> i -> table.put(new Put(concat(row, i)).addColumn(FAMILY, QUALIFIER, concat(VALUE, i)))</span> |
| <span class="source-line-no">171</span><span id="line-171"> .thenAccept(x -> putLatch.countDown()));</span> |
| <span class="source-line-no">172</span><span id="line-172"> putLatch.await();</span> |
| <span class="source-line-no">173</span><span id="line-173"> BlockingQueue<Boolean> existsResp = new ArrayBlockingQueue<>(count);</span> |
| <span class="source-line-no">174</span><span id="line-174"> IntStream.range(0, count)</span> |
| <span class="source-line-no">175</span><span id="line-175"> .forEach(i -> table.exists(new Get(concat(row, i)).addColumn(FAMILY, QUALIFIER))</span> |
| <span class="source-line-no">176</span><span id="line-176"> .thenAccept(x -> existsResp.add(x)));</span> |
| <span class="source-line-no">177</span><span id="line-177"> for (int i = 0; i < count; i++) {</span> |
| <span class="source-line-no">178</span><span id="line-178"> assertTrue(existsResp.take());</span> |
| <span class="source-line-no">179</span><span id="line-179"> }</span> |
| <span class="source-line-no">180</span><span id="line-180"> BlockingQueue<Pair<Integer, Result>> getResp = new ArrayBlockingQueue<>(count);</span> |
| <span class="source-line-no">181</span><span id="line-181"> IntStream.range(0, count)</span> |
| <span class="source-line-no">182</span><span id="line-182"> .forEach(i -> table.get(new Get(concat(row, i)).addColumn(FAMILY, QUALIFIER))</span> |
| <span class="source-line-no">183</span><span id="line-183"> .thenAccept(x -> getResp.add(Pair.newPair(i, x))));</span> |
| <span class="source-line-no">184</span><span id="line-184"> for (int i = 0; i < count; i++) {</span> |
| <span class="source-line-no">185</span><span id="line-185"> Pair<Integer, Result> pair = getResp.take();</span> |
| <span class="source-line-no">186</span><span id="line-186"> assertArrayEquals(concat(VALUE, pair.getFirst()),</span> |
| <span class="source-line-no">187</span><span id="line-187"> pair.getSecond().getValue(FAMILY, QUALIFIER));</span> |
| <span class="source-line-no">188</span><span id="line-188"> }</span> |
| <span class="source-line-no">189</span><span id="line-189"> CountDownLatch deleteLatch = new CountDownLatch(count);</span> |
| <span class="source-line-no">190</span><span id="line-190"> IntStream.range(0, count).forEach(</span> |
| <span class="source-line-no">191</span><span id="line-191"> i -> table.delete(new Delete(concat(row, i))).thenAccept(x -> deleteLatch.countDown()));</span> |
| <span class="source-line-no">192</span><span id="line-192"> deleteLatch.await();</span> |
| <span class="source-line-no">193</span><span id="line-193"> IntStream.range(0, count)</span> |
| <span class="source-line-no">194</span><span id="line-194"> .forEach(i -> table.exists(new Get(concat(row, i)).addColumn(FAMILY, QUALIFIER))</span> |
| <span class="source-line-no">195</span><span id="line-195"> .thenAccept(x -> existsResp.add(x)));</span> |
| <span class="source-line-no">196</span><span id="line-196"> for (int i = 0; i < count; i++) {</span> |
| <span class="source-line-no">197</span><span id="line-197"> assertFalse(existsResp.take());</span> |
| <span class="source-line-no">198</span><span id="line-198"> }</span> |
| <span class="source-line-no">199</span><span id="line-199"> IntStream.range(0, count)</span> |
| <span class="source-line-no">200</span><span id="line-200"> .forEach(i -> table.get(new Get(concat(row, i)).addColumn(FAMILY, QUALIFIER))</span> |
| <span class="source-line-no">201</span><span id="line-201"> .thenAccept(x -> getResp.add(Pair.newPair(i, x))));</span> |
| <span class="source-line-no">202</span><span id="line-202"> for (int i = 0; i < count; i++) {</span> |
| <span class="source-line-no">203</span><span id="line-203"> Pair<Integer, Result> pair = getResp.take();</span> |
| <span class="source-line-no">204</span><span id="line-204"> assertTrue(pair.getSecond().isEmpty());</span> |
| <span class="source-line-no">205</span><span id="line-205"> }</span> |
| <span class="source-line-no">206</span><span id="line-206"> }</span> |
| <span class="source-line-no">207</span><span id="line-207"></span> |
| <span class="source-line-no">208</span><span id="line-208"> @SuppressWarnings("FutureReturnValueIgnored")</span> |
| <span class="source-line-no">209</span><span id="line-209"> @Test</span> |
| <span class="source-line-no">210</span><span id="line-210"> public void testIncrement() throws InterruptedException, ExecutionException {</span> |
| <span class="source-line-no">211</span><span id="line-211"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">212</span><span id="line-212"> int count = 100;</span> |
| <span class="source-line-no">213</span><span id="line-213"> CountDownLatch latch = new CountDownLatch(count);</span> |
| <span class="source-line-no">214</span><span id="line-214"> AtomicLong sum = new AtomicLong(0L);</span> |
| <span class="source-line-no">215</span><span id="line-215"> IntStream.range(0, count)</span> |
| <span class="source-line-no">216</span><span id="line-216"> .forEach(i -> table.incrementColumnValue(row, FAMILY, QUALIFIER, 1).thenAccept(x -> {</span> |
| <span class="source-line-no">217</span><span id="line-217"> sum.addAndGet(x);</span> |
| <span class="source-line-no">218</span><span id="line-218"> latch.countDown();</span> |
| <span class="source-line-no">219</span><span id="line-219"> }));</span> |
| <span class="source-line-no">220</span><span id="line-220"> latch.await();</span> |
| <span class="source-line-no">221</span><span id="line-221"> assertEquals(count, Bytes.toLong(</span> |
| <span class="source-line-no">222</span><span id="line-222"> table.get(new Get(row).addColumn(FAMILY, QUALIFIER)).get().getValue(FAMILY, QUALIFIER)));</span> |
| <span class="source-line-no">223</span><span id="line-223"> assertEquals((1 + count) * count / 2, sum.get());</span> |
| <span class="source-line-no">224</span><span id="line-224"> }</span> |
| <span class="source-line-no">225</span><span id="line-225"></span> |
| <span class="source-line-no">226</span><span id="line-226"> @SuppressWarnings("FutureReturnValueIgnored")</span> |
| <span class="source-line-no">227</span><span id="line-227"> @Test</span> |
| <span class="source-line-no">228</span><span id="line-228"> public void testAppend() throws InterruptedException, ExecutionException {</span> |
| <span class="source-line-no">229</span><span id="line-229"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">230</span><span id="line-230"> int count = 10;</span> |
| <span class="source-line-no">231</span><span id="line-231"> CountDownLatch latch = new CountDownLatch(count);</span> |
| <span class="source-line-no">232</span><span id="line-232"> char suffix = ':';</span> |
| <span class="source-line-no">233</span><span id="line-233"> AtomicLong suffixCount = new AtomicLong(0L);</span> |
| <span class="source-line-no">234</span><span id="line-234"> IntStream.range(0, count)</span> |
| <span class="source-line-no">235</span><span id="line-235"> .forEachOrdered(i -> table</span> |
| <span class="source-line-no">236</span><span id="line-236"> .append(new Append(row).addColumn(FAMILY, QUALIFIER, Bytes.toBytes("" + i + suffix)))</span> |
| <span class="source-line-no">237</span><span id="line-237"> .thenAccept(r -> {</span> |
| <span class="source-line-no">238</span><span id="line-238"> suffixCount.addAndGet(</span> |
| <span class="source-line-no">239</span><span id="line-239"> Bytes.toString(r.getValue(FAMILY, QUALIFIER)).chars().filter(x -> x == suffix).count());</span> |
| <span class="source-line-no">240</span><span id="line-240"> latch.countDown();</span> |
| <span class="source-line-no">241</span><span id="line-241"> }));</span> |
| <span class="source-line-no">242</span><span id="line-242"> latch.await();</span> |
| <span class="source-line-no">243</span><span id="line-243"> assertEquals((1 + count) * count / 2, suffixCount.get());</span> |
| <span class="source-line-no">244</span><span id="line-244"> String value = Bytes.toString(</span> |
| <span class="source-line-no">245</span><span id="line-245"> table.get(new Get(row).addColumn(FAMILY, QUALIFIER)).get().getValue(FAMILY, QUALIFIER));</span> |
| <span class="source-line-no">246</span><span id="line-246"> int[] actual = Arrays.asList(value.split("" + suffix)).stream().mapToInt(Integer::parseInt)</span> |
| <span class="source-line-no">247</span><span id="line-247"> .sorted().toArray();</span> |
| <span class="source-line-no">248</span><span id="line-248"> assertArrayEquals(IntStream.range(0, count).toArray(), actual);</span> |
| <span class="source-line-no">249</span><span id="line-249"> }</span> |
| <span class="source-line-no">250</span><span id="line-250"></span> |
| <span class="source-line-no">251</span><span id="line-251"> @Test</span> |
| <span class="source-line-no">252</span><span id="line-252"> public void testMutateRow() throws InterruptedException, ExecutionException, IOException {</span> |
| <span class="source-line-no">253</span><span id="line-253"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">254</span><span id="line-254"> RowMutations mutation = new RowMutations(row);</span> |
| <span class="source-line-no">255</span><span id="line-255"> mutation.add(new Put(row).addColumn(FAMILY, concat(QUALIFIER, 1), VALUE));</span> |
| <span class="source-line-no">256</span><span id="line-256"> Result result = table.mutateRow(mutation).get();</span> |
| <span class="source-line-no">257</span><span id="line-257"> assertTrue(result.getExists());</span> |
| <span class="source-line-no">258</span><span id="line-258"> assertTrue(result.isEmpty());</span> |
| <span class="source-line-no">259</span><span id="line-259"></span> |
| <span class="source-line-no">260</span><span id="line-260"> result = table.get(new Get(row)).get();</span> |
| <span class="source-line-no">261</span><span id="line-261"> assertArrayEquals(VALUE, result.getValue(FAMILY, concat(QUALIFIER, 1)));</span> |
| <span class="source-line-no">262</span><span id="line-262"></span> |
| <span class="source-line-no">263</span><span id="line-263"> mutation = new RowMutations(row);</span> |
| <span class="source-line-no">264</span><span id="line-264"> mutation.add(new Delete(row).addColumn(FAMILY, concat(QUALIFIER, 1)));</span> |
| <span class="source-line-no">265</span><span id="line-265"> mutation.add(new Put(row).addColumn(FAMILY, concat(QUALIFIER, 2), VALUE));</span> |
| <span class="source-line-no">266</span><span id="line-266"> mutation.add(new Increment(row).addColumn(FAMILY, concat(QUALIFIER, 3), 2L));</span> |
| <span class="source-line-no">267</span><span id="line-267"> mutation.add(new Append(row).addColumn(FAMILY, concat(QUALIFIER, 4), Bytes.toBytes("abc")));</span> |
| <span class="source-line-no">268</span><span id="line-268"> result = table.mutateRow(mutation).get();</span> |
| <span class="source-line-no">269</span><span id="line-269"> assertTrue(result.getExists());</span> |
| <span class="source-line-no">270</span><span id="line-270"> assertEquals(2L, Bytes.toLong(result.getValue(FAMILY, concat(QUALIFIER, 3))));</span> |
| <span class="source-line-no">271</span><span id="line-271"> assertEquals("abc", Bytes.toString(result.getValue(FAMILY, concat(QUALIFIER, 4))));</span> |
| <span class="source-line-no">272</span><span id="line-272"></span> |
| <span class="source-line-no">273</span><span id="line-273"> result = table.get(new Get(row)).get();</span> |
| <span class="source-line-no">274</span><span id="line-274"> assertNull(result.getValue(FAMILY, concat(QUALIFIER, 1)));</span> |
| <span class="source-line-no">275</span><span id="line-275"> assertArrayEquals(VALUE, result.getValue(FAMILY, concat(QUALIFIER, 2)));</span> |
| <span class="source-line-no">276</span><span id="line-276"> assertEquals(2L, Bytes.toLong(result.getValue(FAMILY, concat(QUALIFIER, 3))));</span> |
| <span class="source-line-no">277</span><span id="line-277"> assertEquals("abc", Bytes.toString(result.getValue(FAMILY, concat(QUALIFIER, 4))));</span> |
| <span class="source-line-no">278</span><span id="line-278"> }</span> |
| <span class="source-line-no">279</span><span id="line-279"></span> |
| <span class="source-line-no">280</span><span id="line-280"> // Tests for old checkAndMutate API</span> |
| <span class="source-line-no">281</span><span id="line-281"></span> |
| <span class="source-line-no">282</span><span id="line-282"> @SuppressWarnings("FutureReturnValueIgnored")</span> |
| <span class="source-line-no">283</span><span id="line-283"> @Test</span> |
| <span class="source-line-no">284</span><span id="line-284"> @Deprecated</span> |
| <span class="source-line-no">285</span><span id="line-285"> public void testCheckAndPutForOldApi() throws InterruptedException, ExecutionException {</span> |
| <span class="source-line-no">286</span><span id="line-286"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">287</span><span id="line-287"> AtomicInteger successCount = new AtomicInteger(0);</span> |
| <span class="source-line-no">288</span><span id="line-288"> AtomicInteger successIndex = new AtomicInteger(-1);</span> |
| <span class="source-line-no">289</span><span id="line-289"> int count = 10;</span> |
| <span class="source-line-no">290</span><span id="line-290"> CountDownLatch latch = new CountDownLatch(count);</span> |
| <span class="source-line-no">291</span><span id="line-291"> IntStream.range(0, count)</span> |
| <span class="source-line-no">292</span><span id="line-292"> .forEach(i -> table.checkAndMutate(row, FAMILY).qualifier(QUALIFIER).ifNotExists()</span> |
| <span class="source-line-no">293</span><span id="line-293"> .thenPut(new Put(row).addColumn(FAMILY, QUALIFIER, concat(VALUE, i))).thenAccept(x -> {</span> |
| <span class="source-line-no">294</span><span id="line-294"> if (x) {</span> |
| <span class="source-line-no">295</span><span id="line-295"> successCount.incrementAndGet();</span> |
| <span class="source-line-no">296</span><span id="line-296"> successIndex.set(i);</span> |
| <span class="source-line-no">297</span><span id="line-297"> }</span> |
| <span class="source-line-no">298</span><span id="line-298"> latch.countDown();</span> |
| <span class="source-line-no">299</span><span id="line-299"> }));</span> |
| <span class="source-line-no">300</span><span id="line-300"> latch.await();</span> |
| <span class="source-line-no">301</span><span id="line-301"> assertEquals(1, successCount.get());</span> |
| <span class="source-line-no">302</span><span id="line-302"> String actual = Bytes.toString(table.get(new Get(row)).get().getValue(FAMILY, QUALIFIER));</span> |
| <span class="source-line-no">303</span><span id="line-303"> assertTrue(actual.endsWith(Integer.toString(successIndex.get())));</span> |
| <span class="source-line-no">304</span><span id="line-304"> }</span> |
| <span class="source-line-no">305</span><span id="line-305"></span> |
| <span class="source-line-no">306</span><span id="line-306"> @SuppressWarnings("FutureReturnValueIgnored")</span> |
| <span class="source-line-no">307</span><span id="line-307"> @Test</span> |
| <span class="source-line-no">308</span><span id="line-308"> @Deprecated</span> |
| <span class="source-line-no">309</span><span id="line-309"> public void testCheckAndDeleteForOldApi() throws InterruptedException, ExecutionException {</span> |
| <span class="source-line-no">310</span><span id="line-310"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">311</span><span id="line-311"> int count = 10;</span> |
| <span class="source-line-no">312</span><span id="line-312"> CountDownLatch putLatch = new CountDownLatch(count + 1);</span> |
| <span class="source-line-no">313</span><span id="line-313"> table.put(new Put(row).addColumn(FAMILY, QUALIFIER, VALUE)).thenRun(() -> putLatch.countDown());</span> |
| <span class="source-line-no">314</span><span id="line-314"> IntStream.range(0, count)</span> |
| <span class="source-line-no">315</span><span id="line-315"> .forEach(i -> table.put(new Put(row).addColumn(FAMILY, concat(QUALIFIER, i), VALUE))</span> |
| <span class="source-line-no">316</span><span id="line-316"> .thenRun(() -> putLatch.countDown()));</span> |
| <span class="source-line-no">317</span><span id="line-317"> putLatch.await();</span> |
| <span class="source-line-no">318</span><span id="line-318"></span> |
| <span class="source-line-no">319</span><span id="line-319"> AtomicInteger successCount = new AtomicInteger(0);</span> |
| <span class="source-line-no">320</span><span id="line-320"> AtomicInteger successIndex = new AtomicInteger(-1);</span> |
| <span class="source-line-no">321</span><span id="line-321"> CountDownLatch deleteLatch = new CountDownLatch(count);</span> |
| <span class="source-line-no">322</span><span id="line-322"> IntStream.range(0, count)</span> |
| <span class="source-line-no">323</span><span id="line-323"> .forEach(i -> table.checkAndMutate(row, FAMILY).qualifier(QUALIFIER).ifEquals(VALUE)</span> |
| <span class="source-line-no">324</span><span id="line-324"> .thenDelete(</span> |
| <span class="source-line-no">325</span><span id="line-325"> new Delete(row).addColumn(FAMILY, QUALIFIER).addColumn(FAMILY, concat(QUALIFIER, i)))</span> |
| <span class="source-line-no">326</span><span id="line-326"> .thenAccept(x -> {</span> |
| <span class="source-line-no">327</span><span id="line-327"> if (x) {</span> |
| <span class="source-line-no">328</span><span id="line-328"> successCount.incrementAndGet();</span> |
| <span class="source-line-no">329</span><span id="line-329"> successIndex.set(i);</span> |
| <span class="source-line-no">330</span><span id="line-330"> }</span> |
| <span class="source-line-no">331</span><span id="line-331"> deleteLatch.countDown();</span> |
| <span class="source-line-no">332</span><span id="line-332"> }));</span> |
| <span class="source-line-no">333</span><span id="line-333"> deleteLatch.await();</span> |
| <span class="source-line-no">334</span><span id="line-334"> assertEquals(1, successCount.get());</span> |
| <span class="source-line-no">335</span><span id="line-335"> Result result = table.get(new Get(row)).get();</span> |
| <span class="source-line-no">336</span><span id="line-336"> IntStream.range(0, count).forEach(i -> {</span> |
| <span class="source-line-no">337</span><span id="line-337"> if (i == successIndex.get()) {</span> |
| <span class="source-line-no">338</span><span id="line-338"> assertFalse(result.containsColumn(FAMILY, concat(QUALIFIER, i)));</span> |
| <span class="source-line-no">339</span><span id="line-339"> } else {</span> |
| <span class="source-line-no">340</span><span id="line-340"> assertArrayEquals(VALUE, result.getValue(FAMILY, concat(QUALIFIER, i)));</span> |
| <span class="source-line-no">341</span><span id="line-341"> }</span> |
| <span class="source-line-no">342</span><span id="line-342"> });</span> |
| <span class="source-line-no">343</span><span id="line-343"> }</span> |
| <span class="source-line-no">344</span><span id="line-344"></span> |
| <span class="source-line-no">345</span><span id="line-345"> @SuppressWarnings("FutureReturnValueIgnored")</span> |
| <span class="source-line-no">346</span><span id="line-346"> @Test</span> |
| <span class="source-line-no">347</span><span id="line-347"> @Deprecated</span> |
| <span class="source-line-no">348</span><span id="line-348"> public void testCheckAndMutateForOldApi() throws InterruptedException, ExecutionException {</span> |
| <span class="source-line-no">349</span><span id="line-349"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">350</span><span id="line-350"> int count = 10;</span> |
| <span class="source-line-no">351</span><span id="line-351"> CountDownLatch putLatch = new CountDownLatch(count + 1);</span> |
| <span class="source-line-no">352</span><span id="line-352"> table.put(new Put(row).addColumn(FAMILY, QUALIFIER, VALUE)).thenRun(() -> putLatch.countDown());</span> |
| <span class="source-line-no">353</span><span id="line-353"> IntStream.range(0, count)</span> |
| <span class="source-line-no">354</span><span id="line-354"> .forEach(i -> table.put(new Put(row).addColumn(FAMILY, concat(QUALIFIER, i), VALUE))</span> |
| <span class="source-line-no">355</span><span id="line-355"> .thenRun(() -> putLatch.countDown()));</span> |
| <span class="source-line-no">356</span><span id="line-356"> putLatch.await();</span> |
| <span class="source-line-no">357</span><span id="line-357"></span> |
| <span class="source-line-no">358</span><span id="line-358"> AtomicInteger successCount = new AtomicInteger(0);</span> |
| <span class="source-line-no">359</span><span id="line-359"> AtomicInteger successIndex = new AtomicInteger(-1);</span> |
| <span class="source-line-no">360</span><span id="line-360"> CountDownLatch mutateLatch = new CountDownLatch(count);</span> |
| <span class="source-line-no">361</span><span id="line-361"> IntStream.range(0, count).forEach(i -> {</span> |
| <span class="source-line-no">362</span><span id="line-362"> RowMutations mutation = new RowMutations(row);</span> |
| <span class="source-line-no">363</span><span id="line-363"> try {</span> |
| <span class="source-line-no">364</span><span id="line-364"> mutation.add((Mutation) new Delete(row).addColumn(FAMILY, QUALIFIER));</span> |
| <span class="source-line-no">365</span><span id="line-365"> mutation</span> |
| <span class="source-line-no">366</span><span id="line-366"> .add((Mutation) new Put(row).addColumn(FAMILY, concat(QUALIFIER, i), concat(VALUE, i)));</span> |
| <span class="source-line-no">367</span><span id="line-367"> } catch (IOException e) {</span> |
| <span class="source-line-no">368</span><span id="line-368"> throw new UncheckedIOException(e);</span> |
| <span class="source-line-no">369</span><span id="line-369"> }</span> |
| <span class="source-line-no">370</span><span id="line-370"> table.checkAndMutate(row, FAMILY).qualifier(QUALIFIER).ifEquals(VALUE).thenMutate(mutation)</span> |
| <span class="source-line-no">371</span><span id="line-371"> .thenAccept(x -> {</span> |
| <span class="source-line-no">372</span><span id="line-372"> if (x) {</span> |
| <span class="source-line-no">373</span><span id="line-373"> successCount.incrementAndGet();</span> |
| <span class="source-line-no">374</span><span id="line-374"> successIndex.set(i);</span> |
| <span class="source-line-no">375</span><span id="line-375"> }</span> |
| <span class="source-line-no">376</span><span id="line-376"> mutateLatch.countDown();</span> |
| <span class="source-line-no">377</span><span id="line-377"> });</span> |
| <span class="source-line-no">378</span><span id="line-378"> });</span> |
| <span class="source-line-no">379</span><span id="line-379"> mutateLatch.await();</span> |
| <span class="source-line-no">380</span><span id="line-380"> assertEquals(1, successCount.get());</span> |
| <span class="source-line-no">381</span><span id="line-381"> Result result = table.get(new Get(row)).get();</span> |
| <span class="source-line-no">382</span><span id="line-382"> IntStream.range(0, count).forEach(i -> {</span> |
| <span class="source-line-no">383</span><span id="line-383"> if (i == successIndex.get()) {</span> |
| <span class="source-line-no">384</span><span id="line-384"> assertArrayEquals(concat(VALUE, i), result.getValue(FAMILY, concat(QUALIFIER, i)));</span> |
| <span class="source-line-no">385</span><span id="line-385"> } else {</span> |
| <span class="source-line-no">386</span><span id="line-386"> assertArrayEquals(VALUE, result.getValue(FAMILY, concat(QUALIFIER, i)));</span> |
| <span class="source-line-no">387</span><span id="line-387"> }</span> |
| <span class="source-line-no">388</span><span id="line-388"> });</span> |
| <span class="source-line-no">389</span><span id="line-389"> }</span> |
| <span class="source-line-no">390</span><span id="line-390"></span> |
| <span class="source-line-no">391</span><span id="line-391"> @Test</span> |
| <span class="source-line-no">392</span><span id="line-392"> @Deprecated</span> |
| <span class="source-line-no">393</span><span id="line-393"> public void testCheckAndMutateWithTimeRangeForOldApi() throws Exception {</span> |
| <span class="source-line-no">394</span><span id="line-394"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">395</span><span id="line-395"> final long ts = EnvironmentEdgeManager.currentTime() / 2;</span> |
| <span class="source-line-no">396</span><span id="line-396"> Put put = new Put(row);</span> |
| <span class="source-line-no">397</span><span id="line-397"> put.addColumn(FAMILY, QUALIFIER, ts, VALUE);</span> |
| <span class="source-line-no">398</span><span id="line-398"></span> |
| <span class="source-line-no">399</span><span id="line-399"> boolean ok =</span> |
| <span class="source-line-no">400</span><span id="line-400"> table.checkAndMutate(row, FAMILY).qualifier(QUALIFIER).ifNotExists().thenPut(put).get();</span> |
| <span class="source-line-no">401</span><span id="line-401"> assertTrue(ok);</span> |
| <span class="source-line-no">402</span><span id="line-402"></span> |
| <span class="source-line-no">403</span><span id="line-403"> ok = table.checkAndMutate(row, FAMILY).qualifier(QUALIFIER).timeRange(TimeRange.at(ts + 10000))</span> |
| <span class="source-line-no">404</span><span id="line-404"> .ifEquals(VALUE).thenPut(put).get();</span> |
| <span class="source-line-no">405</span><span id="line-405"> assertFalse(ok);</span> |
| <span class="source-line-no">406</span><span id="line-406"></span> |
| <span class="source-line-no">407</span><span id="line-407"> ok = table.checkAndMutate(row, FAMILY).qualifier(QUALIFIER).timeRange(TimeRange.at(ts))</span> |
| <span class="source-line-no">408</span><span id="line-408"> .ifEquals(VALUE).thenPut(put).get();</span> |
| <span class="source-line-no">409</span><span id="line-409"> assertTrue(ok);</span> |
| <span class="source-line-no">410</span><span id="line-410"></span> |
| <span class="source-line-no">411</span><span id="line-411"> RowMutations rm = new RowMutations(row).add((Mutation) put);</span> |
| <span class="source-line-no">412</span><span id="line-412"></span> |
| <span class="source-line-no">413</span><span id="line-413"> ok = table.checkAndMutate(row, FAMILY).qualifier(QUALIFIER).timeRange(TimeRange.at(ts + 10000))</span> |
| <span class="source-line-no">414</span><span id="line-414"> .ifEquals(VALUE).thenMutate(rm).get();</span> |
| <span class="source-line-no">415</span><span id="line-415"> assertFalse(ok);</span> |
| <span class="source-line-no">416</span><span id="line-416"></span> |
| <span class="source-line-no">417</span><span id="line-417"> ok = table.checkAndMutate(row, FAMILY).qualifier(QUALIFIER).timeRange(TimeRange.at(ts))</span> |
| <span class="source-line-no">418</span><span id="line-418"> .ifEquals(VALUE).thenMutate(rm).get();</span> |
| <span class="source-line-no">419</span><span id="line-419"> assertTrue(ok);</span> |
| <span class="source-line-no">420</span><span id="line-420"></span> |
| <span class="source-line-no">421</span><span id="line-421"> Delete delete = new Delete(row).addColumn(FAMILY, QUALIFIER);</span> |
| <span class="source-line-no">422</span><span id="line-422"></span> |
| <span class="source-line-no">423</span><span id="line-423"> ok = table.checkAndMutate(row, FAMILY).qualifier(QUALIFIER).timeRange(TimeRange.at(ts + 10000))</span> |
| <span class="source-line-no">424</span><span id="line-424"> .ifEquals(VALUE).thenDelete(delete).get();</span> |
| <span class="source-line-no">425</span><span id="line-425"> assertFalse(ok);</span> |
| <span class="source-line-no">426</span><span id="line-426"></span> |
| <span class="source-line-no">427</span><span id="line-427"> ok = table.checkAndMutate(row, FAMILY).qualifier(QUALIFIER).timeRange(TimeRange.at(ts))</span> |
| <span class="source-line-no">428</span><span id="line-428"> .ifEquals(VALUE).thenDelete(delete).get();</span> |
| <span class="source-line-no">429</span><span id="line-429"> assertTrue(ok);</span> |
| <span class="source-line-no">430</span><span id="line-430"> }</span> |
| <span class="source-line-no">431</span><span id="line-431"></span> |
| <span class="source-line-no">432</span><span id="line-432"> @Test</span> |
| <span class="source-line-no">433</span><span id="line-433"> @Deprecated</span> |
| <span class="source-line-no">434</span><span id="line-434"> public void testCheckAndMutateWithSingleFilterForOldApi() throws Throwable {</span> |
| <span class="source-line-no">435</span><span id="line-435"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">436</span><span id="line-436"></span> |
| <span class="source-line-no">437</span><span id="line-437"> // Put one row</span> |
| <span class="source-line-no">438</span><span id="line-438"> Put put = new Put(row);</span> |
| <span class="source-line-no">439</span><span id="line-439"> put.addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"));</span> |
| <span class="source-line-no">440</span><span id="line-440"> put.addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"));</span> |
| <span class="source-line-no">441</span><span id="line-441"> put.addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"));</span> |
| <span class="source-line-no">442</span><span id="line-442"> table.put(put).get();</span> |
| <span class="source-line-no">443</span><span id="line-443"></span> |
| <span class="source-line-no">444</span><span id="line-444"> // Put with success</span> |
| <span class="source-line-no">445</span><span id="line-445"> boolean ok = table</span> |
| <span class="source-line-no">446</span><span id="line-446"> .checkAndMutate(row,</span> |
| <span class="source-line-no">447</span><span id="line-447"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">448</span><span id="line-448"> Bytes.toBytes("a")))</span> |
| <span class="source-line-no">449</span><span id="line-449"> .thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d"))).get();</span> |
| <span class="source-line-no">450</span><span id="line-450"> assertTrue(ok);</span> |
| <span class="source-line-no">451</span><span id="line-451"></span> |
| <span class="source-line-no">452</span><span id="line-452"> Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();</span> |
| <span class="source-line-no">453</span><span id="line-453"> assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">454</span><span id="line-454"></span> |
| <span class="source-line-no">455</span><span id="line-455"> // Put with failure</span> |
| <span class="source-line-no">456</span><span id="line-456"> ok = table</span> |
| <span class="source-line-no">457</span><span id="line-457"> .checkAndMutate(row,</span> |
| <span class="source-line-no">458</span><span id="line-458"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">459</span><span id="line-459"> Bytes.toBytes("b")))</span> |
| <span class="source-line-no">460</span><span id="line-460"> .thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e"))).get();</span> |
| <span class="source-line-no">461</span><span id="line-461"> assertFalse(ok);</span> |
| <span class="source-line-no">462</span><span id="line-462"></span> |
| <span class="source-line-no">463</span><span id="line-463"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("E"))).get());</span> |
| <span class="source-line-no">464</span><span id="line-464"></span> |
| <span class="source-line-no">465</span><span id="line-465"> // Delete with success</span> |
| <span class="source-line-no">466</span><span id="line-466"> ok = table</span> |
| <span class="source-line-no">467</span><span id="line-467"> .checkAndMutate(row,</span> |
| <span class="source-line-no">468</span><span id="line-468"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">469</span><span id="line-469"> Bytes.toBytes("a")))</span> |
| <span class="source-line-no">470</span><span id="line-470"> .thenDelete(new Delete(row).addColumns(FAMILY, Bytes.toBytes("D"))).get();</span> |
| <span class="source-line-no">471</span><span id="line-471"> assertTrue(ok);</span> |
| <span class="source-line-no">472</span><span id="line-472"></span> |
| <span class="source-line-no">473</span><span id="line-473"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get());</span> |
| <span class="source-line-no">474</span><span id="line-474"></span> |
| <span class="source-line-no">475</span><span id="line-475"> // Mutate with success</span> |
| <span class="source-line-no">476</span><span id="line-476"> ok = table</span> |
| <span class="source-line-no">477</span><span id="line-477"> .checkAndMutate(row,</span> |
| <span class="source-line-no">478</span><span id="line-478"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">479</span><span id="line-479"> Bytes.toBytes("b")))</span> |
| <span class="source-line-no">480</span><span id="line-480"> .thenMutate(new RowMutations(row)</span> |
| <span class="source-line-no">481</span><span id="line-481"> .add((Mutation) new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))</span> |
| <span class="source-line-no">482</span><span id="line-482"> .add((Mutation) new Delete(row).addColumns(FAMILY, Bytes.toBytes("A"))))</span> |
| <span class="source-line-no">483</span><span id="line-483"> .get();</span> |
| <span class="source-line-no">484</span><span id="line-484"> assertTrue(ok);</span> |
| <span class="source-line-no">485</span><span id="line-485"></span> |
| <span class="source-line-no">486</span><span id="line-486"> result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();</span> |
| <span class="source-line-no">487</span><span id="line-487"> assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">488</span><span id="line-488"></span> |
| <span class="source-line-no">489</span><span id="line-489"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get());</span> |
| <span class="source-line-no">490</span><span id="line-490"> }</span> |
| <span class="source-line-no">491</span><span id="line-491"></span> |
| <span class="source-line-no">492</span><span id="line-492"> @Test</span> |
| <span class="source-line-no">493</span><span id="line-493"> @Deprecated</span> |
| <span class="source-line-no">494</span><span id="line-494"> public void testCheckAndMutateWithMultipleFiltersForOldApi() throws Throwable {</span> |
| <span class="source-line-no">495</span><span id="line-495"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">496</span><span id="line-496"></span> |
| <span class="source-line-no">497</span><span id="line-497"> // Put one row</span> |
| <span class="source-line-no">498</span><span id="line-498"> Put put = new Put(row);</span> |
| <span class="source-line-no">499</span><span id="line-499"> put.addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"));</span> |
| <span class="source-line-no">500</span><span id="line-500"> put.addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"));</span> |
| <span class="source-line-no">501</span><span id="line-501"> put.addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"));</span> |
| <span class="source-line-no">502</span><span id="line-502"> table.put(put).get();</span> |
| <span class="source-line-no">503</span><span id="line-503"></span> |
| <span class="source-line-no">504</span><span id="line-504"> // Put with success</span> |
| <span class="source-line-no">505</span><span id="line-505"> boolean ok = table</span> |
| <span class="source-line-no">506</span><span id="line-506"> .checkAndMutate(row,</span> |
| <span class="source-line-no">507</span><span id="line-507"> new FilterList(</span> |
| <span class="source-line-no">508</span><span id="line-508"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">509</span><span id="line-509"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">510</span><span id="line-510"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">511</span><span id="line-511"> Bytes.toBytes("b"))))</span> |
| <span class="source-line-no">512</span><span id="line-512"> .thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d"))).get();</span> |
| <span class="source-line-no">513</span><span id="line-513"> assertTrue(ok);</span> |
| <span class="source-line-no">514</span><span id="line-514"></span> |
| <span class="source-line-no">515</span><span id="line-515"> Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();</span> |
| <span class="source-line-no">516</span><span id="line-516"> assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">517</span><span id="line-517"></span> |
| <span class="source-line-no">518</span><span id="line-518"> // Put with failure</span> |
| <span class="source-line-no">519</span><span id="line-519"> ok = table</span> |
| <span class="source-line-no">520</span><span id="line-520"> .checkAndMutate(row,</span> |
| <span class="source-line-no">521</span><span id="line-521"> new FilterList(</span> |
| <span class="source-line-no">522</span><span id="line-522"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">523</span><span id="line-523"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">524</span><span id="line-524"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">525</span><span id="line-525"> Bytes.toBytes("c"))))</span> |
| <span class="source-line-no">526</span><span id="line-526"> .thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e"))).get();</span> |
| <span class="source-line-no">527</span><span id="line-527"> assertFalse(ok);</span> |
| <span class="source-line-no">528</span><span id="line-528"></span> |
| <span class="source-line-no">529</span><span id="line-529"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("E"))).get());</span> |
| <span class="source-line-no">530</span><span id="line-530"></span> |
| <span class="source-line-no">531</span><span id="line-531"> // Delete with success</span> |
| <span class="source-line-no">532</span><span id="line-532"> ok = table</span> |
| <span class="source-line-no">533</span><span id="line-533"> .checkAndMutate(row,</span> |
| <span class="source-line-no">534</span><span id="line-534"> new FilterList(</span> |
| <span class="source-line-no">535</span><span id="line-535"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">536</span><span id="line-536"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">537</span><span id="line-537"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">538</span><span id="line-538"> Bytes.toBytes("b"))))</span> |
| <span class="source-line-no">539</span><span id="line-539"> .thenDelete(new Delete(row).addColumns(FAMILY, Bytes.toBytes("D"))).get();</span> |
| <span class="source-line-no">540</span><span id="line-540"> assertTrue(ok);</span> |
| <span class="source-line-no">541</span><span id="line-541"></span> |
| <span class="source-line-no">542</span><span id="line-542"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get());</span> |
| <span class="source-line-no">543</span><span id="line-543"></span> |
| <span class="source-line-no">544</span><span id="line-544"> // Mutate with success</span> |
| <span class="source-line-no">545</span><span id="line-545"> ok = table</span> |
| <span class="source-line-no">546</span><span id="line-546"> .checkAndMutate(row,</span> |
| <span class="source-line-no">547</span><span id="line-547"> new FilterList(</span> |
| <span class="source-line-no">548</span><span id="line-548"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">549</span><span id="line-549"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">550</span><span id="line-550"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">551</span><span id="line-551"> Bytes.toBytes("b"))))</span> |
| <span class="source-line-no">552</span><span id="line-552"> .thenMutate(new RowMutations(row)</span> |
| <span class="source-line-no">553</span><span id="line-553"> .add((Mutation) new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))</span> |
| <span class="source-line-no">554</span><span id="line-554"> .add((Mutation) new Delete(row).addColumns(FAMILY, Bytes.toBytes("A"))))</span> |
| <span class="source-line-no">555</span><span id="line-555"> .get();</span> |
| <span class="source-line-no">556</span><span id="line-556"> assertTrue(ok);</span> |
| <span class="source-line-no">557</span><span id="line-557"></span> |
| <span class="source-line-no">558</span><span id="line-558"> result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();</span> |
| <span class="source-line-no">559</span><span id="line-559"> assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">560</span><span id="line-560"></span> |
| <span class="source-line-no">561</span><span id="line-561"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get());</span> |
| <span class="source-line-no">562</span><span id="line-562"> }</span> |
| <span class="source-line-no">563</span><span id="line-563"></span> |
| <span class="source-line-no">564</span><span id="line-564"> @Test</span> |
| <span class="source-line-no">565</span><span id="line-565"> @Deprecated</span> |
| <span class="source-line-no">566</span><span id="line-566"> public void testCheckAndMutateWithTimestampFilterForOldApi() throws Throwable {</span> |
| <span class="source-line-no">567</span><span id="line-567"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">568</span><span id="line-568"></span> |
| <span class="source-line-no">569</span><span id="line-569"> // Put with specifying the timestamp</span> |
| <span class="source-line-no">570</span><span id="line-570"> table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a"))).get();</span> |
| <span class="source-line-no">571</span><span id="line-571"></span> |
| <span class="source-line-no">572</span><span id="line-572"> // Put with success</span> |
| <span class="source-line-no">573</span><span id="line-573"> boolean ok = table</span> |
| <span class="source-line-no">574</span><span id="line-574"> .checkAndMutate(row,</span> |
| <span class="source-line-no">575</span><span id="line-575"> new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)),</span> |
| <span class="source-line-no">576</span><span id="line-576"> new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))),</span> |
| <span class="source-line-no">577</span><span id="line-577"> new TimestampsFilter(Collections.singletonList(100L))))</span> |
| <span class="source-line-no">578</span><span id="line-578"> .thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"))).get();</span> |
| <span class="source-line-no">579</span><span id="line-579"> assertTrue(ok);</span> |
| <span class="source-line-no">580</span><span id="line-580"></span> |
| <span class="source-line-no">581</span><span id="line-581"> Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">582</span><span id="line-582"> assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">583</span><span id="line-583"></span> |
| <span class="source-line-no">584</span><span id="line-584"> // Put with failure</span> |
| <span class="source-line-no">585</span><span id="line-585"> ok = table</span> |
| <span class="source-line-no">586</span><span id="line-586"> .checkAndMutate(row,</span> |
| <span class="source-line-no">587</span><span id="line-587"> new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)),</span> |
| <span class="source-line-no">588</span><span id="line-588"> new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))),</span> |
| <span class="source-line-no">589</span><span id="line-589"> new TimestampsFilter(Collections.singletonList(101L))))</span> |
| <span class="source-line-no">590</span><span id="line-590"> .thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"))).get();</span> |
| <span class="source-line-no">591</span><span id="line-591"> assertFalse(ok);</span> |
| <span class="source-line-no">592</span><span id="line-592"></span> |
| <span class="source-line-no">593</span><span id="line-593"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get());</span> |
| <span class="source-line-no">594</span><span id="line-594"> }</span> |
| <span class="source-line-no">595</span><span id="line-595"></span> |
| <span class="source-line-no">596</span><span id="line-596"> @Test</span> |
| <span class="source-line-no">597</span><span id="line-597"> @Deprecated</span> |
| <span class="source-line-no">598</span><span id="line-598"> public void testCheckAndMutateWithFilterAndTimeRangeForOldApi() throws Throwable {</span> |
| <span class="source-line-no">599</span><span id="line-599"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">600</span><span id="line-600"></span> |
| <span class="source-line-no">601</span><span id="line-601"> // Put with specifying the timestamp</span> |
| <span class="source-line-no">602</span><span id="line-602"> table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a"))).get();</span> |
| <span class="source-line-no">603</span><span id="line-603"></span> |
| <span class="source-line-no">604</span><span id="line-604"> // Put with success</span> |
| <span class="source-line-no">605</span><span id="line-605"> boolean ok = table</span> |
| <span class="source-line-no">606</span><span id="line-606"> .checkAndMutate(row,</span> |
| <span class="source-line-no">607</span><span id="line-607"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">608</span><span id="line-608"> Bytes.toBytes("a")))</span> |
| <span class="source-line-no">609</span><span id="line-609"> .timeRange(TimeRange.between(0, 101))</span> |
| <span class="source-line-no">610</span><span id="line-610"> .thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"))).get();</span> |
| <span class="source-line-no">611</span><span id="line-611"> assertTrue(ok);</span> |
| <span class="source-line-no">612</span><span id="line-612"></span> |
| <span class="source-line-no">613</span><span id="line-613"> Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">614</span><span id="line-614"> assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">615</span><span id="line-615"></span> |
| <span class="source-line-no">616</span><span id="line-616"> // Put with failure</span> |
| <span class="source-line-no">617</span><span id="line-617"> ok = table</span> |
| <span class="source-line-no">618</span><span id="line-618"> .checkAndMutate(row,</span> |
| <span class="source-line-no">619</span><span id="line-619"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">620</span><span id="line-620"> Bytes.toBytes("a")))</span> |
| <span class="source-line-no">621</span><span id="line-621"> .timeRange(TimeRange.between(0, 100))</span> |
| <span class="source-line-no">622</span><span id="line-622"> .thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"))).get();</span> |
| <span class="source-line-no">623</span><span id="line-623"> assertFalse(ok);</span> |
| <span class="source-line-no">624</span><span id="line-624"></span> |
| <span class="source-line-no">625</span><span id="line-625"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get());</span> |
| <span class="source-line-no">626</span><span id="line-626"> }</span> |
| <span class="source-line-no">627</span><span id="line-627"></span> |
| <span class="source-line-no">628</span><span id="line-628"> @Test(expected = NullPointerException.class)</span> |
| <span class="source-line-no">629</span><span id="line-629"> @Deprecated</span> |
| <span class="source-line-no">630</span><span id="line-630"> public void testCheckAndMutateWithoutConditionForOldApi() {</span> |
| <span class="source-line-no">631</span><span id="line-631"> getTable.get().checkAndMutate(row, FAMILY)</span> |
| <span class="source-line-no">632</span><span id="line-632"> .thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")));</span> |
| <span class="source-line-no">633</span><span id="line-633"> }</span> |
| <span class="source-line-no">634</span><span id="line-634"></span> |
| <span class="source-line-no">635</span><span id="line-635"> // Tests for new CheckAndMutate API</span> |
| <span class="source-line-no">636</span><span id="line-636"></span> |
| <span class="source-line-no">637</span><span id="line-637"> @SuppressWarnings("FutureReturnValueIgnored")</span> |
| <span class="source-line-no">638</span><span id="line-638"> @Test</span> |
| <span class="source-line-no">639</span><span id="line-639"> public void testCheckAndPut() throws InterruptedException, ExecutionException {</span> |
| <span class="source-line-no">640</span><span id="line-640"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">641</span><span id="line-641"> AtomicInteger successCount = new AtomicInteger(0);</span> |
| <span class="source-line-no">642</span><span id="line-642"> AtomicInteger successIndex = new AtomicInteger(-1);</span> |
| <span class="source-line-no">643</span><span id="line-643"> int count = 10;</span> |
| <span class="source-line-no">644</span><span id="line-644"> CountDownLatch latch = new CountDownLatch(count);</span> |
| <span class="source-line-no">645</span><span id="line-645"></span> |
| <span class="source-line-no">646</span><span id="line-646"> IntStream.range(0, count).forEach(</span> |
| <span class="source-line-no">647</span><span id="line-647"> i -> table.checkAndMutate(CheckAndMutate.newBuilder(row).ifNotExists(FAMILY, QUALIFIER)</span> |
| <span class="source-line-no">648</span><span id="line-648"> .build(new Put(row).addColumn(FAMILY, QUALIFIER, concat(VALUE, i)))).thenAccept(x -> {</span> |
| <span class="source-line-no">649</span><span id="line-649"> if (x.isSuccess()) {</span> |
| <span class="source-line-no">650</span><span id="line-650"> successCount.incrementAndGet();</span> |
| <span class="source-line-no">651</span><span id="line-651"> successIndex.set(i);</span> |
| <span class="source-line-no">652</span><span id="line-652"> }</span> |
| <span class="source-line-no">653</span><span id="line-653"> assertNull(x.getResult());</span> |
| <span class="source-line-no">654</span><span id="line-654"> latch.countDown();</span> |
| <span class="source-line-no">655</span><span id="line-655"> }));</span> |
| <span class="source-line-no">656</span><span id="line-656"> latch.await();</span> |
| <span class="source-line-no">657</span><span id="line-657"> assertEquals(1, successCount.get());</span> |
| <span class="source-line-no">658</span><span id="line-658"> String actual = Bytes.toString(table.get(new Get(row)).get().getValue(FAMILY, QUALIFIER));</span> |
| <span class="source-line-no">659</span><span id="line-659"> assertTrue(actual.endsWith(Integer.toString(successIndex.get())));</span> |
| <span class="source-line-no">660</span><span id="line-660"> }</span> |
| <span class="source-line-no">661</span><span id="line-661"></span> |
| <span class="source-line-no">662</span><span id="line-662"> @SuppressWarnings("FutureReturnValueIgnored")</span> |
| <span class="source-line-no">663</span><span id="line-663"> @Test</span> |
| <span class="source-line-no">664</span><span id="line-664"> public void testCheckAndDelete() throws InterruptedException, ExecutionException {</span> |
| <span class="source-line-no">665</span><span id="line-665"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">666</span><span id="line-666"> int count = 10;</span> |
| <span class="source-line-no">667</span><span id="line-667"> CountDownLatch putLatch = new CountDownLatch(count + 1);</span> |
| <span class="source-line-no">668</span><span id="line-668"> table.put(new Put(row).addColumn(FAMILY, QUALIFIER, VALUE)).thenRun(() -> putLatch.countDown());</span> |
| <span class="source-line-no">669</span><span id="line-669"> IntStream.range(0, count)</span> |
| <span class="source-line-no">670</span><span id="line-670"> .forEach(i -> table.put(new Put(row).addColumn(FAMILY, concat(QUALIFIER, i), VALUE))</span> |
| <span class="source-line-no">671</span><span id="line-671"> .thenRun(() -> putLatch.countDown()));</span> |
| <span class="source-line-no">672</span><span id="line-672"> putLatch.await();</span> |
| <span class="source-line-no">673</span><span id="line-673"></span> |
| <span class="source-line-no">674</span><span id="line-674"> AtomicInteger successCount = new AtomicInteger(0);</span> |
| <span class="source-line-no">675</span><span id="line-675"> AtomicInteger successIndex = new AtomicInteger(-1);</span> |
| <span class="source-line-no">676</span><span id="line-676"> CountDownLatch deleteLatch = new CountDownLatch(count);</span> |
| <span class="source-line-no">677</span><span id="line-677"></span> |
| <span class="source-line-no">678</span><span id="line-678"> IntStream.range(0, count)</span> |
| <span class="source-line-no">679</span><span id="line-679"> .forEach(i -> table</span> |
| <span class="source-line-no">680</span><span id="line-680"> .checkAndMutate(CheckAndMutate.newBuilder(row).ifEquals(FAMILY, QUALIFIER, VALUE).build(</span> |
| <span class="source-line-no">681</span><span id="line-681"> new Delete(row).addColumn(FAMILY, QUALIFIER).addColumn(FAMILY, concat(QUALIFIER, i))))</span> |
| <span class="source-line-no">682</span><span id="line-682"> .thenAccept(x -> {</span> |
| <span class="source-line-no">683</span><span id="line-683"> if (x.isSuccess()) {</span> |
| <span class="source-line-no">684</span><span id="line-684"> successCount.incrementAndGet();</span> |
| <span class="source-line-no">685</span><span id="line-685"> successIndex.set(i);</span> |
| <span class="source-line-no">686</span><span id="line-686"> }</span> |
| <span class="source-line-no">687</span><span id="line-687"> assertNull(x.getResult());</span> |
| <span class="source-line-no">688</span><span id="line-688"> deleteLatch.countDown();</span> |
| <span class="source-line-no">689</span><span id="line-689"> }));</span> |
| <span class="source-line-no">690</span><span id="line-690"> deleteLatch.await();</span> |
| <span class="source-line-no">691</span><span id="line-691"> assertEquals(1, successCount.get());</span> |
| <span class="source-line-no">692</span><span id="line-692"> Result result = table.get(new Get(row)).get();</span> |
| <span class="source-line-no">693</span><span id="line-693"> IntStream.range(0, count).forEach(i -> {</span> |
| <span class="source-line-no">694</span><span id="line-694"> if (i == successIndex.get()) {</span> |
| <span class="source-line-no">695</span><span id="line-695"> assertFalse(result.containsColumn(FAMILY, concat(QUALIFIER, i)));</span> |
| <span class="source-line-no">696</span><span id="line-696"> } else {</span> |
| <span class="source-line-no">697</span><span id="line-697"> assertArrayEquals(VALUE, result.getValue(FAMILY, concat(QUALIFIER, i)));</span> |
| <span class="source-line-no">698</span><span id="line-698"> }</span> |
| <span class="source-line-no">699</span><span id="line-699"> });</span> |
| <span class="source-line-no">700</span><span id="line-700"> }</span> |
| <span class="source-line-no">701</span><span id="line-701"></span> |
| <span class="source-line-no">702</span><span id="line-702"> @SuppressWarnings("FutureReturnValueIgnored")</span> |
| <span class="source-line-no">703</span><span id="line-703"> @Test</span> |
| <span class="source-line-no">704</span><span id="line-704"> public void testCheckAndMutate() throws InterruptedException, ExecutionException {</span> |
| <span class="source-line-no">705</span><span id="line-705"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">706</span><span id="line-706"> int count = 10;</span> |
| <span class="source-line-no">707</span><span id="line-707"> CountDownLatch putLatch = new CountDownLatch(count + 1);</span> |
| <span class="source-line-no">708</span><span id="line-708"> table.put(new Put(row).addColumn(FAMILY, QUALIFIER, VALUE)).thenRun(() -> putLatch.countDown());</span> |
| <span class="source-line-no">709</span><span id="line-709"> IntStream.range(0, count)</span> |
| <span class="source-line-no">710</span><span id="line-710"> .forEach(i -> table.put(new Put(row).addColumn(FAMILY, concat(QUALIFIER, i), VALUE))</span> |
| <span class="source-line-no">711</span><span id="line-711"> .thenRun(() -> putLatch.countDown()));</span> |
| <span class="source-line-no">712</span><span id="line-712"> putLatch.await();</span> |
| <span class="source-line-no">713</span><span id="line-713"></span> |
| <span class="source-line-no">714</span><span id="line-714"> AtomicInteger successCount = new AtomicInteger(0);</span> |
| <span class="source-line-no">715</span><span id="line-715"> AtomicInteger successIndex = new AtomicInteger(-1);</span> |
| <span class="source-line-no">716</span><span id="line-716"> CountDownLatch mutateLatch = new CountDownLatch(count);</span> |
| <span class="source-line-no">717</span><span id="line-717"> IntStream.range(0, count).forEach(i -> {</span> |
| <span class="source-line-no">718</span><span id="line-718"> RowMutations mutation = new RowMutations(row);</span> |
| <span class="source-line-no">719</span><span id="line-719"> try {</span> |
| <span class="source-line-no">720</span><span id="line-720"> mutation.add((Mutation) new Delete(row).addColumn(FAMILY, QUALIFIER));</span> |
| <span class="source-line-no">721</span><span id="line-721"> mutation</span> |
| <span class="source-line-no">722</span><span id="line-722"> .add((Mutation) new Put(row).addColumn(FAMILY, concat(QUALIFIER, i), concat(VALUE, i)));</span> |
| <span class="source-line-no">723</span><span id="line-723"> } catch (IOException e) {</span> |
| <span class="source-line-no">724</span><span id="line-724"> throw new UncheckedIOException(e);</span> |
| <span class="source-line-no">725</span><span id="line-725"> }</span> |
| <span class="source-line-no">726</span><span id="line-726"></span> |
| <span class="source-line-no">727</span><span id="line-727"> table</span> |
| <span class="source-line-no">728</span><span id="line-728"> .checkAndMutate(</span> |
| <span class="source-line-no">729</span><span id="line-729"> CheckAndMutate.newBuilder(row).ifEquals(FAMILY, QUALIFIER, VALUE).build(mutation))</span> |
| <span class="source-line-no">730</span><span id="line-730"> .thenAccept(x -> {</span> |
| <span class="source-line-no">731</span><span id="line-731"> if (x.isSuccess()) {</span> |
| <span class="source-line-no">732</span><span id="line-732"> successCount.incrementAndGet();</span> |
| <span class="source-line-no">733</span><span id="line-733"> successIndex.set(i);</span> |
| <span class="source-line-no">734</span><span id="line-734"> }</span> |
| <span class="source-line-no">735</span><span id="line-735"> assertNull(x.getResult());</span> |
| <span class="source-line-no">736</span><span id="line-736"> mutateLatch.countDown();</span> |
| <span class="source-line-no">737</span><span id="line-737"> });</span> |
| <span class="source-line-no">738</span><span id="line-738"> });</span> |
| <span class="source-line-no">739</span><span id="line-739"> mutateLatch.await();</span> |
| <span class="source-line-no">740</span><span id="line-740"> assertEquals(1, successCount.get());</span> |
| <span class="source-line-no">741</span><span id="line-741"> Result result = table.get(new Get(row)).get();</span> |
| <span class="source-line-no">742</span><span id="line-742"> IntStream.range(0, count).forEach(i -> {</span> |
| <span class="source-line-no">743</span><span id="line-743"> if (i == successIndex.get()) {</span> |
| <span class="source-line-no">744</span><span id="line-744"> assertArrayEquals(concat(VALUE, i), result.getValue(FAMILY, concat(QUALIFIER, i)));</span> |
| <span class="source-line-no">745</span><span id="line-745"> } else {</span> |
| <span class="source-line-no">746</span><span id="line-746"> assertArrayEquals(VALUE, result.getValue(FAMILY, concat(QUALIFIER, i)));</span> |
| <span class="source-line-no">747</span><span id="line-747"> }</span> |
| <span class="source-line-no">748</span><span id="line-748"> });</span> |
| <span class="source-line-no">749</span><span id="line-749"> }</span> |
| <span class="source-line-no">750</span><span id="line-750"></span> |
| <span class="source-line-no">751</span><span id="line-751"> @Test</span> |
| <span class="source-line-no">752</span><span id="line-752"> public void testCheckAndMutateWithTimeRange() throws Exception {</span> |
| <span class="source-line-no">753</span><span id="line-753"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">754</span><span id="line-754"> final long ts = EnvironmentEdgeManager.currentTime() / 2;</span> |
| <span class="source-line-no">755</span><span id="line-755"> Put put = new Put(row);</span> |
| <span class="source-line-no">756</span><span id="line-756"> put.addColumn(FAMILY, QUALIFIER, ts, VALUE);</span> |
| <span class="source-line-no">757</span><span id="line-757"></span> |
| <span class="source-line-no">758</span><span id="line-758"> CheckAndMutateResult result =</span> |
| <span class="source-line-no">759</span><span id="line-759"> table.checkAndMutate(CheckAndMutate.newBuilder(row).ifNotExists(FAMILY, QUALIFIER).build(put))</span> |
| <span class="source-line-no">760</span><span id="line-760"> .get();</span> |
| <span class="source-line-no">761</span><span id="line-761"> assertTrue(result.isSuccess());</span> |
| <span class="source-line-no">762</span><span id="line-762"> assertNull(result.getResult());</span> |
| <span class="source-line-no">763</span><span id="line-763"></span> |
| <span class="source-line-no">764</span><span id="line-764"> result = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifEquals(FAMILY, QUALIFIER, VALUE)</span> |
| <span class="source-line-no">765</span><span id="line-765"> .timeRange(TimeRange.at(ts + 10000)).build(put)).get();</span> |
| <span class="source-line-no">766</span><span id="line-766"> assertFalse(result.isSuccess());</span> |
| <span class="source-line-no">767</span><span id="line-767"> assertNull(result.getResult());</span> |
| <span class="source-line-no">768</span><span id="line-768"></span> |
| <span class="source-line-no">769</span><span id="line-769"> result = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifEquals(FAMILY, QUALIFIER, VALUE)</span> |
| <span class="source-line-no">770</span><span id="line-770"> .timeRange(TimeRange.at(ts)).build(put)).get();</span> |
| <span class="source-line-no">771</span><span id="line-771"> assertTrue(result.isSuccess());</span> |
| <span class="source-line-no">772</span><span id="line-772"> assertNull(result.getResult());</span> |
| <span class="source-line-no">773</span><span id="line-773"></span> |
| <span class="source-line-no">774</span><span id="line-774"> RowMutations rm = new RowMutations(row).add((Mutation) put);</span> |
| <span class="source-line-no">775</span><span id="line-775"></span> |
| <span class="source-line-no">776</span><span id="line-776"> result = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifEquals(FAMILY, QUALIFIER, VALUE)</span> |
| <span class="source-line-no">777</span><span id="line-777"> .timeRange(TimeRange.at(ts + 10000)).build(rm)).get();</span> |
| <span class="source-line-no">778</span><span id="line-778"> assertFalse(result.isSuccess());</span> |
| <span class="source-line-no">779</span><span id="line-779"> assertNull(result.getResult());</span> |
| <span class="source-line-no">780</span><span id="line-780"></span> |
| <span class="source-line-no">781</span><span id="line-781"> result = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifEquals(FAMILY, QUALIFIER, VALUE)</span> |
| <span class="source-line-no">782</span><span id="line-782"> .timeRange(TimeRange.at(ts)).build(rm)).get();</span> |
| <span class="source-line-no">783</span><span id="line-783"> assertTrue(result.isSuccess());</span> |
| <span class="source-line-no">784</span><span id="line-784"> assertNull(result.getResult());</span> |
| <span class="source-line-no">785</span><span id="line-785"></span> |
| <span class="source-line-no">786</span><span id="line-786"> Delete delete = new Delete(row).addColumn(FAMILY, QUALIFIER);</span> |
| <span class="source-line-no">787</span><span id="line-787"></span> |
| <span class="source-line-no">788</span><span id="line-788"> result = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifEquals(FAMILY, QUALIFIER, VALUE)</span> |
| <span class="source-line-no">789</span><span id="line-789"> .timeRange(TimeRange.at(ts + 10000)).build(delete)).get();</span> |
| <span class="source-line-no">790</span><span id="line-790"> assertFalse(result.isSuccess());</span> |
| <span class="source-line-no">791</span><span id="line-791"> assertNull(result.getResult());</span> |
| <span class="source-line-no">792</span><span id="line-792"></span> |
| <span class="source-line-no">793</span><span id="line-793"> result = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifEquals(FAMILY, QUALIFIER, VALUE)</span> |
| <span class="source-line-no">794</span><span id="line-794"> .timeRange(TimeRange.at(ts)).build(delete)).get();</span> |
| <span class="source-line-no">795</span><span id="line-795"> assertTrue(result.isSuccess());</span> |
| <span class="source-line-no">796</span><span id="line-796"> assertNull(result.getResult());</span> |
| <span class="source-line-no">797</span><span id="line-797"> }</span> |
| <span class="source-line-no">798</span><span id="line-798"></span> |
| <span class="source-line-no">799</span><span id="line-799"> @Test</span> |
| <span class="source-line-no">800</span><span id="line-800"> public void testCheckAndMutateWithSingleFilter() throws Throwable {</span> |
| <span class="source-line-no">801</span><span id="line-801"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">802</span><span id="line-802"></span> |
| <span class="source-line-no">803</span><span id="line-803"> // Put one row</span> |
| <span class="source-line-no">804</span><span id="line-804"> Put put = new Put(row);</span> |
| <span class="source-line-no">805</span><span id="line-805"> put.addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"));</span> |
| <span class="source-line-no">806</span><span id="line-806"> put.addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"));</span> |
| <span class="source-line-no">807</span><span id="line-807"> put.addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"));</span> |
| <span class="source-line-no">808</span><span id="line-808"> table.put(put).get();</span> |
| <span class="source-line-no">809</span><span id="line-809"></span> |
| <span class="source-line-no">810</span><span id="line-810"> // Put with success</span> |
| <span class="source-line-no">811</span><span id="line-811"> CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">812</span><span id="line-812"> .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">813</span><span id="line-813"> Bytes.toBytes("a")))</span> |
| <span class="source-line-no">814</span><span id="line-814"> .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))).get();</span> |
| <span class="source-line-no">815</span><span id="line-815"> assertTrue(result.isSuccess());</span> |
| <span class="source-line-no">816</span><span id="line-816"> assertNull(result.getResult());</span> |
| <span class="source-line-no">817</span><span id="line-817"></span> |
| <span class="source-line-no">818</span><span id="line-818"> Result r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();</span> |
| <span class="source-line-no">819</span><span id="line-819"> assertEquals("d", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">820</span><span id="line-820"></span> |
| <span class="source-line-no">821</span><span id="line-821"> // Put with failure</span> |
| <span class="source-line-no">822</span><span id="line-822"> result = table.checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">823</span><span id="line-823"> .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">824</span><span id="line-824"> Bytes.toBytes("b")))</span> |
| <span class="source-line-no">825</span><span id="line-825"> .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e")))).get();</span> |
| <span class="source-line-no">826</span><span id="line-826"> assertFalse(result.isSuccess());</span> |
| <span class="source-line-no">827</span><span id="line-827"> assertNull(result.getResult());</span> |
| <span class="source-line-no">828</span><span id="line-828"></span> |
| <span class="source-line-no">829</span><span id="line-829"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("E"))).get());</span> |
| <span class="source-line-no">830</span><span id="line-830"></span> |
| <span class="source-line-no">831</span><span id="line-831"> // Delete with success</span> |
| <span class="source-line-no">832</span><span id="line-832"> result =</span> |
| <span class="source-line-no">833</span><span id="line-833"> table</span> |
| <span class="source-line-no">834</span><span id="line-834"> .checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">835</span><span id="line-835"> .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">836</span><span id="line-836"> Bytes.toBytes("a")))</span> |
| <span class="source-line-no">837</span><span id="line-837"> .build(new Delete(row).addColumns(FAMILY, Bytes.toBytes("D"))))</span> |
| <span class="source-line-no">838</span><span id="line-838"> .get();</span> |
| <span class="source-line-no">839</span><span id="line-839"> assertTrue(result.isSuccess());</span> |
| <span class="source-line-no">840</span><span id="line-840"> assertNull(result.getResult());</span> |
| <span class="source-line-no">841</span><span id="line-841"></span> |
| <span class="source-line-no">842</span><span id="line-842"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get());</span> |
| <span class="source-line-no">843</span><span id="line-843"></span> |
| <span class="source-line-no">844</span><span id="line-844"> // Mutate with success</span> |
| <span class="source-line-no">845</span><span id="line-845"> result = table.checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">846</span><span id="line-846"> .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">847</span><span id="line-847"> Bytes.toBytes("b")))</span> |
| <span class="source-line-no">848</span><span id="line-848"> .build(new RowMutations(row)</span> |
| <span class="source-line-no">849</span><span id="line-849"> .add((Mutation) new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))</span> |
| <span class="source-line-no">850</span><span id="line-850"> .add((Mutation) new Delete(row).addColumns(FAMILY, Bytes.toBytes("A")))))</span> |
| <span class="source-line-no">851</span><span id="line-851"> .get();</span> |
| <span class="source-line-no">852</span><span id="line-852"> assertTrue(result.isSuccess());</span> |
| <span class="source-line-no">853</span><span id="line-853"> assertNull(result.getResult());</span> |
| <span class="source-line-no">854</span><span id="line-854"></span> |
| <span class="source-line-no">855</span><span id="line-855"> r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();</span> |
| <span class="source-line-no">856</span><span id="line-856"> assertEquals("d", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">857</span><span id="line-857"></span> |
| <span class="source-line-no">858</span><span id="line-858"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get());</span> |
| <span class="source-line-no">859</span><span id="line-859"> }</span> |
| <span class="source-line-no">860</span><span id="line-860"></span> |
| <span class="source-line-no">861</span><span id="line-861"> @Test</span> |
| <span class="source-line-no">862</span><span id="line-862"> public void testCheckAndMutateWithMultipleFilters() throws Throwable {</span> |
| <span class="source-line-no">863</span><span id="line-863"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">864</span><span id="line-864"></span> |
| <span class="source-line-no">865</span><span id="line-865"> // Put one row</span> |
| <span class="source-line-no">866</span><span id="line-866"> Put put = new Put(row);</span> |
| <span class="source-line-no">867</span><span id="line-867"> put.addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"));</span> |
| <span class="source-line-no">868</span><span id="line-868"> put.addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"));</span> |
| <span class="source-line-no">869</span><span id="line-869"> put.addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"));</span> |
| <span class="source-line-no">870</span><span id="line-870"> table.put(put).get();</span> |
| <span class="source-line-no">871</span><span id="line-871"></span> |
| <span class="source-line-no">872</span><span id="line-872"> // Put with success</span> |
| <span class="source-line-no">873</span><span id="line-873"> CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">874</span><span id="line-874"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">875</span><span id="line-875"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">876</span><span id="line-876"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">877</span><span id="line-877"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">878</span><span id="line-878"> Bytes.toBytes("b"))))</span> |
| <span class="source-line-no">879</span><span id="line-879"> .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))).get();</span> |
| <span class="source-line-no">880</span><span id="line-880"> assertTrue(result.isSuccess());</span> |
| <span class="source-line-no">881</span><span id="line-881"> assertNull(result.getResult());</span> |
| <span class="source-line-no">882</span><span id="line-882"></span> |
| <span class="source-line-no">883</span><span id="line-883"> Result r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();</span> |
| <span class="source-line-no">884</span><span id="line-884"> assertEquals("d", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">885</span><span id="line-885"></span> |
| <span class="source-line-no">886</span><span id="line-886"> // Put with failure</span> |
| <span class="source-line-no">887</span><span id="line-887"> result = table.checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">888</span><span id="line-888"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">889</span><span id="line-889"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">890</span><span id="line-890"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">891</span><span id="line-891"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">892</span><span id="line-892"> Bytes.toBytes("c"))))</span> |
| <span class="source-line-no">893</span><span id="line-893"> .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e")))).get();</span> |
| <span class="source-line-no">894</span><span id="line-894"> assertFalse(result.isSuccess());</span> |
| <span class="source-line-no">895</span><span id="line-895"> assertNull(result.getResult());</span> |
| <span class="source-line-no">896</span><span id="line-896"></span> |
| <span class="source-line-no">897</span><span id="line-897"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("E"))).get());</span> |
| <span class="source-line-no">898</span><span id="line-898"></span> |
| <span class="source-line-no">899</span><span id="line-899"> // Delete with success</span> |
| <span class="source-line-no">900</span><span id="line-900"> result = table</span> |
| <span class="source-line-no">901</span><span id="line-901"> .checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">902</span><span id="line-902"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">903</span><span id="line-903"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">904</span><span id="line-904"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">905</span><span id="line-905"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">906</span><span id="line-906"> Bytes.toBytes("b"))))</span> |
| <span class="source-line-no">907</span><span id="line-907"> .build(new Delete(row).addColumns(FAMILY, Bytes.toBytes("D"))))</span> |
| <span class="source-line-no">908</span><span id="line-908"> .get();</span> |
| <span class="source-line-no">909</span><span id="line-909"> assertTrue(result.isSuccess());</span> |
| <span class="source-line-no">910</span><span id="line-910"> assertNull(result.getResult());</span> |
| <span class="source-line-no">911</span><span id="line-911"></span> |
| <span class="source-line-no">912</span><span id="line-912"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get());</span> |
| <span class="source-line-no">913</span><span id="line-913"></span> |
| <span class="source-line-no">914</span><span id="line-914"> // Mutate with success</span> |
| <span class="source-line-no">915</span><span id="line-915"> result = table.checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">916</span><span id="line-916"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">917</span><span id="line-917"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">918</span><span id="line-918"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">919</span><span id="line-919"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">920</span><span id="line-920"> Bytes.toBytes("b"))))</span> |
| <span class="source-line-no">921</span><span id="line-921"> .build(new RowMutations(row)</span> |
| <span class="source-line-no">922</span><span id="line-922"> .add((Mutation) new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))</span> |
| <span class="source-line-no">923</span><span id="line-923"> .add((Mutation) new Delete(row).addColumns(FAMILY, Bytes.toBytes("A")))))</span> |
| <span class="source-line-no">924</span><span id="line-924"> .get();</span> |
| <span class="source-line-no">925</span><span id="line-925"> assertTrue(result.isSuccess());</span> |
| <span class="source-line-no">926</span><span id="line-926"> assertNull(result.getResult());</span> |
| <span class="source-line-no">927</span><span id="line-927"></span> |
| <span class="source-line-no">928</span><span id="line-928"> r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();</span> |
| <span class="source-line-no">929</span><span id="line-929"> assertEquals("d", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">930</span><span id="line-930"></span> |
| <span class="source-line-no">931</span><span id="line-931"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get());</span> |
| <span class="source-line-no">932</span><span id="line-932"> }</span> |
| <span class="source-line-no">933</span><span id="line-933"></span> |
| <span class="source-line-no">934</span><span id="line-934"> @Test</span> |
| <span class="source-line-no">935</span><span id="line-935"> public void testCheckAndMutateWithTimestampFilter() throws Throwable {</span> |
| <span class="source-line-no">936</span><span id="line-936"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">937</span><span id="line-937"></span> |
| <span class="source-line-no">938</span><span id="line-938"> // Put with specifying the timestamp</span> |
| <span class="source-line-no">939</span><span id="line-939"> table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a"))).get();</span> |
| <span class="source-line-no">940</span><span id="line-940"></span> |
| <span class="source-line-no">941</span><span id="line-941"> // Put with success</span> |
| <span class="source-line-no">942</span><span id="line-942"> CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">943</span><span id="line-943"> .ifMatches(</span> |
| <span class="source-line-no">944</span><span id="line-944"> new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)),</span> |
| <span class="source-line-no">945</span><span id="line-945"> new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))),</span> |
| <span class="source-line-no">946</span><span id="line-946"> new TimestampsFilter(Collections.singletonList(100L))))</span> |
| <span class="source-line-no">947</span><span id="line-947"> .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")))).get();</span> |
| <span class="source-line-no">948</span><span id="line-948"> assertTrue(result.isSuccess());</span> |
| <span class="source-line-no">949</span><span id="line-949"> assertNull(result.getResult());</span> |
| <span class="source-line-no">950</span><span id="line-950"></span> |
| <span class="source-line-no">951</span><span id="line-951"> Result r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">952</span><span id="line-952"> assertEquals("b", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">953</span><span id="line-953"></span> |
| <span class="source-line-no">954</span><span id="line-954"> // Put with failure</span> |
| <span class="source-line-no">955</span><span id="line-955"> result = table.checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">956</span><span id="line-956"> .ifMatches(</span> |
| <span class="source-line-no">957</span><span id="line-957"> new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)),</span> |
| <span class="source-line-no">958</span><span id="line-958"> new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))),</span> |
| <span class="source-line-no">959</span><span id="line-959"> new TimestampsFilter(Collections.singletonList(101L))))</span> |
| <span class="source-line-no">960</span><span id="line-960"> .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")))).get();</span> |
| <span class="source-line-no">961</span><span id="line-961"> assertFalse(result.isSuccess());</span> |
| <span class="source-line-no">962</span><span id="line-962"> assertNull(result.getResult());</span> |
| <span class="source-line-no">963</span><span id="line-963"></span> |
| <span class="source-line-no">964</span><span id="line-964"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get());</span> |
| <span class="source-line-no">965</span><span id="line-965"> }</span> |
| <span class="source-line-no">966</span><span id="line-966"></span> |
| <span class="source-line-no">967</span><span id="line-967"> @Test</span> |
| <span class="source-line-no">968</span><span id="line-968"> public void testCheckAndMutateWithFilterAndTimeRange() throws Throwable {</span> |
| <span class="source-line-no">969</span><span id="line-969"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">970</span><span id="line-970"></span> |
| <span class="source-line-no">971</span><span id="line-971"> // Put with specifying the timestamp</span> |
| <span class="source-line-no">972</span><span id="line-972"> table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a"))).get();</span> |
| <span class="source-line-no">973</span><span id="line-973"></span> |
| <span class="source-line-no">974</span><span id="line-974"> // Put with success</span> |
| <span class="source-line-no">975</span><span id="line-975"> CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">976</span><span id="line-976"> .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">977</span><span id="line-977"> Bytes.toBytes("a")))</span> |
| <span class="source-line-no">978</span><span id="line-978"> .timeRange(TimeRange.between(0, 101))</span> |
| <span class="source-line-no">979</span><span id="line-979"> .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")))).get();</span> |
| <span class="source-line-no">980</span><span id="line-980"> assertTrue(result.isSuccess());</span> |
| <span class="source-line-no">981</span><span id="line-981"> assertNull(result.getResult());</span> |
| <span class="source-line-no">982</span><span id="line-982"></span> |
| <span class="source-line-no">983</span><span id="line-983"> Result r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">984</span><span id="line-984"> assertEquals("b", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">985</span><span id="line-985"></span> |
| <span class="source-line-no">986</span><span id="line-986"> // Put with failure</span> |
| <span class="source-line-no">987</span><span id="line-987"> result = table.checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">988</span><span id="line-988"> .ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">989</span><span id="line-989"> Bytes.toBytes("a")))</span> |
| <span class="source-line-no">990</span><span id="line-990"> .timeRange(TimeRange.between(0, 100))</span> |
| <span class="source-line-no">991</span><span id="line-991"> .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")))).get();</span> |
| <span class="source-line-no">992</span><span id="line-992"> assertFalse(result.isSuccess());</span> |
| <span class="source-line-no">993</span><span id="line-993"> assertNull(result.getResult());</span> |
| <span class="source-line-no">994</span><span id="line-994"></span> |
| <span class="source-line-no">995</span><span id="line-995"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get());</span> |
| <span class="source-line-no">996</span><span id="line-996"> }</span> |
| <span class="source-line-no">997</span><span id="line-997"></span> |
| <span class="source-line-no">998</span><span id="line-998"> @Test</span> |
| <span class="source-line-no">999</span><span id="line-999"> public void testCheckAndIncrement() throws Throwable {</span> |
| <span class="source-line-no">1000</span><span id="line-1000"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">1001</span><span id="line-1001"></span> |
| <span class="source-line-no">1002</span><span id="line-1002"> table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"))).get();</span> |
| <span class="source-line-no">1003</span><span id="line-1003"></span> |
| <span class="source-line-no">1004</span><span id="line-1004"> // CheckAndIncrement with correct value</span> |
| <span class="source-line-no">1005</span><span id="line-1005"> CheckAndMutateResult res = table.checkAndMutate(</span> |
| <span class="source-line-no">1006</span><span id="line-1006"> CheckAndMutate.newBuilder(row).ifEquals(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"))</span> |
| <span class="source-line-no">1007</span><span id="line-1007"> .build(new Increment(row).addColumn(FAMILY, Bytes.toBytes("B"), 1)))</span> |
| <span class="source-line-no">1008</span><span id="line-1008"> .get();</span> |
| <span class="source-line-no">1009</span><span id="line-1009"> assertTrue(res.isSuccess());</span> |
| <span class="source-line-no">1010</span><span id="line-1010"> assertEquals(1, Bytes.toLong(res.getResult().getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1011</span><span id="line-1011"></span> |
| <span class="source-line-no">1012</span><span id="line-1012"> Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">1013</span><span id="line-1013"> assertEquals(1, Bytes.toLong(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1014</span><span id="line-1014"></span> |
| <span class="source-line-no">1015</span><span id="line-1015"> // CheckAndIncrement with wrong value</span> |
| <span class="source-line-no">1016</span><span id="line-1016"> res = table.checkAndMutate(</span> |
| <span class="source-line-no">1017</span><span id="line-1017"> CheckAndMutate.newBuilder(row).ifEquals(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("b"))</span> |
| <span class="source-line-no">1018</span><span id="line-1018"> .build(new Increment(row).addColumn(FAMILY, Bytes.toBytes("B"), 1)))</span> |
| <span class="source-line-no">1019</span><span id="line-1019"> .get();</span> |
| <span class="source-line-no">1020</span><span id="line-1020"> assertFalse(res.isSuccess());</span> |
| <span class="source-line-no">1021</span><span id="line-1021"> assertNull(res.getResult());</span> |
| <span class="source-line-no">1022</span><span id="line-1022"></span> |
| <span class="source-line-no">1023</span><span id="line-1023"> result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">1024</span><span id="line-1024"> assertEquals(1, Bytes.toLong(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1025</span><span id="line-1025"></span> |
| <span class="source-line-no">1026</span><span id="line-1026"> table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")));</span> |
| <span class="source-line-no">1027</span><span id="line-1027"></span> |
| <span class="source-line-no">1028</span><span id="line-1028"> // CheckAndIncrement with a filter and correct value</span> |
| <span class="source-line-no">1029</span><span id="line-1029"> res = table.checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">1030</span><span id="line-1030"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">1031</span><span id="line-1031"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1032</span><span id="line-1032"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">1033</span><span id="line-1033"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("C"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1034</span><span id="line-1034"> Bytes.toBytes("c"))))</span> |
| <span class="source-line-no">1035</span><span id="line-1035"> .build(new Increment(row).addColumn(FAMILY, Bytes.toBytes("B"), 2))).get();</span> |
| <span class="source-line-no">1036</span><span id="line-1036"> assertTrue(res.isSuccess());</span> |
| <span class="source-line-no">1037</span><span id="line-1037"> assertEquals(3, Bytes.toLong(res.getResult().getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1038</span><span id="line-1038"></span> |
| <span class="source-line-no">1039</span><span id="line-1039"> result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">1040</span><span id="line-1040"> assertEquals(3, Bytes.toLong(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1041</span><span id="line-1041"></span> |
| <span class="source-line-no">1042</span><span id="line-1042"> // CheckAndIncrement with a filter and correct value</span> |
| <span class="source-line-no">1043</span><span id="line-1043"> res = table.checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">1044</span><span id="line-1044"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">1045</span><span id="line-1045"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1046</span><span id="line-1046"> Bytes.toBytes("b")),</span> |
| <span class="source-line-no">1047</span><span id="line-1047"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("C"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1048</span><span id="line-1048"> Bytes.toBytes("d"))))</span> |
| <span class="source-line-no">1049</span><span id="line-1049"> .build(new Increment(row).addColumn(FAMILY, Bytes.toBytes("B"), 2))).get();</span> |
| <span class="source-line-no">1050</span><span id="line-1050"> assertFalse(res.isSuccess());</span> |
| <span class="source-line-no">1051</span><span id="line-1051"> assertNull(res.getResult());</span> |
| <span class="source-line-no">1052</span><span id="line-1052"></span> |
| <span class="source-line-no">1053</span><span id="line-1053"> result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">1054</span><span id="line-1054"> assertEquals(3, Bytes.toLong(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1055</span><span id="line-1055"> }</span> |
| <span class="source-line-no">1056</span><span id="line-1056"></span> |
| <span class="source-line-no">1057</span><span id="line-1057"> @Test</span> |
| <span class="source-line-no">1058</span><span id="line-1058"> public void testCheckAndAppend() throws Throwable {</span> |
| <span class="source-line-no">1059</span><span id="line-1059"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">1060</span><span id="line-1060"></span> |
| <span class="source-line-no">1061</span><span id="line-1061"> table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"))).get();</span> |
| <span class="source-line-no">1062</span><span id="line-1062"></span> |
| <span class="source-line-no">1063</span><span id="line-1063"> // CheckAndAppend with correct value</span> |
| <span class="source-line-no">1064</span><span id="line-1064"> CheckAndMutateResult res =</span> |
| <span class="source-line-no">1065</span><span id="line-1065"> table</span> |
| <span class="source-line-no">1066</span><span id="line-1066"> .checkAndMutate(</span> |
| <span class="source-line-no">1067</span><span id="line-1067"> CheckAndMutate.newBuilder(row).ifEquals(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"))</span> |
| <span class="source-line-no">1068</span><span id="line-1068"> .build(new Append(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"))))</span> |
| <span class="source-line-no">1069</span><span id="line-1069"> .get();</span> |
| <span class="source-line-no">1070</span><span id="line-1070"> assertTrue(res.isSuccess());</span> |
| <span class="source-line-no">1071</span><span id="line-1071"> assertEquals("b", Bytes.toString(res.getResult().getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1072</span><span id="line-1072"></span> |
| <span class="source-line-no">1073</span><span id="line-1073"> Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">1074</span><span id="line-1074"> assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1075</span><span id="line-1075"></span> |
| <span class="source-line-no">1076</span><span id="line-1076"> // CheckAndAppend with correct value</span> |
| <span class="source-line-no">1077</span><span id="line-1077"> res =</span> |
| <span class="source-line-no">1078</span><span id="line-1078"> table</span> |
| <span class="source-line-no">1079</span><span id="line-1079"> .checkAndMutate(</span> |
| <span class="source-line-no">1080</span><span id="line-1080"> CheckAndMutate.newBuilder(row).ifEquals(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("b"))</span> |
| <span class="source-line-no">1081</span><span id="line-1081"> .build(new Append(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"))))</span> |
| <span class="source-line-no">1082</span><span id="line-1082"> .get();</span> |
| <span class="source-line-no">1083</span><span id="line-1083"> assertFalse(res.isSuccess());</span> |
| <span class="source-line-no">1084</span><span id="line-1084"> assertNull(res.getResult());</span> |
| <span class="source-line-no">1085</span><span id="line-1085"></span> |
| <span class="source-line-no">1086</span><span id="line-1086"> result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">1087</span><span id="line-1087"> assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1088</span><span id="line-1088"></span> |
| <span class="source-line-no">1089</span><span id="line-1089"> table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")));</span> |
| <span class="source-line-no">1090</span><span id="line-1090"></span> |
| <span class="source-line-no">1091</span><span id="line-1091"> // CheckAndAppend with a filter and correct value</span> |
| <span class="source-line-no">1092</span><span id="line-1092"> res = table.checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">1093</span><span id="line-1093"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">1094</span><span id="line-1094"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1095</span><span id="line-1095"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">1096</span><span id="line-1096"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("C"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1097</span><span id="line-1097"> Bytes.toBytes("c"))))</span> |
| <span class="source-line-no">1098</span><span id="line-1098"> .build(new Append(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("bb")))).get();</span> |
| <span class="source-line-no">1099</span><span id="line-1099"> assertTrue(res.isSuccess());</span> |
| <span class="source-line-no">1100</span><span id="line-1100"> assertEquals("bbb", Bytes.toString(res.getResult().getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1101</span><span id="line-1101"></span> |
| <span class="source-line-no">1102</span><span id="line-1102"> result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">1103</span><span id="line-1103"> assertEquals("bbb", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1104</span><span id="line-1104"></span> |
| <span class="source-line-no">1105</span><span id="line-1105"> // CheckAndAppend with a filter and wrong value</span> |
| <span class="source-line-no">1106</span><span id="line-1106"> res = table.checkAndMutate(CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">1107</span><span id="line-1107"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">1108</span><span id="line-1108"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1109</span><span id="line-1109"> Bytes.toBytes("b")),</span> |
| <span class="source-line-no">1110</span><span id="line-1110"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("C"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1111</span><span id="line-1111"> Bytes.toBytes("d"))))</span> |
| <span class="source-line-no">1112</span><span id="line-1112"> .build(new Append(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("bb")))).get();</span> |
| <span class="source-line-no">1113</span><span id="line-1113"> assertFalse(res.isSuccess());</span> |
| <span class="source-line-no">1114</span><span id="line-1114"> assertNull(res.getResult());</span> |
| <span class="source-line-no">1115</span><span id="line-1115"></span> |
| <span class="source-line-no">1116</span><span id="line-1116"> result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">1117</span><span id="line-1117"> assertEquals("bbb", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1118</span><span id="line-1118"> }</span> |
| <span class="source-line-no">1119</span><span id="line-1119"></span> |
| <span class="source-line-no">1120</span><span id="line-1120"> @Test</span> |
| <span class="source-line-no">1121</span><span id="line-1121"> public void testCheckAndRowMutations() throws Throwable {</span> |
| <span class="source-line-no">1122</span><span id="line-1122"> final byte[] q1 = Bytes.toBytes("q1");</span> |
| <span class="source-line-no">1123</span><span id="line-1123"> final byte[] q2 = Bytes.toBytes("q2");</span> |
| <span class="source-line-no">1124</span><span id="line-1124"> final byte[] q3 = Bytes.toBytes("q3");</span> |
| <span class="source-line-no">1125</span><span id="line-1125"> final byte[] q4 = Bytes.toBytes("q4");</span> |
| <span class="source-line-no">1126</span><span id="line-1126"> final String v1 = "v1";</span> |
| <span class="source-line-no">1127</span><span id="line-1127"></span> |
| <span class="source-line-no">1128</span><span id="line-1128"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">1129</span><span id="line-1129"></span> |
| <span class="source-line-no">1130</span><span id="line-1130"> // Initial values</span> |
| <span class="source-line-no">1131</span><span id="line-1131"> table.putAll(Arrays.asList(new Put(row).addColumn(FAMILY, q2, Bytes.toBytes("toBeDeleted")),</span> |
| <span class="source-line-no">1132</span><span id="line-1132"> new Put(row).addColumn(FAMILY, q3, Bytes.toBytes(5L)),</span> |
| <span class="source-line-no">1133</span><span id="line-1133"> new Put(row).addColumn(FAMILY, q4, Bytes.toBytes("a")))).get();</span> |
| <span class="source-line-no">1134</span><span id="line-1134"></span> |
| <span class="source-line-no">1135</span><span id="line-1135"> // Do CheckAndRowMutations</span> |
| <span class="source-line-no">1136</span><span id="line-1136"> CheckAndMutate checkAndMutate = CheckAndMutate.newBuilder(row).ifNotExists(FAMILY, q1).build(</span> |
| <span class="source-line-no">1137</span><span id="line-1137"> new RowMutations(row).add(Arrays.asList(new Put(row).addColumn(FAMILY, q1, Bytes.toBytes(v1)),</span> |
| <span class="source-line-no">1138</span><span id="line-1138"> new Delete(row).addColumns(FAMILY, q2), new Increment(row).addColumn(FAMILY, q3, 1),</span> |
| <span class="source-line-no">1139</span><span id="line-1139"> new Append(row).addColumn(FAMILY, q4, Bytes.toBytes("b")))));</span> |
| <span class="source-line-no">1140</span><span id="line-1140"></span> |
| <span class="source-line-no">1141</span><span id="line-1141"> CheckAndMutateResult result = table.checkAndMutate(checkAndMutate).get();</span> |
| <span class="source-line-no">1142</span><span id="line-1142"> assertTrue(result.isSuccess());</span> |
| <span class="source-line-no">1143</span><span id="line-1143"> assertEquals(6L, Bytes.toLong(result.getResult().getValue(FAMILY, q3)));</span> |
| <span class="source-line-no">1144</span><span id="line-1144"> assertEquals("ab", Bytes.toString(result.getResult().getValue(FAMILY, q4)));</span> |
| <span class="source-line-no">1145</span><span id="line-1145"></span> |
| <span class="source-line-no">1146</span><span id="line-1146"> // Verify the value</span> |
| <span class="source-line-no">1147</span><span id="line-1147"> Result r = table.get(new Get(row)).get();</span> |
| <span class="source-line-no">1148</span><span id="line-1148"> assertEquals(v1, Bytes.toString(r.getValue(FAMILY, q1)));</span> |
| <span class="source-line-no">1149</span><span id="line-1149"> assertNull(r.getValue(FAMILY, q2));</span> |
| <span class="source-line-no">1150</span><span id="line-1150"> assertEquals(6L, Bytes.toLong(r.getValue(FAMILY, q3)));</span> |
| <span class="source-line-no">1151</span><span id="line-1151"> assertEquals("ab", Bytes.toString(r.getValue(FAMILY, q4)));</span> |
| <span class="source-line-no">1152</span><span id="line-1152"></span> |
| <span class="source-line-no">1153</span><span id="line-1153"> // Do CheckAndRowMutations again</span> |
| <span class="source-line-no">1154</span><span id="line-1154"> checkAndMutate = CheckAndMutate.newBuilder(row).ifNotExists(FAMILY, q1)</span> |
| <span class="source-line-no">1155</span><span id="line-1155"> .build(new RowMutations(row).add(Arrays.asList(new Delete(row).addColumns(FAMILY, q1),</span> |
| <span class="source-line-no">1156</span><span id="line-1156"> new Put(row).addColumn(FAMILY, q2, Bytes.toBytes(v1)),</span> |
| <span class="source-line-no">1157</span><span id="line-1157"> new Increment(row).addColumn(FAMILY, q3, 1),</span> |
| <span class="source-line-no">1158</span><span id="line-1158"> new Append(row).addColumn(FAMILY, q4, Bytes.toBytes("b")))));</span> |
| <span class="source-line-no">1159</span><span id="line-1159"></span> |
| <span class="source-line-no">1160</span><span id="line-1160"> result = table.checkAndMutate(checkAndMutate).get();</span> |
| <span class="source-line-no">1161</span><span id="line-1161"> assertFalse(result.isSuccess());</span> |
| <span class="source-line-no">1162</span><span id="line-1162"> assertNull(result.getResult());</span> |
| <span class="source-line-no">1163</span><span id="line-1163"></span> |
| <span class="source-line-no">1164</span><span id="line-1164"> // Verify the value</span> |
| <span class="source-line-no">1165</span><span id="line-1165"> r = table.get(new Get(row)).get();</span> |
| <span class="source-line-no">1166</span><span id="line-1166"> assertEquals(v1, Bytes.toString(r.getValue(FAMILY, q1)));</span> |
| <span class="source-line-no">1167</span><span id="line-1167"> assertNull(r.getValue(FAMILY, q2));</span> |
| <span class="source-line-no">1168</span><span id="line-1168"> assertEquals(6L, Bytes.toLong(r.getValue(FAMILY, q3)));</span> |
| <span class="source-line-no">1169</span><span id="line-1169"> assertEquals("ab", Bytes.toString(r.getValue(FAMILY, q4)));</span> |
| <span class="source-line-no">1170</span><span id="line-1170"> }</span> |
| <span class="source-line-no">1171</span><span id="line-1171"></span> |
| <span class="source-line-no">1172</span><span id="line-1172"> // Tests for batch version of checkAndMutate</span> |
| <span class="source-line-no">1173</span><span id="line-1173"></span> |
| <span class="source-line-no">1174</span><span id="line-1174"> @Test</span> |
| <span class="source-line-no">1175</span><span id="line-1175"> public void testCheckAndMutateBatch() throws Throwable {</span> |
| <span class="source-line-no">1176</span><span id="line-1176"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">1177</span><span id="line-1177"> byte[] row2 = Bytes.toBytes(Bytes.toString(row) + "2");</span> |
| <span class="source-line-no">1178</span><span id="line-1178"> byte[] row3 = Bytes.toBytes(Bytes.toString(row) + "3");</span> |
| <span class="source-line-no">1179</span><span id="line-1179"> byte[] row4 = Bytes.toBytes(Bytes.toString(row) + "4");</span> |
| <span class="source-line-no">1180</span><span id="line-1180"></span> |
| <span class="source-line-no">1181</span><span id="line-1181"> table</span> |
| <span class="source-line-no">1182</span><span id="line-1182"> .putAll(Arrays.asList(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a")),</span> |
| <span class="source-line-no">1183</span><span id="line-1183"> new Put(row2).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")),</span> |
| <span class="source-line-no">1184</span><span id="line-1184"> new Put(row3).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")),</span> |
| <span class="source-line-no">1185</span><span id="line-1185"> new Put(row4).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d"))))</span> |
| <span class="source-line-no">1186</span><span id="line-1186"> .get();</span> |
| <span class="source-line-no">1187</span><span id="line-1187"></span> |
| <span class="source-line-no">1188</span><span id="line-1188"> // Test for Put</span> |
| <span class="source-line-no">1189</span><span id="line-1189"> CheckAndMutate checkAndMutate1 =</span> |
| <span class="source-line-no">1190</span><span id="line-1190"> CheckAndMutate.newBuilder(row).ifEquals(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"))</span> |
| <span class="source-line-no">1191</span><span id="line-1191"> .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("e")));</span> |
| <span class="source-line-no">1192</span><span id="line-1192"></span> |
| <span class="source-line-no">1193</span><span id="line-1193"> CheckAndMutate checkAndMutate2 =</span> |
| <span class="source-line-no">1194</span><span id="line-1194"> CheckAndMutate.newBuilder(row2).ifEquals(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("a"))</span> |
| <span class="source-line-no">1195</span><span id="line-1195"> .build(new Put(row2).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("f")));</span> |
| <span class="source-line-no">1196</span><span id="line-1196"></span> |
| <span class="source-line-no">1197</span><span id="line-1197"> List<CheckAndMutateResult> results =</span> |
| <span class="source-line-no">1198</span><span id="line-1198"> table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();</span> |
| <span class="source-line-no">1199</span><span id="line-1199"></span> |
| <span class="source-line-no">1200</span><span id="line-1200"> assertTrue(results.get(0).isSuccess());</span> |
| <span class="source-line-no">1201</span><span id="line-1201"> assertNull(results.get(0).getResult());</span> |
| <span class="source-line-no">1202</span><span id="line-1202"> assertFalse(results.get(1).isSuccess());</span> |
| <span class="source-line-no">1203</span><span id="line-1203"> assertNull(results.get(1).getResult());</span> |
| <span class="source-line-no">1204</span><span id="line-1204"></span> |
| <span class="source-line-no">1205</span><span id="line-1205"> Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get();</span> |
| <span class="source-line-no">1206</span><span id="line-1206"> assertEquals("e", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A"))));</span> |
| <span class="source-line-no">1207</span><span id="line-1207"></span> |
| <span class="source-line-no">1208</span><span id="line-1208"> result = table.get(new Get(row2).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">1209</span><span id="line-1209"> assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1210</span><span id="line-1210"></span> |
| <span class="source-line-no">1211</span><span id="line-1211"> // Test for Delete</span> |
| <span class="source-line-no">1212</span><span id="line-1212"> checkAndMutate1 = CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">1213</span><span id="line-1213"> .ifEquals(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("e")).build(new Delete(row));</span> |
| <span class="source-line-no">1214</span><span id="line-1214"></span> |
| <span class="source-line-no">1215</span><span id="line-1215"> checkAndMutate2 = CheckAndMutate.newBuilder(row2)</span> |
| <span class="source-line-no">1216</span><span id="line-1216"> .ifEquals(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("a")).build(new Delete(row2));</span> |
| <span class="source-line-no">1217</span><span id="line-1217"></span> |
| <span class="source-line-no">1218</span><span id="line-1218"> results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();</span> |
| <span class="source-line-no">1219</span><span id="line-1219"></span> |
| <span class="source-line-no">1220</span><span id="line-1220"> assertTrue(results.get(0).isSuccess());</span> |
| <span class="source-line-no">1221</span><span id="line-1221"> assertNull(results.get(0).getResult());</span> |
| <span class="source-line-no">1222</span><span id="line-1222"> assertFalse(results.get(1).isSuccess());</span> |
| <span class="source-line-no">1223</span><span id="line-1223"> assertNull(results.get(1).getResult());</span> |
| <span class="source-line-no">1224</span><span id="line-1224"></span> |
| <span class="source-line-no">1225</span><span id="line-1225"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get());</span> |
| <span class="source-line-no">1226</span><span id="line-1226"></span> |
| <span class="source-line-no">1227</span><span id="line-1227"> result = table.get(new Get(row2).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">1228</span><span id="line-1228"> assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1229</span><span id="line-1229"></span> |
| <span class="source-line-no">1230</span><span id="line-1230"> // Test for RowMutations</span> |
| <span class="source-line-no">1231</span><span id="line-1231"> checkAndMutate1 =</span> |
| <span class="source-line-no">1232</span><span id="line-1232"> CheckAndMutate.newBuilder(row3).ifEquals(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"))</span> |
| <span class="source-line-no">1233</span><span id="line-1233"> .build(new RowMutations(row3)</span> |
| <span class="source-line-no">1234</span><span id="line-1234"> .add((Mutation) new Put(row3).addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("f")))</span> |
| <span class="source-line-no">1235</span><span id="line-1235"> .add((Mutation) new Delete(row3).addColumns(FAMILY, Bytes.toBytes("C"))));</span> |
| <span class="source-line-no">1236</span><span id="line-1236"></span> |
| <span class="source-line-no">1237</span><span id="line-1237"> checkAndMutate2 =</span> |
| <span class="source-line-no">1238</span><span id="line-1238"> CheckAndMutate.newBuilder(row4).ifEquals(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("f"))</span> |
| <span class="source-line-no">1239</span><span id="line-1239"> .build(new RowMutations(row4)</span> |
| <span class="source-line-no">1240</span><span id="line-1240"> .add((Mutation) new Put(row4).addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("f")))</span> |
| <span class="source-line-no">1241</span><span id="line-1241"> .add((Mutation) new Delete(row4).addColumns(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">1242</span><span id="line-1242"></span> |
| <span class="source-line-no">1243</span><span id="line-1243"> results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();</span> |
| <span class="source-line-no">1244</span><span id="line-1244"></span> |
| <span class="source-line-no">1245</span><span id="line-1245"> assertTrue(results.get(0).isSuccess());</span> |
| <span class="source-line-no">1246</span><span id="line-1246"> assertNull(results.get(0).getResult());</span> |
| <span class="source-line-no">1247</span><span id="line-1247"> assertFalse(results.get(1).isSuccess());</span> |
| <span class="source-line-no">1248</span><span id="line-1248"> assertNull(results.get(1).getResult());</span> |
| <span class="source-line-no">1249</span><span id="line-1249"></span> |
| <span class="source-line-no">1250</span><span id="line-1250"> result = table.get(new Get(row3)).get();</span> |
| <span class="source-line-no">1251</span><span id="line-1251"> assertEquals("f", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("F"))));</span> |
| <span class="source-line-no">1252</span><span id="line-1252"> assertNull(result.getValue(FAMILY, Bytes.toBytes("D")));</span> |
| <span class="source-line-no">1253</span><span id="line-1253"></span> |
| <span class="source-line-no">1254</span><span id="line-1254"> result = table.get(new Get(row4)).get();</span> |
| <span class="source-line-no">1255</span><span id="line-1255"> assertNull(result.getValue(FAMILY, Bytes.toBytes("F")));</span> |
| <span class="source-line-no">1256</span><span id="line-1256"> assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">1257</span><span id="line-1257"> }</span> |
| <span class="source-line-no">1258</span><span id="line-1258"></span> |
| <span class="source-line-no">1259</span><span id="line-1259"> @Test</span> |
| <span class="source-line-no">1260</span><span id="line-1260"> public void testCheckAndMutateBatch2() throws Throwable {</span> |
| <span class="source-line-no">1261</span><span id="line-1261"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">1262</span><span id="line-1262"> byte[] row2 = Bytes.toBytes(Bytes.toString(row) + "2");</span> |
| <span class="source-line-no">1263</span><span id="line-1263"> byte[] row3 = Bytes.toBytes(Bytes.toString(row) + "3");</span> |
| <span class="source-line-no">1264</span><span id="line-1264"> byte[] row4 = Bytes.toBytes(Bytes.toString(row) + "4");</span> |
| <span class="source-line-no">1265</span><span id="line-1265"></span> |
| <span class="source-line-no">1266</span><span id="line-1266"> table</span> |
| <span class="source-line-no">1267</span><span id="line-1267"> .putAll(Arrays.asList(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a")),</span> |
| <span class="source-line-no">1268</span><span id="line-1268"> new Put(row2).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")),</span> |
| <span class="source-line-no">1269</span><span id="line-1269"> new Put(row3).addColumn(FAMILY, Bytes.toBytes("C"), 100, Bytes.toBytes("c")),</span> |
| <span class="source-line-no">1270</span><span id="line-1270"> new Put(row4).addColumn(FAMILY, Bytes.toBytes("D"), 100, Bytes.toBytes("d"))))</span> |
| <span class="source-line-no">1271</span><span id="line-1271"> .get();</span> |
| <span class="source-line-no">1272</span><span id="line-1272"></span> |
| <span class="source-line-no">1273</span><span id="line-1273"> // Test for ifNotExists()</span> |
| <span class="source-line-no">1274</span><span id="line-1274"> CheckAndMutate checkAndMutate1 =</span> |
| <span class="source-line-no">1275</span><span id="line-1275"> CheckAndMutate.newBuilder(row).ifNotExists(FAMILY, Bytes.toBytes("B"))</span> |
| <span class="source-line-no">1276</span><span id="line-1276"> .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("e")));</span> |
| <span class="source-line-no">1277</span><span id="line-1277"></span> |
| <span class="source-line-no">1278</span><span id="line-1278"> CheckAndMutate checkAndMutate2 =</span> |
| <span class="source-line-no">1279</span><span id="line-1279"> CheckAndMutate.newBuilder(row2).ifNotExists(FAMILY, Bytes.toBytes("B"))</span> |
| <span class="source-line-no">1280</span><span id="line-1280"> .build(new Put(row2).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("f")));</span> |
| <span class="source-line-no">1281</span><span id="line-1281"></span> |
| <span class="source-line-no">1282</span><span id="line-1282"> List<CheckAndMutateResult> results =</span> |
| <span class="source-line-no">1283</span><span id="line-1283"> table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();</span> |
| <span class="source-line-no">1284</span><span id="line-1284"></span> |
| <span class="source-line-no">1285</span><span id="line-1285"> assertTrue(results.get(0).isSuccess());</span> |
| <span class="source-line-no">1286</span><span id="line-1286"> assertNull(results.get(0).getResult());</span> |
| <span class="source-line-no">1287</span><span id="line-1287"> assertFalse(results.get(1).isSuccess());</span> |
| <span class="source-line-no">1288</span><span id="line-1288"> assertNull(results.get(1).getResult());</span> |
| <span class="source-line-no">1289</span><span id="line-1289"></span> |
| <span class="source-line-no">1290</span><span id="line-1290"> Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get();</span> |
| <span class="source-line-no">1291</span><span id="line-1291"> assertEquals("e", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A"))));</span> |
| <span class="source-line-no">1292</span><span id="line-1292"></span> |
| <span class="source-line-no">1293</span><span id="line-1293"> result = table.get(new Get(row2).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">1294</span><span id="line-1294"> assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1295</span><span id="line-1295"></span> |
| <span class="source-line-no">1296</span><span id="line-1296"> // Test for ifMatches()</span> |
| <span class="source-line-no">1297</span><span id="line-1297"> checkAndMutate1 = CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">1298</span><span id="line-1298"> .ifMatches(FAMILY, Bytes.toBytes("A"), CompareOperator.NOT_EQUAL, Bytes.toBytes("a"))</span> |
| <span class="source-line-no">1299</span><span id="line-1299"> .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a")));</span> |
| <span class="source-line-no">1300</span><span id="line-1300"></span> |
| <span class="source-line-no">1301</span><span id="line-1301"> checkAndMutate2 = CheckAndMutate.newBuilder(row2)</span> |
| <span class="source-line-no">1302</span><span id="line-1302"> .ifMatches(FAMILY, Bytes.toBytes("B"), CompareOperator.GREATER, Bytes.toBytes("b"))</span> |
| <span class="source-line-no">1303</span><span id="line-1303"> .build(new Put(row2).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("f")));</span> |
| <span class="source-line-no">1304</span><span id="line-1304"></span> |
| <span class="source-line-no">1305</span><span id="line-1305"> results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();</span> |
| <span class="source-line-no">1306</span><span id="line-1306"></span> |
| <span class="source-line-no">1307</span><span id="line-1307"> assertTrue(results.get(0).isSuccess());</span> |
| <span class="source-line-no">1308</span><span id="line-1308"> assertNull(results.get(0).getResult());</span> |
| <span class="source-line-no">1309</span><span id="line-1309"> assertFalse(results.get(1).isSuccess());</span> |
| <span class="source-line-no">1310</span><span id="line-1310"> assertNull(results.get(1).getResult());</span> |
| <span class="source-line-no">1311</span><span id="line-1311"></span> |
| <span class="source-line-no">1312</span><span id="line-1312"> result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get();</span> |
| <span class="source-line-no">1313</span><span id="line-1313"> assertEquals("a", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A"))));</span> |
| <span class="source-line-no">1314</span><span id="line-1314"></span> |
| <span class="source-line-no">1315</span><span id="line-1315"> result = table.get(new Get(row2).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">1316</span><span id="line-1316"> assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1317</span><span id="line-1317"></span> |
| <span class="source-line-no">1318</span><span id="line-1318"> // Test for timeRange()</span> |
| <span class="source-line-no">1319</span><span id="line-1319"> checkAndMutate1 = CheckAndMutate.newBuilder(row3)</span> |
| <span class="source-line-no">1320</span><span id="line-1320"> .ifEquals(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")).timeRange(TimeRange.between(0, 101))</span> |
| <span class="source-line-no">1321</span><span id="line-1321"> .build(new Put(row3).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("e")));</span> |
| <span class="source-line-no">1322</span><span id="line-1322"></span> |
| <span class="source-line-no">1323</span><span id="line-1323"> checkAndMutate2 = CheckAndMutate.newBuilder(row4)</span> |
| <span class="source-line-no">1324</span><span id="line-1324"> .ifEquals(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")).timeRange(TimeRange.between(0, 100))</span> |
| <span class="source-line-no">1325</span><span id="line-1325"> .build(new Put(row4).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("f")));</span> |
| <span class="source-line-no">1326</span><span id="line-1326"></span> |
| <span class="source-line-no">1327</span><span id="line-1327"> results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();</span> |
| <span class="source-line-no">1328</span><span id="line-1328"></span> |
| <span class="source-line-no">1329</span><span id="line-1329"> assertTrue(results.get(0).isSuccess());</span> |
| <span class="source-line-no">1330</span><span id="line-1330"> assertNull(results.get(0).getResult());</span> |
| <span class="source-line-no">1331</span><span id="line-1331"> assertFalse(results.get(1).isSuccess());</span> |
| <span class="source-line-no">1332</span><span id="line-1332"> assertNull(results.get(1).getResult());</span> |
| <span class="source-line-no">1333</span><span id="line-1333"></span> |
| <span class="source-line-no">1334</span><span id="line-1334"> result = table.get(new Get(row3).addColumn(FAMILY, Bytes.toBytes("C"))).get();</span> |
| <span class="source-line-no">1335</span><span id="line-1335"> assertEquals("e", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C"))));</span> |
| <span class="source-line-no">1336</span><span id="line-1336"></span> |
| <span class="source-line-no">1337</span><span id="line-1337"> result = table.get(new Get(row4).addColumn(FAMILY, Bytes.toBytes("D"))).get();</span> |
| <span class="source-line-no">1338</span><span id="line-1338"> assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">1339</span><span id="line-1339"> }</span> |
| <span class="source-line-no">1340</span><span id="line-1340"></span> |
| <span class="source-line-no">1341</span><span id="line-1341"> @Test</span> |
| <span class="source-line-no">1342</span><span id="line-1342"> public void testCheckAndMutateBatchWithFilter() throws Throwable {</span> |
| <span class="source-line-no">1343</span><span id="line-1343"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">1344</span><span id="line-1344"> byte[] row2 = Bytes.toBytes(Bytes.toString(row) + "2");</span> |
| <span class="source-line-no">1345</span><span id="line-1345"></span> |
| <span class="source-line-no">1346</span><span id="line-1346"> table.putAll(Arrays.asList(</span> |
| <span class="source-line-no">1347</span><span id="line-1347"> new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"))</span> |
| <span class="source-line-no">1348</span><span id="line-1348"> .addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"))</span> |
| <span class="source-line-no">1349</span><span id="line-1349"> .addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")),</span> |
| <span class="source-line-no">1350</span><span id="line-1350"> new Put(row2).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d"))</span> |
| <span class="source-line-no">1351</span><span id="line-1351"> .addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e"))</span> |
| <span class="source-line-no">1352</span><span id="line-1352"> .addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("f"))))</span> |
| <span class="source-line-no">1353</span><span id="line-1353"> .get();</span> |
| <span class="source-line-no">1354</span><span id="line-1354"></span> |
| <span class="source-line-no">1355</span><span id="line-1355"> // Test for Put</span> |
| <span class="source-line-no">1356</span><span id="line-1356"> CheckAndMutate checkAndMutate1 = CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">1357</span><span id="line-1357"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">1358</span><span id="line-1358"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1359</span><span id="line-1359"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">1360</span><span id="line-1360"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1361</span><span id="line-1361"> Bytes.toBytes("b"))))</span> |
| <span class="source-line-no">1362</span><span id="line-1362"> .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("g")));</span> |
| <span class="source-line-no">1363</span><span id="line-1363"></span> |
| <span class="source-line-no">1364</span><span id="line-1364"> CheckAndMutate checkAndMutate2 = CheckAndMutate.newBuilder(row2)</span> |
| <span class="source-line-no">1365</span><span id="line-1365"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">1366</span><span id="line-1366"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("D"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1367</span><span id="line-1367"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">1368</span><span id="line-1368"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("E"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1369</span><span id="line-1369"> Bytes.toBytes("b"))))</span> |
| <span class="source-line-no">1370</span><span id="line-1370"> .build(new Put(row2).addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("h")));</span> |
| <span class="source-line-no">1371</span><span id="line-1371"></span> |
| <span class="source-line-no">1372</span><span id="line-1372"> List<CheckAndMutateResult> results =</span> |
| <span class="source-line-no">1373</span><span id="line-1373"> table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();</span> |
| <span class="source-line-no">1374</span><span id="line-1374"></span> |
| <span class="source-line-no">1375</span><span id="line-1375"> assertTrue(results.get(0).isSuccess());</span> |
| <span class="source-line-no">1376</span><span id="line-1376"> assertNull(results.get(0).getResult());</span> |
| <span class="source-line-no">1377</span><span id="line-1377"> assertFalse(results.get(1).isSuccess());</span> |
| <span class="source-line-no">1378</span><span id="line-1378"> assertNull(results.get(1).getResult());</span> |
| <span class="source-line-no">1379</span><span id="line-1379"></span> |
| <span class="source-line-no">1380</span><span id="line-1380"> Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get();</span> |
| <span class="source-line-no">1381</span><span id="line-1381"> assertEquals("g", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C"))));</span> |
| <span class="source-line-no">1382</span><span id="line-1382"></span> |
| <span class="source-line-no">1383</span><span id="line-1383"> result = table.get(new Get(row2).addColumn(FAMILY, Bytes.toBytes("F"))).get();</span> |
| <span class="source-line-no">1384</span><span id="line-1384"> assertEquals("f", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("F"))));</span> |
| <span class="source-line-no">1385</span><span id="line-1385"></span> |
| <span class="source-line-no">1386</span><span id="line-1386"> // Test for Delete</span> |
| <span class="source-line-no">1387</span><span id="line-1387"> checkAndMutate1 = CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">1388</span><span id="line-1388"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">1389</span><span id="line-1389"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1390</span><span id="line-1390"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">1391</span><span id="line-1391"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1392</span><span id="line-1392"> Bytes.toBytes("b"))))</span> |
| <span class="source-line-no">1393</span><span id="line-1393"> .build(new Delete(row).addColumns(FAMILY, Bytes.toBytes("C")));</span> |
| <span class="source-line-no">1394</span><span id="line-1394"></span> |
| <span class="source-line-no">1395</span><span id="line-1395"> checkAndMutate2 = CheckAndMutate.newBuilder(row2)</span> |
| <span class="source-line-no">1396</span><span id="line-1396"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">1397</span><span id="line-1397"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("D"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1398</span><span id="line-1398"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">1399</span><span id="line-1399"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("E"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1400</span><span id="line-1400"> Bytes.toBytes("b"))))</span> |
| <span class="source-line-no">1401</span><span id="line-1401"> .build(new Delete(row2).addColumn(FAMILY, Bytes.toBytes("F")));</span> |
| <span class="source-line-no">1402</span><span id="line-1402"></span> |
| <span class="source-line-no">1403</span><span id="line-1403"> results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();</span> |
| <span class="source-line-no">1404</span><span id="line-1404"></span> |
| <span class="source-line-no">1405</span><span id="line-1405"> assertTrue(results.get(0).isSuccess());</span> |
| <span class="source-line-no">1406</span><span id="line-1406"> assertNull(results.get(0).getResult());</span> |
| <span class="source-line-no">1407</span><span id="line-1407"> assertFalse(results.get(1).isSuccess());</span> |
| <span class="source-line-no">1408</span><span id="line-1408"> assertNull(results.get(1).getResult());</span> |
| <span class="source-line-no">1409</span><span id="line-1409"></span> |
| <span class="source-line-no">1410</span><span id="line-1410"> assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get());</span> |
| <span class="source-line-no">1411</span><span id="line-1411"></span> |
| <span class="source-line-no">1412</span><span id="line-1412"> result = table.get(new Get(row2).addColumn(FAMILY, Bytes.toBytes("F"))).get();</span> |
| <span class="source-line-no">1413</span><span id="line-1413"> assertEquals("f", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("F"))));</span> |
| <span class="source-line-no">1414</span><span id="line-1414"></span> |
| <span class="source-line-no">1415</span><span id="line-1415"> // Test for RowMutations</span> |
| <span class="source-line-no">1416</span><span id="line-1416"> checkAndMutate1 = CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">1417</span><span id="line-1417"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">1418</span><span id="line-1418"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1419</span><span id="line-1419"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">1420</span><span id="line-1420"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1421</span><span id="line-1421"> Bytes.toBytes("b"))))</span> |
| <span class="source-line-no">1422</span><span id="line-1422"> .build(new RowMutations(row)</span> |
| <span class="source-line-no">1423</span><span id="line-1423"> .add((Mutation) new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")))</span> |
| <span class="source-line-no">1424</span><span id="line-1424"> .add((Mutation) new Delete(row).addColumns(FAMILY, Bytes.toBytes("A"))));</span> |
| <span class="source-line-no">1425</span><span id="line-1425"></span> |
| <span class="source-line-no">1426</span><span id="line-1426"> checkAndMutate2 = CheckAndMutate.newBuilder(row2)</span> |
| <span class="source-line-no">1427</span><span id="line-1427"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">1428</span><span id="line-1428"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("D"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1429</span><span id="line-1429"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">1430</span><span id="line-1430"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("E"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1431</span><span id="line-1431"> Bytes.toBytes("b"))))</span> |
| <span class="source-line-no">1432</span><span id="line-1432"> .build(new RowMutations(row2)</span> |
| <span class="source-line-no">1433</span><span id="line-1433"> .add((Mutation) new Put(row2).addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("g")))</span> |
| <span class="source-line-no">1434</span><span id="line-1434"> .add((Mutation) new Delete(row2).addColumns(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">1435</span><span id="line-1435"></span> |
| <span class="source-line-no">1436</span><span id="line-1436"> results = table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();</span> |
| <span class="source-line-no">1437</span><span id="line-1437"></span> |
| <span class="source-line-no">1438</span><span id="line-1438"> assertTrue(results.get(0).isSuccess());</span> |
| <span class="source-line-no">1439</span><span id="line-1439"> assertNull(results.get(0).getResult());</span> |
| <span class="source-line-no">1440</span><span id="line-1440"> assertFalse(results.get(1).isSuccess());</span> |
| <span class="source-line-no">1441</span><span id="line-1441"> assertNull(results.get(1).getResult());</span> |
| <span class="source-line-no">1442</span><span id="line-1442"></span> |
| <span class="source-line-no">1443</span><span id="line-1443"> result = table.get(new Get(row)).get();</span> |
| <span class="source-line-no">1444</span><span id="line-1444"> assertNull(result.getValue(FAMILY, Bytes.toBytes("A")));</span> |
| <span class="source-line-no">1445</span><span id="line-1445"> assertEquals("c", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C"))));</span> |
| <span class="source-line-no">1446</span><span id="line-1446"></span> |
| <span class="source-line-no">1447</span><span id="line-1447"> result = table.get(new Get(row2)).get();</span> |
| <span class="source-line-no">1448</span><span id="line-1448"> assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">1449</span><span id="line-1449"> assertEquals("f", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("F"))));</span> |
| <span class="source-line-no">1450</span><span id="line-1450"> }</span> |
| <span class="source-line-no">1451</span><span id="line-1451"></span> |
| <span class="source-line-no">1452</span><span id="line-1452"> @Test</span> |
| <span class="source-line-no">1453</span><span id="line-1453"> public void testCheckAndMutateBatchWithFilterAndTimeRange() throws Throwable {</span> |
| <span class="source-line-no">1454</span><span id="line-1454"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">1455</span><span id="line-1455"> byte[] row2 = Bytes.toBytes(Bytes.toString(row) + "2");</span> |
| <span class="source-line-no">1456</span><span id="line-1456"></span> |
| <span class="source-line-no">1457</span><span id="line-1457"> table.putAll(Arrays.asList(</span> |
| <span class="source-line-no">1458</span><span id="line-1458"> new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a"))</span> |
| <span class="source-line-no">1459</span><span id="line-1459"> .addColumn(FAMILY, Bytes.toBytes("B"), 100, Bytes.toBytes("b"))</span> |
| <span class="source-line-no">1460</span><span id="line-1460"> .addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")),</span> |
| <span class="source-line-no">1461</span><span id="line-1461"> new Put(row2).addColumn(FAMILY, Bytes.toBytes("D"), 100, Bytes.toBytes("d"))</span> |
| <span class="source-line-no">1462</span><span id="line-1462"> .addColumn(FAMILY, Bytes.toBytes("E"), 100, Bytes.toBytes("e"))</span> |
| <span class="source-line-no">1463</span><span id="line-1463"> .addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("f"))))</span> |
| <span class="source-line-no">1464</span><span id="line-1464"> .get();</span> |
| <span class="source-line-no">1465</span><span id="line-1465"></span> |
| <span class="source-line-no">1466</span><span id="line-1466"> CheckAndMutate checkAndMutate1 = CheckAndMutate.newBuilder(row)</span> |
| <span class="source-line-no">1467</span><span id="line-1467"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">1468</span><span id="line-1468"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1469</span><span id="line-1469"> Bytes.toBytes("a")),</span> |
| <span class="source-line-no">1470</span><span id="line-1470"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1471</span><span id="line-1471"> Bytes.toBytes("b"))))</span> |
| <span class="source-line-no">1472</span><span id="line-1472"> .timeRange(TimeRange.between(0, 101))</span> |
| <span class="source-line-no">1473</span><span id="line-1473"> .build(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("g")));</span> |
| <span class="source-line-no">1474</span><span id="line-1474"></span> |
| <span class="source-line-no">1475</span><span id="line-1475"> CheckAndMutate checkAndMutate2 = CheckAndMutate.newBuilder(row2)</span> |
| <span class="source-line-no">1476</span><span id="line-1476"> .ifMatches(new FilterList(</span> |
| <span class="source-line-no">1477</span><span id="line-1477"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("D"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1478</span><span id="line-1478"> Bytes.toBytes("d")),</span> |
| <span class="source-line-no">1479</span><span id="line-1479"> new SingleColumnValueFilter(FAMILY, Bytes.toBytes("E"), CompareOperator.EQUAL,</span> |
| <span class="source-line-no">1480</span><span id="line-1480"> Bytes.toBytes("e"))))</span> |
| <span class="source-line-no">1481</span><span id="line-1481"> .timeRange(TimeRange.between(0, 100))</span> |
| <span class="source-line-no">1482</span><span id="line-1482"> .build(new Put(row2).addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("h")));</span> |
| <span class="source-line-no">1483</span><span id="line-1483"></span> |
| <span class="source-line-no">1484</span><span id="line-1484"> List<CheckAndMutateResult> results =</span> |
| <span class="source-line-no">1485</span><span id="line-1485"> table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();</span> |
| <span class="source-line-no">1486</span><span id="line-1486"></span> |
| <span class="source-line-no">1487</span><span id="line-1487"> assertTrue(results.get(0).isSuccess());</span> |
| <span class="source-line-no">1488</span><span id="line-1488"> assertNull(results.get(0).getResult());</span> |
| <span class="source-line-no">1489</span><span id="line-1489"> assertFalse(results.get(1).isSuccess());</span> |
| <span class="source-line-no">1490</span><span id="line-1490"> assertNull(results.get(1).getResult());</span> |
| <span class="source-line-no">1491</span><span id="line-1491"></span> |
| <span class="source-line-no">1492</span><span id="line-1492"> Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get();</span> |
| <span class="source-line-no">1493</span><span id="line-1493"> assertEquals("g", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("C"))));</span> |
| <span class="source-line-no">1494</span><span id="line-1494"></span> |
| <span class="source-line-no">1495</span><span id="line-1495"> result = table.get(new Get(row2).addColumn(FAMILY, Bytes.toBytes("F"))).get();</span> |
| <span class="source-line-no">1496</span><span id="line-1496"> assertEquals("f", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("F"))));</span> |
| <span class="source-line-no">1497</span><span id="line-1497"> }</span> |
| <span class="source-line-no">1498</span><span id="line-1498"></span> |
| <span class="source-line-no">1499</span><span id="line-1499"> @Test</span> |
| <span class="source-line-no">1500</span><span id="line-1500"> public void testCheckAndIncrementBatch() throws Throwable {</span> |
| <span class="source-line-no">1501</span><span id="line-1501"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">1502</span><span id="line-1502"> byte[] row2 = Bytes.toBytes(Bytes.toString(row) + "2");</span> |
| <span class="source-line-no">1503</span><span id="line-1503"></span> |
| <span class="source-line-no">1504</span><span id="line-1504"> table.putAll(Arrays.asList(</span> |
| <span class="source-line-no">1505</span><span id="line-1505"> new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a")).addColumn(FAMILY,</span> |
| <span class="source-line-no">1506</span><span id="line-1506"> Bytes.toBytes("B"), Bytes.toBytes(0L)),</span> |
| <span class="source-line-no">1507</span><span id="line-1507"> new Put(row2).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")).addColumn(FAMILY,</span> |
| <span class="source-line-no">1508</span><span id="line-1508"> Bytes.toBytes("D"), Bytes.toBytes(0L))))</span> |
| <span class="source-line-no">1509</span><span id="line-1509"> .get();</span> |
| <span class="source-line-no">1510</span><span id="line-1510"></span> |
| <span class="source-line-no">1511</span><span id="line-1511"> // CheckAndIncrement with correct value</span> |
| <span class="source-line-no">1512</span><span id="line-1512"> CheckAndMutate checkAndMutate1 =</span> |
| <span class="source-line-no">1513</span><span id="line-1513"> CheckAndMutate.newBuilder(row).ifEquals(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"))</span> |
| <span class="source-line-no">1514</span><span id="line-1514"> .build(new Increment(row).addColumn(FAMILY, Bytes.toBytes("B"), 1));</span> |
| <span class="source-line-no">1515</span><span id="line-1515"></span> |
| <span class="source-line-no">1516</span><span id="line-1516"> // CheckAndIncrement with wrong value</span> |
| <span class="source-line-no">1517</span><span id="line-1517"> CheckAndMutate checkAndMutate2 =</span> |
| <span class="source-line-no">1518</span><span id="line-1518"> CheckAndMutate.newBuilder(row2).ifEquals(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("d"))</span> |
| <span class="source-line-no">1519</span><span id="line-1519"> .build(new Increment(row2).addColumn(FAMILY, Bytes.toBytes("D"), 1));</span> |
| <span class="source-line-no">1520</span><span id="line-1520"></span> |
| <span class="source-line-no">1521</span><span id="line-1521"> List<CheckAndMutateResult> results =</span> |
| <span class="source-line-no">1522</span><span id="line-1522"> table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();</span> |
| <span class="source-line-no">1523</span><span id="line-1523"></span> |
| <span class="source-line-no">1524</span><span id="line-1524"> assertTrue(results.get(0).isSuccess());</span> |
| <span class="source-line-no">1525</span><span id="line-1525"> assertEquals(1, Bytes.toLong(results.get(0).getResult().getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1526</span><span id="line-1526"> assertFalse(results.get(1).isSuccess());</span> |
| <span class="source-line-no">1527</span><span id="line-1527"> assertNull(results.get(1).getResult());</span> |
| <span class="source-line-no">1528</span><span id="line-1528"></span> |
| <span class="source-line-no">1529</span><span id="line-1529"> Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">1530</span><span id="line-1530"> assertEquals(1, Bytes.toLong(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1531</span><span id="line-1531"></span> |
| <span class="source-line-no">1532</span><span id="line-1532"> result = table.get(new Get(row2).addColumn(FAMILY, Bytes.toBytes("D"))).get();</span> |
| <span class="source-line-no">1533</span><span id="line-1533"> assertEquals(0, Bytes.toLong(result.getValue(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">1534</span><span id="line-1534"> }</span> |
| <span class="source-line-no">1535</span><span id="line-1535"></span> |
| <span class="source-line-no">1536</span><span id="line-1536"> @Test</span> |
| <span class="source-line-no">1537</span><span id="line-1537"> public void testCheckAndAppendBatch() throws Throwable {</span> |
| <span class="source-line-no">1538</span><span id="line-1538"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">1539</span><span id="line-1539"> byte[] row2 = Bytes.toBytes(Bytes.toString(row) + "2");</span> |
| <span class="source-line-no">1540</span><span id="line-1540"></span> |
| <span class="source-line-no">1541</span><span id="line-1541"> table.putAll(Arrays.asList(</span> |
| <span class="source-line-no">1542</span><span id="line-1542"> new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a")).addColumn(FAMILY,</span> |
| <span class="source-line-no">1543</span><span id="line-1543"> Bytes.toBytes("B"), Bytes.toBytes("b")),</span> |
| <span class="source-line-no">1544</span><span id="line-1544"> new Put(row2).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")).addColumn(FAMILY,</span> |
| <span class="source-line-no">1545</span><span id="line-1545"> Bytes.toBytes("D"), Bytes.toBytes("d"))))</span> |
| <span class="source-line-no">1546</span><span id="line-1546"> .get();</span> |
| <span class="source-line-no">1547</span><span id="line-1547"></span> |
| <span class="source-line-no">1548</span><span id="line-1548"> // CheckAndAppend with correct value</span> |
| <span class="source-line-no">1549</span><span id="line-1549"> CheckAndMutate checkAndMutate1 =</span> |
| <span class="source-line-no">1550</span><span id="line-1550"> CheckAndMutate.newBuilder(row).ifEquals(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"))</span> |
| <span class="source-line-no">1551</span><span id="line-1551"> .build(new Append(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")));</span> |
| <span class="source-line-no">1552</span><span id="line-1552"></span> |
| <span class="source-line-no">1553</span><span id="line-1553"> // CheckAndAppend with wrong value</span> |
| <span class="source-line-no">1554</span><span id="line-1554"> CheckAndMutate checkAndMutate2 =</span> |
| <span class="source-line-no">1555</span><span id="line-1555"> CheckAndMutate.newBuilder(row2).ifEquals(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("d"))</span> |
| <span class="source-line-no">1556</span><span id="line-1556"> .build(new Append(row2).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")));</span> |
| <span class="source-line-no">1557</span><span id="line-1557"></span> |
| <span class="source-line-no">1558</span><span id="line-1558"> List<CheckAndMutateResult> results =</span> |
| <span class="source-line-no">1559</span><span id="line-1559"> table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();</span> |
| <span class="source-line-no">1560</span><span id="line-1560"></span> |
| <span class="source-line-no">1561</span><span id="line-1561"> assertTrue(results.get(0).isSuccess());</span> |
| <span class="source-line-no">1562</span><span id="line-1562"> assertEquals("bb",</span> |
| <span class="source-line-no">1563</span><span id="line-1563"> Bytes.toString(results.get(0).getResult().getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1564</span><span id="line-1564"> assertFalse(results.get(1).isSuccess());</span> |
| <span class="source-line-no">1565</span><span id="line-1565"> assertNull(results.get(1).getResult());</span> |
| <span class="source-line-no">1566</span><span id="line-1566"></span> |
| <span class="source-line-no">1567</span><span id="line-1567"> Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();</span> |
| <span class="source-line-no">1568</span><span id="line-1568"> assertEquals("bb", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));</span> |
| <span class="source-line-no">1569</span><span id="line-1569"></span> |
| <span class="source-line-no">1570</span><span id="line-1570"> result = table.get(new Get(row2).addColumn(FAMILY, Bytes.toBytes("D"))).get();</span> |
| <span class="source-line-no">1571</span><span id="line-1571"> assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">1572</span><span id="line-1572"> }</span> |
| <span class="source-line-no">1573</span><span id="line-1573"></span> |
| <span class="source-line-no">1574</span><span id="line-1574"> @Test</span> |
| <span class="source-line-no">1575</span><span id="line-1575"> public void testCheckAndRowMutationsBatch() throws Throwable {</span> |
| <span class="source-line-no">1576</span><span id="line-1576"> AsyncTable<?> table = getTable.get();</span> |
| <span class="source-line-no">1577</span><span id="line-1577"> byte[] row2 = Bytes.toBytes(Bytes.toString(row) + "2");</span> |
| <span class="source-line-no">1578</span><span id="line-1578"></span> |
| <span class="source-line-no">1579</span><span id="line-1579"> table.putAll(Arrays.asList(</span> |
| <span class="source-line-no">1580</span><span id="line-1580"> new Put(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"))</span> |
| <span class="source-line-no">1581</span><span id="line-1581"> .addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes(1L))</span> |
| <span class="source-line-no">1582</span><span id="line-1582"> .addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")),</span> |
| <span class="source-line-no">1583</span><span id="line-1583"> new Put(row2).addColumn(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("f"))</span> |
| <span class="source-line-no">1584</span><span id="line-1584"> .addColumn(FAMILY, Bytes.toBytes("G"), Bytes.toBytes(1L))</span> |
| <span class="source-line-no">1585</span><span id="line-1585"> .addColumn(FAMILY, Bytes.toBytes("H"), Bytes.toBytes("h"))))</span> |
| <span class="source-line-no">1586</span><span id="line-1586"> .get();</span> |
| <span class="source-line-no">1587</span><span id="line-1587"></span> |
| <span class="source-line-no">1588</span><span id="line-1588"> // CheckAndIncrement with correct value</span> |
| <span class="source-line-no">1589</span><span id="line-1589"> CheckAndMutate checkAndMutate1 =</span> |
| <span class="source-line-no">1590</span><span id="line-1590"> CheckAndMutate.newBuilder(row).ifEquals(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"))</span> |
| <span class="source-line-no">1591</span><span id="line-1591"> .build(new RowMutations(row)</span> |
| <span class="source-line-no">1592</span><span id="line-1592"> .add(Arrays.asList(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a")),</span> |
| <span class="source-line-no">1593</span><span id="line-1593"> new Delete(row).addColumns(FAMILY, Bytes.toBytes("B")),</span> |
| <span class="source-line-no">1594</span><span id="line-1594"> new Increment(row).addColumn(FAMILY, Bytes.toBytes("C"), 1L),</span> |
| <span class="source-line-no">1595</span><span id="line-1595"> new Append(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))));</span> |
| <span class="source-line-no">1596</span><span id="line-1596"></span> |
| <span class="source-line-no">1597</span><span id="line-1597"> // CheckAndIncrement with wrong value</span> |
| <span class="source-line-no">1598</span><span id="line-1598"> CheckAndMutate checkAndMutate2 =</span> |
| <span class="source-line-no">1599</span><span id="line-1599"> CheckAndMutate.newBuilder(row2).ifEquals(FAMILY, Bytes.toBytes("F"), Bytes.toBytes("a"))</span> |
| <span class="source-line-no">1600</span><span id="line-1600"> .build(new RowMutations(row2).add(</span> |
| <span class="source-line-no">1601</span><span id="line-1601"> Arrays.asList(new Put(row2).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e")),</span> |
| <span class="source-line-no">1602</span><span id="line-1602"> new Delete(row2).addColumns(FAMILY, Bytes.toBytes("F")),</span> |
| <span class="source-line-no">1603</span><span id="line-1603"> new Increment(row2).addColumn(FAMILY, Bytes.toBytes("G"), 1L),</span> |
| <span class="source-line-no">1604</span><span id="line-1604"> new Append(row2).addColumn(FAMILY, Bytes.toBytes("H"), Bytes.toBytes("h")))));</span> |
| <span class="source-line-no">1605</span><span id="line-1605"></span> |
| <span class="source-line-no">1606</span><span id="line-1606"> List<CheckAndMutateResult> results =</span> |
| <span class="source-line-no">1607</span><span id="line-1607"> table.checkAndMutateAll(Arrays.asList(checkAndMutate1, checkAndMutate2)).get();</span> |
| <span class="source-line-no">1608</span><span id="line-1608"></span> |
| <span class="source-line-no">1609</span><span id="line-1609"> assertTrue(results.get(0).isSuccess());</span> |
| <span class="source-line-no">1610</span><span id="line-1610"> assertEquals(2, Bytes.toLong(results.get(0).getResult().getValue(FAMILY, Bytes.toBytes("C"))));</span> |
| <span class="source-line-no">1611</span><span id="line-1611"> assertEquals("dd",</span> |
| <span class="source-line-no">1612</span><span id="line-1612"> Bytes.toString(results.get(0).getResult().getValue(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">1613</span><span id="line-1613"></span> |
| <span class="source-line-no">1614</span><span id="line-1614"> assertFalse(results.get(1).isSuccess());</span> |
| <span class="source-line-no">1615</span><span id="line-1615"> assertNull(results.get(1).getResult());</span> |
| <span class="source-line-no">1616</span><span id="line-1616"></span> |
| <span class="source-line-no">1617</span><span id="line-1617"> Result result = table.get(new Get(row)).get();</span> |
| <span class="source-line-no">1618</span><span id="line-1618"> assertEquals("a", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("A"))));</span> |
| <span class="source-line-no">1619</span><span id="line-1619"> assertNull(result.getValue(FAMILY, Bytes.toBytes("B")));</span> |
| <span class="source-line-no">1620</span><span id="line-1620"> assertEquals(2, Bytes.toLong(result.getValue(FAMILY, Bytes.toBytes("C"))));</span> |
| <span class="source-line-no">1621</span><span id="line-1621"> assertEquals("dd", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D"))));</span> |
| <span class="source-line-no">1622</span><span id="line-1622"></span> |
| <span class="source-line-no">1623</span><span id="line-1623"> result = table.get(new Get(row2)).get();</span> |
| <span class="source-line-no">1624</span><span id="line-1624"> assertNull(result.getValue(FAMILY, Bytes.toBytes("E")));</span> |
| <span class="source-line-no">1625</span><span id="line-1625"> assertEquals("f", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("F"))));</span> |
| <span class="source-line-no">1626</span><span id="line-1626"> assertEquals(1, Bytes.toLong(result.getValue(FAMILY, Bytes.toBytes("G"))));</span> |
| <span class="source-line-no">1627</span><span id="line-1627"> assertEquals("h", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("H"))));</span> |
| <span class="source-line-no">1628</span><span id="line-1628"> }</span> |
| <span class="source-line-no">1629</span><span id="line-1629"></span> |
| <span class="source-line-no">1630</span><span id="line-1630"> @Test</span> |
| <span class="source-line-no">1631</span><span id="line-1631"> public void testDisabled() throws InterruptedException, ExecutionException {</span> |
| <span class="source-line-no">1632</span><span id="line-1632"> ASYNC_CONN.getAdmin().disableTable(TABLE_NAME).get();</span> |
| <span class="source-line-no">1633</span><span id="line-1633"> try {</span> |
| <span class="source-line-no">1634</span><span id="line-1634"> getTable.get().get(new Get(row)).get();</span> |
| <span class="source-line-no">1635</span><span id="line-1635"> fail("Should fail since table has been disabled");</span> |
| <span class="source-line-no">1636</span><span id="line-1636"> } catch (ExecutionException e) {</span> |
| <span class="source-line-no">1637</span><span id="line-1637"> Throwable cause = e.getCause();</span> |
| <span class="source-line-no">1638</span><span id="line-1638"> assertThat(cause, instanceOf(TableNotEnabledException.class));</span> |
| <span class="source-line-no">1639</span><span id="line-1639"> assertThat(cause.getMessage(), containsString(TABLE_NAME.getNameAsString()));</span> |
| <span class="source-line-no">1640</span><span id="line-1640"> }</span> |
| <span class="source-line-no">1641</span><span id="line-1641"> }</span> |
| <span class="source-line-no">1642</span><span id="line-1642"></span> |
| <span class="source-line-no">1643</span><span id="line-1643"> @Test</span> |
| <span class="source-line-no">1644</span><span id="line-1644"> public void testInvalidPut() {</span> |
| <span class="source-line-no">1645</span><span id="line-1645"> try {</span> |
| <span class="source-line-no">1646</span><span id="line-1646"> getTable.get().put(new Put(Bytes.toBytes(0)));</span> |
| <span class="source-line-no">1647</span><span id="line-1647"> fail("Should fail since the put does not contain any cells");</span> |
| <span class="source-line-no">1648</span><span id="line-1648"> } catch (IllegalArgumentException e) {</span> |
| <span class="source-line-no">1649</span><span id="line-1649"> assertThat(e.getMessage(), containsString("No columns to insert"));</span> |
| <span class="source-line-no">1650</span><span id="line-1650"> }</span> |
| <span class="source-line-no">1651</span><span id="line-1651"></span> |
| <span class="source-line-no">1652</span><span id="line-1652"> try {</span> |
| <span class="source-line-no">1653</span><span id="line-1653"> getTable.get()</span> |
| <span class="source-line-no">1654</span><span id="line-1654"> .put(new Put(Bytes.toBytes(0)).addColumn(FAMILY, QUALIFIER, new byte[MAX_KEY_VALUE_SIZE]));</span> |
| <span class="source-line-no">1655</span><span id="line-1655"> fail("Should fail since the put exceeds the max key value size");</span> |
| <span class="source-line-no">1656</span><span id="line-1656"> } catch (IllegalArgumentException e) {</span> |
| <span class="source-line-no">1657</span><span id="line-1657"> assertThat(e.getMessage(), containsString("KeyValue size too large"));</span> |
| <span class="source-line-no">1658</span><span id="line-1658"> }</span> |
| <span class="source-line-no">1659</span><span id="line-1659"> }</span> |
| <span class="source-line-no">1660</span><span id="line-1660"></span> |
| <span class="source-line-no">1661</span><span id="line-1661"> @Test</span> |
| <span class="source-line-no">1662</span><span id="line-1662"> public void testInvalidPutInRowMutations() throws IOException {</span> |
| <span class="source-line-no">1663</span><span id="line-1663"> final byte[] row = Bytes.toBytes(0);</span> |
| <span class="source-line-no">1664</span><span id="line-1664"> try {</span> |
| <span class="source-line-no">1665</span><span id="line-1665"> getTable.get().mutateRow(new RowMutations(row).add(new Put(row)));</span> |
| <span class="source-line-no">1666</span><span id="line-1666"> fail("Should fail since the put does not contain any cells");</span> |
| <span class="source-line-no">1667</span><span id="line-1667"> } catch (IllegalArgumentException e) {</span> |
| <span class="source-line-no">1668</span><span id="line-1668"> assertThat(e.getMessage(), containsString("No columns to insert"));</span> |
| <span class="source-line-no">1669</span><span id="line-1669"> }</span> |
| <span class="source-line-no">1670</span><span id="line-1670"></span> |
| <span class="source-line-no">1671</span><span id="line-1671"> try {</span> |
| <span class="source-line-no">1672</span><span id="line-1672"> getTable.get().mutateRow(new RowMutations(row)</span> |
| <span class="source-line-no">1673</span><span id="line-1673"> .add(new Put(row).addColumn(FAMILY, QUALIFIER, new byte[MAX_KEY_VALUE_SIZE])));</span> |
| <span class="source-line-no">1674</span><span id="line-1674"> fail("Should fail since the put exceeds the max key value size");</span> |
| <span class="source-line-no">1675</span><span id="line-1675"> } catch (IllegalArgumentException e) {</span> |
| <span class="source-line-no">1676</span><span id="line-1676"> assertThat(e.getMessage(), containsString("KeyValue size too large"));</span> |
| <span class="source-line-no">1677</span><span id="line-1677"> }</span> |
| <span class="source-line-no">1678</span><span id="line-1678"> }</span> |
| <span class="source-line-no">1679</span><span id="line-1679"></span> |
| <span class="source-line-no">1680</span><span id="line-1680"> @Test</span> |
| <span class="source-line-no">1681</span><span id="line-1681"> public void testInvalidPutInRowMutationsInCheckAndMutate() throws IOException {</span> |
| <span class="source-line-no">1682</span><span id="line-1682"> final byte[] row = Bytes.toBytes(0);</span> |
| <span class="source-line-no">1683</span><span id="line-1683"> try {</span> |
| <span class="source-line-no">1684</span><span id="line-1684"> getTable.get().checkAndMutate(CheckAndMutate.newBuilder(row).ifNotExists(FAMILY, QUALIFIER)</span> |
| <span class="source-line-no">1685</span><span id="line-1685"> .build(new RowMutations(row).add(new Put(row))));</span> |
| <span class="source-line-no">1686</span><span id="line-1686"> fail("Should fail since the put does not contain any cells");</span> |
| <span class="source-line-no">1687</span><span id="line-1687"> } catch (IllegalArgumentException e) {</span> |
| <span class="source-line-no">1688</span><span id="line-1688"> assertThat(e.getMessage(), containsString("No columns to insert"));</span> |
| <span class="source-line-no">1689</span><span id="line-1689"> }</span> |
| <span class="source-line-no">1690</span><span id="line-1690"></span> |
| <span class="source-line-no">1691</span><span id="line-1691"> try {</span> |
| <span class="source-line-no">1692</span><span id="line-1692"> getTable.get().checkAndMutate(</span> |
| <span class="source-line-no">1693</span><span id="line-1693"> CheckAndMutate.newBuilder(row).ifNotExists(FAMILY, QUALIFIER).build(new RowMutations(row)</span> |
| <span class="source-line-no">1694</span><span id="line-1694"> .add(new Put(row).addColumn(FAMILY, QUALIFIER, new byte[MAX_KEY_VALUE_SIZE]))));</span> |
| <span class="source-line-no">1695</span><span id="line-1695"> fail("Should fail since the put exceeds the max key value size");</span> |
| <span class="source-line-no">1696</span><span id="line-1696"> } catch (IllegalArgumentException e) {</span> |
| <span class="source-line-no">1697</span><span id="line-1697"> assertThat(e.getMessage(), containsString("KeyValue size too large"));</span> |
| <span class="source-line-no">1698</span><span id="line-1698"> }</span> |
| <span class="source-line-no">1699</span><span id="line-1699"> }</span> |
| <span class="source-line-no">1700</span><span id="line-1700">}</span> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| </pre> |
| </div> |
| </main> |
| </body> |
| </html> |