@@ -904,6 +904,68 @@ TEST(AsyncWriterConnectionTest, CloseError) {
904904 EXPECT_THAT (response.get (), StatusIs (PermanentError ().code ()));
905905}
906906
907+ TEST (AsyncWriterConnectionTest, FinalizeExpectedChecksumMismatchImmediate) {
908+ auto mock = std::make_unique<MockStream>();
909+ EXPECT_CALL (*mock, Cancel).Times (1 );
910+ EXPECT_CALL (*mock, Finish).WillOnce ([] {
911+ return make_ready_future (Status{});
912+ });
913+ auto hash = std::make_shared<MockHashFunction>();
914+ EXPECT_CALL (*hash, Finish).WillOnce (Return (storage::internal::HashValues{" ImIEBA==" , " " }));
915+
916+ auto tested = std::make_unique<AsyncWriterConnectionImpl>(
917+ TestOptions (), MakeRequest (), std::move (mock), hash, 1024 );
918+ auto response = tested->Finalize (WritePayload{}, storage::Crc32cChecksumValue (" AAAAAA==" ));
919+ EXPECT_THAT (response.get (), StatusIs (StatusCode::kDataLoss ));
920+ }
921+
922+ TEST (AsyncWriterConnectionTest, FinalizeExpectedChecksumMatchImmediate) {
923+ auto mock = std::make_unique<MockStream>();
924+ EXPECT_CALL (*mock, Cancel).Times (1 );
925+ EXPECT_CALL (*mock, Finish).WillOnce ([] {
926+ return make_ready_future (Status{});
927+ });
928+ EXPECT_CALL (*mock, Write).WillOnce ([](Request const &, grpc::WriteOptions) {
929+ return make_ready_future (true );
930+ });
931+ EXPECT_CALL (*mock, Read).WillOnce ([] {
932+ return make_ready_future (absl::make_optional (MakeTestResponse ()));
933+ });
934+ auto hash = std::make_shared<MockHashFunction>();
935+ EXPECT_CALL (*hash, Finish).WillRepeatedly (Return (storage::internal::HashValues{" ImIEBA==" , " " }));
936+
937+ auto tested = std::make_unique<AsyncWriterConnectionImpl>(
938+ TestOptions (), MakeRequest (), std::move (mock), hash, 1024 );
939+ auto response = tested->Finalize (WritePayload{}, storage::Crc32cChecksumValue (" ImIEBA==" ));
940+ EXPECT_THAT (response.get (), IsOk ());
941+ }
942+
943+ TEST (AsyncWriterConnectionTest, FinalizeExpectedChecksumMismatchOnComplete) {
944+ AsyncSequencer<bool > sequencer;
945+ auto mock = std::make_unique<MockStream>();
946+ EXPECT_CALL (*mock, Cancel).Times (1 );
947+ EXPECT_CALL (*mock, Finish).WillOnce ([] {
948+ return make_ready_future (Status{});
949+ });
950+ EXPECT_CALL (*mock, Write)
951+ .WillOnce ([&](Request const & request, grpc::WriteOptions wopt) {
952+ EXPECT_TRUE (request.finish_write ());
953+ EXPECT_TRUE (wopt.is_last_message ());
954+ return sequencer.PushBack (" Write" );
955+ });
956+ auto hash = std::make_shared<MockHashFunction>();
957+ EXPECT_CALL (*hash, Update (_, An<absl::Cord const &>(), _)).Times (1 );
958+ EXPECT_CALL (*hash, Finish).WillRepeatedly (Return (storage::internal::HashValues{" ImIEBA==" , " " }));
959+
960+ auto tested = std::make_unique<AsyncWriterConnectionImpl>(
961+ TestOptions (), MakeRequest (), std::move (mock), hash, 1024 );
962+ auto response = tested->Finalize (WritePayload (std::string (128 , ' A' )), storage::Crc32cChecksumValue (" AAAAAA==" ));
963+ auto next = sequencer.PopFrontWithName ();
964+ ASSERT_THAT (next.second , " Write" );
965+ next.first .set_value (true );
966+ EXPECT_THAT (response.get (), StatusIs (StatusCode::kDataLoss ));
967+ }
968+
907969GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
908970} // namespace storage_internal
909971} // namespace cloud
0 commit comments