@@ -619,4 +619,109 @@ describe("StreamLayerClient", function() {
619
619
) ;
620
620
} ) ;
621
621
} ) ;
622
+
623
+ it ( "Should not post offsets if no data" , async function ( ) {
624
+ const headers = new Headers ( ) ;
625
+ headers . append ( "X-Correlation-Id" , "9141392.f96875c-9422-4df4-bdfj" ) ;
626
+ const mockResponse = ( {
627
+ headers,
628
+ json : function ( ) {
629
+ return {
630
+ messages : [ ]
631
+ } ;
632
+ }
633
+ } as unknown ) as Response ;
634
+ pollStub . callsFake (
635
+ ( builder : any , params : any ) : Promise < Response > => {
636
+ return Promise . resolve ( mockResponse ) ;
637
+ }
638
+ ) ;
639
+
640
+ let settings = sandbox . createStubInstance ( core . OlpClientSettings ) ;
641
+ const subscribtionId = await streamLayerClient . subscribe (
642
+ new dataServiceRead . SubscribeRequest ( ) . withMode ( "serial" )
643
+ ) ;
644
+ const request = new dataServiceRead . PollRequest ( ) . withSubscriptionId (
645
+ subscribtionId
646
+ ) ;
647
+ const messages = await streamLayerClient . poll ( request ) ;
648
+
649
+ assert . isDefined ( messages ) ;
650
+ expect ( messages . length ) . to . be . equal ( 0 ) ;
651
+ expect ( commitOffsetsStub . notCalled ) ;
652
+ } ) ;
653
+
654
+ it ( "Should not throw if commiting offsets failed" , async function ( ) {
655
+ const headers = new Headers ( ) ;
656
+ headers . append ( "X-Correlation-Id" , "9141392.f96875c-9422-4df4-bdfj" ) ;
657
+ const mockResponse = ( {
658
+ headers,
659
+ json : function ( ) {
660
+ return {
661
+ messages : [
662
+ {
663
+ metaData : {
664
+ partition : "314010583" ,
665
+ checksum : "ff7494d6f17da702862e550c907c0a91" ,
666
+ compressedDataSize : 152417 ,
667
+ dataSize : 100500 ,
668
+ data : "" ,
669
+ dataHandle :
670
+ "iVBORw0-Lf9HdIZBfNEiKAA-AAAE-lFTkSuQmCC" ,
671
+ timestamp : 1517916706
672
+ } ,
673
+ offset : {
674
+ partition : 7 ,
675
+ offset : 38562
676
+ }
677
+ } ,
678
+ {
679
+ metaData : {
680
+ partition : "314010584" ,
681
+ checksum : "ff7494d6f17da702862e550c907c0a91" ,
682
+ dataSize : 100500 ,
683
+ data :
684
+ "7n348c7y49nry394y39yv39y384tvn3984tvn34ty034ynt3yvt983ny" ,
685
+ dataHandle : "" ,
686
+ timestamp : 1517916707
687
+ } ,
688
+ offset : {
689
+ partition : 8 ,
690
+ offset : 38563
691
+ }
692
+ }
693
+ ]
694
+ } ;
695
+ }
696
+ } as unknown ) as Response ;
697
+ pollStub . callsFake (
698
+ ( builder : any , params : any ) : Promise < Response > => {
699
+ return Promise . resolve ( mockResponse ) ;
700
+ }
701
+ ) ;
702
+
703
+ commitOffsetsStub . callsFake (
704
+ ( builder : any , params : any ) : Promise < Response > => {
705
+ return Promise . reject ( new Error ( "fake error" ) ) ;
706
+ }
707
+ ) ;
708
+
709
+ let settings = sandbox . createStubInstance ( core . OlpClientSettings ) ;
710
+ const params = {
711
+ catalogHrn : mockedHRN ,
712
+ layerId : mockedLayerId ,
713
+ settings : ( settings as unknown ) as core . OlpClientSettings
714
+ } ;
715
+ const subscribtionId = await streamLayerClient . subscribe (
716
+ new dataServiceRead . SubscribeRequest ( ) . withMode ( "serial" )
717
+ ) ;
718
+ const request = new dataServiceRead . PollRequest ( ) . withSubscriptionId (
719
+ subscribtionId
720
+ ) ;
721
+ const messages = await streamLayerClient . poll ( request ) ;
722
+
723
+ assert . isDefined ( messages ) ;
724
+ expect ( messages . length ) . to . be . equal ( 2 ) ;
725
+ expect ( messages [ 0 ] . metaData . dataSize ) . to . be . equal ( 100500 ) ;
726
+ } ) ;
622
727
} ) ;
0 commit comments