From 8c723a76b81c276205fdece473968ffb8fc566f4 Mon Sep 17 00:00:00 2001 From: Siddharth Agrawal Date: Tue, 31 Oct 2023 12:32:34 -0700 Subject: [PATCH] test: add e2e test to verify proto3 optional tag works --- .../it/ITBigQueryWriteManualClientTest.java | 39 +++++++++++++++++++ .../src/test/proto/optionalTest.proto | 26 +++++++++++++ pom.xml | 2 +- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 google-cloud-bigquerystorage/src/test/proto/optionalTest.proto diff --git a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryWriteManualClientTest.java b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryWriteManualClientTest.java index 7cae021fff..39b660ffb2 100644 --- a/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryWriteManualClientTest.java +++ b/google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1/it/ITBigQueryWriteManualClientTest.java @@ -28,6 +28,7 @@ import com.google.cloud.bigquery.Field.Mode; import com.google.cloud.bigquery.Schema; import com.google.cloud.bigquery.storage.test.Test.*; +import com.google.cloud.bigquery.storage.test.TestOptional.*; import com.google.cloud.bigquery.storage.v1.*; import com.google.cloud.bigquery.storage.v1.AppendRowsRequest.MissingValueInterpretation; import com.google.cloud.bigquery.storage.v1.Exceptions.AppendSerializationError; @@ -207,6 +208,15 @@ ProtoRows CreateProtoRows(String[] messages) { return rows.build(); } + ProtoRows CreateProtoOptionalRows(String[] messages) { + ProtoRows.Builder rows = ProtoRows.newBuilder(); + for (String message : messages) { + FooOptionalType foo = FooOptionalType.newBuilder().setFoo(message).build(); + rows.addSerializedRows(foo.toByteString()); + } + return rows.build(); + } + ProtoRows CreateProtoRowsMultipleColumns(String[] messages) { ProtoRows.Builder rows = ProtoRows.newBuilder(); for (String message : messages) { @@ -274,6 +284,35 @@ public void testBatchWriteWithCommittedStreamEU() assertEquals(3, response2.get().getAppendResult().getOffset().getValue()); } + @Test + public void testProto3OptionalBatchWriteWithCommittedStream() + throws IOException, InterruptedException, ExecutionException { + WriteStream writeStream = + client.createWriteStream( + CreateWriteStreamRequest.newBuilder() + .setParent(tableId) + .setWriteStream( + WriteStream.newBuilder().setType(WriteStream.Type.COMMITTED).build()) + .build()); + StreamWriter streamWriter = + StreamWriter.newBuilder(writeStream.getName()) + .setWriterSchema(ProtoSchemaConverter.convert(FooOptionalType.getDescriptor())) + .build(); + LOG.info("Sending one message"); + + ApiFuture response = + streamWriter.append(CreateProtoOptionalRows(new String[] {"aaa"}), 0); + assertEquals(0, response.get().getAppendResult().getOffset().getValue()); + + LOG.info("Sending two more messages"); + ApiFuture response1 = + streamWriter.append(CreateProtoOptionalRows(new String[] {"bbb", "ccc"}), 1); + ApiFuture response2 = + streamWriter.append(CreateProtoOptionalRows(new String[] {""}), 3); + assertEquals(1, response1.get().getAppendResult().getOffset().getValue()); + assertEquals(3, response2.get().getAppendResult().getOffset().getValue()); + } + @Test public void testJsonStreamWriterCommittedStream() throws IOException, InterruptedException, ExecutionException, diff --git a/google-cloud-bigquerystorage/src/test/proto/optionalTest.proto b/google-cloud-bigquerystorage/src/test/proto/optionalTest.proto new file mode 100644 index 0000000000..41e13f05a3 --- /dev/null +++ b/google-cloud-bigquerystorage/src/test/proto/optionalTest.proto @@ -0,0 +1,26 @@ +/* + * Copyright 2023 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +syntax = "proto3"; + +package com.google.cloud.bigquery.storage.test; + +option java_package = "com.google.cloud.bigquery.storage.test"; +option java_outer_classname = "TestOptional"; + +message FooOptionalType { + optional string foo = 1; +} + diff --git a/pom.xml b/pom.xml index cdf72002dc..dcf66e25a1 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ UTF-8 UTF-8 - 3.14.0 + 3.23.0 github google-cloud-bigquerystorage-parent