* ============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);
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<String, String> settings = new HashMap<String, String> ();
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) {
graph = inMemGraphBuilder.build();
break;
- case TITAN:
+ case "TITAN":
final TitanChampGraphImpl.Builder graphBuilder = new TitanChampGraphImpl.Builder(getGraphName());
for (Entry<String, String> setting : settings.entrySet()) {
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);
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) {
for (int i = 0; i < NUM_RELATIONSHIPS; i++) {
final long startTime = System.nanoTime();
- final Stream<ChampRelationship> objects = graph.queryRelationships(Collections.singletonMap("relationshipNumber", i));
+ Stream<ChampRelationship> 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;
for (int i = 0; i < NUM_OBJECTS; i++) {
final long startTime = System.nanoTime();
- final Stream<ChampObject> objects = graph.queryObjects(Collections.singletonMap("objectNumber", i));
+ Stream<ChampObject> objects;
+ try {
+ objects = graph.queryObjects(Collections.singletonMap("objectNumber", i), Optional.empty());
+ } catch (ChampTransactionException e) {
+ throw new RuntimeException(e);
+ }
objects.findFirst().get();
private static List<ChampObject> retrieveBulkObjects(ChampGraph graph, boolean warmUp) {
final long startTime = System.nanoTime();
- final Stream<ChampObject> objects = graph.queryObjects(
- Collections.singletonMap(
- ChampObject.ReservedPropertyKeys.CHAMP_OBJECT_TYPE.toString(), "foo"
- )
- );
+ Stream<ChampObject> 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<ChampObject> 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<ChampRelationship> retrieveBulkRelationships(ChampGraph graph, boolean warmUp) {
final long startTime = System.nanoTime();
- final Stream<ChampRelationship> relationships = graph.queryRelationships(
- Collections.singletonMap(
- ChampRelationship.ReservedPropertyKeys.CHAMP_RELATIONSHIP_TYPE.toString(), "bazz"
- )
- );
+ Stream<ChampRelationship> 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<ChampRelationship> 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;
}
.ofType("foo")
.withoutKey()
.withProperty("objectNumber", i)
- .build()
+ .build(), Optional.empty()
);
final double elapsedMs = (System.nanoTime() - startTime) / 1000.0 / 1000.0;
//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;
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;
throw new RuntimeException(e);
} catch (ChampUnmarshallingException e) {
throw new RuntimeException(e);
+ } catch (ChampTransactionException e) {
+ throw new RuntimeException(e);
}
}