Search in sources :

Example 16 with Async

use of io.vertx.ext.unit.Async in project vertx-proton by vert-x3.

the class ProtonServerImplTest method testCustomAuthenticatorSuceedsAuthentication.

@Test(timeout = 20000)
public void testCustomAuthenticatorSuceedsAuthentication(TestContext context) {
    Async connectedAsync = context.async();
    Async authenticatedAsync = context.async();
    ProtonServer.create(vertx).saslAuthenticatorFactory(new TestPlainAuthenticatorFactory()).connectHandler(protonConnection -> {
        // Verify the expected auth detail was recorded in the connection attachments, just using a String here.
        String authValue = protonConnection.attachments().get(AUTH_KEY, String.class);
        context.assertEquals(AUTH_VALUE, authValue);
        authenticatedAsync.complete();
    }).listen(server -> ProtonClient.create(vertx).connect("localhost", server.result().actualPort(), GOOD_USER, PASSWD, protonConnectionAsyncResult -> {
        context.assertTrue(protonConnectionAsyncResult.succeeded());
        protonConnectionAsyncResult.result().disconnect();
        connectedAsync.complete();
    }));
    authenticatedAsync.awaitSuccess();
    connectedAsync.awaitSuccess();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) ProtonConnection(io.vertx.proton.ProtonConnection) Async(io.vertx.ext.unit.Async) ProtonSaslAuthenticator(io.vertx.proton.sasl.ProtonSaslAuthenticator) Vertx(io.vertx.core.Vertx) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProtonClient(io.vertx.proton.ProtonClient) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Sasl(org.apache.qpid.proton.engine.Sasl) SaslOutcome(org.apache.qpid.proton.engine.Sasl.SaslOutcome) Context(io.vertx.core.Context) ProtonServer(io.vertx.proton.ProtonServer) StandardCharsets(java.nio.charset.StandardCharsets) Transport(org.apache.qpid.proton.engine.Transport) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) Handler(io.vertx.core.Handler) ProtonSaslAuthenticatorFactory(io.vertx.proton.sasl.ProtonSaslAuthenticatorFactory) NetSocket(io.vertx.core.net.NetSocket) Before(org.junit.Before) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 17 with Async

use of io.vertx.ext.unit.Async in project vertx-proton by vert-x3.

the class ProtonBenchmark method benchmarkAtLeastOnceSendThroughput.

@Test
public void benchmarkAtLeastOnceSendThroughput(TestContext context) {
    server.setProducerCredits(1000);
    Async async = context.async();
    connect(context, connection -> {
        connection.open();
        ProtonSender sender = connection.createSender(MockServer.Addresses.drop.toString()).setQoS(ProtonQoS.AT_LEAST_ONCE).open();
        String name = "At Least Once Send Throughput";
        Message message = message("drop", "Hello World");
        benchmark(BENCHMARK_DURATION, name, counter -> {
            sender.sendQueueDrainHandler(s -> {
                while (!sender.sendQueueFull()) {
                    sender.send(message, d -> {
                        if (d.remotelySettled()) {
                            counter.incrementAndGet();
                        }
                    });
                }
            });
        }, () -> {
            connection.disconnect();
            async.complete();
        });
    });
}
Also used : Message(org.apache.qpid.proton.message.Message) Async(io.vertx.ext.unit.Async) Test(org.junit.Test)

Example 18 with Async

use of io.vertx.ext.unit.Async in project vertx-proton by vert-x3.

the class ProtonClientSslTest method testConnectWithSslToServerWhileUsingTrustAll.

@Test(timeout = 20000)
public void testConnectWithSslToServerWhileUsingTrustAll(TestContext context) throws Exception {
    Async async = context.async();
    // Create a server that accept a connection and expects a client connection+session+receiver
    ProtonServerOptions serverOptions = new ProtonServerOptions();
    serverOptions.setSsl(true);
    PfxOptions serverPfxOptions = new PfxOptions().setPath(KEYSTORE).setPassword(PASSWORD);
    serverOptions.setPfxKeyCertOptions(serverPfxOptions);
    protonServer = createServer(serverOptions, this::handleClientConnectionSessionReceiverOpen);
    // Try to connect the client and expect it to succeed due to trusting all certs
    ProtonClientOptions clientOptions = new ProtonClientOptions();
    clientOptions.setSsl(true);
    clientOptions.setTrustAll(true);
    ProtonClient client = ProtonClient.create(vertx);
    client.connect(clientOptions, "localhost", protonServer.actualPort(), res -> {
        // Expect connect to succeed
        context.assertTrue(res.succeeded());
        async.complete();
    });
    async.awaitSuccess();
}
Also used : Async(io.vertx.ext.unit.Async) PfxOptions(io.vertx.core.net.PfxOptions) Test(org.junit.Test)

Example 19 with Async

use of io.vertx.ext.unit.Async in project vertx-proton by vert-x3.

the class ProtonClientSslTest method testConnectWithSslSucceeds.

@Test(timeout = 20000)
public void testConnectWithSslSucceeds(TestContext context) throws Exception {
    Async async = context.async();
    // Create a server that accept a connection and expects a client connection+session+receiver
    ProtonServerOptions serverOptions = new ProtonServerOptions();
    serverOptions.setSsl(true);
    PfxOptions serverPfxOptions = new PfxOptions().setPath(KEYSTORE).setPassword(PASSWORD);
    serverOptions.setPfxKeyCertOptions(serverPfxOptions);
    protonServer = createServer(serverOptions, this::handleClientConnectionSessionReceiverOpen);
    // Connect the client and open a receiver to verify the connection works
    ProtonClientOptions clientOptions = new ProtonClientOptions();
    clientOptions.setSsl(true);
    PfxOptions clientPfxOptions = new PfxOptions().setPath(TRUSTSTORE).setPassword(PASSWORD);
    clientOptions.setPfxTrustOptions(clientPfxOptions);
    ProtonClient client = ProtonClient.create(vertx);
    client.connect(clientOptions, "localhost", protonServer.actualPort(), res -> {
        // Expect connect to succeed
        context.assertTrue(res.succeeded());
        ProtonConnection connection = res.result();
        connection.open();
        ProtonReceiver receiver = connection.createReceiver("some-address");
        receiver.openHandler(recvResult -> {
            context.assertTrue(recvResult.succeeded());
            LOG.trace("Client reciever open");
            async.complete();
        }).open();
    });
    async.awaitSuccess();
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) RunWith(org.junit.runner.RunWith) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) LoggerFactory(io.vertx.core.logging.LoggerFactory) PfxOptions(io.vertx.core.net.PfxOptions) ExecutionException(java.util.concurrent.ExecutionException) After(org.junit.After) ClientAuth(io.vertx.core.http.ClientAuth) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) Logger(io.vertx.core.logging.Logger) Before(org.junit.Before) Async(io.vertx.ext.unit.Async) PfxOptions(io.vertx.core.net.PfxOptions) Test(org.junit.Test)

Example 20 with Async

use of io.vertx.ext.unit.Async in project vertx-camel-bridge by vert-x3.

the class InboundEndpointTest method testWithDirectEndpointWithPublishAndCustomTypeNoCodec.

@Test
public void testWithDirectEndpointWithPublishAndCustomTypeNoCodec(TestContext context) throws Exception {
    Async async = context.async();
    Endpoint endpoint = camel.getEndpoint("direct:foo");
    bridge = CamelBridge.create(vertx, new CamelBridgeOptions(camel).addInboundMapping(fromCamel(endpoint).toVertx("test").usePublish()));
    camel.start();
    BridgeHelper.startBlocking(bridge);
    ProducerTemplate producer = camel.createProducerTemplate();
    producer.asyncSend(endpoint, exchange -> {
        Message message = exchange.getIn();
        message.setBody(new Person().setName("bob"));
        exchange.addOnCompletion(new SynchronizationAdapter() {

            @Override
            public void onFailure(Exchange exchange) {
                context.assertTrue(exchange.getException().getMessage().contains("No message codec"));
                async.complete();
            }
        });
    });
}
Also used : Exchange(org.apache.camel.Exchange) ProducerTemplate(org.apache.camel.ProducerTemplate) Endpoint(org.apache.camel.Endpoint) Message(org.apache.camel.Message) Async(io.vertx.ext.unit.Async) SynchronizationAdapter(org.apache.camel.support.SynchronizationAdapter) Test(org.junit.Test)

Aggregations

Async (io.vertx.ext.unit.Async)156 Test (org.junit.Test)143 TestContext (io.vertx.ext.unit.TestContext)89 Handler (io.vertx.core.Handler)87 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)83 RunWith (org.junit.runner.RunWith)83 Future (io.vertx.core.Future)70 Vertx (io.vertx.core.Vertx)69 Before (org.junit.Before)69 JsonObject (io.vertx.core.json.JsonObject)65 HttpURLConnection (java.net.HttpURLConnection)55 Mockito (org.mockito.Mockito)55 Context (io.vertx.core.Context)44 Message (org.apache.qpid.proton.message.Message)44 Constants (org.eclipse.hono.util.Constants)44 Rule (org.junit.Rule)44 Timeout (org.junit.rules.Timeout)43 Assert.assertThat (org.junit.Assert.assertThat)40 Buffer (io.vertx.core.buffer.Buffer)39 AsyncResult (io.vertx.core.AsyncResult)37