Skip to content

Commit

Permalink
Add a test for applySchemasAndSecurity performance
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Apr 18, 2023
1 parent 47aee42 commit d6df128
Show file tree
Hide file tree
Showing 6 changed files with 307 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
package com.evolveum.midpoint.testing.story;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.evolveum.midpoint.schema.internals.InternalsConfig;
import com.evolveum.midpoint.util.exception.CommonException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
Expand All @@ -34,6 +40,10 @@
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

/**
* Originally, this class checks number of selected infra operations needed to execute "object add" operation.
*
* It is now extended to cover other performance aspects, e.g. MID-8479.
*
* @author Radovan Semancik
*/
@ContextConfiguration(locations = {"classpath:ctx-story-test-main.xml"})
Expand All @@ -42,24 +52,28 @@ public class TestOperationPerf extends AbstractStoryTest {

public static final File TEST_DIR = new File(MidPointTestConstants.TEST_RESOURCES_DIR, "operation-perf");

protected static final File USER_ALICE_FILE = new File(TEST_DIR, "user-alice.xml");
protected static final String USER_ALICE_OID = "a077357a-1c5f-11e8-ad16-af1b03cecee9";
public static final File SYSTEM_CONFIGURATION_FILE = new File(TEST_DIR, "system-configuration.xml");

protected static final File USER_BOB_FILE = new File(TEST_DIR, "user-bob.xml");
protected static final String USER_BOB_OID = "ab43445c-1c83-11e8-a669-331e1f2cbbac";
private static final File USER_ALICE_FILE = new File(TEST_DIR, "user-alice.xml");
private static final String USER_ALICE_OID = "a077357a-1c5f-11e8-ad16-af1b03cecee9";

protected static final File OBJECT_TEMPLATE_USER_FILE = new File(TEST_DIR, "object-template-user.xml");
private static final File USER_BOB_FILE = new File(TEST_DIR, "user-bob.xml");
private static final String USER_BOB_OID = "ab43445c-1c83-11e8-a669-331e1f2cbbac";

private static final File OBJECT_TEMPLATE_USER_FILE = new File(TEST_DIR, "object-template-user.xml");
protected static final String OBJECT_TEMPLATE_USER_OID = "995aa1a6-1c5e-11e8-8d2f-6784dbc320a9";

private static final int NUMBER_OF_ORDINARY_ROLES = 1; // including superuser role
private static final int NUMBER_OF_GENERATED_EMPTY_ROLES = 1000;
private static final int NUMBER_OF_GENERATED_EMPTY_ROLES = 200;
private static final String GENERATED_EMPTY_ROLE_OID_FORMAT = "00000000-0000-ffff-2000-e0000000%04d";
private static final String GENERATED_EMPTY_ROLE_NAME_FORMAT = "Empty Role %04d";

private static final int NUMBER_OF_USER_EXTENSION_PROPERTIES = 30;
private static final int MAX_NUMBER_OF_USER_EXTENSION_PROPERTIES = 50; // see big-user-extension.xsd
private static final String USER_EXTENSION_NS = "http://midpoint.evolveum.com/xml/ns/samples/gen";
private static final String USER_EXTENSION_PROPERTY_NAME_FORMAT = "prop%04d";

private static final int GET_ITERATIONS = 1_000;

@Autowired ClockworkMedic clockworkMedic;
@Autowired RepositoryCache repositoryCache;
@Autowired protected MappingFactory mappingFactory;
Expand All @@ -84,6 +98,22 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
clockworkMedic.setDiagnosticContextManager(profilingModelInspectorManager);

InternalMonitor.setCloneTimingEnabled(true);
InternalsConfig.reset(); // We want to measure performance, after all.
}

@Override
protected File getSystemConfigurationFile() {
return SYSTEM_CONFIGURATION_FILE;
}

@Override
protected boolean isAvoidLoggingChange() {
return false;
}

@Override
protected void importSystemTasks(OperationResult initResult) throws FileNotFoundException {
// we don't want any
}

@Test
Expand All @@ -94,23 +124,29 @@ public void test000Sanity() throws Exception {
displayValue("Object compares", InternalMonitor.getCount(InternalCounters.PRISM_OBJECT_COMPARE_COUNT));
}

/** "Basic user" - 10 extension properties, 3 assignments. */
@Test
public void test100AddAlice() throws Exception {
testAddUser(USER_ALICE_FILE, USER_ALICE_OID, 1);
testAddUser(USER_ALICE_FILE, USER_ALICE_OID, 10, 3);
testGetUser(USER_ALICE_OID);
}

/** "Heavy user" - 50 properties, 40 assignments. */
@Test
public void test110AddBob() throws Exception {
testAddUser(USER_BOB_FILE, USER_BOB_OID, 1);
testAddUser(USER_BOB_FILE, USER_BOB_OID, 50, 40);
testGetUser(USER_BOB_OID);
}

public void testAddUser(File userFile, String userOid, int roles) throws Exception {
private void testAddUser(File userFile, String userOid, int extProperties, int roles) throws Exception {

assert extProperties <= MAX_NUMBER_OF_USER_EXTENSION_PROPERTIES;

Task task = getTestTask();
OperationResult result = task.getResult();

PrismObject<UserType> userBefore = parseObject(userFile);
populateUserExtension(userBefore, NUMBER_OF_USER_EXTENSION_PROPERTIES);
populateUserExtension(userBefore, extProperties);
setRandomOrganizations(userBefore, roles);
display("User before", userBefore);

Expand Down Expand Up @@ -140,36 +176,52 @@ public void testAddUser(File userFile, String userOid, int roles) throws Excepti

PrismObject<UserType> userAfter = getUser(userOid);
display("User after", userAfter);
assertAssignments(userAfter, 1);
assertAssignments(userAfter, roles);

displayValue("Repo reads", InternalMonitor.getCount(InternalCounters.REPOSITORY_READ_COUNT));
displayValue("Object compares", InternalMonitor.getCount(InternalCounters.PRISM_OBJECT_COMPARE_COUNT));
displayValue("Object clones", InternalMonitor.getCount(InternalCounters.PRISM_OBJECT_CLONE_COUNT));

assertCounterIncrement(InternalCounters.PRISM_OBJECT_COMPARE_COUNT, 0);
}

private void populateUserExtension(PrismObject<UserType> user,
int numberOfProperties) throws SchemaException {
private void populateUserExtension(PrismObject<UserType> user, int numberOfProperties) throws SchemaException {
PrismContainer<?> extension = user.getExtension();
if (extension == null) {
extension = user.createExtension();
}
for (int i=0; i<numberOfProperties; i++) {
for (int i = 0; i < numberOfProperties; i++) {
String propName = String.format(USER_EXTENSION_PROPERTY_NAME_FORMAT, i);
PrismProperty<String> prop = extension.findOrCreateProperty(new ItemName(USER_EXTENSION_NS, propName));
prop.setRealValue("val "+i);
prop.setRealValue("val " + i);
}

}

private void setRandomOrganizations(PrismObject<UserType> userBefore, int numberOfOrganizations) {
List<PolyStringType> organizations = userBefore.asObjectable().getOrganization();
for (int i=0; i<numberOfOrganizations; i++) {
organizations.add(
createPolyStringType(
String.format(GENERATED_EMPTY_ROLE_NAME_FORMAT, RND.nextInt(NUMBER_OF_GENERATED_EMPTY_ROLES))));
assert numberOfOrganizations <= NUMBER_OF_GENERATED_EMPTY_ROLES/2; // to avoid long random generation
Set<Integer> selectedOrganizationNumbers = new HashSet<>();
while (selectedOrganizationNumbers.size() < numberOfOrganizations) {
selectedOrganizationNumbers.add(RND.nextInt(NUMBER_OF_GENERATED_EMPTY_ROLES));
}
List<PolyStringType> userOrganizations = userBefore.asObjectable().getOrganization();
selectedOrganizationNumbers.stream()
.map(number -> createPolyStringType(String.format(GENERATED_EMPTY_ROLE_NAME_FORMAT, number)))
.forEach(userOrganizations::add);
}

/** MID-8479 */
private void testGetUser(String oid) throws CommonException {
Task task = getTestTask();
OperationResult result = task.getResult();

long start = System.currentTimeMillis();
for (int i = 0; i < GET_ITERATIONS; i++) {
modelService.getObject(UserType.class, oid, null, task, result);
}
long duration = System.currentTimeMillis() - start;

display(String.format("Retrieved a user in %.3f ms", (double) duration / GET_ITERATIONS));

assertSuccess(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
~ and European Union Public License. See LICENSE file for details.
-->
<objectTemplate oid="995aa1a6-1c5e-11e8-8d2f-6784dbc320a9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:t="http://prism.evolveum.com/xml/ns/public/types-3" xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
xmlns:icfs="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
xmlns:piracy='http://midpoint.evolveum.com/xml/ns/samples/piracy'>
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3">
<name>Operation perf object template: users</name>

<mapping>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
~ Copyright (C) 2010-2023 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<systemConfiguration oid="00000000-0000-0000-0000-000000000001" version="0"
xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3">
<name>SystemConfiguration</name>
<logging>
<rootLoggerAppender>File Appender</rootLoggerAppender>
<rootLoggerLevel>INFO</rootLoggerLevel>
<classLogger>
<level>TRACE</level>
<package>com.evolveum.midpoint.common.LoggingConfigurationManager</package>
</classLogger>
<appender xsi:type="c:FileAppenderConfigurationType" name="File Appender" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<pattern>%date [%thread] %-5level \(%logger{46}\): %message%n</pattern>
<fileName>target/test.log</fileName>
<append>true</append>
</appender>
</logging>
<internals>
<caching>
<profile>
<global>true</global>
<localRepoCache>
<objectTypeSettings>
<objectType>__ALL__</objectType>
</objectTypeSettings>
</localRepoCache>
<globalRepoCache>
<timeToLive>120</timeToLive>
<objectTypeSettings>
<objectType>SystemConfigurationType</objectType>
<objectType>ArchetypeType</objectType>
<objectType>MarkType</objectType>
<objectType>ObjectTemplateType</objectType>
<objectType>ResourceType</objectType>
<objectType>ConnectorType</objectType>
<objectType>SecurityPolicyType</objectType>
<objectType>UserType</objectType> <!-- to reduce repo access time -->
<timeToVersionCheck>120</timeToVersionCheck>
</objectTypeSettings>
</globalRepoCache>
<localFocusConstraintCheckerCache>
<objectTypeSettings>
<objectType>__ALL__</objectType>
</objectTypeSettings>
</localFocusConstraintCheckerCache>
<localShadowConstraintCheckerCache>
<objectTypeSettings>
<objectType>ShadowType</objectType>
</objectTypeSettings>
</localShadowConstraintCheckerCache>
<localAssociationTargetSearchEvaluatorCache>
<objectTypeSettings>
<objectType>ShadowType</objectType>
</objectTypeSettings>
</localAssociationTargetSearchEvaluatorCache>
</profile>
</caching>
</internals>
<workflowConfiguration>
<useDefaultApprovalPolicyRules>never</useDefaultApprovalPolicyRules>
</workflowConfiguration>
</systemConfiguration>
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
~ and European Union Public License. See LICENSE file for details.
-->
<user oid="a077357a-1c5f-11e8-ad16-af1b03cecee9"
xmlns='http://midpoint.evolveum.com/xml/ns/public/common/common-3'
xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3'
xmlns:t='http://prism.evolveum.com/xml/ns/public/types-3'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:piracy='http://midpoint.evolveum.com/xml/ns/samples/piracy'>
xmlns='http://midpoint.evolveum.com/xml/ns/public/common/common-3'>
<name>alice</name>
<givenName>Alice</givenName>
<familyName>Anderson</familyName>
Expand Down
7 changes: 1 addition & 6 deletions testing/story/src/test/resources/operation-perf/user-bob.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
~ and European Union Public License. See LICENSE file for details.
-->
<user oid="ab43445c-1c83-11e8-a669-331e1f2cbbac"
xmlns='http://midpoint.evolveum.com/xml/ns/public/common/common-3'
xmlns:c='http://midpoint.evolveum.com/xml/ns/public/common/common-3'
xmlns:t='http://prism.evolveum.com/xml/ns/public/types-3'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:piracy='http://midpoint.evolveum.com/xml/ns/samples/piracy'>
xmlns='http://midpoint.evolveum.com/xml/ns/public/common/common-3'>
<name>bob</name>
<givenName>Bob</givenName>
<familyName>Brown</familyName>
Expand Down

0 comments on commit d6df128

Please sign in to comment.