[Java] Change StreamItem to have items instead of results (#3317)

This commit is contained in:
Mikael Mengistu 2018-11-19 10:32:43 -08:00 committed by GitHub
parent 6c4f7b430a
commit 86787f1c28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 19 deletions

View File

@ -30,8 +30,8 @@ class InvocationRequest {
}
public void addItem(StreamItem streamItem) {
if (streamItem.getResult() != null) {
pendingCall.onNext(streamItem.getResult());
if (streamItem.getItem() != null) {
pendingCall.onNext(streamItem.getItem());
}
}

View File

@ -73,15 +73,13 @@ class JsonHubProtocol implements HubProtocol {
error = reader.nextString();
break;
case "result":
case "item":
if (invocationId == null || binder.getReturnType(invocationId) == null) {
resultToken = jsonParser.parse(reader);
} else {
result = gson.fromJson(reader, binder.getReturnType(invocationId));
}
break;
case "item":
reader.skipValue();
break;
case "arguments":
if (target != null) {
boolean startedArray = false;

View File

@ -6,19 +6,19 @@ package com.microsoft.signalr;
final class StreamItem extends HubMessage {
private final int type = HubMessageType.STREAM_ITEM.value;
private final String invocationId;
private final Object result;
private final Object item;
public StreamItem(String invocationId, Object result) {
public StreamItem(String invocationId, Object item) {
this.invocationId = invocationId;
this.result = result;
this.item = item;
}
public String getInvocationId() {
return invocationId;
}
public Object getResult() {
return result;
public Object getItem() {
return item;
}
@Override

View File

@ -388,7 +388,7 @@ class HubConnectionTest {
assertFalse(completed.get());
assertFalse(onNextCalled.get());
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"result\":\"First\"}" + RECORD_SEPARATOR);
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"item\":\"First\"}" + RECORD_SEPARATOR);
assertTrue(onNextCalled.get());
@ -416,7 +416,7 @@ class HubConnectionTest {
assertFalse(completed.get());
assertFalse(onNextCalled.get());
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"result\":\"First\"}" + RECORD_SEPARATOR);
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"item\":\"First\"}" + RECORD_SEPARATOR);
assertTrue(onNextCalled.get());
@ -446,7 +446,7 @@ class HubConnectionTest {
assertFalse(onErrorCalled.get());
assertFalse(onNextCalled.get());
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"result\":\"First\"}" + RECORD_SEPARATOR);
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"item\":\"First\"}" + RECORD_SEPARATOR);
assertTrue(onNextCalled.get());
@ -474,8 +474,8 @@ class HubConnectionTest {
assertEquals("{\"type\":4,\"invocationId\":\"1\",\"target\":\"echo\",\"arguments\":[\"message\"]}" + RECORD_SEPARATOR, mockTransport.getSentMessages()[1]);
assertFalse(completed.get());
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"result\":\"First\"}" + RECORD_SEPARATOR);
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"result\":\"Second\"}" + RECORD_SEPARATOR);
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"item\":\"First\"}" + RECORD_SEPARATOR);
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"item\":\"Second\"}" + RECORD_SEPARATOR);
mockTransport.receiveMessage("{\"type\":3,\"invocationId\":\"1\",\"result\":\"null\"}" + RECORD_SEPARATOR);
Iterator<String> resultIterator = result.timeout(1000, TimeUnit.MILLISECONDS).blockingIterable().iterator();
@ -545,10 +545,10 @@ class HubConnectionTest {
assertEquals("{\"type\":4,\"invocationId\":\"1\",\"target\":\"echo\",\"arguments\":[\"message\"]}" + RECORD_SEPARATOR, mockTransport.getSentMessages()[1]);
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"result\":\"First\"}" + RECORD_SEPARATOR);
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"item\":\"First\"}" + RECORD_SEPARATOR);
subscription.dispose();
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"result\":\"Second\"}" + RECORD_SEPARATOR);
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"item\":\"Second\"}" + RECORD_SEPARATOR);
assertEquals("First", result.timeout(1000, TimeUnit.MILLISECONDS).blockingLast());
}
@ -573,10 +573,10 @@ class HubConnectionTest {
assertEquals("{\"type\":4,\"invocationId\":\"1\",\"target\":\"echo\",\"arguments\":[\"message\"]}" + RECORD_SEPARATOR, mockTransport.getSentMessages()[1]);
assertFalse(completed.get());
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"result\":\"First\"}" + RECORD_SEPARATOR);
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"item\":\"First\"}" + RECORD_SEPARATOR);
subscription.dispose();
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"result\":\"Second\"}" + RECORD_SEPARATOR);
mockTransport.receiveMessage("{\"type\":2,\"invocationId\":\"1\",\"item\":\"Second\"}" + RECORD_SEPARATOR);
mockTransport.receiveMessage("{\"type\":3,\"invocationId\":\"1\"}" + RECORD_SEPARATOR);
assertTrue(completed.get());

View File

@ -8,6 +8,7 @@ import java.util.Scanner;
import com.microsoft.signalr.HubConnection;
import com.microsoft.signalr.HubConnectionBuilder;
public class Chat {
public static void main(String[] args) {
System.out.println("Enter the URL of the SignalR Chat you want to join");