Merge pull request #3180 from dotnet-maestro-bot/merge/release/2.2-to-master
[automated] Merge branch 'release/2.2' => 'master'
This commit is contained in:
commit
4990c315e5
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
package com.microsoft.signalr;
|
package com.microsoft.signalr;
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -18,7 +17,7 @@ public class HttpHubConnectionBuilder {
|
||||||
private HttpClient httpClient;
|
private HttpClient httpClient;
|
||||||
private boolean skipNegotiate;
|
private boolean skipNegotiate;
|
||||||
private Single<String> accessTokenProvider;
|
private Single<String> accessTokenProvider;
|
||||||
private Duration handshakeResponseTimeout;
|
private long handshakeResponseTimeout = 0;
|
||||||
private Map<String, String> headers;
|
private Map<String, String> headers;
|
||||||
|
|
||||||
HttpHubConnectionBuilder(String url) {
|
HttpHubConnectionBuilder(String url) {
|
||||||
|
|
@ -73,11 +72,11 @@ public class HttpHubConnectionBuilder {
|
||||||
/**
|
/**
|
||||||
* Sets the duration the {@link HubConnection} should wait for a Handshake Response from the server.
|
* Sets the duration the {@link HubConnection} should wait for a Handshake Response from the server.
|
||||||
*
|
*
|
||||||
* @param timeout The duration that the {@link HubConnection} should wait for a Handshake Response from the server.
|
* @param timeoutInMilliseconds The duration (specified in milliseconds) that the {@link HubConnection} should wait for a Handshake Response from the server.
|
||||||
* @return This instance of the HttpHubConnectionBuilder.
|
* @return This instance of the HttpHubConnectionBuilder.
|
||||||
*/
|
*/
|
||||||
public HttpHubConnectionBuilder withHandshakeResponseTimeout(Duration timeout) {
|
public HttpHubConnectionBuilder withHandshakeResponseTimeout(long timeoutInMilliseconds) {
|
||||||
this.handshakeResponseTimeout = timeout;
|
this.handshakeResponseTimeout = timeoutInMilliseconds;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,4 +114,4 @@ public class HttpHubConnectionBuilder {
|
||||||
public HubConnection build() {
|
public HubConnection build() {
|
||||||
return new HubConnection(url, transport, skipNegotiate, httpClient, accessTokenProvider, handshakeResponseTimeout, headers);
|
return new HubConnection(url, transport, skipNegotiate, httpClient, accessTokenProvider, handshakeResponseTimeout, headers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
package com.microsoft.signalr;
|
package com.microsoft.signalr;
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -47,57 +46,57 @@ public class HubConnection {
|
||||||
private Timer pingTimer = null;
|
private Timer pingTimer = null;
|
||||||
private final AtomicLong nextServerTimeout = new AtomicLong();
|
private final AtomicLong nextServerTimeout = new AtomicLong();
|
||||||
private final AtomicLong nextPingActivation = new AtomicLong();
|
private final AtomicLong nextPingActivation = new AtomicLong();
|
||||||
private Duration keepAliveInterval = Duration.ofSeconds(15);
|
private long keepAliveInterval = 15*1000;
|
||||||
private Duration serverTimeout = Duration.ofSeconds(30);
|
private long serverTimeout = 30*1000;
|
||||||
private Duration tickRate = Duration.ofSeconds(1);
|
private long tickRate = 1000;
|
||||||
private CompletableFuture<Void> handshakeResponseFuture;
|
private CompletableFuture<Void> handshakeResponseFuture;
|
||||||
private Duration handshakeResponseTimeout = Duration.ofSeconds(15);
|
private long handshakeResponseTimeout = 15*1000;
|
||||||
private final Logger logger = LoggerFactory.getLogger(HubConnection.class);
|
private final Logger logger = LoggerFactory.getLogger(HubConnection.class);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the server timeout interval for the connection.
|
* Sets the server timeout interval for the connection.
|
||||||
*
|
*
|
||||||
* @param serverTimeout The server timeout duration.
|
* @param serverTimeoutInMilliseconds The server timeout duration (specified in milliseconds).
|
||||||
*/
|
*/
|
||||||
public void setServerTimeout(Duration serverTimeout) {
|
public void setServerTimeout(long serverTimeoutInMilliseconds) {
|
||||||
this.serverTimeout = serverTimeout;
|
this.serverTimeout = serverTimeoutInMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the server timeout duration.
|
* Gets the server timeout duration.
|
||||||
*
|
*
|
||||||
* @return The server timeout duration.
|
* @return The server timeout duration (specified in milliseconds).
|
||||||
*/
|
*/
|
||||||
public Duration getServerTimeout() {
|
public long getServerTimeout() {
|
||||||
return this.serverTimeout;
|
return this.serverTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the keep alive interval duration.
|
* Sets the keep alive interval duration.
|
||||||
*
|
*
|
||||||
* @param keepAliveInterval The interval at which the connection should send keep alive messages.
|
* @param keepAliveIntervalInMilliseconds The interval (specified in milliseconds) at which the connection should send keep alive messages.
|
||||||
*/
|
*/
|
||||||
public void setKeepAliveInterval(Duration keepAliveInterval) {
|
public void setKeepAliveInterval(long keepAliveIntervalInMilliseconds) {
|
||||||
this.keepAliveInterval = keepAliveInterval;
|
this.keepAliveInterval = keepAliveIntervalInMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the keep alive interval.
|
* Gets the keep alive interval.
|
||||||
*
|
*
|
||||||
* @return The interval between keep alive messages.
|
* @return The interval (specified in milliseconds) between keep alive messages.
|
||||||
*/
|
*/
|
||||||
public Duration getKeepAliveInterval() {
|
public long getKeepAliveInterval() {
|
||||||
return this.keepAliveInterval;
|
return this.keepAliveInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For testing purposes
|
// For testing purposes
|
||||||
void setTickRate(Duration tickRate) {
|
void setTickRate(long tickRateInMilliseconds) {
|
||||||
this.tickRate = tickRate;
|
this.tickRate = tickRateInMilliseconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
HubConnection(String url, Transport transport, boolean skipNegotiate, HttpClient httpClient,
|
HubConnection(String url, Transport transport, boolean skipNegotiate, HttpClient httpClient,
|
||||||
Single<String> accessTokenProvider, Duration handshakeResponseTimeout, Map<String, String> headers) {
|
Single<String> accessTokenProvider, long handshakeResponseTimeout, Map<String, String> headers) {
|
||||||
if (url == null || url.isEmpty()) {
|
if (url == null || url.isEmpty()) {
|
||||||
throw new IllegalArgumentException("A valid url is required.");
|
throw new IllegalArgumentException("A valid url is required.");
|
||||||
}
|
}
|
||||||
|
|
@ -121,7 +120,7 @@ public class HubConnection {
|
||||||
this.transport = transport;
|
this.transport = transport;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handshakeResponseTimeout != null) {
|
if (handshakeResponseTimeout > 0) {
|
||||||
this.handshakeResponseTimeout = handshakeResponseTimeout;
|
this.handshakeResponseTimeout = handshakeResponseTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -249,6 +248,7 @@ public class HubConnection {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a connection to the server.
|
* Starts a connection to the server.
|
||||||
|
*
|
||||||
* @return A Completable that completes when the connection has been established.
|
* @return A Completable that completes when the connection has been established.
|
||||||
*/
|
*/
|
||||||
public Completable start() {
|
public Completable start() {
|
||||||
|
|
@ -287,7 +287,7 @@ public class HubConnection {
|
||||||
String handshake = HandshakeProtocol.createHandshakeRequestMessage(
|
String handshake = HandshakeProtocol.createHandshakeRequestMessage(
|
||||||
new HandshakeRequestMessage(protocol.getName(), protocol.getVersion()));
|
new HandshakeRequestMessage(protocol.getName(), protocol.getVersion()));
|
||||||
return transport.send(handshake).thenCompose((innerFuture) -> {
|
return transport.send(handshake).thenCompose((innerFuture) -> {
|
||||||
timeoutHandshakeResponse(handshakeResponseTimeout.toMillis(), TimeUnit.MILLISECONDS);
|
timeoutHandshakeResponse(handshakeResponseTimeout, TimeUnit.MILLISECONDS);
|
||||||
return handshakeResponseFuture.thenRun(() -> {
|
return handshakeResponseFuture.thenRun(() -> {
|
||||||
hubConnectionStateLock.lock();
|
hubConnectionStateLock.lock();
|
||||||
try {
|
try {
|
||||||
|
|
@ -316,7 +316,7 @@ public class HubConnection {
|
||||||
pingTimer.cancel();
|
pingTimer.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, new Date(0), tickRate.toMillis());
|
}, new Date(0), tickRate);
|
||||||
} finally {
|
} finally {
|
||||||
hubConnectionStateLock.unlock();
|
hubConnectionStateLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
@ -492,11 +492,11 @@ public class HubConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetServerTimeout() {
|
private void resetServerTimeout() {
|
||||||
this.nextServerTimeout.set(System.currentTimeMillis() + serverTimeout.toMillis());
|
this.nextServerTimeout.set(System.currentTimeMillis() + serverTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetKeepAlive() {
|
private void resetKeepAlive() {
|
||||||
this.nextPingActivation.set(System.currentTimeMillis() + keepAliveInterval.toMillis());
|
this.nextPingActivation.set(System.currentTimeMillis() + keepAliveInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -824,4 +824,4 @@ public class HubConnection {
|
||||||
return handlers.get(0).getClasses();
|
return handlers.get(0).getClasses();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ package com.microsoft.signalr;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CancellationException;
|
import java.util.concurrent.CancellationException;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
@ -68,7 +67,7 @@ class HubConnectionTest {
|
||||||
.withTransport(mockTransport)
|
.withTransport(mockTransport)
|
||||||
.withHttpClient(new TestHttpClient())
|
.withHttpClient(new TestHttpClient())
|
||||||
.shouldSkipNegotiate(true)
|
.shouldSkipNegotiate(true)
|
||||||
.withHandshakeResponseTimeout(Duration.ofMillis(100))
|
.withHandshakeResponseTimeout(100)
|
||||||
.build();
|
.build();
|
||||||
Throwable exception = assertThrows(RuntimeException.class, () -> hubConnection.start().blockingAwait(1000, TimeUnit.MILLISECONDS));
|
Throwable exception = assertThrows(RuntimeException.class, () -> hubConnection.start().blockingAwait(1000, TimeUnit.MILLISECONDS));
|
||||||
assertEquals(ExecutionException.class, exception.getCause().getClass());
|
assertEquals(ExecutionException.class, exception.getCause().getClass());
|
||||||
|
|
@ -1066,8 +1065,8 @@ class HubConnectionTest {
|
||||||
@Test
|
@Test
|
||||||
public void connectionTimesOutIfServerDoesNotSendMessage() throws InterruptedException, ExecutionException, TimeoutException {
|
public void connectionTimesOutIfServerDoesNotSendMessage() throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com");
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com");
|
||||||
hubConnection.setServerTimeout(Duration.ofMillis(1));
|
hubConnection.setServerTimeout(1);
|
||||||
hubConnection.setTickRate(Duration.ofMillis(1));
|
hubConnection.setTickRate(1);
|
||||||
CompletableFuture<Exception> closedFuture = new CompletableFuture<>();
|
CompletableFuture<Exception> closedFuture = new CompletableFuture<>();
|
||||||
hubConnection.onClosed((e) -> {
|
hubConnection.onClosed((e) -> {
|
||||||
closedFuture.complete(e);
|
closedFuture.complete(e);
|
||||||
|
|
@ -1082,8 +1081,8 @@ class HubConnectionTest {
|
||||||
public void connectionSendsPingsRegularly() throws InterruptedException {
|
public void connectionSendsPingsRegularly() throws InterruptedException {
|
||||||
MockTransport mockTransport = new MockTransport(true, false);
|
MockTransport mockTransport = new MockTransport(true, false);
|
||||||
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
||||||
hubConnection.setKeepAliveInterval(Duration.ofMillis(1));
|
hubConnection.setKeepAliveInterval(1);
|
||||||
hubConnection.setTickRate(Duration.ofMillis(1));
|
hubConnection.setTickRate(1);
|
||||||
|
|
||||||
hubConnection.start().blockingAwait(1000, TimeUnit.MILLISECONDS);
|
hubConnection.start().blockingAwait(1000, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue