Search in sources :

Example 1 with DefaultLongPollingManager

use of eu.bcvsolutions.idm.core.model.service.impl.DefaultLongPollingManager in project CzechIdMng by bcvsolutions.

the class DefaultSysSystemServiceIntegrationTest method testExecuteDeferredResultOnCreateSyncItemLog.

@Test
public void testExecuteDeferredResultOnCreateSyncItemLog() {
    DefaultLongPollingManager defaultPollingManager = (DefaultLongPollingManager) longPollingManager;
    // Clear deferred result and subscribers
    defaultPollingManager.getSuspendedRequests().clear();
    defaultPollingManager.getRegistredSubscribers().clear();
    // create test system and sync
    SysSystemDto system = helper.createTestResourceSystem(true);
    AbstractSysSyncConfigDto syncConfig = createSync(system);
    DeferredResult<OperationResultDto> result = new DeferredResult<OperationResultDto>(1000000l, new OperationResultDto(OperationState.NOT_EXECUTED));
    DeferredResultWrapper wrapper = new DeferredResultWrapper(system.getId(), system.getClass(), result);
    wrapper.onCheckResultCallback(new CheckLongPollingResult() {

        @Override
        public void checkDeferredResult(DeferredResult<OperationResultDto> result, LongPollingSubscriber subscriber) {
            systemController.checkDeferredRequest(result, subscriber);
        }
    });
    Queue<DeferredResultWrapper> suspendedRequests = defaultPollingManager.getSuspendedRequests();
    assertEquals(0, suspendedRequests.size());
    longPollingManager.addSuspendedResult(wrapper);
    suspendedRequests = defaultPollingManager.getSuspendedRequests();
    assertEquals(1, suspendedRequests.size());
    longPollingManager.checkDeferredRequests(SysSystemDto.class);
    suspendedRequests = defaultPollingManager.getSuspendedRequests();
    assertEquals(1, suspendedRequests.size());
    helper.startSynchronization(syncConfig);
    SysSyncConfigFilter logFilter = new SysSyncConfigFilter();
    logFilter.setId(syncConfig.getId());
    logFilter.setIncludeLastLog(Boolean.TRUE);
    List<AbstractSysSyncConfigDto> configs = syncConfigService.find(logFilter, null).getContent();
    Assert.assertEquals(1, configs.size());
    SysSyncLogDto log = new SysSyncLogDto();
    log.setSynchronizationConfig(syncConfig.getId());
    log = syncLogService.save(log);
    SysSyncActionLogDto mockAction = new SysSyncActionLogDto();
    mockAction.setSyncAction(SynchronizationActionType.IGNORE);
    mockAction.setSyncLog(log.getId());
    mockAction.setOperationResult(OperationResultType.IGNORE);
    mockAction = syncActionLogService.save(mockAction);
    // Sync item log created -> must be detected
    SysSyncItemLogDto mockItemLogDto = new SysSyncItemLogDto();
    mockItemLogDto.setSyncActionLog(mockAction.getId());
    mockItemLogDto.setIdentification(helper.createName());
    mockItemLogDto = syncItemLogService.save(mockItemLogDto);
    // Check must be called twice, because first detect the change and second remove
    // ended deferred result (from some reason is not invoked method
    // result.onCompleted)
    longPollingManager.checkDeferredRequests(SysSystemDto.class);
    longPollingManager.checkDeferredRequests(SysSystemDto.class);
    suspendedRequests = defaultPollingManager.getSuspendedRequests();
    assertEquals(0, suspendedRequests.size());
    // Clear deferred result and subscribers
    defaultPollingManager.getSuspendedRequests().clear();
    defaultPollingManager.getRegistredSubscribers().clear();
}
Also used : LongPollingSubscriber(eu.bcvsolutions.idm.core.rest.LongPollingSubscriber) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) DeferredResultWrapper(eu.bcvsolutions.idm.core.rest.DeferredResultWrapper) DefaultLongPollingManager(eu.bcvsolutions.idm.core.model.service.impl.DefaultLongPollingManager) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) CheckLongPollingResult(eu.bcvsolutions.idm.core.model.service.api.CheckLongPollingResult) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) DeferredResult(org.springframework.web.context.request.async.DeferredResult) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)1 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)1 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)1 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)1 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)1 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)1 CheckLongPollingResult (eu.bcvsolutions.idm.core.model.service.api.CheckLongPollingResult)1 DefaultLongPollingManager (eu.bcvsolutions.idm.core.model.service.impl.DefaultLongPollingManager)1 DeferredResultWrapper (eu.bcvsolutions.idm.core.rest.DeferredResultWrapper)1 LongPollingSubscriber (eu.bcvsolutions.idm.core.rest.LongPollingSubscriber)1 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)1 Test (org.junit.Test)1 DeferredResult (org.springframework.web.context.request.async.DeferredResult)1