Search in sources :

Example 31 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project hono by eclipse.

the class CoapTestBase method testUploadMessagesWithTtdThatReplyWithCommand.

/**
 * Verifies that the CoAP adapter delivers a command to a device and accepts
 * the corresponding response from the device.
 *
 * @param endpointConfig The endpoints to use for sending/receiving commands.
 * @param ctx The test context.
 * @throws InterruptedException if the test fails.
 */
@ParameterizedTest(name = IntegrationTestSupport.PARAMETERIZED_TEST_NAME_PATTERN)
@MethodSource("commandAndControlVariants")
public void testUploadMessagesWithTtdThatReplyWithCommand(final CoapCommandEndpointConfiguration endpointConfig, final VertxTestContext ctx) throws InterruptedException {
    final Tenant tenant = new Tenant();
    testUploadMessagesWithTtdThatReplyWithCommand(endpointConfig, tenant, ctx);
}
Also used : Tenant(org.eclipse.hono.service.management.tenant.Tenant) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 32 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project hono by eclipse.

the class AmqpUploadTestBase method testUploadMessagesUsingSaslExternal.

/**
 * Verifies that a number of messages uploaded to the AMQP adapter using client certificate
 * based authentication can be successfully consumed via the AMQP Messaging Network.
 *
 * @param senderQos The delivery semantics used by the device for uploading messages.
 * @throws InterruptedException if test execution is interrupted.
 */
@ParameterizedTest(name = IntegrationTestSupport.PARAMETERIZED_TEST_NAME_PATTERN)
@MethodSource("senderQoSTypes")
public void testUploadMessagesUsingSaslExternal(final ProtonQoS senderQos) throws InterruptedException {
    final String tenantId = helper.getRandomTenantId();
    final String deviceId = helper.getRandomDeviceId(tenantId);
    final SelfSignedCertificate deviceCert = SelfSignedCertificate.create(deviceId + ".iot.eclipse.org");
    final VertxTestContext setup = new VertxTestContext();
    helper.getCertificate(deviceCert.certificatePath()).compose(cert -> {
        final var tenant = Tenants.createTenantForTrustAnchor(cert);
        prepareTenantConfig(tenant);
        return helper.registry.addDeviceForTenant(tenantId, tenant, deviceId, cert);
    }).compose(ok -> connectToAdapter(deviceCert)).compose(con -> createProducer(null, senderQos)).onComplete(setup.succeeding(s -> {
        setup.verify(() -> {
            final UnsignedLong maxMessageSize = s.getRemoteMaxMessageSize();
            assertWithMessage("max-message-size included in adapter's attach frame").that(maxMessageSize).isNotNull();
            assertWithMessage("max-message-size").that(maxMessageSize.longValue()).isGreaterThan(0);
        });
        sender = s;
        setup.completeNow();
    }));
    assertThat(setup.awaitCompletion(5, TimeUnit.SECONDS)).isTrue();
    assertWithMessage("adapter connection failure occurred").that(setup.failed()).isFalse();
    testUploadMessages(tenantId, senderQos);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) VertxTestContext(io.vertx.junit5.VertxTestContext) AmqpErrorException(org.eclipse.hono.util.AmqpErrorException) DownstreamMessage(org.eclipse.hono.application.client.DownstreamMessage) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) Function(java.util.function.Function) Constants(org.eclipse.hono.util.Constants) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Timeout(io.vertx.junit5.Timeout) IntegrationTestSupport(org.eclipse.hono.tests.IntegrationTestSupport) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Symbol(org.apache.qpid.proton.amqp.Symbol) UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) Message(org.apache.qpid.proton.message.Message) Binary(org.apache.qpid.proton.amqp.Binary) Tenants(org.eclipse.hono.tests.Tenants) RegistryManagementConstants(org.eclipse.hono.util.RegistryManagementConstants) MethodSource(org.junit.jupiter.params.provider.MethodSource) Data(org.apache.qpid.proton.amqp.messaging.Data) Device(org.eclipse.hono.service.management.device.Device) MessageContext(org.eclipse.hono.application.client.MessageContext) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) LinkError(org.apache.qpid.proton.amqp.transport.LinkError) Promise(io.vertx.core.Promise) ServerErrorException(org.eclipse.hono.client.ServerErrorException) DownstreamMessageAssertions(org.eclipse.hono.tests.DownstreamMessageAssertions) ProtonHelper(io.vertx.proton.ProtonHelper) ProtonQoS(io.vertx.proton.ProtonQoS) Truth.assertThat(com.google.common.truth.Truth.assertThat) MessageHelper(org.eclipse.hono.util.MessageHelper) EventConstants(org.eclipse.hono.util.EventConstants) Future(io.vertx.core.Future) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Buffer(io.vertx.core.buffer.Buffer) Assertions(org.junit.jupiter.api.Assertions) MessageConsumer(org.eclipse.hono.application.client.MessageConsumer) ProtonSender(io.vertx.proton.ProtonSender) Handler(io.vertx.core.Handler) Collections(java.util.Collections) Accepted(org.apache.qpid.proton.amqp.messaging.Accepted) QoS(org.eclipse.hono.util.QoS) SelfSignedCertificate(io.vertx.core.net.SelfSignedCertificate) UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) VertxTestContext(io.vertx.junit5.VertxTestContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 33 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project hono by eclipse.

the class MicrometerBasedMetricsTest method testConnectionTimeDuration.

/**
 * Verifies that the connection time duration is recorded for the given tenant when devices get connected and
 * disconnected.
 *
 * @param registry The registry that the tests should be run against.
 */
@ParameterizedTest
@MethodSource("registries")
public void testConnectionTimeDuration(final MeterRegistry registry) {
    final MeterRegistry meterRegistry = Mockito.spy(registry);
    final Metrics metrics = new MicrometerBasedMetrics(meterRegistry, mock(Vertx.class));
    metrics.incrementConnections("TEST_TENANT");
    metrics.decrementConnections("TEST_TENANT");
    verify(meterRegistry, times(1)).timer(MicrometerBasedMetrics.METER_CONNECTIONS_AUTHENTICATED_DURATION, Tags.of(MetricsTags.getTenantTag("TEST_TENANT")));
}
Also used : Vertx(io.vertx.core.Vertx) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 34 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project hono by eclipse.

the class MicrometerBasedMetricsTest method testPayloadSizeForTelemetryMessages.

/**
 * Verifies that the payload size is calculated based on the configured minimum message size
 * when reporting downstream telemetry messages.
 *
 * @param registry The registry that the tests should be run against.
 */
@ParameterizedTest
@MethodSource("registries")
public void testPayloadSizeForTelemetryMessages(final MeterRegistry registry) {
    final Metrics metrics = new MicrometerBasedMetrics(registry, mock(Vertx.class));
    final TenantObject tenantObject = TenantObject.from("TEST_TENANT", true).setMinimumMessageSize(4 * 1024);
    metrics.reportTelemetry(MetricsTags.EndpointType.TELEMETRY, "tenant", tenantObject, MetricsTags.ProcessingOutcome.FORWARDED, MetricsTags.QoS.UNKNOWN, 1 * 1024, MetricsTags.TtdStatus.NONE, metrics.startTimer());
    assertEquals(4 * 1024, registry.find(MicrometerBasedMetrics.METER_MESSAGES_PAYLOAD).summary().totalAmount());
}
Also used : TenantObject(org.eclipse.hono.util.TenantObject) Vertx(io.vertx.core.Vertx) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 35 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project hono by eclipse.

the class MicrometerBasedMetricsTest method testNoTenantTimeoutOnDefault.

/**
 * Verifies that collecting the last message send time is disabled by default.
 *
 * @param registry The registry that the tests should be run against.
 */
@ParameterizedTest
@MethodSource("registries")
public void testNoTenantTimeoutOnDefault(final MeterRegistry registry) {
    final MicrometerBasedMetrics metrics = new MicrometerBasedMetrics(registry, mock(Vertx.class));
    reportTelemetry(metrics);
    assertTrue(metrics.getLastSeenTimestampPerTenant().isEmpty());
    metrics.setProtocolAdapterProperties(new ProtocolAdapterProperties());
    reportTelemetry(metrics);
    assertTrue(metrics.getLastSeenTimestampPerTenant().isEmpty());
    final ProtocolAdapterProperties config = new ProtocolAdapterProperties();
    config.setTenantIdleTimeout(Duration.ZERO);
    metrics.setProtocolAdapterProperties(config);
    reportTelemetry(metrics);
    assertTrue(metrics.getLastSeenTimestampPerTenant().isEmpty());
}
Also used : ProtocolAdapterProperties(org.eclipse.hono.config.ProtocolAdapterProperties) Vertx(io.vertx.core.Vertx) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

MethodSource (org.junit.jupiter.params.provider.MethodSource)1376 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1361 Transaction (org.neo4j.graphdb.Transaction)103 Stream (java.util.stream.Stream)70 Test (org.junit.jupiter.api.Test)67 ArrayList (java.util.ArrayList)63 InterruptAfter (io.aeron.test.InterruptAfter)60 List (java.util.List)60 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)58 IOException (java.io.IOException)58 ArrowableSingleShape (net.sf.latexdraw.model.api.shape.ArrowableSingleShape)55 TimeUnit (java.util.concurrent.TimeUnit)54 CountDownLatch (java.util.concurrent.CountDownLatch)53 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)52 lombok.val (lombok.val)52 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)51 Arguments (org.junit.jupiter.params.provider.Arguments)47 AfterEach (org.junit.jupiter.api.AfterEach)46 SSLEngine (javax.net.ssl.SSLEngine)44 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)43