use of com.google.spanner.v1.Mutation in project beam by apache.
the class BigtableWriteIT method testE2EBigtableWrite.
@Test
public void testE2EBigtableWrite() throws Exception {
final String tableName = bigtableOptions.getInstanceName().toTableNameStr(tableId);
final String instanceName = bigtableOptions.getInstanceName().toString();
final int numRows = 1000;
final List<KV<ByteString, ByteString>> testData = generateTableData(numRows);
createEmptyTable(instanceName, tableId);
Pipeline p = Pipeline.create(options);
p.apply(GenerateSequence.from(0).to(numRows)).apply(ParDo.of(new DoFn<Long, KV<ByteString, Iterable<Mutation>>>() {
@ProcessElement
public void processElement(ProcessContext c) {
int index = c.element().intValue();
Iterable<Mutation> mutations = ImmutableList.of(Mutation.newBuilder().setSetCell(Mutation.SetCell.newBuilder().setValue(testData.get(index).getValue()).setFamilyName(COLUMN_FAMILY_NAME)).build());
c.output(KV.of(testData.get(index).getKey(), mutations));
}
})).apply(BigtableIO.write().withBigtableOptions(bigtableOptions).withTableId(tableId));
p.run();
// Test number of column families and column family name equality
Table table = getTable(tableName);
assertThat(table.getColumnFamiliesMap().keySet(), Matchers.hasSize(1));
assertThat(table.getColumnFamiliesMap(), Matchers.hasKey(COLUMN_FAMILY_NAME));
// Test table data equality
List<KV<ByteString, ByteString>> tableData = getTableData(tableName);
assertThat(tableData, Matchers.containsInAnyOrder(testData.toArray()));
}
use of com.google.spanner.v1.Mutation in project pgadapter by GoogleCloudPlatform.
the class JdbcMockServerTest method testCopyIn.
@Test
public void testCopyIn() throws SQLException, IOException {
setupCopyInformationSchemaResults();
try (Connection connection = DriverManager.getConnection(createUrl())) {
CopyManager copyManager = new CopyManager(connection.unwrap(BaseConnection.class));
copyManager.copyIn("COPY users FROM STDIN;", new StringReader("5\t5\t5\n6\t6\t6\n7\t7\t7\n"));
}
List<CommitRequest> commitRequests = mockSpanner.getRequestsOfType(CommitRequest.class);
assertEquals(1, commitRequests.size());
CommitRequest commitRequest = commitRequests.get(0);
assertEquals(1, commitRequest.getMutationsCount());
Mutation mutation = commitRequest.getMutations(0);
assertEquals(OperationCase.INSERT, mutation.getOperationCase());
assertEquals(3, mutation.getInsert().getValuesCount());
}
use of com.google.spanner.v1.Mutation in project SpinalTap by airbnb.
the class ColumnSerializationUtilTest method testDeserializeColumn.
@Test
public void testDeserializeColumn() throws Exception {
Mutation mutation = new Mutation(MutationType.DELETE, TIMESTAMP, SOURCE_ID, DATA_SOURCE, BINLOG_HEADER, TABLE, getEntity());
TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
byte[] serialized = serializer.serialize(mutation);
Mutation deserialized = new Mutation();
deserializer.deserialize(deserialized, serialized);
assertEquals(mutation, deserialized);
}
use of com.google.spanner.v1.Mutation in project google-cloud-java by GoogleCloudPlatform.
the class SessionImplTest method writeAtLeastOnce.
@Test
public void writeAtLeastOnce() throws ParseException {
String timestampString = "2015-10-01T10:54:20.021Z";
ArgumentCaptor<CommitRequest> commit = ArgumentCaptor.forClass(CommitRequest.class);
CommitResponse response = CommitResponse.newBuilder().setCommitTimestamp(Timestamps.parse(timestampString)).build();
Mockito.when(rpc.commit(commit.capture(), Mockito.eq(options))).thenReturn(response);
Timestamp timestamp = session.writeAtLeastOnce(Arrays.asList(Mutation.newInsertBuilder("T").set("C").to("x").build()));
assertThat(timestamp.getSeconds()).isEqualTo(utcTimeSeconds(2015, Calendar.OCTOBER, 1, 10, 54, 20));
assertThat(timestamp.getNanos()).isEqualTo(TimeUnit.MILLISECONDS.toNanos(21));
CommitRequest request = commit.getValue();
assertThat(request.getSingleUseTransaction()).isNotNull();
assertThat(request.getSingleUseTransaction().getReadWrite()).isNotNull();
com.google.spanner.v1.Mutation mutation = com.google.spanner.v1.Mutation.newBuilder().setInsert(Write.newBuilder().setTable("T").addColumns("C").addValues(ListValue.newBuilder().addValues(com.google.protobuf.Value.newBuilder().setStringValue("x")))).build();
assertThat(request.getMutationsList()).containsExactly(mutation);
}
use of com.google.spanner.v1.Mutation in project simple-bigtable by spotify.
the class BigtableMutationImplTest method testDeleteRow.
@Test
public void testDeleteRow() throws Exception {
final BigtableMutationImpl bigtableMutationImpl = (BigtableMutationImpl) this.bigtableMutation.deleteRow();
verifyGetMutateRowRequest();
bigtableMutationImpl.execute();
bigtableMutationImpl.executeAsync();
assertEquals(1, bigtableMutationImpl.getMutateRowRequest().getMutationsCount());
final Mutation mutation = bigtableMutationImpl.getMutateRowRequest().getMutations(0);
assertEquals(Mutation.MutationCase.DELETE_FROM_ROW, mutation.getMutationCase());
assertEquals(Mutation.DeleteFromRow.getDefaultInstance(), mutation.getDeleteFromRow());
assertEquals(Mutation.DeleteFromFamily.getDefaultInstance(), mutation.getDeleteFromFamily());
assertEquals(Mutation.DeleteFromColumn.getDefaultInstance(), mutation.getDeleteFromColumn());
assertEquals(Mutation.SetCell.getDefaultInstance(), mutation.getSetCell());
verify(bigtableMock.getMockedDataClient()).mutateRow(bigtableMutation.getMutateRowRequest().build());
verify(bigtableMock.getMockedDataClient()).mutateRowAsync(bigtableMutation.getMutateRowRequest().build());
verifyNoMoreInteractions(bigtableMock.getMockedDataClient());
}
Aggregations