Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Commit

Permalink
Fix "echo" method with one param bug.
Browse files Browse the repository at this point in the history
Issue: #37
Signed-off-by: Hechao Li <hechaol@outlook.com>
  • Loading branch information
hechaoli committed Sep 7, 2018
1 parent cd0a94a commit da67349
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
Expand Up @@ -139,25 +139,19 @@ private Object[] toMethodParams(ArrayNode paramsNode, Method method) {
int actualParamSize = paramsNode.size();

Object[] actualParams = new Object[methodParamSize];
if (methodParamSize != actualParamSize) {
// This is not an error only if the last arg is a vararg
// And the actual params number must be >= methods params number - 1
// For e.g. if a methods has n params, the last one is an vararg,
// then the number of actual params can be [n-1, ...)
int lastIndex = methodParamSize - 1;
if (lastIndex >= 0
&& parameters[lastIndex].isVarArgs()
&& actualParamSize >= lastIndex) {

Class<?> type = parameters[lastIndex].getType().getComponentType();
actualParams[lastIndex] = buildVarargParam(paramsNode, lastIndex, type);
// We have handled the last param, no need to handle it later
--methodParamSize;
} else {
throw new IllegalArgumentException(
"Parameters number doesn't match. Expected: "
+ methodParamSize + ". Got: " + paramsNode.size());
}
int lastIndex = methodParamSize - 1;

// If a methods has n params and the last one is a vararg,
// then the number of actual params must be in range [n-1, ...)
if (lastIndex >= 0 && parameters[lastIndex].isVarArgs() && actualParamSize >= lastIndex) {
Class<?> type = parameters[lastIndex].getType().getComponentType();
actualParams[lastIndex] = buildVarargParam(paramsNode, lastIndex, type);
// We have handled the last param, no need to handle it later
--methodParamSize;
} else if (methodParamSize != actualParamSize) {
throw new IllegalArgumentException(
"Parameters number doesn't match. Expected: "
+ methodParamSize + ". Got: " + paramsNode.size());
}

for (int i = 0; i < methodParamSize; i++) {
Expand Down
Expand Up @@ -613,6 +613,22 @@ private void testEcho() {
} catch (InterruptedException | ExecutionException | TimeoutException e) {
fail(e.getMessage());
}

CompletableFuture<Void> successFuture3 = new CompletableFuture<>();
final String expectedResponse3 = "{\"result\":[\"inactivity probe\"]," + "\"error\":null,"
+ "\"id\":\"echo\"}";
ovsdbServerEmulator.registerReadCallback(msg -> {
if (msg.equals(expectedResponse3)) {
successFuture3.complete(null);
}
});
ovsdbServerEmulator.write("{\"method\":\"echo\",\"params\":[\"inactivity probe\"],"
+ "\"id\":\"echo\"}");
try {
successFuture3.get(VERIFY_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
fail(e.getMessage());
}
}

private void testInvalidJsonRpcMessage() throws OvsdbClientException, IOException {
Expand Down

0 comments on commit da67349

Please sign in to comment.