List of usage examples for java.time Duration ofMillis
public static Duration ofMillis(long millis)
From source file:org.springframework.web.reactive.socket.WebSocketIntegrationTests.java
@Test public void subProtocol() throws Exception { String protocol = "echo-v1"; AtomicReference<HandshakeInfo> infoRef = new AtomicReference<>(); MonoProcessor<Object> output = MonoProcessor.create(); this.client.execute(getUrl("/sub-protocol"), new WebSocketHandler() { @Override//from www. j a va 2 s. co m public List<String> getSubProtocols() { return Collections.singletonList(protocol); } @Override public Mono<Void> handle(WebSocketSession session) { infoRef.set(session.getHandshakeInfo()); return session.receive().map(WebSocketMessage::getPayloadAsText).subscribeWith(output).then(); } }).block(Duration.ofMillis(5000)); HandshakeInfo info = infoRef.get(); assertThat(info.getHeaders().getFirst("Upgrade"), Matchers.equalToIgnoringCase("websocket")); assertEquals(protocol, info.getHeaders().getFirst("Sec-WebSocket-Protocol")); assertEquals("Wrong protocol accepted", protocol, info.getSubProtocol()); assertEquals("Wrong protocol detected on the server side", protocol, output.block(Duration.ofMillis(5000))); }
From source file:org.springframework.web.reactive.socket.WebSocketIntegrationTests.java
@Test public void customHeader() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add("my-header", "my-value"); MonoProcessor<Object> output = MonoProcessor.create(); this.client.execute(getUrl("/custom-header"), headers, session -> session.receive().map(WebSocketMessage::getPayloadAsText).subscribeWith(output).then()) .block(Duration.ofMillis(5000)); assertEquals("my-header:my-value", output.block(Duration.ofMillis(5000))); }