use of org.apereo.cas.util.cache.DistributedCacheObject in project cas by apereo.
the class CasServicesStreamingKafkaConfigurationTests method verifyAction.
@Test
public void verifyAction() throws Exception {
val registeredService = RegisteredServiceTestUtils.getRegisteredService();
var obj = registeredServiceDistributedCacheManager.get(registeredService);
assertNull(obj);
assertFalse(registeredServiceDistributedCacheManager.contains(registeredService));
val cache = DistributedCacheObject.<RegisteredService>builder().value(registeredService).publisherIdentifier(casRegisteredServiceStreamPublisherIdentifier).build();
registeredServiceDistributedCacheManager.set(registeredService, cache, true);
Thread.sleep(2000);
assertFalse(registeredServiceDistributedCacheManager.getAll().isEmpty());
obj = registeredServiceDistributedCacheManager.get(registeredService);
assertNotNull(obj);
var c = registeredServiceDistributedCacheManager.findAll(obj1 -> obj1.getValue().equals(registeredService));
assertFalse(c.isEmpty());
registeredServiceDistributedCacheManager.remove(registeredService, cache, true);
Thread.sleep(5000);
c = registeredServiceDistributedCacheManager.findAll(obj1 -> obj1.getValue().equals(registeredService));
assertTrue(c.isEmpty());
registeredServiceDistributedCacheManager.clear();
assertTrue(registeredServiceDistributedCacheManager.getAll().isEmpty());
}
use of org.apereo.cas.util.cache.DistributedCacheObject in project cas by apereo.
the class RegisteredServiceKafkaDistributedCacheManagerTests method verifyOperation.
@Test
public void verifyOperation() {
val service = RegisteredServiceTestUtils.getRegisteredService();
assertFalse(registeredServiceDistributedCacheManager.contains(service));
assertTrue(registeredServiceDistributedCacheManager.getAll().isEmpty());
assertTrue(registeredServiceDistributedCacheManager.findAll(Objects::nonNull).isEmpty());
val item = new DistributedCacheObject<RegisteredService>(Map.of(), System.currentTimeMillis(), service, new PublisherIdentifier());
assertNotNull(registeredServiceDistributedCacheManager.set(service, item, true));
assertNotNull(registeredServiceDistributedCacheManager.set(service, item, false));
assertNotNull(registeredServiceDistributedCacheManager.update(service, item, true));
assertNotNull(registeredServiceDistributedCacheManager.update(service, item, false));
}
use of org.apereo.cas.util.cache.DistributedCacheObject in project cas by apereo.
the class RegisteredServiceKafkaDistributedCacheListenerTests method verifyRemoval.
@Test
public void verifyRemoval() {
val service = RegisteredServiceTestUtils.getRegisteredService();
val item = new DistributedCacheObject<RegisteredService>(Map.of("event", CasRegisteredServiceDeletedEvent.class.getSimpleName()), System.currentTimeMillis(), service, new PublisherIdentifier());
assertDoesNotThrow(new Executable() {
@Override
public void execute() throws Throwable {
listener.registeredServiceDistributedCacheKafkaListener(item);
}
});
}
use of org.apereo.cas.util.cache.DistributedCacheObject in project cas by apereo.
the class RegisteredServiceKafkaDistributedCacheListenerTests method verifyUpdate.
@Test
public void verifyUpdate() {
val service = RegisteredServiceTestUtils.getRegisteredService();
val item = new DistributedCacheObject<RegisteredService>(Map.of(), System.currentTimeMillis(), service, new PublisherIdentifier());
assertDoesNotThrow(new Executable() {
@Override
public void execute() throws Throwable {
listener.registeredServiceDistributedCacheKafkaListener(item);
}
});
}
use of org.apereo.cas.util.cache.DistributedCacheObject in project cas by apereo.
the class CasServicesStreamingKafkaConfiguration method registeredServiceKafkaListenerContainerFactory.
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnMissingBean(name = "registeredServiceKafkaListenerContainerFactory")
public ConcurrentKafkaListenerContainerFactory<String, DistributedCacheObject> registeredServiceKafkaListenerContainerFactory(final CasConfigurationProperties casProperties) {
val kafka = casProperties.getServiceRegistry().getStream().getKafka();
val factory = new KafkaObjectFactory<String, DistributedCacheObject>(kafka.getBootstrapAddress());
factory.setConsumerGroupId("registeredServices");
val mapper = new RegisteredServiceJsonSerializer().getObjectMapper();
return factory.getKafkaListenerContainerFactory(new StringDeserializer(), new JsonDeserializer<>(DistributedCacheObject.class, mapper));
}
Aggregations