Search in sources :

Example 1 with UnsignedLong

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();
        }
    }
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LoggerFactory(io.vertx.core.logging.LoggerFactory) LinkedHashMap(java.util.LinkedHashMap) Symbol(org.apache.qpid.proton.amqp.Symbol) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProtonHelper.message(io.vertx.proton.ProtonHelper.message) Target(org.apache.qpid.proton.amqp.transport.Target) Map(java.util.Map) UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) Message(org.apache.qpid.proton.message.Message) AsyncResult(io.vertx.core.AsyncResult) AmqpError(org.apache.qpid.proton.amqp.transport.AmqpError) Logger(io.vertx.core.logging.Logger) ProtonServerImpl(io.vertx.proton.impl.ProtonServerImpl) ProtonMetaDataSupportImpl(io.vertx.proton.impl.ProtonMetaDataSupportImpl) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Future(io.vertx.core.Future) Proton(org.apache.qpid.proton.Proton) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Source(org.apache.qpid.proton.amqp.messaging.Source) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) Section(org.apache.qpid.proton.amqp.messaging.Section) NetServer(io.vertx.core.net.NetServer) ProtonConnectionImpl(io.vertx.proton.impl.ProtonConnectionImpl) Handler(io.vertx.core.Handler) Collections(java.util.Collections) UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 2 with UnsignedLong

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;
}
Also used : UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) JsonObject(io.vertx.core.json.JsonObject) Binary(org.apache.qpid.proton.amqp.Binary) UUID(java.util.UUID)

Aggregations

UnsignedLong (org.apache.qpid.proton.amqp.UnsignedLong)2 AsyncResult (io.vertx.core.AsyncResult)1 Future (io.vertx.core.Future)1 Handler (io.vertx.core.Handler)1 JsonObject (io.vertx.core.json.JsonObject)1 Logger (io.vertx.core.logging.Logger)1 LoggerFactory (io.vertx.core.logging.LoggerFactory)1 NetServer (io.vertx.core.net.NetServer)1 Async (io.vertx.ext.unit.Async)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 ProtonHelper.message (io.vertx.proton.ProtonHelper.message)1 ProtonConnectionImpl (io.vertx.proton.impl.ProtonConnectionImpl)1 ProtonMetaDataSupportImpl (io.vertx.proton.impl.ProtonMetaDataSupportImpl)1 ProtonServerImpl (io.vertx.proton.impl.ProtonServerImpl)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1