1616package io .reactivesocket ;
1717
1818import io .reactivesocket .lease .FairLeaseGovernor ;
19+ import io .reactivesocket .rx .Completable ;
1920import io .reactivex .disposables .Disposable ;
2021import io .reactivex .observables .ConnectableObservable ;
2122import io .reactivex .subscribers .TestSubscriber ;
@@ -256,6 +257,74 @@ private void awaitSocketAvailability(ReactiveSocket socket, long timeout, TimeUn
256257 assertTrue ("client socket has positive avaibility" , socket .availability () > 0.0 );
257258 }
258259
260+ @ Test (timeout = 2000 )
261+ public void testShutdownListener () throws Exception {
262+ socketClient = DefaultReactiveSocket .fromClientConnection (
263+ clientConnection ,
264+ ConnectionSetupPayload .create ("UTF-8" , "UTF-8" , NO_FLAGS ),
265+ err -> err .printStackTrace ()
266+ );
267+
268+ CountDownLatch latch = new CountDownLatch (1 );
269+
270+ socketClient .onShutdown (new Completable () {
271+ @ Override
272+ public void success () {
273+ latch .countDown ();
274+ }
275+
276+ @ Override
277+ public void error (Throwable e ) {
278+
279+ }
280+ });
281+
282+ socketClient .close ();
283+
284+ latch .await ();
285+ }
286+
287+ @ Test (timeout = 2000 )
288+ public void testMultipleShutdownListeners () throws Exception {
289+ socketClient = DefaultReactiveSocket .fromClientConnection (
290+ clientConnection ,
291+ ConnectionSetupPayload .create ("UTF-8" , "UTF-8" , NO_FLAGS ),
292+ err -> err .printStackTrace ()
293+ );
294+
295+ CountDownLatch latch = new CountDownLatch (2 );
296+
297+ socketClient
298+ .onShutdown (new Completable () {
299+ @ Override
300+ public void success () {
301+ latch .countDown ();
302+ }
303+
304+ @ Override
305+ public void error (Throwable e ) {
306+
307+ }
308+ });
309+
310+ socketClient
311+ .onShutdown (new Completable () {
312+ @ Override
313+ public void success () {
314+ latch .countDown ();
315+ }
316+
317+ @ Override
318+ public void error (Throwable e ) {
319+
320+ }
321+ });
322+
323+ socketClient .close ();
324+
325+ latch .await ();
326+ }
327+
259328 @ Test (timeout =2000 )
260329 @ Theory
261330 public void testRequestResponse (int setupFlag ) throws InterruptedException {
@@ -269,7 +338,7 @@ public void testRequestResponse(int setupFlag) throws InterruptedException {
269338 ts .assertNoErrors ();
270339 ts .assertValue (TestUtil .utf8EncodedPayload ("hello world" , null ));
271340 }
272-
341+
273342 @ Test (timeout =2000 , expected =IllegalStateException .class )
274343 public void testRequestResponsePremature () throws InterruptedException {
275344 socketClient = DefaultReactiveSocket .fromClientConnection (
0 commit comments