Search in sources :

Example 71 with SearchResultMetadata

use of com.evolveum.midpoint.schema.SearchResultMetadata in project midpoint by Evolveum.

the class SqaleRepoSearchIterativeTest method test112SearchIterativeWithLastPageNotFullWithAndFilter.

@Test
public void test112SearchIterativeWithLastPageNotFullWithAndFilter() throws Exception {
    // Like test111 but detects error when conditions are accumulating in provided AND filter with each page.
    OperationResult operationResult = createOperationResult();
    SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
    pm.clearGlobalPerformanceInformation();
    given("total result count not multiple of the page size");
    long totalCount = count(QUser.class);
    int iterativePageSize = 47;
    repositoryConfiguration.setIterativeSearchByPagingBatchSize(iterativePageSize);
    assertThat(totalCount % repositoryConfiguration.getIterativeSearchByPagingBatchSize()).isNotZero();
    queryRecorder.clearBufferAndStartRecording();
    when("calling search iterative with query containing condition");
    SearchResultMetadata metadata = searchObjectsIterative(prismContext.queryFor(UserType.class).not().item(UserType.F_NAME).isNull().and().item(UserType.F_GIVEN_NAME).isNull().build(), operationResult);
    then("result metadata is not null and reports the handled objects");
    assertThatOperationResult(operationResult).isSuccess();
    assertThat(metadata).isNotNull();
    assertThat(metadata.getApproxNumberOfAllResults()).isEqualTo(testHandler.getCounter());
    assertThat(metadata.isPartialResults()).isFalse();
    // page cookie is not null and it's OID in UUID format
    assertThat(UUID.fromString(metadata.getPagingCookie())).isNotNull();
    and("search operations were called");
    assertOperationRecordedCount(REPO_OP_PREFIX + RepositoryService.OP_SEARCH_OBJECTS_ITERATIVE, 1);
    assertTypicalPageOperationCount(metadata);
    and("all objects of the specified type were processed");
    assertThat(testHandler.getCounter()).isEqualTo(count(QUser.class));
    and("last iteration query has proper conditions");
    List<SqlRecorder.QueryEntry> iterativeSelects = queryRecorder.getQueryBuffer().stream().filter(e -> e.sql.contains("order by u.oid asc")).collect(Collectors.toList());
    // +1 for the last page
    assertThat(iterativeSelects).hasSize((int) totalCount / iterativePageSize + 1);
    SqlRecorder.QueryEntry lastEntry = iterativeSelects.get(iterativeSelects.size() - 1);
    // We want to be sure no accidental filter accumulation happens, see ObjectQueryUtil.filterAnd() vs createAnd().
    assertThat(lastEntry.sql).contains("where not (u.nameNorm is null and u.nameOrig is null)" + " and (u.givenNameNorm is null and u.givenNameOrig is null) and u.oid > ?\norder");
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Test(org.testng.annotations.Test) AfterMethod(org.testng.annotations.AfterMethod) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest) SqlRecorder(com.evolveum.midpoint.repo.sqlbase.querydsl.SqlRecorder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) QUser(com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser) QObject(com.evolveum.midpoint.repo.sqale.qmodel.object.QObject) Predicate(java.util.function.Predicate) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) UUID(java.util.UUID) PrismObject(com.evolveum.midpoint.prism.PrismObject) Collectors(java.util.stream.Collectors) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) List(java.util.List) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SqaleRepositoryService(com.evolveum.midpoint.repo.sqale.SqaleRepositoryService) QUser(com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SqlRecorder(com.evolveum.midpoint.repo.sqlbase.querydsl.SqlRecorder) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 72 with SearchResultMetadata

use of com.evolveum.midpoint.schema.SearchResultMetadata in project midpoint by Evolveum.

the class SqaleAuditSearchIterativeTest method test120SearchIterativeWithMaxSize.

@Test
public void test120SearchIterativeWithMaxSize() throws Exception {
    OperationResult operationResult = createOperationResult();
    SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
    pm.clearGlobalPerformanceInformation();
    given("query with maxSize specified");
    ObjectQuery query = prismContext.queryFor(UserType.class).maxSize(101).build();
    when("calling search iterative");
    SearchResultMetadata metadata = searchObjectsIterative(query, operationResult);
    then("result metadata is not null and reports partial result (because of the break)");
    assertThat(metadata).isNotNull();
    assertThat(metadata.getApproxNumberOfAllResults()).isEqualTo(testHandler.processedCount());
    assertThat(metadata.isPartialResults()).isFalse();
    and("search operations were called");
    assertOperationRecordedCount(AUDIT_OP_PREFIX + AuditService.OP_SEARCH_OBJECTS_ITERATIVE, 1);
    assertTypicalPageOperationCount(metadata);
    and("specified amount of objects was processed");
    assertThat(testHandler.processedCount()).isEqualTo(101);
}
Also used : SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 73 with SearchResultMetadata

use of com.evolveum.midpoint.schema.SearchResultMetadata in project midpoint by Evolveum.

the class SqaleAuditSearchIterativeTest method test110SearchIterativeWithEmptyFilter.

@Test
public void test110SearchIterativeWithEmptyFilter() throws Exception {
    OperationResult operationResult = createOperationResult();
    SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
    pm.clearGlobalPerformanceInformation();
    when("calling search iterative with null query");
    SearchResultMetadata metadata = searchObjectsIterative(null, operationResult);
    then("result metadata is not null and reports the handled objects");
    assertThatOperationResult(operationResult).isSuccess();
    assertThat(metadata).isNotNull();
    assertThat(metadata.getApproxNumberOfAllResults()).isEqualTo(testHandler.processedCount());
    assertThat(metadata.isPartialResults()).isFalse();
    assertThat(metadata.getPagingCookie()).isNotNull();
    and("search operations were called");
    assertOperationRecordedCount(AUDIT_OP_PREFIX + AuditService.OP_SEARCH_OBJECTS_ITERATIVE, 1);
    assertTypicalPageOperationCount(metadata);
    and("all objects of the specified type (here User) were processed");
    assertThat(testHandler.processedCount()).isEqualTo(count(aer));
}
Also used : SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 74 with SearchResultMetadata

use of com.evolveum.midpoint.schema.SearchResultMetadata in project midpoint by Evolveum.

the class AbstractAdLdapMultidomainTest method test174SearchFirst5AccountsOffset2.

/**
 * There is offset, so VLV should be used.
 * No explicit sorting.
 */
@Test
public void test174SearchFirst5AccountsOffset2() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
    ObjectPaging paging = prismContext.queryFactory().createPaging(2, 5);
    query.setPaging(paging);
    allowDuplicateSearchResults = true;
    // WHEN
    SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(query, 5, task, result);
    // THEN
    allowDuplicateSearchResults = false;
    // TODO: Why 2? Why not 1?
    assertCounterIncrement(InternalCounters.CONNECTOR_OPERATION_COUNT, 2);
    assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
    SearchResultMetadata metadata = searchResultList.getMetadata();
    if (metadata != null) {
        assertFalse(metadata.isPartialResults());
    }
    assertLdapConnectorReasonableInstances();
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test) AbstractAdLdapTest(com.evolveum.midpoint.testing.conntest.ad.AbstractAdLdapTest)

Example 75 with SearchResultMetadata

use of com.evolveum.midpoint.schema.SearchResultMetadata in project midpoint by Evolveum.

the class AbstractLdapConnTest method test152SearchFirst50Accounts.

/**
 * Blocksize is 100, so this is in one block.
 */
@Test
public void test152SearchFirst50Accounts() throws Exception {
    // GIVEN
    Task task = getTestTask();
    OperationResult result = task.getResult();
    ObjectQuery query = ObjectQueryUtil.createResourceAndObjectClassQuery(getResourceOid(), getAccountObjectClass(), prismContext);
    ObjectPaging paging = prismContext.queryFactory().createPaging();
    paging.setMaxSize(50);
    query.setPaging(paging);
    SearchResultList<PrismObject<ShadowType>> searchResultList = doSearch(query, 50, task, result);
    assertConnectorOperationIncrement(1, 51);
    assertCounterIncrement(InternalCounters.CONNECTOR_SIMULATED_PAGING_SEARCH_COUNT, 0);
    SearchResultMetadata metadata = searchResultList.getMetadata();
    if (metadata != null) {
        assertFalse(metadata.isPartialResults());
    }
    // Uknown number of results. This is SPR search.
    assertApproxNumberOfAllResults(metadata, null);
    assertLdapConnectorReasonableInstances();
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) SearchResultMetadata(com.evolveum.midpoint.schema.SearchResultMetadata) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) Test(org.testng.annotations.Test)

Aggregations

SearchResultMetadata (com.evolveum.midpoint.schema.SearchResultMetadata)84 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)83 Test (org.testng.annotations.Test)80 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)76 PrismObject (com.evolveum.midpoint.prism.PrismObject)70 Task (com.evolveum.midpoint.task.api.Task)67 ObjectPaging (com.evolveum.midpoint.prism.query.ObjectPaging)35 AbstractAdLdapTest (com.evolveum.midpoint.testing.conntest.ad.AbstractAdLdapTest)19 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)13 SqlPerformanceMonitorImpl (com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl)13 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)11 AbstractIntegrationTest (com.evolveum.midpoint.test.AbstractIntegrationTest)9 AbstractLdapSynchronizationTest (com.evolveum.midpoint.testing.conntest.AbstractLdapSynchronizationTest)8 QUser (com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser)5 JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)3 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)3 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3