use of org.eclipse.hono.notification.deviceregistry.AllDevicesOfTenantDeletedNotification in project hono by eclipse.
the class AbstractVertxBasedMqttProtocolAdapterTest method testDeviceConnectionIsClosedOnAllDevicesOfTenantDeletedNotification.
/**
* Verifies that the adapter closes the connection to an authenticated device when a notification
* about the deletion of all device data of the tenant of that device has been received.
*
* @param ctx The vert.x test context.
*/
@Test
public void testDeviceConnectionIsClosedOnAllDevicesOfTenantDeletedNotification(final VertxTestContext ctx) {
final Device device = new Device("tenant", "deviceId");
testDeviceConnectionIsClosedOnDeviceOrTenantChangeNotification(ctx, device, new AllDevicesOfTenantDeletedNotification("tenant", Instant.now()));
}
use of org.eclipse.hono.notification.deviceregistry.AllDevicesOfTenantDeletedNotification in project hono by eclipse.
the class KafkaBasedNotificationSenderTest method testProducerRecordForAllDevicesOfTenantDeletedNotification.
/**
* Verifies that the expected Kafka record is created when publishing a {@link AllDevicesOfTenantDeletedNotification}.
*
* @param ctx The vert.x test context.
*/
@Test
public void testProducerRecordForAllDevicesOfTenantDeletedNotification(final VertxTestContext ctx) {
final AllDevicesOfTenantDeletedNotification notification = new AllDevicesOfTenantDeletedNotification(TENANT_ID, CREATION_TIME);
testProducerRecordForNotification(ctx, notification, TENANT_ID);
}
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));
}
use of org.eclipse.hono.notification.deviceregistry.AllDevicesOfTenantDeletedNotification in project hono by eclipse.
the class ProtonBasedDeviceRegistrationClientTest method testAllDevicesOfTenantDeletedNotificationRemovesValueFromCache.
/**
* Verifies that the client removes all registrations of a tenant from the cache if it receives a notification that
* tenant all devices of the tenant have been deleted.
*
* @param ctx The vert.x test context.
*/
@Test
public void testAllDevicesOfTenantDeletedNotificationRemovesValueFromCache(final VertxTestContext ctx) {
final String tenantId = "the-tenant-id";
givenAClient(cache);
final var notificationHandlerCaptor = getEventBusConsumerHandlerArgumentCaptor(AllDevicesOfTenantDeletedNotification.TYPE);
final Set<AnnotatedCacheKey<?>> expectedCacheRemovals = new HashSet<>();
// GIVEN a client with a cache containing device registrations of two tenants
client.start().compose(v -> addResultToCache("other-tenant", "device-id1", "gateway-id")).compose(v -> addResultToCache(tenantId, "device-id1", "gateway-id")).map(expectedCacheRemovals::add).compose(v -> addResultToCache(tenantId, "device-id2", "gateway-id")).map(expectedCacheRemovals::add).onComplete(ctx.succeeding(ok -> ctx.verify(() -> {
// WHEN receiving a notification that all devices of a tenant have been deleted
sendViaEventBusMock(new AllDevicesOfTenantDeletedNotification(tenantId, Instant.now()), notificationHandlerCaptor.getValue());
// THEN the cache is invalidated for all registrations of the tenant
ctx.verify(() -> verify(cache).invalidateAll(expectedCacheRemovals));
ctx.completeNow();
})));
}
use of org.eclipse.hono.notification.deviceregistry.AllDevicesOfTenantDeletedNotification in project hono by eclipse.
the class ProtonBasedCredentialsClientTest method testAllDevicesOfTenantDeletedNotificationRemovesValueFromCache.
/**
* Verifies that the client removes all credentials of a tenant from the cache if it receives a notification that
* tenant all devices of the tenant have been deleted.
*
* @param ctx The vert.x test context.
*/
@Test
public void testAllDevicesOfTenantDeletedNotificationRemovesValueFromCache(final VertxTestContext ctx) {
final String tenantId = "the-tenant-id";
final String deviceId = "the-device-id";
givenAClient(cache);
final var notificationHandlerCaptor = getEventBusConsumerHandlerArgumentCaptor(AllDevicesOfTenantDeletedNotification.TYPE);
final Set<AnnotatedCacheKey<?>> expectedCacheRemovals = new HashSet<>();
// GIVEN a client with a cache containing credentials of two tenants
client.start().compose(v -> addResultToCache("other-tenant", deviceId, "other")).compose(v -> addResultToCache(tenantId, deviceId, "auth-id1")).map(expectedCacheRemovals::add).compose(v -> addResultToCache(tenantId, deviceId, "auth-id2")).map(expectedCacheRemovals::add).onComplete(ctx.succeeding(ok -> ctx.verify(() -> {
// WHEN receiving a notification that all devices of a tenant have been deleted
sendViaEventBusMock(new AllDevicesOfTenantDeletedNotification(tenantId, Instant.now()), notificationHandlerCaptor.getValue());
// THEN the cache is invalidated for all credentials of the tenant and not for other tenants
ctx.verify(() -> verify(cache).invalidateAll(expectedCacheRemovals));
ctx.completeNow();
})));
}
Aggregations