Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Sep 23, 2021
2 parents c312c17 + 72b67ec commit d707a82
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class SqaleRepoBaseTest extends AbstractSpringTest
protected SqlRecorder queryRecorder;

@BeforeClass
public void clearDatabase() {
public void initDatabase() throws Exception {
queryRecorder = new SqlRecorder(QUERY_BUFFER_SIZE);
sqlRepoContext.setQuerydslSqlListener(queryRecorder);

Expand Down Expand Up @@ -112,7 +112,6 @@ public void clearDatabase() {
cacheTablesCleared = true;
display("URI cache and Extension item catalog tables cleared");
}
// TODO m_ext_item is not deleted now, do we want it too? session scope like URI cache?
}

// Called on demand
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.repo.sqale.perf;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest;
import com.evolveum.midpoint.repo.sqale.qmodel.role.MRole;
import com.evolveum.midpoint.repo.sqale.qmodel.role.QRole;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

/**
* This creates specified number of roles and then assigns user to them randomly
* so that roles with lower numbers have more users and higher have much less.
*/
public class RoleMemberListRepoTest extends SqaleRepoBaseTest {

public static final int ROLE_MIN = 1;
public static final int ROLE_MAX = 200;
public static final int USER_MIN = 200001;
public static final int USER_MAX = 300000;

public static final int FIND_COUNT = 1000;

private static final Random RND = new Random();

private final List<String> roleOids = new ArrayList<>();

@BeforeClass
@Override
public void initDatabase() throws Exception {
// super.initDatabase();
// Commented to avoid DB clearing.
// Then we can use this to fill production/manual test database too.
}

@Test
public void fillDatabase() throws SchemaException, ObjectAlreadyExistsException {
OperationResult operationResult = createOperationResult();
for (int roleIndex = ROLE_MIN; roleIndex <= ROLE_MAX; roleIndex++) {
String name = String.format("role-%05d", roleIndex);
RoleType role = new RoleType(prismContext)
.name(PolyStringType.fromOrig(name));
try {
repositoryService.addObject(role.asPrismObject(), null, operationResult);
roleOids.add(role.getOid());
System.out.println("Created role " + name);
} catch (ObjectAlreadyExistsException e) {
// never mind, we'll use the existing one
QRole r = aliasFor(QRole.class);
MRole existingRow = selectOne(r, r.nameOrig.eq(name));
roleOids.add(existingRow.oid.toString());
System.out.println("Reused existing role " + name);
}
}

for (int userIndex = USER_MIN; userIndex <= USER_MAX; userIndex++) {
String name = String.format("user-%07d", userIndex);
UserType user = new UserType(prismContext)
.name(PolyStringType.fromOrig(name));
addRoles(user);
try {
repositoryService.addObject(user.asPrismObject(), null, operationResult);
System.out.println("Created user " + name + " with " + user.getRoleMembershipRef().size() + " roles");
} catch (ObjectAlreadyExistsException e) {
System.out.println("User " + name + " already exists");
}
}
}

private void addRoles(UserType user) {
int size = roleOids.size();
int counter = 0;
for (String roleOid : roleOids) {
// 2d converts size to double and also gives minuscule chance to the last role.
double probability = (size - counter) / (2d + size);
if (probability > RND.nextDouble()) {
user.assignment(new AssignmentType(prismContext)
.targetRef(roleOid, RoleType.COMPLEX_TYPE));
user.roleMembershipRef(roleOid, RoleType.COMPLEX_TYPE);
}
counter += 1;
}
}

/*
@Test
public void test110GetUser() throws SchemaException, ObjectNotFoundException {
OperationResult operationResult = createOperationResult();
Stopwatch stopwatch = stopwatch("user.get1", "Repository getObject() -> user, 1st test");
for (int i = 1; i <= FIND_COUNT; i++) {
String randomName = String.format("user-%07d", RND.nextInt(BASE_USER_COUNT) + 1);
if (i == FIND_COUNT) {
queryRecorder.startRecording();
}
try (Split ignored = stopwatch.start()) {
assertThat(repositoryService.getObject(
UserType.class, users.get(randomName), null, operationResult))
.isNotNull();
}
}
queryRecorder.stopRecording();
}
*/
}
11 changes: 10 additions & 1 deletion repo/repo-sqale/testng-unit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@
~ and European Union Public License. See LICENSE file for details.
-->
<suite name="Suite" parallel="none">
<test name="Test" parallel="none">
<test name="Fast functional tests" parallel="none">
<classes>
<class name="com.evolveum.midpoint.repo.sqale.func.AuditCleanupTest"/>
<class name="com.evolveum.midpoint.repo.sqale.func.AuditSearchTest"/>
<class name="com.evolveum.midpoint.repo.sqale.func.SequenceTestFunctional"/>
<class name="com.evolveum.midpoint.repo.sqale.func.SqaleAuditSearchIterativeTest"/>
<class name="com.evolveum.midpoint.repo.sqale.func.SqaleRepoAddDeleteObjectTest"/>
<class name="com.evolveum.midpoint.repo.sqale.func.SqaleRepoLookupTableTest"/>
<class name="com.evolveum.midpoint.repo.sqale.func.SqaleRepoModifyObjectTest"/>
<class name="com.evolveum.midpoint.repo.sqale.func.SqaleRepoSearchIterativeTest"/>
<class name="com.evolveum.midpoint.repo.sqale.func.SqaleRepoSearchTest"/>
<class name="com.evolveum.midpoint.repo.sqale.func.SqaleRepoSmokeTest"/>
<class name="com.evolveum.midpoint.repo.sqale.func.SqaleSearchFullTextTest"/>
<class name="com.evolveum.midpoint.repo.sqale.func.UriCacheTest"/>
</classes>
</test>
<test name="Slow functional tests" parallel="none">
<classes>
<class name="com.evolveum.midpoint.repo.sqale.slow.SequenceTestConcurrency"/>
</classes>
</test>

<!-- Perf tests are not here, some of them are only for manual use. -->
</suite>

0 comments on commit d707a82

Please sign in to comment.