package io.scalecube.gateway.websocket;

import io.scalecube.gateway.clientsdk.ClientMessage;
import io.scalecube.gateway.clientsdk.ClientSettings;
import io.scalecube.gateway.clientsdk.codec.WebsocketGatewayMessageCodec;
import io.scalecube.gateway.clientsdk.websocket.WebsocketClientTransport;
import io.scalecube.services.codec.DataCodec;
import java.time.Duration;
import reactor.core.publisher.Mono;
import reactor.ipc.netty.resources.LoopResources;

public class WebsocketClientTransportTest {

  public static void main(String[] args) throws InterruptedException {
    String contentType = "application/json";
    ClientSettings settings =
        ClientSettings.builder().contentType(contentType).host("localhost").port(7070).build();
    LoopResources loopResources = LoopResources.create("worker");

    WebsocketClientTransport transport =
        new WebsocketClientTransport(
            settings,
            new WebsocketGatewayMessageCodec(DataCodec.getInstance(contentType)),
            loopResources);

    ClientMessage request =
        ClientMessage.builder().qualifier("/greeting/one").header("sid", "1").build();

    Mono.delay(Duration.ofSeconds(3))
        .doOnTerminate(
            () -> {
              System.err.println("closing ...");
              transport.close().subscribe();
            })
        .subscribe();

    transport.requestResponse(request).subscribe(System.out::println, System.err::println);

    Thread.currentThread().join();
  }
}

@@ -339,71 +339,8 @@
 ec;%0A
-import java.time.Duration;%0Aimport reactor.core.publisher.Mono;%0A
 impo
@@ -1064,24 +1064,30 @@
 ).build();%0A%0A
+    //
     Mono.del
@@ -1112,12 +1112,19 @@
 nds(
-3
+15
 ))%0A
+    //
     
@@ -1143,16 +1143,22 @@
 minate(%0A
+    //
         
@@ -1169,16 +1169,22 @@
 () -%3E %7B%0A
+    //
         
@@ -1209,17 +1209,21 @@
 rintln(%22
-c
+### C
 losing .
@@ -1228,16 +1228,22 @@
  ...%22);%0A
+    //
         
@@ -1275,24 +1275,30 @@
 ubscribe();%0A
+    //
             
@@ -1300,16 +1300,22 @@
      %7D)%0A
+    //
         
@@ -1342,16 +1342,25 @@
 ransport
+%0A        
 .request
@@ -1376,16 +1376,25 @@
 request)
+%0A        
 .subscri
@@ -1396,16 +1396,29 @@
 bscribe(
+%0A            
 System.o
@@ -1449,16 +1449,58 @@
 :println
+, () -%3E System.out.println(%22### Complete%22)
 );%0A%0A    

Fix session send