@@ -96,29 +96,26 @@ TEST(ClientTest, ReadSuccess) {
9696 )pb" ,
9797 &metadata));
9898 EXPECT_CALL (*source, Metadata ()).WillRepeatedly (Return (metadata));
99- EXPECT_CALL (*source, Stats ())
100- .WillRepeatedly (Return (optional<spanner_proto::ResultSetStats>()));
10199 EXPECT_CALL (*source, NextValue ())
102100 .WillOnce (Return (optional<Value>(" Steve" )))
103101 .WillOnce (Return (optional<Value>(12 )))
104102 .WillOnce (Return (optional<Value>(" Ann" )))
105103 .WillOnce (Return (optional<Value>(42 )))
106104 .WillOnce (Return (optional<Value>()));
107105
108- ResultSet result_set (std::move (source));
106+ ReadResult result_set (std::move (source));
109107 EXPECT_CALL (*conn, Read (_)).WillOnce (Return (ByMove (std::move (result_set))));
110108
111109 KeySet keys = KeySet::All ();
112110 auto result = client.Read (" table" , std::move (keys), {" column1" , " column2" });
113- EXPECT_STATUS_OK (result);
114111
115112 using RowType = Row<std::string, std::int64_t >;
116113 auto expected = std::vector<RowType>{
117114 RowType (" Steve" , 12 ),
118115 RowType (" Ann" , 42 ),
119116 };
120117 int row_number = 0 ;
121- for (auto & row : result-> Rows <RowType>()) {
118+ for (auto & row : result. Rows <RowType>()) {
122119 EXPECT_STATUS_OK (row);
123120 EXPECT_EQ (*row, expected[row_number]);
124121 ++row_number;
@@ -143,21 +140,18 @@ TEST(ClientTest, ReadFailure) {
143140 )pb" ,
144141 &metadata));
145142 EXPECT_CALL (*source, Metadata ()).WillRepeatedly (Return (metadata));
146- EXPECT_CALL (*source, Stats ())
147- .WillRepeatedly (Return (optional<spanner_proto::ResultSetStats>()));
148143 EXPECT_CALL (*source, NextValue ())
149144 .WillOnce (Return (optional<Value>(" Steve" )))
150145 .WillOnce (Return (optional<Value>(" Ann" )))
151146 .WillOnce (Return (Status (StatusCode::kDeadlineExceeded , " deadline!" )));
152147
153- ResultSet result_set (std::move (source));
148+ ReadResult result_set (std::move (source));
154149 EXPECT_CALL (*conn, Read (_)).WillOnce (Return (ByMove (std::move (result_set))));
155150
156151 KeySet keys = KeySet::All ();
157152 auto result = client.Read (" table" , std::move (keys), {" column1" });
158- EXPECT_STATUS_OK (result);
159153
160- auto rows = result-> Rows <Row<std::string>>();
154+ auto rows = result. Rows <Row<std::string>>();
161155 auto iter = rows.begin ();
162156 EXPECT_NE (iter, rows.end ());
163157 EXPECT_STATUS_OK (*iter);
@@ -194,8 +188,6 @@ TEST(ClientTest, ExecuteQuerySuccess) {
194188 )pb" ,
195189 &metadata));
196190 EXPECT_CALL (*source, Metadata ()).WillRepeatedly (Return (metadata));
197- EXPECT_CALL (*source, Stats ())
198- .WillRepeatedly (Return (optional<spanner_proto::ResultSetStats>()));
199191 EXPECT_CALL (*source, NextValue ())
200192 .WillOnce (Return (optional<Value>(" Steve" )))
201193 .WillOnce (Return (optional<Value>(12 )))
@@ -241,8 +233,6 @@ TEST(ClientTest, ExecuteQueryFailure) {
241233 )pb" ,
242234 &metadata));
243235 EXPECT_CALL (*source, Metadata ()).WillRepeatedly (Return (metadata));
244- EXPECT_CALL (*source, Stats ())
245- .WillRepeatedly (Return (optional<spanner_proto::ResultSetStats>()));
246236 EXPECT_CALL (*source, NextValue ())
247237 .WillOnce (Return (optional<Value>(" Steve" )))
248238 .WillOnce (Return (optional<Value>(" Ann" )))
@@ -329,8 +319,6 @@ TEST(ClientTest, ExecutePartitionedDml_Success) {
329319 auto source = make_unique<MockResultSetSource>();
330320 spanner_proto::ResultSetMetadata metadata;
331321 EXPECT_CALL (*source, Metadata ()).WillRepeatedly (Return (metadata));
332- EXPECT_CALL (*source, Stats ())
333- .WillRepeatedly (Return (optional<spanner_proto::ResultSetStats>()));
334322 EXPECT_CALL (*source, NextValue ()).WillRepeatedly (Return (optional<Value>()));
335323
336324 std::string const sql_statement = " UPDATE Singers SET MarketingBudget = 1000" ;
@@ -418,17 +406,38 @@ TEST(ClientTest, RunTransactionCommit) {
418406 Transaction txn = MakeReadWriteTransaction (); // dummy
419407 Connection::ReadParams actual_read_params{txn, {}, {}, {}, {}};
420408 Connection::CommitParams actual_commit_params{txn, {}};
409+
410+ auto source = make_unique<MockResultSetSource>();
411+ spanner_proto::ResultSetMetadata metadata;
412+ ASSERT_TRUE (TextFormat::ParseFromString (
413+ R"pb(
414+ row_type: {
415+ fields: {
416+ name: "Name",
417+ type: { code: STRING }
418+ }
419+ }
420+ )pb" ,
421+ &metadata));
422+ EXPECT_CALL (*source, Metadata ()).WillRepeatedly (Return (metadata));
423+ EXPECT_CALL (*source, NextValue ())
424+ .WillOnce (Return (optional<Value>(" Bob" )))
425+ .WillOnce (Return (optional<Value>()));
426+ ReadResult result_set (std::move (source));
427+
421428 EXPECT_CALL (*conn, Read (_))
422- .WillOnce (
423- DoAll (SaveArg< 0 >(&actual_read_params), Return (ByMove (ResultSet{} ))));
429+ .WillOnce (DoAll (SaveArg< 0 >(&actual_read_params),
430+ Return (ByMove (std::move (result_set) ))));
424431 EXPECT_CALL (*conn, Commit (_))
425432 .WillOnce (DoAll (SaveArg<0 >(&actual_commit_params),
426433 Return (CommitResult{*timestamp})));
427434
428435 auto mutation = MakeDeleteMutation (" table" , KeySet::All ());
429436 auto f = [&mutation](Client client, Transaction txn) -> StatusOr<Mutations> {
430437 auto read = client.Read (std::move (txn), " T" , KeySet::All (), {" C" });
431- if (!read) return read.status ();
438+ for (auto & row : read.Rows <Row<std::string>>()) {
439+ if (!row) return row.status ();
440+ }
432441 return Mutations{mutation};
433442 };
434443
@@ -447,16 +456,35 @@ TEST(ClientTest, RunTransactionRollback) {
447456 auto conn = std::make_shared<MockConnection>();
448457 Transaction txn = MakeReadWriteTransaction (); // dummy
449458 Connection::ReadParams actual_read_params{txn, {}, {}, {}, {}};
459+
460+ auto source = make_unique<MockResultSetSource>();
461+ spanner_proto::ResultSetMetadata metadata;
462+ ASSERT_TRUE (TextFormat::ParseFromString (
463+ R"pb(
464+ row_type: {
465+ fields: {
466+ name: "Name",
467+ type: { code: INT64 }
468+ }
469+ }
470+ )pb" ,
471+ &metadata));
472+ EXPECT_CALL (*source, Metadata ()).WillRepeatedly (Return (metadata));
473+ EXPECT_CALL (*source, NextValue ())
474+ .WillOnce (Return (Status (StatusCode::kInvalidArgument , " blah" )));
475+ ReadResult result_set (std::move (source));
476+
450477 EXPECT_CALL (*conn, Read (_))
451- .WillOnce (
452- DoAll (SaveArg<0 >(&actual_read_params),
453- Return (ByMove (Status (StatusCode::kInvalidArgument , " blah" )))));
478+ .WillOnce (DoAll (SaveArg<0 >(&actual_read_params),
479+ Return (ByMove (std::move (result_set)))));
454480 EXPECT_CALL (*conn, Rollback (_)).WillOnce (Return (Status ()));
455481
456482 auto mutation = MakeDeleteMutation (" table" , KeySet::All ());
457483 auto f = [&mutation](Client client, Transaction txn) -> StatusOr<Mutations> {
458484 auto read = client.Read (std::move (txn), " T" , KeySet::All (), {" C" });
459- if (!read) return read.status ();
485+ for (auto & row : read.Rows <Row<std::string>>()) {
486+ if (!row) return row.status ();
487+ }
460488 return Mutations{mutation};
461489 };
462490
@@ -475,17 +503,36 @@ TEST(ClientTest, RunTransactionRollbackError) {
475503 auto conn = std::make_shared<MockConnection>();
476504 Transaction txn = MakeReadWriteTransaction (); // dummy
477505 Connection::ReadParams actual_read_params{txn, {}, {}, {}, {}};
506+
507+ auto source = make_unique<MockResultSetSource>();
508+ spanner_proto::ResultSetMetadata metadata;
509+ ASSERT_TRUE (TextFormat::ParseFromString (
510+ R"pb(
511+ row_type: {
512+ fields: {
513+ name: "Name",
514+ type: { code: INT64 }
515+ }
516+ }
517+ )pb" ,
518+ &metadata));
519+ EXPECT_CALL (*source, Metadata ()).WillRepeatedly (Return (metadata));
520+ EXPECT_CALL (*source, NextValue ())
521+ .WillOnce (Return (Status (StatusCode::kInvalidArgument , " blah" )));
522+ ReadResult result_set (std::move (source));
523+
478524 EXPECT_CALL (*conn, Read (_))
479- .WillOnce (
480- DoAll (SaveArg<0 >(&actual_read_params),
481- Return (ByMove (Status (StatusCode::kInvalidArgument , " blah" )))));
525+ .WillOnce (DoAll (SaveArg<0 >(&actual_read_params),
526+ Return (ByMove (std::move (result_set)))));
482527 EXPECT_CALL (*conn, Rollback (_))
483528 .WillOnce (Return (Status (StatusCode::kInternal , " oops" )));
484529
485530 auto mutation = MakeDeleteMutation (" table" , KeySet::All ());
486531 auto f = [&mutation](Client client, Transaction txn) -> StatusOr<Mutations> {
487532 auto read = client.Read (std::move (txn), " T" , KeySet::All (), {" C" });
488- if (!read) return read.status ();
533+ for (auto & row : read.Rows <Row<std::string>>()) {
534+ if (!row) return row.status ();
535+ }
489536 return Mutations{mutation};
490537 };
491538
@@ -503,14 +550,33 @@ TEST(ClientTest, RunTransactionRollbackError) {
503550#if GOOGLE_CLOUD_CPP_HAVE_EXCEPTIONS
504551TEST (ClientTest, RunTransactionException) {
505552 auto conn = std::make_shared<MockConnection>();
506- EXPECT_CALL (*conn, Read (_))
507- .WillOnce (Return (ByMove (Status (StatusCode::kInvalidArgument , " blah" ))));
553+
554+ auto source = make_unique<MockResultSetSource>();
555+ spanner_proto::ResultSetMetadata metadata;
556+ ASSERT_TRUE (TextFormat::ParseFromString (
557+ R"pb(
558+ row_type: {
559+ fields: {
560+ name: "Name",
561+ type: { code: INT64 }
562+ }
563+ }
564+ )pb" ,
565+ &metadata));
566+ EXPECT_CALL (*source, Metadata ()).WillRepeatedly (Return (metadata));
567+ EXPECT_CALL (*source, NextValue ())
568+ .WillOnce (Return (Status (StatusCode::kInvalidArgument , " blah" )));
569+ ReadResult result_set (std::move (source));
570+
571+ EXPECT_CALL (*conn, Read (_)).WillOnce (Return (ByMove (std::move (result_set))));
508572 EXPECT_CALL (*conn, Rollback (_)).WillOnce (Return (Status ()));
509573
510574 auto mutation = MakeDeleteMutation (" table" , KeySet::All ());
511575 auto f = [&mutation](Client client, Transaction txn) -> StatusOr<Mutations> {
512576 auto read = client.Read (std::move (txn), " T" , KeySet::All (), {" C" });
513- if (!read) throw " Read() error" ;
577+ for (auto & row : read.Rows <Row<std::string>>()) {
578+ if (!row) throw " Read() error" ;
579+ }
514580 return Mutations{mutation};
515581 };
516582
0 commit comments