3333import com .google .api .gax .retrying .ResultRetryAlgorithm ;
3434import com .google .api .services .storage .model .StorageObject ;
3535import com .google .cloud .storage .FakeHttpServer .HttpRequestHandler ;
36+ import com .google .cloud .storage .it .ChecksummedTestContent ;
3637import com .google .cloud .storage .it .runner .StorageITRunner ;
3738import com .google .cloud .storage .it .runner .annotations .Backend ;
3839import com .google .cloud .storage .it .runner .annotations .ParallelFriendly ;
3940import com .google .cloud .storage .it .runner .annotations .SingleBackend ;
41+ import com .google .common .collect .ImmutableList ;
4042import com .google .common .collect .ImmutableMap ;
4143import io .grpc .netty .shaded .io .netty .buffer .ByteBuf ;
4244import io .grpc .netty .shaded .io .netty .buffer .Unpooled ;
@@ -791,13 +793,23 @@ public void jsonParseFailure() throws Exception {
791793 }
792794
793795 @ Test
794- public void jsonDeserializationOnlyAttemptedWhenContentPresent () throws Exception {
796+ public void whenContentNotPresentFallBackToHeaders () throws Exception {
795797
798+ ChecksummedTestContent testContent = ChecksummedTestContent .of (new byte [] {'A' });
796799 HttpRequestHandler handler =
797800 req -> {
798801 DefaultFullHttpResponse resp = new DefaultFullHttpResponse (req .protocolVersion (), OK );
799802 resp .headers ().set (CONTENT_TYPE , "text/html; charset=UTF-8" );
800- resp .headers ().set ("x-goog-stored-content-length" , "0" );
803+ resp .headers ().set ("x-goog-generation" , "3" );
804+ resp .headers ().set ("x-goog-metageneration" , "7" );
805+ resp .headers ().set ("x-goog-stored-content-length" , "1" );
806+ resp .headers ().set ("x-goog-stored-content-encoding" , "identity" );
807+ resp .headers ()
808+ .set (
809+ "x-goog-hash" ,
810+ ImmutableList .of (
811+ "crc32c=" + testContent .getCrc32cBase64 (),
812+ "md5=" + testContent .getMd5Base64 ()));
801813 return resp ;
802814 };
803815
@@ -810,13 +822,15 @@ public void jsonDeserializationOnlyAttemptedWhenContentPresent() throws Exceptio
810822 new JsonResumableSessionPutTask (
811823 httpClientContext ,
812824 jsonResumableWrite (uploadUrl ),
813- RewindableContent .empty ( ),
814- HttpContentRange .of (0 ));
825+ RewindableContent .of ( ByteBuffer . wrap ( testContent . getBytes ()) ),
826+ HttpContentRange .of (1 ));
815827
816828 ResumableOperationResult <@ Nullable StorageObject > operationResult = task .call ();
817829 StorageObject call = operationResult .getObject ();
818- assertThat (call ).isNull ();
819- assertThat (operationResult .getPersistedSize ()).isEqualTo (0L );
830+ assertThat (call ).isNotNull ();
831+ assertThat (call .getCrc32c ()).isEqualTo (testContent .getCrc32cBase64 ());
832+ assertThat (call .getSize ()).isEqualTo (BigInteger .ONE );
833+ assertThat (operationResult .getPersistedSize ()).isEqualTo (1L );
820834 }
821835 }
822836
0 commit comments