Search in sources :

Example 1 with DistributedCacheObject

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());
}
Also used : lombok.val(lombok.val) lombok.val(lombok.val) Autowired(org.springframework.beans.factory.annotation.Autowired) FileUtils(org.apache.commons.io.FileUtils) CasRegisteredServiceLoadedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceLoadedEvent) UUID(java.util.UUID) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) DistributedCacheObject(org.apereo.cas.util.cache.DistributedCacheObject) RegisteredService(org.apereo.cas.services.RegisteredService) File(java.io.File) CasRegisteredServiceDeletedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent) Test(org.junit.jupiter.api.Test) DistributedCacheManager(org.apereo.cas.util.cache.DistributedCacheManager) EnabledIfPortOpen(org.apereo.cas.util.junit.EnabledIfPortOpen) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RefreshAutoConfiguration(org.springframework.cloud.autoconfigure.RefreshAutoConfiguration) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) RegisteredServiceTestUtils(org.apereo.cas.services.RegisteredServiceTestUtils) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Assertions(org.junit.jupiter.api.Assertions) CasRegisteredServiceStreamPublisher(org.apereo.cas.services.publisher.CasRegisteredServiceStreamPublisher) CasRegisteredServiceSavedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceSavedEvent) Tag(org.junit.jupiter.api.Tag) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with DistributedCacheObject

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));
}
Also used : lombok.val(lombok.val) DistributedCacheObject(org.apereo.cas.util.cache.DistributedCacheObject) Objects(java.util.Objects) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with DistributedCacheObject

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);
        }
    });
}
Also used : lombok.val(lombok.val) DistributedCacheObject(org.apereo.cas.util.cache.DistributedCacheObject) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with DistributedCacheObject

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);
        }
    });
}
Also used : lombok.val(lombok.val) DistributedCacheObject(org.apereo.cas.util.cache.DistributedCacheObject) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with DistributedCacheObject

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));
}
Also used : lombok.val(lombok.val) KafkaObjectFactory(org.apereo.cas.kafka.KafkaObjectFactory) RegisteredServiceJsonSerializer(org.apereo.cas.services.util.RegisteredServiceJsonSerializer) DistributedCacheObject(org.apereo.cas.util.cache.DistributedCacheObject) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

lombok.val (lombok.val)5 DistributedCacheObject (org.apereo.cas.util.cache.DistributedCacheObject)5 PublisherIdentifier (org.apereo.cas.util.PublisherIdentifier)4 Test (org.junit.jupiter.api.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 RegisteredServiceJsonSerializer (org.apereo.cas.services.util.RegisteredServiceJsonSerializer)2 Executable (org.junit.jupiter.api.function.Executable)2 File (java.io.File)1 Objects (java.util.Objects)1 UUID (java.util.UUID)1 FileUtils (org.apache.commons.io.FileUtils)1 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)1 KafkaObjectFactory (org.apereo.cas.kafka.KafkaObjectFactory)1 RegisteredService (org.apereo.cas.services.RegisteredService)1 RegisteredServiceTestUtils (org.apereo.cas.services.RegisteredServiceTestUtils)1 CasRegisteredServiceStreamPublisher (org.apereo.cas.services.publisher.CasRegisteredServiceStreamPublisher)1 CasRegisteredServiceDeletedEvent (org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent)1 CasRegisteredServiceLoadedEvent (org.apereo.cas.support.events.service.CasRegisteredServiceLoadedEvent)1 CasRegisteredServiceSavedEvent (org.apereo.cas.support.events.service.CasRegisteredServiceSavedEvent)1 DistributedCacheManager (org.apereo.cas.util.cache.DistributedCacheManager)1