Search in sources :

Example 16 with SqlPerformanceMonitorImpl

use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.

the class SqaleRepoSearchIterativeTest method test115SearchIterativeWithBreakingConditionCheckingOidOrdering.

@Test
public void test115SearchIterativeWithBreakingConditionCheckingOidOrdering() throws Exception {
    OperationResult operationResult = createOperationResult();
    SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
    pm.clearGlobalPerformanceInformation();
    String midOid = "80000000-0000-0000-0000-000000000000";
    given("condition that breaks iterative search based on UUID");
    testHandler.setStoppingPredicate(u -> u.getOid().compareTo(midOid) >= 0);
    when("calling search iterative with null query");
    SearchResultMetadata metadata = searchObjectsIterative(null, operationResult);
    then("result metadata is not null and reports partial result (because of the break)");
    assertThat(metadata).isNotNull();
    assertThat(metadata.getApproxNumberOfAllResults()).isEqualTo(testHandler.getCounter());
    // extremely likely with enough items
    assertThat(metadata.isPartialResults()).isTrue();
    and("search operations were called");
    assertOperationRecordedCount(REPO_OP_PREFIX + RepositoryService.OP_SEARCH_OBJECTS_ITERATIVE, 1);
    assertTypicalPageOperationCount(metadata);
    and("all objects up to specified UUID were processed");
    QUser u = aliasFor(QUser.class);
    assertThat(testHandler.getCounter()).isEqualTo(count(u, u.oid.lt(UUID.fromString(midOid))) + 1);
}
Also used : 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) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 17 with SqlPerformanceMonitorImpl

use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.

the class SqaleRepoSmokeTest method test110DeleteObject.

@Test
public void test110DeleteObject() throws Exception {
    OperationResult result = createOperationResult();
    given("existing user");
    UserType user = new UserType(prismContext).name("user" + getTestNumber());
    String userOid = repositoryService.addObject(user.asPrismObject(), null, result);
    and("cleared performance information");
    SqlPerformanceMonitorImpl pm = repositoryService.getPerformanceMonitor();
    pm.clearGlobalPerformanceInformation();
    when("user is deleted from the repository");
    DeleteObjectResult deleteResult = repositoryService.deleteObject(UserType.class, userOid, result);
    then("added object is assigned OID and operation is success");
    assertThat(deleteResult).isNotNull();
    assertThatOperationResult(result).isSuccess();
    assertThat(selectNullableObjectByOid(QUser.class, userOid)).isNull();
    assertSingleOperationRecorded(REPO_OP_PREFIX + RepositoryService.OP_DELETE_OBJECT);
}
Also used : SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) DeleteObjectResult(com.evolveum.midpoint.repo.api.DeleteObjectResult) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 18 with SqlPerformanceMonitorImpl

use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.

the class SqaleRepoSmokeTest method test210GetVersion.

@Test
public void test210GetVersion() throws Exception {
    OperationResult result = createOperationResult();
    given("existing user and cleared performance information");
    UserType user = new UserType(prismContext).name("user" + getTestNumber());
    String userOid = repositoryService.addObject(user.asPrismObject(), null, result);
    SqlPerformanceMonitorImpl pm = repositoryService.getPerformanceMonitor();
    pm.clearGlobalPerformanceInformation();
    when("getVersion is called for known OID");
    String version = repositoryService.getVersion(UserType.class, userOid, result);
    then("non-null version string is obtained and performance monitor is updated");
    assertThatOperationResult(result).isSuccess();
    assertThat(version).isNotNull();
    assertSingleOperationRecorded(REPO_OP_PREFIX + RepositoryService.OP_GET_VERSION);
}
Also used : SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 19 with SqlPerformanceMonitorImpl

use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl in project midpoint by Evolveum.

the class SqaleRepoSearchIterativeTest method test111SearchIterativeWithLastPageNotFull.

@Test
public void test111SearchIterativeWithLastPageNotFull() throws Exception {
    OperationResult operationResult = createOperationResult();
    SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
    pm.clearGlobalPerformanceInformation();
    given("total result count not multiple of the page size");
    long totalCount = count(QObject.CLASS);
    int iterativePageSize = 47;
    repositoryConfiguration.setIterativeSearchByPagingBatchSize(iterativePageSize);
    assertThat(totalCount % repositoryConfiguration.getIterativeSearchByPagingBatchSize()).isNotZero();
    queryRecorder.clearBufferAndStartRecording();
    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.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
    assertThat(lastEntry.sql).contains("where u.oid > ?\norder by u.oid asc");
}
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 20 with SqlPerformanceMonitorImpl

use of com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl 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)

Aggregations

SqlPerformanceMonitorImpl (com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl)34 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)25 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)16 Test (org.testng.annotations.Test)16 SearchResultMetadata (com.evolveum.midpoint.schema.SearchResultMetadata)13 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)8 QUser (com.evolveum.midpoint.repo.sqale.qmodel.focus.QUser)5 NotNull (org.jetbrains.annotations.NotNull)5 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)3 com.evolveum.midpoint.prism.query (com.evolveum.midpoint.prism.query)3 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)3 Collectors (java.util.stream.Collectors)3 Nullable (org.jetbrains.annotations.Nullable)3 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)2 AuditReferenceValue (com.evolveum.midpoint.audit.api.AuditReferenceValue)2 AuditResultHandler (com.evolveum.midpoint.audit.api.AuditResultHandler)2 AuditService (com.evolveum.midpoint.audit.api.AuditService)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 ChangeType (com.evolveum.midpoint.prism.delta.ChangeType)2