@@ -138,6 +138,58 @@ TEST(ClientTest, ReadSuccess) {
138138 IsOkAndHolds (RowType (" Ann" , 42 ))));
139139}
140140
141+ TEST (ClientTest, ReadWithLockHint) {
142+ auto conn = std::make_shared<MockConnection>();
143+ Client client (conn);
144+
145+ auto constexpr kText = R"pb(
146+ row_type: {
147+ fields: {
148+ name: "Name",
149+ type: { code: INT64 }
150+ }
151+ fields: {
152+ name: "Id",
153+ type: { code: INT64 }
154+ }
155+ }
156+ )pb" ;
157+ google::spanner::v1::ResultSetMetadata metadata;
158+ ASSERT_TRUE (TextFormat::ParseFromString (kText , &metadata));
159+
160+ EXPECT_CALL (*conn, Read)
161+ .WillOnce ([&metadata](Connection::ReadParams const & params) {
162+ EXPECT_THAT (
163+ params.directed_read_option ,
164+ VariantWith<IncludeReplicas>(AllOf (
165+ Property (&IncludeReplicas::replica_selections,
166+ ElementsAre (ReplicaSelection (ReplicaType::kReadOnly ))),
167+ Property (&IncludeReplicas::auto_failover_disabled, true ))));
168+ EXPECT_THAT (params.lock_hint , Eq (LockHint::kLockHintShared ));
169+ auto source = std::make_unique<MockResultSetSource>();
170+ EXPECT_CALL (*source, Metadata ()).WillRepeatedly (Return (metadata));
171+ EXPECT_CALL (*source, NextRow ())
172+ .WillOnce (Return (spanner_mocks::MakeRow (" Steve" , 12 )))
173+ .WillOnce (Return (spanner_mocks::MakeRow (" Ann" , 42 )))
174+ .WillOnce (Return (Row ()));
175+ return RowStream (std::move (source));
176+ });
177+
178+ KeySet keys = KeySet::All ();
179+ auto rows = client.Read (" table" , std::move (keys), {" column1" , " column2" },
180+ Options{}
181+ .set <DirectedReadOption>(IncludeReplicas (
182+ {ReplicaSelection (ReplicaType::kReadOnly )},
183+ /* auto_failover_disabled=*/ true ))
184+ .set <LockHintOption>(LockHint::kLockHintShared ));
185+
186+ using RowType = std::tuple<std::string, std::int64_t >;
187+ auto stream = StreamOf<RowType>(rows);
188+ auto actual = std::vector<StatusOr<RowType>>{stream.begin (), stream.end ()};
189+ EXPECT_THAT (actual, ElementsAre (IsOkAndHolds (RowType (" Steve" , 12 )),
190+ IsOkAndHolds (RowType (" Ann" , 42 ))));
191+ }
192+
141193TEST (ClientTest, ReadFailure) {
142194 auto conn = std::make_shared<MockConnection>();
143195 Client client (conn);
0 commit comments