Merge pull request #2920 from aspnet/release/2.2

This commit is contained in:
Mikael Mengistu 2018-09-06 12:05:42 -07:00 committed by GitHub
commit 4dbc21c785
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 13 deletions

View File

@ -50,7 +50,7 @@ public class HubConnection {
if (handshakeResponse.error != null) {
String errorMessage = "Error in handshake " + handshakeResponse.error;
logger.log(LogLevel.Error, errorMessage);
throw new Exception(errorMessage);
throw new HubException(errorMessage);
}
handshakeReceived = true;

View File

@ -47,16 +47,10 @@ public class JsonHubProtocol implements HubProtocol {
hubMessages.add(new InvocationMessage(target, new Object[] {args}));
break;
case STREAM_ITEM:
throw new UnsupportedOperationException("Support for streaming is not yet available");
case COMPLETION:
//Don't care yet
break;
case STREAM_INVOCATION:
//Don't care yet;
throw new UnsupportedOperationException("Support for streaming is not yet available");
case CANCEL_INVOCATION:
// Not tracking invocations yet
break;
throw new UnsupportedOperationException(String.format("The message type %s is not supported yet.", messageType));
case PING:
//Ping
hubMessages.add(new PingMessage());

View File

@ -14,6 +14,9 @@ import static org.junit.Assert.*;
public class HubConnectionTest {
private static final String RECORD_SEPARATOR = "\u001e";
@Rule
public ExpectedException exceptionRule = ExpectedException.none();
@Test
public void checkHubConnectionState() throws Exception {
Transport mockTransport = new MockTransport();
@ -40,6 +43,18 @@ public class HubConnectionTest {
assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState());
}
@Test
public void HubConnectionReceiveHandshakeResponseWithError() throws Exception {
exceptionRule.expect(HubException.class);
exceptionRule.expectMessage("Requested protocol 'messagepack' is not available.");
MockTransport mockTransport = new MockTransport();
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport, true);
hubConnection.start();
mockTransport.receiveMessage("{\"error\":\"Requested protocol 'messagepack' is not available.\"}" + RECORD_SEPARATOR);
}
@Test
public void RegisteringMultipleHandlersAndBothGetTriggered() throws Exception {
AtomicReference<Double> value = new AtomicReference<>(0.0);
@ -673,9 +688,6 @@ public class HubConnectionTest {
assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState());
}
@Rule
public ExpectedException exceptionRule = ExpectedException.none();
@Test
public void CannotSendBeforeStart() throws Exception {
exceptionRule.expect(HubException.class);

View File

@ -103,7 +103,7 @@ public class JsonHubProtocolTest {
@Test
public void ParseSingleUnsupportedStreamItemMessage() {
exceptionRule.expect(UnsupportedOperationException.class);
exceptionRule.expectMessage("Support for streaming is not yet available");
exceptionRule.expectMessage("The message type STREAM_ITEM is not supported yet.");
String stringifiedMessage = "{\"type\":2,\"Id\":1,\"Item\":42}\u001E";
HubMessage[] messages = jsonHubProtocol.parseMessages(stringifiedMessage);
}
@ -111,8 +111,25 @@ public class JsonHubProtocolTest {
@Test
public void ParseSingleUnsupportedStreamInvocationMessage() {
exceptionRule.expect(UnsupportedOperationException.class);
exceptionRule.expectMessage("Support for streaming is not yet available");
exceptionRule.expectMessage("The message type STREAM_INVOCATION is not supported yet.");
String stringifiedMessage = "{\"type\":4,\"Id\":1,\"target\":\"test\",\"arguments\":[42]}\u001E";
HubMessage[] messages = jsonHubProtocol.parseMessages(stringifiedMessage);
}
@Test
public void ParseSingleUnsupportedCancelInvocationMessage() {
exceptionRule.expect(UnsupportedOperationException.class);
exceptionRule.expectMessage("The message type CANCEL_INVOCATION is not supported yet.");
String stringifiedMessage = "{\"type\":5,\"invocationId\":123}\u001E";
HubMessage[] messages = jsonHubProtocol.parseMessages(stringifiedMessage);
}
@Test
public void ParseSingleUnsupportedCompletionMessage() {
exceptionRule.expect(UnsupportedOperationException.class);
exceptionRule.expectMessage("The message type COMPLETION is not supported yet.");
String stringifiedMessage = "{\"type\":3,\"invocationId\":123}\u001E";
HubMessage[] messages = jsonHubProtocol.parseMessages(stringifiedMessage);
}