Allow sending null params in Java client (#11272)
This commit is contained in:
parent
9c4faf86e5
commit
4235dd2999
|
|
@ -577,6 +577,10 @@ public class HubConnection {
|
|||
}
|
||||
|
||||
Object[] checkUploadStream(Object[] args, List<String> streamIds) {
|
||||
if (args == null) {
|
||||
return new Object[] { null };
|
||||
}
|
||||
|
||||
List<Object> params = new ArrayList<>(Arrays.asList(args));
|
||||
for (Object arg: args) {
|
||||
if (arg instanceof Observable) {
|
||||
|
|
@ -587,7 +591,7 @@ public class HubConnection {
|
|||
this.streamMap.put(streamId, stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return params.toArray();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -954,6 +954,42 @@ class HubConnectionTest {
|
|||
|
||||
assertEquals(Integer.valueOf(42), result.timeout(1000, TimeUnit.MILLISECONDS).blockingGet());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canSendNullArgInInvocation() {
|
||||
MockTransport mockTransport = new MockTransport();
|
||||
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
||||
|
||||
hubConnection.start().timeout(1, TimeUnit.SECONDS).blockingAwait();
|
||||
|
||||
AtomicBoolean done = new AtomicBoolean();
|
||||
Single<String> result = hubConnection.invoke(String.class, "fixedMessage", null);
|
||||
result.doOnSuccess(value -> done.set(true));
|
||||
assertEquals("{\"type\":1,\"invocationId\":\"1\",\"target\":\"fixedMessage\",\"arguments\":[null]}" + RECORD_SEPARATOR, mockTransport.getSentMessages()[1]);
|
||||
assertFalse(done.get());
|
||||
|
||||
mockTransport.receiveMessage("{\"type\":3,\"invocationId\":\"1\",\"result\":\"Hello World\"}" + RECORD_SEPARATOR);
|
||||
|
||||
assertEquals("Hello World", result.timeout(1000, TimeUnit.MILLISECONDS).blockingGet());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canSendMultipleNullArgsInInvocation() {
|
||||
MockTransport mockTransport = new MockTransport();
|
||||
HubConnection hubConnection = TestUtils.createHubConnection("http://example.com", mockTransport);
|
||||
|
||||
hubConnection.start().timeout(1, TimeUnit.SECONDS).blockingAwait();
|
||||
|
||||
AtomicBoolean done = new AtomicBoolean();
|
||||
Single<String> result = hubConnection.invoke(String.class, "fixedMessage", null, null);
|
||||
result.doOnSuccess(value -> done.set(true));
|
||||
assertEquals("{\"type\":1,\"invocationId\":\"1\",\"target\":\"fixedMessage\",\"arguments\":[null,null]}"+ RECORD_SEPARATOR, mockTransport.getSentMessages()[1]);
|
||||
assertFalse(done.get());
|
||||
|
||||
mockTransport.receiveMessage("{\"type\":3,\"invocationId\":\"1\",\"result\":\"Hello World\"}" + RECORD_SEPARATOR);
|
||||
|
||||
assertEquals("Hello World", result.timeout(1000, TimeUnit.MILLISECONDS).blockingGet());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleInvokesWaitForOwnCompletionMessage() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue