use of org.apache.qpid.proton.amqp.UnsignedLong in project vertx-proton by vert-x3.
the class ProtonClientTest method testMaxMessageSize.
@Test(timeout = 20000)
public void testMaxMessageSize(TestContext context) throws Exception {
server.close();
Async serverAsync = context.async();
Async clientAsync = context.async();
final UnsignedLong clientMaxMsgSize = UnsignedLong.valueOf(54321);
final UnsignedLong serverMaxMsgSize = UnsignedLong.valueOf(12345);
ProtonServer protonServer = null;
try {
protonServer = createServer((serverConnection) -> {
serverConnection.openHandler(result -> {
serverConnection.open();
});
serverConnection.sessionOpenHandler(session -> {
session.open();
});
serverConnection.senderOpenHandler(serverSender -> {
context.assertEquals(clientMaxMsgSize, serverSender.getRemoteMaxMessageSize(), "unexpected remote max message size at server");
context.assertNull(serverSender.getMaxMessageSize(), "Expected no value to be set");
serverSender.setMaxMessageSize(serverMaxMsgSize);
context.assertEquals(serverMaxMsgSize, serverSender.getMaxMessageSize(), "Expected value to now be set");
LOG.trace("Server sender opened");
serverSender.open();
serverAsync.complete();
});
});
// ===== Client Handling =====
ProtonClient client = ProtonClient.create(vertx);
client.connect("localhost", protonServer.actualPort(), res -> {
context.assertTrue(res.succeeded());
ProtonConnection connection = res.result();
connection.openHandler(x -> {
LOG.trace("Client connection opened");
final ProtonLink<?> receiver = connection.createReceiver("some-address");
context.assertNull(receiver.getMaxMessageSize(), "Expected no value to be set");
receiver.setMaxMessageSize(clientMaxMsgSize);
context.assertEquals(clientMaxMsgSize, receiver.getMaxMessageSize(), "Expected value to now be set");
receiver.openHandler(y -> {
LOG.trace("Client link opened");
context.assertEquals(serverMaxMsgSize, receiver.getRemoteMaxMessageSize(), "unexpected remote max message size at client");
clientAsync.complete();
});
receiver.open();
}).open();
});
serverAsync.awaitSuccess();
clientAsync.awaitSuccess();
} finally {
if (protonServer != null) {
protonServer.close();
}
}
}
use of org.apache.qpid.proton.amqp.UnsignedLong in project hono by eclipse.
the class EventBusMessage method encodeIdToJson.
/**
* Serializes a correlation identifier to JSON.
* <p>
* Supported types for AMQP 1.0 correlation IDs are
* {@code String}, {@code UnsignedLong}, {@code UUID} and {@code Binary}.
*
* @param id The identifier to encode.
* @return The JSON representation of the identifier.
* @throws NullPointerException if the correlation id is {@code null}.
* @throws IllegalArgumentException if the type is not supported.
*/
private static JsonObject encodeIdToJson(final Object id) {
Objects.requireNonNull(id);
final JsonObject json = new JsonObject();
if (id instanceof String) {
json.put(FIELD_CORRELATION_ID_TYPE, "string");
json.put(FIELD_CORRELATION_ID, id);
} else if (id instanceof UnsignedLong) {
json.put(FIELD_CORRELATION_ID_TYPE, "ulong");
json.put(FIELD_CORRELATION_ID, id.toString());
} else if (id instanceof UUID) {
json.put(FIELD_CORRELATION_ID_TYPE, "uuid");
json.put(FIELD_CORRELATION_ID, id.toString());
} else if (id instanceof Binary) {
json.put(FIELD_CORRELATION_ID_TYPE, "binary");
final Binary binary = (Binary) id;
json.put(FIELD_CORRELATION_ID, Base64.getEncoder().encodeToString(binary.getArray()));
} else {
throw new IllegalArgumentException("type " + id.getClass().getName() + " is not supported");
}
return json;
}
Aggregations