@@ -515,6 +515,74 @@ public void checkStreamUploadThroughSendWithArgs() {
515
515
assertEquals ("{\" type\" :3,\" invocationId\" :\" 1\" }\u001E " , messages [3 ]);
516
516
}
517
517
518
+ @ Test
519
+ public void streamMapIsClearedOnClose () {
520
+ MockTransport mockTransport = new MockTransport ();
521
+ HubConnection hubConnection = TestUtils .createHubConnection ("http://example.com" , mockTransport );
522
+
523
+ hubConnection .start ().timeout (1 , TimeUnit .SECONDS ).blockingAwait ();
524
+
525
+ ReplaySubject <String > stream = ReplaySubject .create ();
526
+ hubConnection .send ("UploadStream" , stream , 12 );
527
+
528
+ stream .onNext ("FirstItem" );
529
+ String [] messages = mockTransport .getSentMessages ();
530
+ assertEquals ("{\" type\" :1,\" target\" :\" UploadStream\" ,\" arguments\" :[12],\" streamIds\" :[\" 1\" ]}\u001E " , messages [1 ]);
531
+ assertEquals ("{\" type\" :2,\" invocationId\" :\" 1\" ,\" item\" :\" FirstItem\" }\u001E " , messages [2 ]);
532
+
533
+ stream .onComplete ();
534
+ messages = mockTransport .getSentMessages ();
535
+ assertEquals ("{\" type\" :3,\" invocationId\" :\" 1\" }\u001E " , messages [3 ]);
536
+
537
+ hubConnection .stop ().timeout (1 , TimeUnit .SECONDS ).blockingAwait ();
538
+
539
+ assertTrue (hubConnection .getStreamMap ().isEmpty ());
540
+ }
541
+
542
+ @ Test
543
+ public void streamMapEntriesRemovedOnStreamClose () {
544
+ MockTransport mockTransport = new MockTransport ();
545
+ HubConnection hubConnection = TestUtils .createHubConnection ("http://example.com" , mockTransport );
546
+
547
+ hubConnection .start ().timeout (1 , TimeUnit .SECONDS ).blockingAwait ();
548
+
549
+ ReplaySubject <String > stream = ReplaySubject .create ();
550
+ hubConnection .send ("UploadStream" , stream , 12 );
551
+
552
+ ReplaySubject <String > secondStream = ReplaySubject .create ();
553
+ hubConnection .send ("SecondUploadStream" , secondStream , 13 );
554
+
555
+
556
+ stream .onNext ("FirstItem" );
557
+ secondStream .onNext ("SecondItem" );
558
+ String [] messages = mockTransport .getSentMessages ();
559
+ assertEquals ("{\" type\" :1,\" target\" :\" UploadStream\" ,\" arguments\" :[12],\" streamIds\" :[\" 1\" ]}\u001E " , messages [1 ]);
560
+ assertEquals ("{\" type\" :1,\" target\" :\" SecondUploadStream\" ,\" arguments\" :[13],\" streamIds\" :[\" 2\" ]}\u001E " , messages [2 ]);
561
+ assertEquals ("{\" type\" :2,\" invocationId\" :\" 1\" ,\" item\" :\" FirstItem\" }\u001E " , messages [3 ]);
562
+ assertEquals ("{\" type\" :2,\" invocationId\" :\" 2\" ,\" item\" :\" SecondItem\" }\u001E " , messages [4 ]);
563
+
564
+
565
+ assertEquals (2 , hubConnection .getStreamMap ().size ());
566
+ assertTrue (hubConnection .getStreamMap ().keySet ().contains ("1" ));
567
+ assertTrue (hubConnection .getStreamMap ().keySet ().contains ("2" ));
568
+
569
+ // Verify that we clear the entry from the stream map after we clear the first stream.
570
+ stream .onComplete ();
571
+ assertEquals (1 , hubConnection .getStreamMap ().size ());
572
+ assertTrue (hubConnection .getStreamMap ().keySet ().contains ("2" ));
573
+
574
+ secondStream .onError (new Exception ("Exception" ));
575
+ assertEquals (0 , hubConnection .getStreamMap ().size ());
576
+ assertTrue (hubConnection .getStreamMap ().isEmpty ());
577
+
578
+ messages = mockTransport .getSentMessages ();
579
+ assertEquals ("{\" type\" :3,\" invocationId\" :\" 1\" }\u001E " , messages [5 ]);
580
+ assertEquals ("{\" type\" :3,\" invocationId\" :\" 2\" ,\" error\" :\" java.lang.Exception: Exception\" }\u001E " , messages [6 ]);
581
+
582
+ hubConnection .stop ().timeout (1 , TimeUnit .SECONDS ).blockingAwait ();
583
+ assertTrue (hubConnection .getStreamMap ().isEmpty ());
584
+ }
585
+
518
586
@ Test
519
587
public void useSameSubjectMultipleTimes () {
520
588
MockTransport mockTransport = new MockTransport ();
0 commit comments