|
16 | 16 | package com.google.cloud.bigtable.data.v2.it;
|
17 | 17 |
|
18 | 18 | import static com.google.common.truth.Truth.assertThat;
|
| 19 | +import static com.google.common.truth.TruthJUnit.assume; |
19 | 20 |
|
20 | 21 | import com.google.api.gax.batching.BatcherImpl;
|
| 22 | +import com.google.api.gax.batching.BatchingSettings; |
21 | 23 | import com.google.api.gax.batching.FlowControlEventStats;
|
22 | 24 | import com.google.cloud.bigtable.data.v2.BigtableDataClient;
|
23 | 25 | import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
|
24 | 26 | import com.google.cloud.bigtable.data.v2.models.BulkMutation;
|
25 | 27 | import com.google.cloud.bigtable.data.v2.models.Query;
|
26 | 28 | import com.google.cloud.bigtable.data.v2.models.Row;
|
27 | 29 | import com.google.cloud.bigtable.data.v2.models.RowMutationEntry;
|
| 30 | +import com.google.cloud.bigtable.test_helpers.env.EmulatorEnv; |
28 | 31 | import com.google.cloud.bigtable.test_helpers.env.TestEnvRule;
|
29 | 32 | import java.io.IOException;
|
30 | 33 | import java.util.Objects;
|
|
33 | 36 | import org.junit.Test;
|
34 | 37 | import org.junit.runner.RunWith;
|
35 | 38 | import org.junit.runners.JUnit4;
|
| 39 | +import org.threeten.bp.Duration; |
36 | 40 |
|
37 | 41 | @RunWith(JUnit4.class)
|
38 | 42 | public class BulkMutateIT {
|
@@ -83,4 +87,52 @@ public void test() throws IOException, InterruptedException {
|
83 | 87 | assertThat(row.getCells()).hasSize(1);
|
84 | 88 | }
|
85 | 89 | }
|
| 90 | + |
| 91 | + @Test |
| 92 | + public void testManyMutations() throws IOException, InterruptedException { |
| 93 | + // Emulator is very slow and will take a long time for the test to run |
| 94 | + assume() |
| 95 | + .withMessage("testManyMutations is not supported on Emulator") |
| 96 | + .that(testEnvRule.env()) |
| 97 | + .isNotInstanceOf(EmulatorEnv.class); |
| 98 | + |
| 99 | + BigtableDataSettings settings = testEnvRule.env().getDataClientSettings(); |
| 100 | + String rowPrefix = UUID.randomUUID().toString(); |
| 101 | + |
| 102 | + BatchingSettings batchingSettings = |
| 103 | + settings.getStubSettings().bulkMutateRowsSettings().getBatchingSettings(); |
| 104 | + |
| 105 | + settings |
| 106 | + .toBuilder() |
| 107 | + .stubSettings() |
| 108 | + .bulkMutateRowsSettings() |
| 109 | + .setBatchingSettings( |
| 110 | + batchingSettings.toBuilder().setDelayThreshold(Duration.ofHours(1)).build()); |
| 111 | + try (BigtableDataClient client = BigtableDataClient.create(settings); |
| 112 | + BatcherImpl<RowMutationEntry, Void, BulkMutation, Void> batcher = |
| 113 | + (BatcherImpl<RowMutationEntry, Void, BulkMutation, Void>) |
| 114 | + client.newBulkMutationBatcher(testEnvRule.env().getTableId())) { |
| 115 | + |
| 116 | + String familyId = testEnvRule.env().getFamilyId(); |
| 117 | + for (int i = 0; i < 2; i++) { |
| 118 | + String key = rowPrefix + "test-key"; |
| 119 | + RowMutationEntry rowMutationEntry = RowMutationEntry.create(key); |
| 120 | + // Create mutation entries with many columns. The batcher should flush every time. |
| 121 | + for (long j = 0; j < 50001; j++) { |
| 122 | + rowMutationEntry.setCell(familyId, "q" + j + i, j); |
| 123 | + } |
| 124 | + batcher.add(rowMutationEntry); |
| 125 | + } |
| 126 | + batcher.flush(); |
| 127 | + // Query a key to make sure the write succeeded |
| 128 | + Row row = |
| 129 | + testEnvRule |
| 130 | + .env() |
| 131 | + .getDataClient() |
| 132 | + .readRowsCallable() |
| 133 | + .first() |
| 134 | + .call(Query.create(testEnvRule.env().getTableId()).rowKey(rowPrefix + "test-key")); |
| 135 | + assertThat(row.getCells()).hasSize(100002); |
| 136 | + } |
| 137 | + } |
86 | 138 | }
|
0 commit comments