use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class AmqpUploadTestBase method testUploadMessagesUsingSaslPlain.
/**
* Verifies that a number of messages published through the AMQP adapter can be successfully consumed by
* applications connected to the AMQP messaging network.
*
* @param senderQos The delivery semantics to use for the device.
* @throws InterruptedException if test is interrupted while running.
*/
@ParameterizedTest(name = IntegrationTestSupport.PARAMETERIZED_TEST_NAME_PATTERN)
@MethodSource("senderQoSTypes")
public void testUploadMessagesUsingSaslPlain(final ProtonQoS senderQos) throws InterruptedException {
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final Tenant tenantConfig = new Tenant();
prepareTenantConfig(tenantConfig);
final VertxTestContext setup = new VertxTestContext();
setupProtocolAdapter(tenantId, tenantConfig, deviceId, 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);
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class AmqpUploadTestBase method testAutoProvisioningViaGateway.
/**
* Verifies that an edge device is auto-provisioned if it connects via a gateway equipped with the corresponding
* authority.
*
* @param ctx The Vert.x test context.
*/
@Test
@Timeout(timeUnit = TimeUnit.SECONDS, value = 10)
public void testAutoProvisioningViaGateway(final VertxTestContext ctx) {
final String tenantId = helper.getRandomTenantId();
final String gatewayId = helper.getRandomDeviceId(tenantId);
final Device gateway = new Device().setAuthorities(Collections.singleton(RegistryManagementConstants.AUTHORITY_AUTO_PROVISIONING_ENABLED));
final String username = IntegrationTestSupport.getUsername(gatewayId, tenantId);
final String edgeDeviceId = helper.getRandomDeviceId(tenantId);
final Promise<Void> provisioningNotificationReceived = Promise.promise();
helper.createAutoProvisioningMessageConsumers(ctx, provisioningNotificationReceived, tenantId, edgeDeviceId).compose(ok -> helper.registry.addDeviceForTenant(tenantId, new Tenant(), gatewayId, gateway, DEVICE_PASSWORD)).compose(ok -> connectToAdapter(username, DEVICE_PASSWORD)).compose(con -> createProducer(null, ProtonQoS.AT_LEAST_ONCE)).compose(sender -> {
final Message msg = ProtonHelper.message("apFoobar");
msg.setContentType("text/plain");
msg.setAddress(String.format("%s/%s/%s", getEndpointName(), tenantId, edgeDeviceId));
final Promise<Void> result = Promise.promise();
sender.send(msg, delivery -> {
ctx.verify(() -> assertThat(delivery.getRemoteState()).isInstanceOf(Accepted.class));
result.complete();
});
return result.future();
}).compose(ok -> provisioningNotificationReceived.future()).compose(ok -> helper.registry.getRegistrationInfo(tenantId, edgeDeviceId)).onComplete(ctx.succeeding(registrationResult -> {
ctx.verify(() -> {
final var info = registrationResult.bodyAsJsonObject();
IntegrationTestSupport.assertDeviceStatusProperties(info.getJsonObject(RegistryManagementConstants.FIELD_STATUS), true);
});
ctx.completeNow();
}));
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class EventAmqpIT method testEventMessageAlreadySentIsDeliveredWhenConsumerConnects.
/**
* Verifies that an event message from a device has been successfully sent and a north bound application,
* which connects after the event has been sent, can successfully receive this event message.
*
* @param ctx The vert.x test context.
* @throws InterruptedException if test execution gets interrupted.
*/
@Test
public void testEventMessageAlreadySentIsDeliveredWhenConsumerConnects(final VertxTestContext ctx) throws InterruptedException {
final VertxTestContext setup = new VertxTestContext();
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final String messagePayload = UUID.randomUUID().toString();
final Message event = ProtonHelper.message();
setupProtocolAdapter(tenantId, new Tenant(), deviceId, ProtonQoS.AT_LEAST_ONCE).map(s -> sender = s).onComplete(setup.succeedingThenComplete());
assertThat(setup.awaitCompletion(IntegrationTestSupport.getTestSetupTimeout(), TimeUnit.SECONDS)).isTrue();
if (setup.failed()) {
ctx.failNow(setup.causeOfFailure());
return;
}
// WHEN a device that belongs to the tenant publishes an event
MessageHelper.setPayload(event, "text/plain", Buffer.buffer(messagePayload));
event.setAddress(getEndpointName());
sender.send(event, delivery -> {
if (delivery.getRemoteState() instanceof Accepted) {
log.debug("event message has been sent");
// THEN create a consumer once the event message has been successfully sent
log.debug("opening event consumer for tenant [{}]", tenantId);
createConsumer(tenantId, msg -> {
// THEN verify that the event message has been received by the consumer
log.debug("event message has been received by the consumer");
ctx.verify(() -> assertThat(msg.getPayload().toString()).isEqualTo(messagePayload));
ctx.completeNow();
});
} else {
ctx.failNow(AmqpErrorException.from(delivery.getRemoteState()));
}
});
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class TelemetryJmsQoS1IT method testTelemetryUpload.
/**
* Verifies that telemetry messages uploaded to the Hono server are all received
* by a downstream consumer.
*
* @throws Exception if the test fails.
*/
@Test
@AssumeMessagingSystem(type = MessagingType.amqp)
public void testTelemetryUpload() throws Exception {
final String tenantId = helper.getRandomTenantId();
final String deviceId = helper.getRandomDeviceId(tenantId);
final String username = IntegrationTestSupport.getUsername(deviceId, tenantId);
final String pwd = "secret";
final Tenant tenant = new Tenant();
final VertxTestContext setup = new VertxTestContext();
helper.registry.addDeviceForTenant(tenantId, tenant, deviceId, pwd).compose(ok -> getAmqpAdapterConnection(username, pwd)).onComplete(setup.succeeding(connection -> {
amqpAdapter = connection;
setup.completeNow();
}));
assertTrue(setup.awaitCompletion(IntegrationTestSupport.getTestSetupTimeout(), TimeUnit.SECONDS));
if (setup.failed()) {
fail(setup.causeOfFailure());
}
final CountDownLatch latch = new CountDownLatch(IntegrationTestSupport.MSG_COUNT);
final LongSummaryStatistics stats = new LongSummaryStatistics();
givenATelemetryConsumer(tenantId);
downstreamConsumer.setMessageListener(message -> {
latch.countDown();
gatherStatistics(stats, message);
if (LOG.isInfoEnabled()) {
final long messagesReceived = IntegrationTestSupport.MSG_COUNT - latch.getCount();
if (messagesReceived % 100 == 0) {
LOG.info("Received {} messages.", messagesReceived);
}
}
});
final MessageProducer messageProducer = amqpAdapter.createAnonymousProducer();
final Destination telemetryEndpoint = JmsBasedHonoConnection.getDestination(TelemetryConstants.TELEMETRY_ENDPOINT);
IntStream.range(1, IntegrationTestSupport.MSG_COUNT + 1).forEach(i -> {
try {
final Message message = amqpAdapter.newMessage("msg " + i, deviceId);
messageProducer.send(telemetryEndpoint, message, DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
if (i % 100 == 0) {
LOG.info("Sent {} messages", i);
}
} catch (final JMSException e) {
LOG.error("Error occurred while sending message: {}", e.getMessage(), e);
}
});
final long timeToWait = Math.max(DEFAULT_TEST_TIMEOUT, Math.round(IntegrationTestSupport.MSG_COUNT * 1.2));
// wait for messages to arrive
assertTrue(latch.await(timeToWait, TimeUnit.MILLISECONDS), () -> "did not receive all " + IntegrationTestSupport.MSG_COUNT + " messages");
LOG.info("Delivery statistics: {}", stats);
}
use of org.eclipse.hono.service.management.tenant.Tenant in project hono by eclipse.
the class AmqpConnectionIT method testConnectFailsIfAutoProvisioningIsDisabled.
/**
* Verifies that the adapter rejects connection attempts from an unknown device for which auto-provisioning is
* disabled.
*
* @param ctx The test context
*/
@Test
public void testConnectFailsIfAutoProvisioningIsDisabled(final VertxTestContext ctx) {
final String tenantId = helper.getRandomTenantId();
final SelfSignedCertificate deviceCert = SelfSignedCertificate.create(UUID.randomUUID().toString());
// GIVEN a tenant configured with a trust anchor that does not allow auto-provisioning
helper.getCertificate(deviceCert.certificatePath()).compose(cert -> {
final var tenant = Tenants.createTenantForTrustAnchor(cert);
tenant.getTrustedCertificateAuthorities().get(0).setAutoProvisioningEnabled(false);
return helper.registry.addTenant(tenantId, tenant);
}).compose(ok -> connectToAdapter(deviceCert)).onComplete(ctx.failing(t -> {
// THEN the connection is refused
ctx.verify(() -> assertThat(t).isInstanceOf(SaslException.class));
ctx.completeNow();
}));
}
Aggregations