-
Notifications
You must be signed in to change notification settings - Fork 10.4k
SignalR Java Client LongPolling Transport #6856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a82ed35
to
a6f4a27
Compare
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/DefaultHttpClient.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/DefaultHttpClient.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/DefaultHttpClient.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/HubConnection.java
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/HubConnection.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/JsonHubProtocol.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/HubConnection.java
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/HubConnection.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would poison both the LongPollingTransport and WebSocketTransport after they've stopped so they can no longer be used. Making transports restartable is more trouble than it's worth.
this.active = false; | ||
return Completable.error(new Exception("Failed to connect")); | ||
} else { | ||
this.active = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this just throw away the content of the first poll response?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first response should be empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to validate that. If the response is non-empty, the content should probably go in an exception that gets raised to the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't something we do in any of the clients. I don't think it's necessary. But we can add it
...gnalR/clients/java/signalr/src/main/java/com/microsoft/signalr/HttpHubConnectionBuilder.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/HubConnection.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/HubConnection.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/TransportEnum.java
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/test/java/com/microsoft/signalr/HubConnectionTest.java
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/DefaultHttpClient.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/HubConnection.java
Outdated
Show resolved
Hide resolved
@@ -368,7 +381,9 @@ public void run() { | |||
} | |||
|
|||
if (response.getRedirectUrl() == null) { | |||
if (!response.getAvailableTransports().contains("WebSockets")) { | |||
if ((this.transportEnum == TransportEnum.ALL && !(response.getAvailableTransports().contains("WebSockets") || response.getAvailableTransports().contains("LongPolling"))) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should cleanup this if statement
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/DefaultHttpClient.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
I think this is almost ready to go in. |
Ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't add a whole feature without tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do a formatting pass.
Also, you should manually test that the LongPolling stuff doesn't change the API level
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/DefaultHttpClient.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/HubConnection.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
...gnalR/clients/java/signalr/src/test/java/com/microsoft/signalr/LongPollingTransportTest.java
Outdated
Show resolved
Hide resolved
...gnalR/clients/java/signalr/src/test/java/com/microsoft/signalr/LongPollingTransportTest.java
Outdated
Show resolved
Hide resolved
...gnalR/clients/java/signalr/src/test/java/com/microsoft/signalr/LongPollingTransportTest.java
Outdated
Show resolved
Hide resolved
...gnalR/clients/java/signalr/src/test/java/com/microsoft/signalr/LongPollingTransportTest.java
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/DefaultHttpClient.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/DefaultHttpClient.java
Outdated
Show resolved
Hide resolved
...SignalR/clients/java/signalr/src/test/java/com/microsoft/signalr/WebSocketTransportTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Real close now 👍
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/DefaultHttpClient.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/HubConnection.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/JsonHubProtocol.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
...gnalR/clients/java/signalr/src/test/java/com/microsoft/signalr/LongPollingTransportTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look through the logs and add full stops where they're missing and check the log levels.
Also, should add a test for the auth tokens being passed through correctly.
And you have a couple flaky tests because you need to wait for the polls to finish before doing some checks.
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/main/java/com/microsoft/signalr/LongPollingTransport.java
Outdated
Show resolved
Hide resolved
src/SignalR/clients/java/signalr/src/test/java/com/microsoft/signalr/HubConnectionTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple comments and tests you should add, then good to go
private Completable poll(String url) { | ||
if (this.active) { | ||
pollUrl = url + "&_=" + System.currentTimeMillis(); | ||
logger.debug("Polling {}", pollUrl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: full stop
} else { | ||
logger.debug("Long Polling transport polling complete."); | ||
receiveLoop.onComplete(); | ||
if (!stopCalled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't being set anywhere.
A bool isn't very thread safe, might want to consider an atomic or something else.
Add a test that the 204 calls onclose and afterwards stop doesn't.
And another for calling stop and not getting 2 onclose callbacks.
|
||
assertFalse(onClosedRan.get()); | ||
transport.start("http://example.com").timeout(100, TimeUnit.SECONDS).blockingAwait(); | ||
block.blockingAwait(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These blocks should have timeouts
}); | ||
|
||
assertFalse(onClosedRan.get()); | ||
transport.start("http://example.com").timeout(100, TimeUnit.SECONDS).blockingAwait(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This became 100 seconds again
onClosedRan.set(true); | ||
assertEquals("Unexpected response code 999.", error); | ||
blocker.onComplete(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: newline
transport.setOnClose((error) -> {}); | ||
|
||
transport.start("http://example.com").timeout(1, TimeUnit.SECONDS).blockingAwait(); | ||
blocker.blockingAwait(1, TimeUnit.SECONDS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if you use the timeout overload of blockingAwait
you need to assert true on it
Have you done this? |
|
||
@Override | ||
public Completable stop() { | ||
if (!stopCalled.get()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this isn't thread safe
Can you try 16? That's what we claim to support |
Oh, thought it was 19. Just verified 16 as well. |
More transports!
Issue: #5379