Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic prism-related performance tests
- Loading branch information
Showing
5 changed files
with
614 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...src/test/java/com/evolveum/midpoint/schema/performance/AbstractSchemaPerformanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2010-2018 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.evolveum.midpoint.schema.performance; | ||
|
||
import com.evolveum.midpoint.prism.PrismObject; | ||
import com.evolveum.midpoint.prism.util.PrismTestUtil; | ||
import com.evolveum.midpoint.schema.MidPointPrismContextFactory; | ||
import com.evolveum.midpoint.schema.constants.MidPointConstants; | ||
import com.evolveum.midpoint.util.CheckedProducer; | ||
import com.evolveum.midpoint.util.PrettyPrinter; | ||
import com.evolveum.midpoint.util.exception.CommonException; | ||
import com.evolveum.midpoint.util.exception.SchemaException; | ||
import com.evolveum.midpoint.util.logging.Trace; | ||
import com.evolveum.midpoint.util.logging.TraceManager; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.testng.annotations.BeforeSuite; | ||
import org.xml.sax.SAXException; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import static com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext; | ||
|
||
/** | ||
* | ||
*/ | ||
public class AbstractSchemaPerformanceTest { | ||
|
||
protected static final Trace LOGGER = TraceManager.getTrace(AbstractSchemaPerformanceTest.class); | ||
|
||
public static final File TEST_DIR = new File("src/test/resources/performance"); | ||
public static final File USER_JACK_FILE = new File(TEST_DIR, "user-jack.xml"); | ||
|
||
public static final int DEFAULT_EXECUTION = 10000; | ||
protected static final String NS_FOO = "http://www.example.com/foo"; | ||
|
||
@BeforeSuite | ||
public void setup() throws SchemaException, SAXException, IOException { | ||
PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX); | ||
PrismTestUtil.resetPrismContext(MidPointPrismContextFactory.FACTORY); | ||
} | ||
|
||
protected int measure(String label, CheckedProducer<?> producer) throws CommonException { | ||
return measure(label, producer, DEFAULT_EXECUTION); | ||
} | ||
|
||
protected int measure(String label, CheckedProducer<?> producer, long executionTime) throws CommonException { | ||
long until = System.currentTimeMillis() + executionTime; | ||
int iteration = 0; | ||
while (System.currentTimeMillis() < until) { | ||
if (producer.get() == null) { | ||
// just to make sure the result is used somehow (and not optimized away) | ||
throw new IllegalStateException("null result from the producer"); | ||
} | ||
iteration++; | ||
} | ||
String message = label + ": " + iteration + " iterations in " + executionTime + " milliseconds (" + | ||
((double) executionTime) * 1000 / (double) iteration + " us per iteration)"; | ||
System.out.println(message); | ||
LOGGER.info(message); | ||
return iteration; | ||
} | ||
|
||
@NotNull | ||
public PrismObject<UserType> getJack() throws SchemaException, IOException { | ||
return getPrismContext().parserFor(USER_JACK_FILE).parse(); | ||
} | ||
} |
225 changes: 225 additions & 0 deletions
225
...a/schema/src/test/java/com/evolveum/midpoint/schema/performance/TestBasicPerformance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
/* | ||
* Copyright (c) 2010-2018 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.evolveum.midpoint.schema.performance; | ||
|
||
import com.evolveum.midpoint.prism.PrismObject; | ||
import com.evolveum.midpoint.prism.PrismObjectDefinition; | ||
import com.evolveum.midpoint.prism.path.ItemPath; | ||
import com.evolveum.midpoint.prism.polystring.PolyString; | ||
import com.evolveum.midpoint.prism.schema.SchemaRegistry; | ||
import com.evolveum.midpoint.prism.xnode.RootXNode; | ||
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType; | ||
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType; | ||
import org.testng.annotations.Test; | ||
|
||
import static com.evolveum.midpoint.prism.util.PrismTestUtil.getPrismContext; | ||
|
||
/** | ||
* | ||
* | ||
*/ | ||
public class TestBasicPerformance extends AbstractSchemaPerformanceTest { | ||
|
||
@Test | ||
public void test100FindNameProperty() throws Exception { | ||
System.out.println("===[ test100FindNameProperty ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
measure("findProperty(name)", () -> jack.findProperty(UserType.F_NAME)); | ||
} | ||
|
||
@Test | ||
public void test110FindNameItem() throws Exception { | ||
System.out.println("===[ test110FindNameItem ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
measure("findItem(name)", () -> jack.findItem(UserType.F_NAME)); | ||
} | ||
|
||
@Test | ||
public void test120FindExtensionProperty() throws Exception { | ||
System.out.println("===[ test120FindExtensionProperty ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
ItemPath bar23 = ItemPath.create(UserType.F_EXTENSION, "bar23"); | ||
measure("findProperty(extension/bar23)", () -> jack.findProperty(bar23)); | ||
} | ||
|
||
@Test | ||
public void test130FindExtensionItem() throws Exception { | ||
System.out.println("===[ test130FindExtensionItem ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
ItemPath bar23 = ItemPath.create(UserType.F_EXTENSION, "bar23"); | ||
measure("findItem(extension/bar23)", () -> jack.findItem(bar23)); | ||
} | ||
|
||
@Test | ||
public void test200SetName() throws Exception { | ||
System.out.println("===[ test200SetName ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
measure("setName(name)", () -> { | ||
jack.asObjectable().setName(PolyStringType.fromOrig("jack_" + Math.random())); | ||
return true; | ||
}); | ||
} | ||
|
||
@Test | ||
public void test210SetNameViaProperty() throws Exception { | ||
System.out.println("===[ test210SetNameViaProperty ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
measure("findProperty(name).setRealValue", () -> { | ||
jack.findProperty(UserType.F_NAME).setRealValue(PolyString.fromOrig("jack_" + Math.random())); | ||
return true; | ||
}); | ||
} | ||
|
||
@Test | ||
public void test215SetNameViaPropertyUsingExistingValue() throws Exception { | ||
System.out.println("===[ test215SetNameViaPropertyUsingExistingValue ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
PolyString realValue = PolyString.fromOrig("jack_" + Math.random()); | ||
measure("findProperty(name).setRealValue(existing)", () -> { | ||
jack.findProperty(UserType.F_NAME).setRealValue(realValue); | ||
return true; | ||
}); | ||
} | ||
|
||
@Test | ||
public void test220SetExtensionItemString() throws Exception { | ||
System.out.println("===[ test220SetExtensionItemString ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
ItemPath bar23 = ItemPath.create(UserType.F_EXTENSION, "bar23"); | ||
measure("findProperty(extension/bar23).setRealValue", () -> { | ||
jack.findProperty(bar23).setRealValue("jack_" + Math.random()); | ||
return 1; | ||
}); | ||
} | ||
|
||
@Test | ||
public void test230SetExtensionItemPolyString() throws Exception { | ||
System.out.println("===[ test230SetExtensionItemPolyString ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
ItemPath bar23 = ItemPath.create(UserType.F_EXTENSION, "bar23"); | ||
measure("findProperty(extension/bar23).setRealValue(polystring)", () -> { | ||
jack.findProperty(bar23).setRealValue(PolyString.fromOrig("jack_" + Math.random())); | ||
return 1; | ||
}); | ||
} | ||
|
||
@Test | ||
public void test300Clone() throws Exception { | ||
System.out.println("===[ test300Clone ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
measure("jack.clone", () -> jack.clone()); | ||
} | ||
|
||
@Test | ||
public void test310ParseXml() throws Exception { | ||
System.out.println("===[ test310ParseXml ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
String string = getPrismContext().xmlSerializer().serialize(jack); | ||
measure("parse XML (" + string.length() + " chars)", () -> getPrismContext().parserFor(string).xml().parse()); | ||
measure("parse XML to XNode (" + string.length() + " chars)", () -> getPrismContext().parserFor(string).xml().parseToXNode()); | ||
} | ||
|
||
@Test | ||
public void test320ParseJson() throws Exception { | ||
System.out.println("===[ test320ParseJson ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
String string = getPrismContext().jsonSerializer().serialize(jack); | ||
measure("parse JSON (" + string.length() + " chars)", () -> getPrismContext().parserFor(string).json().parse()); | ||
measure("parse JSON to XNode (" + string.length() + " chars)", () -> getPrismContext().parserFor(string).json().parseToXNode()); | ||
} | ||
|
||
@Test | ||
public void test330ParseYaml() throws Exception { | ||
System.out.println("===[ test330ParseYaml ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
String string = getPrismContext().yamlSerializer().serialize(jack); | ||
measure("parse YAML (" + string.length() + " chars)", () -> getPrismContext().parserFor(string).yaml().parse()); | ||
measure("parse YAML to XNode (" + string.length() + " chars)", () -> getPrismContext().parserFor(string).yaml().parse()); | ||
} | ||
|
||
@Test | ||
public void test340ParseXNode() throws Exception { | ||
System.out.println("===[ test340ParseXNode ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
RootXNode xnode = getPrismContext().xnodeSerializer().serialize(jack); | ||
measure("parse XNode", () -> getPrismContext().parserFor(xnode).parse()); | ||
} | ||
|
||
@Test | ||
public void test350SerializeToXml() throws Exception { | ||
System.out.println("===[ test350SerializeToXml ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
measure("serialize to XML", () -> getPrismContext().xmlSerializer().serialize(jack)); | ||
} | ||
|
||
@Test | ||
public void test360SerializeToJson() throws Exception { | ||
System.out.println("===[ test360SerializeToJson ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
measure("serialize to JSON", () -> getPrismContext().jsonSerializer().serialize(jack)); | ||
} | ||
|
||
@Test | ||
public void test370SerializeToYaml() throws Exception { | ||
System.out.println("===[ test370SerializeToYaml ]==="); | ||
|
||
PrismObject<UserType> jack = getJack(); | ||
measure("serialize to YAML", () -> getPrismContext().yamlSerializer().serialize(jack)); | ||
} | ||
|
||
@Test | ||
public void test400FindNameDefinition() throws Exception { | ||
System.out.println("===[ test400FindNameDefinition ]==="); | ||
|
||
SchemaRegistry schemaRegistry = getPrismContext().getSchemaRegistry(); | ||
PrismObjectDefinition<UserType> userDefinition = schemaRegistry.findObjectDefinitionByCompileTimeClass(UserType.class); | ||
measure("userDefinition.findItemDefinition(UserType.F_NAME)", () -> userDefinition.findItemDefinition(UserType.F_NAME)); | ||
} | ||
|
||
@Test | ||
public void test410FindAdminGuiConfigurationDefinition() throws Exception { | ||
System.out.println("===[ test410FindAdminGuiConfigurationDefinition ]==="); | ||
|
||
SchemaRegistry schemaRegistry = getPrismContext().getSchemaRegistry(); | ||
PrismObjectDefinition<UserType> userDefinition = schemaRegistry.findObjectDefinitionByCompileTimeClass(UserType.class); | ||
measure("userDefinition.findItemDefinition(UserType.F_NAME)", () -> userDefinition.findItemDefinition(UserType.F_ADMIN_GUI_CONFIGURATION)); | ||
} | ||
|
||
@Test | ||
public void test420FindUserDefinition() throws Exception { | ||
System.out.println("===[ test420FindUserDefinition ]==="); | ||
|
||
SchemaRegistry schemaRegistry = getPrismContext().getSchemaRegistry(); | ||
measure("schemaRegistry.findObjectDefinitionByCompileTimeClass(UserType.class)", () -> schemaRegistry.findObjectDefinitionByCompileTimeClass(UserType.class)); | ||
} | ||
|
||
} |
Oops, something went wrong.