|
| 1 | +/* |
| 2 | + * Copyright 2018 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.google.cloud.bigtable.data.v2.it; |
| 17 | + |
| 18 | +import com.google.api.gax.rpc.ServerStream; |
| 19 | +import com.google.cloud.bigtable.data.v2.BigtableDataClient; |
| 20 | +import com.google.cloud.bigtable.data.v2.it.env.TestEnvRule; |
| 21 | +import com.google.cloud.bigtable.data.v2.models.BulkMutationBatcher; |
| 22 | +import com.google.cloud.bigtable.data.v2.models.Query; |
| 23 | +import com.google.cloud.bigtable.data.v2.models.Row; |
| 24 | +import com.google.cloud.bigtable.data.v2.models.RowCell; |
| 25 | +import com.google.cloud.bigtable.data.v2.models.RowMutation; |
| 26 | +import com.google.common.collect.Lists; |
| 27 | +import com.google.common.truth.Truth; |
| 28 | +import com.google.protobuf.ByteString; |
| 29 | +import java.util.List; |
| 30 | +import org.junit.ClassRule; |
| 31 | +import org.junit.Test; |
| 32 | +import org.junit.runner.RunWith; |
| 33 | +import org.junit.runners.JUnit4; |
| 34 | + |
| 35 | +@RunWith(JUnit4.class) |
| 36 | +public class BulkMutationBatcherIT { |
| 37 | + @ClassRule public static TestEnvRule testEnvRule = new TestEnvRule(); |
| 38 | + |
| 39 | + @Test |
| 40 | + public void test() throws Exception { |
| 41 | + BigtableDataClient client = testEnvRule.env().getDataClient(); |
| 42 | + String tableId = testEnvRule.env().getTableName().getTable(); |
| 43 | + String family = testEnvRule.env().getFamilyId(); |
| 44 | + String rowPrefix = testEnvRule.env().getRowPrefix(); |
| 45 | + |
| 46 | + try (BulkMutationBatcher batcher = client.newBulkMutationBatcher()) { |
| 47 | + for (int i = 0; i < 10; i++) { |
| 48 | + batcher.add( |
| 49 | + RowMutation.create(tableId, rowPrefix + "-" + i).setCell(family, "q", 10_000, "value")); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + List<Row> expectedRows = Lists.newArrayList(); |
| 54 | + for (int i = 0; i < 10; i++) { |
| 55 | + expectedRows.add( |
| 56 | + Row.create( |
| 57 | + ByteString.copyFromUtf8(rowPrefix + "-" + i), |
| 58 | + Lists.newArrayList( |
| 59 | + RowCell.create( |
| 60 | + family, |
| 61 | + ByteString.copyFromUtf8("q"), |
| 62 | + 10_000, |
| 63 | + Lists.<String>newArrayList(), |
| 64 | + ByteString.copyFromUtf8("value"))))); |
| 65 | + } |
| 66 | + ServerStream<Row> actualRows = client.readRows(Query.create(tableId).prefix(rowPrefix)); |
| 67 | + |
| 68 | + Truth.assertThat(actualRows).containsExactlyElementsIn(expectedRows); |
| 69 | + } |
| 70 | +} |
0 commit comments