use of org.eclipse.hono.notification.deviceregistry.AllDevicesOfTenantDeletedNotification in project hono by eclipse.
the class KafkaBasedNotificationReceiverTest method testThatCorrectHandlerIsInvoked.
/**
* Verifies that the receiver decodes the notifications it receives and invokes the correct handler.
*
* @param ctx The vert.x test context.
*/
@Test
public void testThatCorrectHandlerIsInvoked(final VertxTestContext ctx) {
final String tenantId = "my-tenant";
final String deviceId = "my-device";
final Instant creationTime = Instant.parse("2007-12-03T10:15:30Z");
mockConsumer.schedulePollTask(() -> {
mockConsumer.addRecord(createKafkaRecord(new TenantChangeNotification(LifecycleChange.CREATE, tenantId, creationTime, false), 0L));
mockConsumer.addRecord(createKafkaRecord(new DeviceChangeNotification(LifecycleChange.CREATE, tenantId, deviceId, creationTime, false), 0L));
mockConsumer.addRecord(createKafkaRecord(new CredentialsChangeNotification(tenantId, deviceId, creationTime), 1L));
mockConsumer.addRecord(createKafkaRecord(new AllDevicesOfTenantDeletedNotification(tenantId, creationTime), 2L));
});
final var receiver = createReceiver();
final Checkpoint handlerInvokedCheckpoint = ctx.checkpoint(4);
receiver.registerConsumer(TenantChangeNotification.TYPE, notification -> ctx.verify(() -> {
assertThat(notification).isInstanceOf(TenantChangeNotification.class);
handlerInvokedCheckpoint.flag();
}));
receiver.registerConsumer(DeviceChangeNotification.TYPE, notification -> ctx.verify(() -> {
assertThat(notification).isInstanceOf(DeviceChangeNotification.class);
handlerInvokedCheckpoint.flag();
}));
receiver.registerConsumer(CredentialsChangeNotification.TYPE, notification -> ctx.verify(() -> {
assertThat(notification).isInstanceOf(CredentialsChangeNotification.class);
handlerInvokedCheckpoint.flag();
}));
receiver.registerConsumer(AllDevicesOfTenantDeletedNotification.TYPE, notification -> ctx.verify(() -> {
assertThat(notification).isInstanceOf(AllDevicesOfTenantDeletedNotification.class);
handlerInvokedCheckpoint.flag();
}));
receiver.start();
}
use of org.eclipse.hono.notification.deviceregistry.AllDevicesOfTenantDeletedNotification in project hono by eclipse.
the class AbstractDeviceManagementService method deleteDevicesOfTenant.
@Override
public final Future<Result<Void>> deleteDevicesOfTenant(final String tenantId, final Span span) {
Objects.requireNonNull(tenantId);
Objects.requireNonNull(span);
return this.tenantInformationService.tenantExists(tenantId, span).otherwise(t -> Result.from(ServiceInvocationException.extractStatusCode(t))).compose(result -> {
switch(result.getStatus()) {
case HttpURLConnection.HTTP_OK:
break;
case HttpURLConnection.HTTP_NOT_FOUND:
span.log("tenant does not exist (anymore)");
LOG.info("trying to delete devices of non-existing tenant [tenant-id: {}]", tenantId);
break;
default:
span.log(Map.of(Fields.EVENT, "could not determine tenant status", Tags.HTTP_STATUS.getKey(), result.getStatus()));
LOG.info("could not determine tenant status [tenant-id: {}, code: {}]", tenantId, result.getStatus());
}
return processDeleteDevicesOfTenant(tenantId, span);
}).onSuccess(result -> NotificationEventBusSupport.sendNotification(vertx, new AllDevicesOfTenantDeletedNotification(tenantId, Instant.now()))).recover(t -> DeviceRegistryUtils.mapError(t, tenantId));
}
Aggregations