@@ -3694,6 +3694,92 @@ TEST_F(DataConnectionTest,
36943694 EXPECT_THAT (row2.values ().at (1 ).get <std::string>(), IsOkAndHolds (" v2" ));
36953695}
36963696
3697+ TEST_F (DataConnectionTest, ExecuteQueryFailureWithSchemaChange) {
3698+ auto factory = std::make_unique<SimpleOperationContextFactory>();
3699+
3700+ auto mock = std::make_shared<MockBigtableStub>();
3701+ auto fake_cq_impl = std::make_shared<FakeCompletionQueueImpl>();
3702+ auto mock_bg = std::make_unique<MockBackgroundThreads>();
3703+ EXPECT_CALL (*mock_bg, cq).WillRepeatedly ([&]() {
3704+ return CompletionQueue{fake_cq_impl};
3705+ });
3706+ auto constexpr kResultMetadataText = R"pb(
3707+ proto_schema {
3708+ columns {
3709+ name: "row_key"
3710+ type { string_type {} }
3711+ }
3712+ columns {
3713+ name: "value"
3714+ type { string_type {} }
3715+ }
3716+ }
3717+ )pb" ;
3718+ v2::PrepareQueryResponse pq_response;
3719+ pq_response.set_prepared_query (" test-pq-id-54321" );
3720+ ASSERT_TRUE (google::protobuf::TextFormat::ParseFromString (
3721+ kResultMetadataText , pq_response.mutable_metadata ()));
3722+ *pq_response.mutable_valid_until () = internal::ToProtoTimestamp (
3723+ std::chrono::system_clock::now () + std::chrono::seconds (3600 ));
3724+
3725+ auto constexpr kExecuteQueryResultMetadataText = R"pb(
3726+ proto_schema {
3727+ columns {
3728+ name: "row_key"
3729+ type { string_type {} }
3730+ }
3731+ columns {
3732+ name: "different_value"
3733+ type { string_type {} }
3734+ }
3735+ }
3736+ )pb" ;
3737+ v2::ExecuteQueryResponse eq_response;
3738+ ASSERT_TRUE (google::protobuf::TextFormat::ParseFromString (
3739+ kExecuteQueryResultMetadataText , eq_response.mutable_metadata ()));
3740+
3741+ auto refresh_fn = []() {
3742+ return make_ready_future (
3743+ StatusOr<google::bigtable::v2::PrepareQueryResponse>(
3744+ Status{StatusCode::kUnimplemented , " not implemented" }));
3745+ };
3746+ // EXPECT_CALL(*mock, ExecuteQuery)
3747+ EXPECT_CALL (*mock, ExecuteQuery)
3748+ .Times (3 )
3749+ .WillRepeatedly (
3750+ [&](auto , auto const &,
3751+ google::bigtable::v2::ExecuteQueryRequest const & request) {
3752+ EXPECT_EQ (request.app_profile_id (), kAppProfile );
3753+ EXPECT_EQ (request.instance_name (),
3754+ " projects/test-project/instances/test-instance" );
3755+ auto stream = std::make_unique<MockExecuteQueryStream>();
3756+ EXPECT_CALL (*stream, Read)
3757+ .WillOnce ([&](google::bigtable::v2::ExecuteQueryResponse* r) {
3758+ *r = eq_response;
3759+ return absl::nullopt ;
3760+ });
3761+ return stream;
3762+ });
3763+
3764+ auto conn = TestConnection (std::move (mock), std::move (factory));
3765+ internal::OptionsSpan span (CallOptions ());
3766+ Project p (" test-project" );
3767+ bigtable::SqlStatement statement (" SELECT * FROM the-table" );
3768+ bigtable::InstanceResource instance (p, " test-instance" );
3769+ auto query_plan =
3770+ QueryPlan::Create (CompletionQueue (fake_cq_impl), std::move (pq_response),
3771+ std::move (refresh_fn));
3772+ auto prepared_query =
3773+ bigtable::PreparedQuery (instance, statement, std::move (query_plan));
3774+ auto bq = prepared_query.BindParameters ({});
3775+ bigtable::ExecuteQueryParams params{std::move (bq)};
3776+ auto row_stream = conn->ExecuteQuery (std::move (params));
3777+ for (auto const & row : row_stream) {
3778+ EXPECT_THAT (row, StatusIs (StatusCode::kAborted ));
3779+ }
3780+ fake_cq_impl->SimulateCompletion (false );
3781+ }
3782+
36973783} // namespace
36983784GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
36993785} // namespace bigtable_internal
0 commit comments