use of org.apereo.cas.util.PublisherIdentifier 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.PublisherIdentifier in project cas by apereo.
the class DefaultRegisteredServiceReplicationStrategyTests method verifyGetInCacheAndRemove.
@Test
public void verifyGetInCacheAndRemove() {
val id = new PublisherIdentifier();
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val serviceRegistry = new InMemoryServiceRegistry(appCtx);
val stream = casProperties.getServiceRegistry().getStream();
val mgr = mock(DistributedCacheManager.class);
val strategy = new DefaultRegisteredServiceReplicationStrategy(mgr, stream, id);
val service = newService("Test");
val object = DistributedCacheObject.<RegisteredService>builder().value(service).publisherIdentifier(id).properties(Map.of("event", CasRegisteredServiceDeletedEvent.class.getSimpleName())).build();
when(mgr.find(any())).thenReturn(Optional.of(object));
val svc = strategy.getRegisteredServiceFromCacheIfAny(service, 1000, serviceRegistry);
assertNotNull(svc);
assertEquals(serviceRegistry.size(), 0);
}
use of org.apereo.cas.util.PublisherIdentifier in project cas by apereo.
the class DefaultRegisteredServiceReplicationStrategyTests method verifyGetInCacheAndSave.
@Test
public void verifyGetInCacheAndSave() {
val id = new PublisherIdentifier();
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val serviceRegistry = new InMemoryServiceRegistry(appCtx);
val stream = casProperties.getServiceRegistry().getStream();
val mgr = mock(DistributedCacheManager.class);
val strategy = new DefaultRegisteredServiceReplicationStrategy(mgr, stream, id);
val service = newService("Test");
val object = DistributedCacheObject.<RegisteredService>builder().value(service).publisherIdentifier(id).build();
when(mgr.find(any())).thenReturn(Optional.of(object));
val svc = strategy.getRegisteredServiceFromCacheIfAny(null, 1000, serviceRegistry);
assertNotNull(svc);
assertEquals(serviceRegistry.size(), 1);
}
use of org.apereo.cas.util.PublisherIdentifier in project cas by apereo.
the class DefaultRegisteredServiceReplicationStrategyTests method verifyUpdateWithMatch.
@Test
public void verifyUpdateWithMatch() {
val id = new PublisherIdentifier();
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val serviceRegistry = new InMemoryServiceRegistry(appCtx);
val stream = casProperties.getServiceRegistry().getStream();
val mgr = mock(DistributedCacheManager.class);
val service = newService("Test1");
val service2 = newService("Test2");
val obj1 = DistributedCacheObject.<RegisteredService>builder().value(service).publisherIdentifier(id).build();
val object = DistributedCacheObject.<RegisteredService>builder().value(service).publisherIdentifier(id).properties(Map.of("event", CasRegisteredServiceDeletedEvent.class.getSimpleName())).build();
when(mgr.getAll()).thenReturn(CollectionUtils.wrapList(obj1, object));
val strategy = new DefaultRegisteredServiceReplicationStrategy(mgr, stream, id);
val results = strategy.updateLoadedRegisteredServicesFromCache(CollectionUtils.wrapList(service, service2), serviceRegistry);
assertFalse(results.isEmpty());
}
use of org.apereo.cas.util.PublisherIdentifier in project cas by apereo.
the class CasServicesStreamingKafkaConfigurationTests method verifyListener.
@Test
public void verifyListener() throws Exception {
val registeredService = RegisteredServiceTestUtils.getRegisteredService();
val publisherId = new PublisherIdentifier();
casRegisteredServiceStreamPublisher.publish(registeredService, new CasRegisteredServiceSavedEvent(this, registeredService), publisherId);
Thread.sleep(3000);
assertFalse(registeredServiceDistributedCacheManager.getAll().isEmpty());
casRegisteredServiceStreamPublisher.publish(registeredService, new CasRegisteredServiceDeletedEvent(this, registeredService), publisherId);
Thread.sleep(2500);
registeredServiceDistributedCacheManager.clear();
assertTrue(registeredServiceDistributedCacheManager.getAll().isEmpty());
}
Aggregations