use of org.eclipse.hono.util.RegistrationAssertion in project hono by eclipse.
the class ProtonBasedDownstreamSenderTest method testDownstreamEventHasCreationTimeAndTtl.
/**
* Verifies that a downstream event always contains a creation-time
* and a time-to-live as defined at the tenant level.
*/
@Test
public void testDownstreamEventHasCreationTimeAndTtl() {
final TenantObject tenant = TenantObject.from(Constants.DEFAULT_TENANT, true);
final RegistrationAssertion device = new RegistrationAssertion("4711");
tenant.setResourceLimits(new ResourceLimits().setMaxTtl(60L));
// WHEN sending a message without specifying any properties
sender.sendEvent(tenant, device, "text/plain", Buffer.buffer("hello"), null, span.context());
// THEN the message contains a creation-time
verify(protonSender).send(argThat(message -> message.getCreationTime() > 0 && message.getTtl() == 60000L), VertxMockSupport.anyHandler());
}
use of org.eclipse.hono.util.RegistrationAssertion in project hono by eclipse.
the class AbstractAutoProvisioningEventSender method sendAutoProvisioningEvent.
/**
* Send an auto-provisioning event with content type
* {@value EventConstants#CONTENT_TYPE_DEVICE_PROVISIONING_NOTIFICATION}.
*
* @param tenantId The tenant identifier.
* @param tenant The tenant information.
* @param deviceId The device identifier.
* @param gatewayId The gateway identifier if an edge device is being auto-provisioned.
* @param span The active OpenTracing span for this operation. It is not to be closed in this method! An
* implementation should log (error) events on this span and it may set tags and use this span as the
* parent for any spans created in this method.
* @return A future indicating the outcome of the operation. The future will be succeeded if the auto-provisioning
* event is sent successfully.
* @throws NullPointerException if any of the parameters except gateway id is {@code null}.
* @see "https://www.eclipse.org/hono/docs/api/event/#device-provisioning-notification"
*/
protected Future<Void> sendAutoProvisioningEvent(final String tenantId, final Tenant tenant, final String deviceId, final String gatewayId, final Span span) {
Objects.requireNonNull(tenantId);
Objects.requireNonNull(deviceId);
Objects.requireNonNull(span);
// TODO to remove once able to send events without providing an argument of type TenantObject
final TenantObject tenantConfig = DeviceRegistryUtils.convertTenant(tenantId, tenant).mapTo(TenantObject.class);
final EventSender eventSender = eventSenderProvider.getClient(tenantConfig);
return eventSender.sendEvent(tenantConfig, new RegistrationAssertion(deviceId), EventConstants.CONTENT_TYPE_DEVICE_PROVISIONING_NOTIFICATION, null, assembleAutoProvisioningEventProperties(tenantId, gatewayId), span.context()).onSuccess(ok -> {
span.log("sent auto-provisioning notification");
LOG.debug("sent auto-provisioning notification [tenant-id: {}, device-id: {}, gateway-id: {}]", tenantId, deviceId, gatewayId);
}).onFailure(t -> {
TracingHelper.logError(span, "error sending auto-provisioning notification", t);
LOG.warn("error sending auto-provisioning notification [tenant-id: {}, device-id: {}, gateway-id: {}]", tenantId, deviceId, gatewayId);
});
}
Aggregations