Skip to content

Commit

Permalink
Allow sending null params in Java client (#11272)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelm12 authored Jun 17, 2019
1 parent 9c4faf8 commit 4235dd2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,10 @@ void launchStreams(List<String> streamIds) {
}

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) {
Expand All @@ -587,7 +591,7 @@ Object[] checkUploadStream(Object[] args, List<String> streamIds) {
this.streamMap.put(streamId, stream);
}
}

return params.toArray();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,42 @@ public void invokeWaitsForCompletionMessage() {

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() {
Expand Down

0 comments on commit 4235dd2

Please sign in to comment.