X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=champ-lib%2Fchamp-titan%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fchamptitan%2Fperf%2FChampAPIPerformanceTest.java;fp=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fchamp%2Fperf%2FChampAPIPerformanceTest.java;h=37ea4ff8738f729b40bc8f18175ee798ae566a56;hb=c74f7b13b573386e70c10721fc391624ee792ed6;hp=e1266aa4bca65f205589651b90e5c56a40e87aab;hpb=9fc28cff11a4b570618c0f533ce9de6209a5dd0c;p=aai%2Fchamp.git diff --git a/src/main/java/org/onap/aai/champ/perf/ChampAPIPerformanceTest.java b/champ-lib/champ-titan/src/main/java/org/onap/aai/champtitan/perf/ChampAPIPerformanceTest.java similarity index 76% rename from src/main/java/org/onap/aai/champ/perf/ChampAPIPerformanceTest.java rename to champ-lib/champ-titan/src/main/java/org/onap/aai/champtitan/perf/ChampAPIPerformanceTest.java index e1266aa..37ea4ff 100644 --- a/src/main/java/org/onap/aai/champ/perf/ChampAPIPerformanceTest.java +++ b/champ-lib/champ-titan/src/main/java/org/onap/aai/champtitan/perf/ChampAPIPerformanceTest.java @@ -19,40 +19,27 @@ * ============LICENSE_END============================================ * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ -package org.onap.aai.champ.perf; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.onap.aai.champ.ChampGraph; -import org.onap.aai.champ.exceptions.ChampMarshallingException; -import org.onap.aai.champ.exceptions.ChampObjectNotExistsException; -import org.onap.aai.champ.exceptions.ChampRelationshipNotExistsException; -import org.onap.aai.champ.exceptions.ChampSchemaViolationException; -import org.onap.aai.champ.exceptions.ChampUnmarshallingException; -import org.onap.aai.champ.graph.impl.InMemoryChampGraphImpl; -import org.onap.aai.champ.graph.impl.TitanChampGraphImpl; -import org.onap.aai.champ.model.ChampField; -import org.onap.aai.champ.model.ChampObject; -import org.onap.aai.champ.model.ChampObjectIndex; -import org.onap.aai.champ.model.ChampRelationship; -import org.onap.aai.champ.model.ChampRelationshipIndex; -import org.onap.aai.champ.model.ChampSchema; -import org.onap.aai.champ.schema.ChampSchemaEnforcer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +package org.onap.aai.champtitan.perf; import com.thinkaurelius.titan.core.TitanFactory; import com.thinkaurelius.titan.core.TitanFactory.Builder; import com.thinkaurelius.titan.core.TitanGraph; import com.thinkaurelius.titan.core.util.TitanCleanup; +import org.onap.aai.champcore.ChampGraph; +import org.onap.aai.champcore.exceptions.*; +import org.onap.aai.champcore.graph.impl.InMemoryChampGraphImpl; +import org.onap.aai.champcore.model.*; +import org.onap.aai.champcore.schema.ChampSchemaEnforcer; +import org.onap.aai.champtitan.graph.impl.TitanChampGraphImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; +import java.util.Map.Entry; +import java.util.stream.Collectors; +import java.util.stream.Stream; + public class ChampAPIPerformanceTest { private static final Logger LOGGER = LoggerFactory.getLogger(ChampAPIPerformanceTest.class); @@ -97,43 +84,51 @@ public class ChampAPIPerformanceTest { public static void main(String[] args) { - if (args.length < 1 || !args[0].startsWith("--champ.graph.type=")) { - throw new RuntimeException("Must provide --champ.graph.type=" + ChampGraph.Type.values() + " as first parameter"); + if (args.length < 1 || !args[0].startsWith("--champcore.graph.type=")) { + throw new RuntimeException("Must provide --champcore.graph.type=" + " as first parameter"); } - final ChampGraph.Type graphType = ChampGraph.Type.valueOf(args[0].split("=")[1]); + final String graphType = args[0].split("=")[1]; final Map settings = new HashMap (); for (int i = 1; i < args.length; i++) { - if (!args[i].startsWith("--")) throw new RuntimeException("Bad command line argument: " + args[i]); + if (!args[i].startsWith("--")) { + throw new RuntimeException("Bad command line argument: " + args[i]); + } final String[] keyValue = args[i].replaceFirst("--", "").split("="); - if (keyValue.length != 2) throw new RuntimeException("Bad command line argument: " + args[i]); + if (keyValue.length != 2) { + throw new RuntimeException("Bad command line argument: " + args[i]); + } settings.put(keyValue[0], keyValue[1]); } LOGGER.info("Provided graph settings: " + settings); - if (graphType == ChampGraph.Type.TITAN) cleanUp(getGraphName(), settings); + if (graphType.equals("TITAN")) { + cleanUp(getGraphName(), settings); + } LOGGER.info("Graph cleaned, instantiating ChampGraph"); final ChampGraph graph; switch (graphType) { - case IN_MEMORY: + case "IN_MEMORY": final InMemoryChampGraphImpl.Builder inMemGraphBuilder = new InMemoryChampGraphImpl.Builder(); - if (settings.containsKey("champ.schema.enforcer")) { - final String schemaEnforcerClassStr = settings.get("champ.schema.enforcer"); + if (settings.containsKey("champcore.schema.enforcer")) { + final String schemaEnforcerClassStr = settings.get("champcore.schema.enforcer"); try { final Class schemaEnforcer = Class.forName(schemaEnforcerClassStr); - if (!schemaEnforcer.isAssignableFrom(ChampSchemaEnforcer.class)) throw new RuntimeException("Unknown ChampSchemaEnforcer " + schemaEnforcer); + if (!schemaEnforcer.isAssignableFrom(ChampSchemaEnforcer.class)) { + throw new RuntimeException("Unknown ChampSchemaEnforcer " + schemaEnforcer); + } inMemGraphBuilder.schemaEnforcer((ChampSchemaEnforcer) schemaEnforcer.newInstance()); } catch (ClassNotFoundException e) { @@ -147,7 +142,7 @@ public class ChampAPIPerformanceTest { graph = inMemGraphBuilder.build(); break; - case TITAN: + case "TITAN": final TitanChampGraphImpl.Builder graphBuilder = new TitanChampGraphImpl.Builder(getGraphName()); for (Entry setting : settings.entrySet()) { @@ -160,10 +155,14 @@ public class ChampAPIPerformanceTest { throw new RuntimeException("Unknown ChampGraph.Type " + graphType); } - if (graph.queryObjects(Collections.emptyMap()).limit(1).count() > 0) { - graph.shutdown(); - throw new RuntimeException("Expected empty graph"); - } + try { + if (graph.queryObjects(Collections.emptyMap(), Optional.empty()).limit(1).count() > 0) { + graph.shutdown(); + throw new RuntimeException("Expected empty graph"); + } + } catch (ChampTransactionException e) { + throw new RuntimeException("Transaction failure"); + } LOGGER.info("Graph instantiated, warming up JVM"); warmUp(graph); @@ -203,22 +202,22 @@ public class ChampAPIPerformanceTest { private static void storeSchema(ChampGraph graph, boolean warmUp) { try { graph.storeSchema( - ChampSchema.create() + ChampSchema.create() .withObjectConstraint() - .onType("foo") - .withPropertyConstraint() - .onField("fooObjectNumber") - .optional() - .build() - .build() + .onType("foo") + .withPropertyConstraint() + .onField("fooObjectNumber") + .optional() + .build() + .build() .withRelationshipConstraint() - .onType("bar") - .withPropertyConstraint() - .onField("barObjectNumber") - .ofType(ChampField.Type.INTEGER) - .optional() - .build() - .build() + .onType("bar") + .withPropertyConstraint() + .onField("barObjectNumber") + .ofType(ChampField.Type.INTEGER) + .optional() + .build() + .build() .build() ); } catch (ChampSchemaViolationException e) { @@ -258,7 +257,13 @@ public class ChampAPIPerformanceTest { for (int i = 0; i < NUM_RELATIONSHIPS; i++) { final long startTime = System.nanoTime(); - final Stream objects = graph.queryRelationships(Collections.singletonMap("relationshipNumber", i)); + Stream objects; + try { + objects = graph.queryRelationships(Collections.singletonMap("relationshipNumber", i), Optional.empty()); + } catch (ChampTransactionException e) { + throw new RuntimeException(e); + } + objects.findFirst().get(); final double elapsedMs = (System.nanoTime() - startTime) / 1000.0 / 1000.0; latencies[i] = elapsedMs; @@ -285,7 +290,12 @@ public class ChampAPIPerformanceTest { for (int i = 0; i < NUM_OBJECTS; i++) { final long startTime = System.nanoTime(); - final Stream objects = graph.queryObjects(Collections.singletonMap("objectNumber", i)); + Stream objects; + try { + objects = graph.queryObjects(Collections.singletonMap("objectNumber", i), Optional.empty()); + } catch (ChampTransactionException e) { + throw new RuntimeException(e); + } objects.findFirst().get(); @@ -311,32 +321,46 @@ public class ChampAPIPerformanceTest { private static List retrieveBulkObjects(ChampGraph graph, boolean warmUp) { final long startTime = System.nanoTime(); - final Stream objects = graph.queryObjects( - Collections.singletonMap( - ChampObject.ReservedPropertyKeys.CHAMP_OBJECT_TYPE.toString(), "foo" - ) - ); + Stream objects; + try { + objects = graph.queryObjects( + Collections.singletonMap( + ChampObject.ReservedPropertyKeys.CHAMP_OBJECT_TYPE.toString(), "foo" + ), Optional.empty() + ); + } catch (ChampTransactionException e) { + throw new RuntimeException(e); + } final List objectsAsList = objects.collect(Collectors.toList()); final double elapsedSecs = (System.nanoTime() - startTime) / 1000.0 / 1000.0 / 1000.0; - if (!warmUp) LOGGER.info("Bulk read " + objectsAsList.size() + " objects in " + elapsedSecs + "s (" + objectsAsList.size() / elapsedSecs + " objects/s)"); + if (!warmUp) { + LOGGER.info("Bulk read " + objectsAsList.size() + " objects in " + elapsedSecs + "s (" + objectsAsList.size() / elapsedSecs + " objects/s)"); + } return objectsAsList; } private static List retrieveBulkRelationships(ChampGraph graph, boolean warmUp) { final long startTime = System.nanoTime(); - final Stream relationships = graph.queryRelationships( - Collections.singletonMap( - ChampRelationship.ReservedPropertyKeys.CHAMP_RELATIONSHIP_TYPE.toString(), "bazz" - ) - ); + Stream relationships; + try { + relationships = graph.queryRelationships( + Collections.singletonMap( + ChampRelationship.ReservedPropertyKeys.CHAMP_RELATIONSHIP_TYPE.toString(), "bazz" + ), Optional.empty() + ); + } catch (ChampTransactionException e) { + throw new RuntimeException(e); + } final List relationshipsAsList = relationships.collect(Collectors.toList()); final double elapsedSecs = (System.nanoTime() - startTime) / 1000.0 / 1000.0 / 1000.0; - if (!warmUp) LOGGER.info("Bulk read " + relationshipsAsList.size() + " relationships in " + elapsedSecs + "s (" + relationshipsAsList.size() / elapsedSecs + " relationships/s)"); + if (!warmUp) { + LOGGER.info("Bulk read " + relationshipsAsList.size() + " relationships in " + elapsedSecs + "s (" + relationshipsAsList.size() / elapsedSecs + " relationships/s)"); + } return relationshipsAsList; } @@ -354,7 +378,7 @@ public class ChampAPIPerformanceTest { .ofType("foo") .withoutKey() .withProperty("objectNumber", i) - .build() + .build(), Optional.empty() ); final double elapsedMs = (System.nanoTime() - startTime) / 1000.0 / 1000.0; @@ -365,7 +389,9 @@ public class ChampAPIPerformanceTest { //Ignore, no schema set } catch (ChampObjectNotExistsException e) { //Ignore, not an update - } + } catch (ChampTransactionException e) { + throw new RuntimeException(e); + } } final double totalElapsedTimeSecs = (System.nanoTime() - totalStartTime) / 1000.0 / 1000.0 / 1000.0; @@ -396,7 +422,7 @@ public class ChampAPIPerformanceTest { objects.get(i % objects.size()), objects.get((i + 1) % objects.size()), "bazz" ).property("relationshipNumber", i) .build() - ); + , Optional.empty()); final double elapsedMs = (System.nanoTime() - startTime) / 1000.0 / 1000.0; @@ -411,6 +437,8 @@ public class ChampAPIPerformanceTest { throw new RuntimeException(e); } catch (ChampUnmarshallingException e) { throw new RuntimeException(e); + } catch (ChampTransactionException e) { + throw new RuntimeException(e); } }