Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add ensureDecoded to proto type #2897

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ protected <T extends AbstractMessage> T getProtoMessageInternal(int columnIndex,
Preconditions.checkNotNull(
message,
"Proto message may not be null. Use MyProtoClass.getDefaultInstance() as a parameter value.");
ensureDecoded(columnIndex);
try {
return (T)
message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;

import com.google.cloud.ByteArray;
import com.google.cloud.spanner.Database;
Expand Down Expand Up @@ -54,14 +55,12 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

// Integration Tests to test DDL, DML and DQL for Proto Columns and Enums
@Ignore("Feature is not yet enabled in production")
@Category(ParallelIntegrationTest.class)
@RunWith(JUnit4.class)
public class ITProtoColumnTest {
Expand All @@ -71,10 +70,17 @@ public class ITProtoColumnTest {
private static DatabaseAdminClient dbAdminClient;
private static DatabaseClient databaseClient;

public static boolean isUsingAllowlistedProject() {
String projectId = System.getProperty("spanner.gce.config.project_id", "");
return projectId.equalsIgnoreCase("gcloud-devel")
|| projectId.equalsIgnoreCase("span-cloud-testing");
}

@BeforeClass
public static void setUpDatabase() throws Exception {
assumeFalse(
"Proto Column is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator());
assumeTrue("Proto Column is not yet enabled in production", isUsingAllowlistedProject());
RemoteSpannerHelper testHelper = env.getTestHelper();
databaseID = DatabaseId.of(testHelper.getInstanceId(), testHelper.getUniqueDatabaseId());
dbAdminClient = testHelper.getClient().getDatabaseAdminClient();
Expand Down Expand Up @@ -133,7 +139,7 @@ public static void createDatabase() throws Exception {
@AfterClass
public static void afterClass() throws Exception {
try {
if (!isUsingEmulator()) {
if (!isUsingEmulator() && isUsingAllowlistedProject()) {
dbAdminClient.dropDatabase(
databaseID.getInstanceId().getInstance(), databaseID.getDatabase());
}
Expand Down Expand Up @@ -163,6 +169,7 @@ public void after() throws Exception {
public void testProtoColumnsUpdateAndRead() {
assumeFalse(
"Proto Column is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator());
assumeTrue("Proto Column is not yet enabled in production", isUsingAllowlistedProject());
SingerInfo singerInfo =
SingerInfo.newBuilder().setSingerId(1).setNationality("Country1").build();
ByteArray singerInfoBytes = ByteArray.copyFrom(singerInfo.toByteArray());
Expand Down Expand Up @@ -270,6 +277,7 @@ public void testProtoColumnsUpdateAndRead() {
public void testProtoColumnsDMLParameterizedQueriesPKAndIndexes() {
assumeFalse(
"Proto Column is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator());
assumeTrue("Proto Column is not yet enabled in production", isUsingAllowlistedProject());

SingerInfo singerInfo1 =
SingerInfo.newBuilder().setSingerId(1).setNationality("Country1").build();
Expand Down Expand Up @@ -376,6 +384,7 @@ public void testProtoColumnsDMLParameterizedQueriesPKAndIndexes() {
public void testProtoMessageDeserializationError() {
assumeFalse(
"Proto Column is not supported in the emulator", EmulatorSpannerHelper.isUsingEmulator());
assumeTrue("Proto Column is not yet enabled in production", isUsingAllowlistedProject());

SingerInfo singerInfo =
SingerInfo.newBuilder().setSingerId(1).setNationality("Country1").build();
Expand Down
Loading