Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.vertx.ext.eventbus.bridge.tcp;

import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.Json;
import io.vertx.core.json.JsonArray;
import io.vertx.ext.eventbus.bridge.tcp.impl.StreamParser;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
Expand Down Expand Up @@ -58,4 +60,56 @@ public void testParseSimpleHeaderless(TestContext should) {

parser.handle(Buffer.buffer("{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":\"hi\"}\r\n"));
}

@Test(timeout = 30_000)
public void testParseSimpleHeaderlessBatch(TestContext should) {
final Async test = should.async();
final StreamParser parser = new StreamParser()
.exceptionHandler(should::fail)
.handler(body -> {
Object json = Json.decodeValue(body);
// it's a batch!
should.assertTrue(json instanceof JsonArray);
test.complete();
});

parser.handle(Buffer.buffer("[\n" +
" {\"jsonrpc\": \"2.0\", \"method\": \"sum\", \"params\": [1,2,4], \"id\": \"1\"},\n" +
" {\"jsonrpc\": \"2.0\", \"method\": \"notify_hello\", \"params\": [7]},\n" +
" {\"jsonrpc\": \"2.0\", \"method\": \"subtract\", \"params\": [42,23], \"id\": \"2\"},\n" +
" {\"foo\": \"boo\"},\n" +
" {\"jsonrpc\": \"2.0\", \"method\": \"foo.get\", \"params\": {\"name\": \"myself\"}, \"id\": \"5\"},\n" +
" {\"jsonrpc\": \"2.0\", \"method\": \"get_data\", \"id\": \"9\"} \n" +
" ]\r\n"));
}

@Test(timeout = 30_000)
public void testParseSimpleHeaderlessBatchFromSpec(TestContext should) {
final Async test = should.async();
final StreamParser parser = new StreamParser()
.exceptionHandler(should::fail)
.handler(body -> {
Object json = Json.decodeValue(body);
// it's a batch!
should.assertTrue(json instanceof JsonArray);
test.complete();
});

parser.handle(Buffer.buffer("[]\r\n"));
}

@Test(timeout = 30_000)
public void testParseSimpleHeaderlessBatchFromSpec2(TestContext should) {
final Async test = should.async();
final StreamParser parser = new StreamParser()
.exceptionHandler(should::fail)
.handler(body -> {
Object json = Json.decodeValue(body);
// it's a batch!
should.assertTrue(json instanceof JsonArray);
test.complete();
});

parser.handle(Buffer.buffer("[1, 2, 3]\r\n"));
}
}