Skip to content

Commit

Permalink
bug: SslConfiguration::setProtocol (#9118)
Browse files Browse the repository at this point in the history
* bug: SslConfiguration::setProtocol

* test: Deflake the BinaryWebSocketSpec (#8725)

---------

Co-authored-by: Tim Yates <tim.yates@gmail.com>
  • Loading branch information
sdelamo and timyates authored Apr 17, 2023
1 parent 77d00c7 commit 1cdac4a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void onOpen(String topic, String username, WebSocketSession session) {
this.topic = topic;
this.username = username;
this.session = session;
System.out.println("Client session opened for username = " + username);
System.out.println("Client session " + session.getId() + " opened for username = " + username);
}

public String getTopic() {
Expand All @@ -72,7 +72,7 @@ public WebSocketSession getSession() {
@OnMessage
public void onMessage(
byte[] message) {
System.out.println("Client received message = " + new String(message));
System.out.println("Client " + username + " received message = " + new String(message));
replies.add(new String(message));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void onOpen(String topic, String username, WebSocketSession session) {
if(isValid(topic, session, openSession)) {
String msg = "[" + username + "] Joined!";
System.out.println("Server sending msg = " + msg);
openSession.sendSync(msg.getBytes());
openSession.sendAsync(msg.getBytes());
}
}
}
Expand All @@ -55,7 +55,7 @@ public void onMessage(
if(isValid(topic, session, openSession)) {
String msg = "[" + username + "] " + new String(message);
System.out.println("Server sending msg = " + msg);
openSession.sendSync(msg.getBytes());
openSession.sendAsync(msg.getBytes());
}
}
}
Expand All @@ -72,7 +72,7 @@ public void onClose(
if(isValid(topic, session, openSession)) {
String msg = "[" + username + "] Disconnected!";
System.out.println("Server sending msg = " + msg);
openSession.sendSync(msg.getBytes());
openSession.sendAsync(msg.getBytes());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,14 @@ import jakarta.inject.Singleton
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import spock.lang.Issue
import spock.lang.Retry
import spock.lang.Specification
import spock.util.concurrent.PollingConditions

import java.nio.ByteBuffer
import java.nio.charset.StandardCharsets

@Retry
class BinaryWebSocketSpec extends Specification {

@Retry
void "test binary websocket exchange"() {
given:
EmbeddedServer embeddedServer = ApplicationContext.builder('micronaut.server.netty.log-level':'TRACE').run(EmbeddedServer)
Expand All @@ -69,7 +66,6 @@ class BinaryWebSocketSpec extends Specification {
fred.replies.size() == 1
}


when:"A message is sent"
fred.send("Hello bob!".bytes)

Expand All @@ -86,7 +82,6 @@ class BinaryWebSocketSpec extends Specification {

then:
conditions.eventually {

fred.replies.contains("[bob] Hi fred. How are things?")
fred.replies.size() == 2
bob.replies.contains("[fred] Hello bob!")
Expand All @@ -99,8 +94,6 @@ class BinaryWebSocketSpec extends Specification {

when:
bob.close()
sleep(1000)


then:
conditions.eventually {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public void setProtocols(String[] protocols) {
* @param protocol The protocol
*/
public void setProtocol(String protocol) {
if (!StringUtils.isNotEmpty(protocol)) {
if (StringUtils.isNotEmpty(protocol)) {
this.protocol = protocol;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.micronaut.http.ssl

import spock.lang.Specification

class SslConfigurationSpec extends Specification {

void "setProtocol should override protocol"() {
given:
SslConfiguration configuration = new SslConfiguration()

expect:
configuration.protocol.isPresent()
"TLS" == configuration.protocol.get()

when:
configuration.protocol = "foo"

then:
configuration.protocol.isPresent()
"foo" == configuration.protocol.get()
}

}

0 comments on commit 1cdac4a

Please sign in to comment.