Search in sources :

Example 11 with AtlasGraph

use of org.apache.atlas.repository.graphdb.AtlasGraph in project incubator-atlas by apache.

the class AtlasEntityQueryTest method testExecute_Collection_rollbackOnException.

@Test
public void testExecute_Collection_rollbackOnException() throws Exception {
    AtlasGraph graph = createStrictMock(AtlasGraph.class);
    QueryExpression expression = createStrictMock(QueryExpression.class);
    ResourceDefinition resourceDefinition = createStrictMock(ResourceDefinition.class);
    Request request = createStrictMock(Request.class);
    GremlinPipeline initialPipeline = createStrictMock(GremlinPipeline.class);
    Pipe queryPipe = createStrictMock(Pipe.class);
    Pipe expressionPipe = createStrictMock(Pipe.class);
    Pipe notDeletedPipe = createStrictMock(Pipe.class);
    GremlinPipeline rootPipeline = createStrictMock(GremlinPipeline.class);
    GremlinPipeline queryPipeline = createStrictMock(GremlinPipeline.class);
    GremlinPipeline expressionPipeline = createStrictMock(GremlinPipeline.class);
    GremlinPipeline notDeletedPipeline = createStrictMock(GremlinPipeline.class);
    // mock expectations
    expect(initialPipeline.add(queryPipe)).andReturn(queryPipeline);
    expect(initialPipeline.add(notDeletedPipe)).andReturn(notDeletedPipeline);
    expect(initialPipeline.as("root")).andReturn(rootPipeline);
    expect(expression.asPipe()).andReturn(expressionPipe);
    expect(rootPipeline.add(expressionPipe)).andReturn(expressionPipeline);
    expect(expressionPipeline.back("root")).andReturn(rootPipeline);
    expect(rootPipeline.toList()).andThrow(new RuntimeException("something bad happened"));
    graph.rollback();
    replay(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline);
    // end mock expectations
    AtlasEntityQuery query = new TestAtlasEntityQuery(expression, resourceDefinition, request, initialPipeline, queryPipe, notDeletedPipe, graph, null);
    try {
        // invoke method being tested
        query.execute();
        fail("expected exception");
    } catch (RuntimeException e) {
        assertEquals(e.getMessage(), "something bad happened");
    }
    verify(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline);
}
Also used : GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) ResourceDefinition(org.apache.atlas.catalog.definition.ResourceDefinition) Request(org.apache.atlas.catalog.Request) Pipe(com.tinkerpop.pipes.Pipe) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) Test(org.testng.annotations.Test)

Example 12 with AtlasGraph

use of org.apache.atlas.repository.graphdb.AtlasGraph in project incubator-atlas by apache.

the class Gremlin3ExpressionFactory method generateFieldExpression.

@Override
public GroovyExpression generateFieldExpression(GroovyExpression parent, FieldInfo fInfo, String propertyName, boolean inSelect) {
    AttributeInfo attrInfo = fInfo.attrInfo();
    IDataType attrType = attrInfo.dataType();
    GroovyExpression propertyNameExpr = new LiteralExpression(propertyName);
    //Whether it is the user or shared graph does not matter here, since we're
    //just getting the conversion expression.  Ideally that would be moved someplace else.
    AtlasGraph graph = AtlasGraphProvider.getGraphInstance();
    if (inSelect) {
        GroovyExpression expr = new FunctionCallExpression(parent, PROPERTY_METHOD, propertyNameExpr);
        expr = new FunctionCallExpression(expr, OR_ELSE_METHOD, LiteralExpression.NULL);
        return graph.generatePersisentToLogicalConversionExpression(expr, attrType);
    } else {
        GroovyExpression unmapped = new FunctionCallExpression(TraversalStepType.FLAT_MAP_TO_VALUES, parent, VALUES_METHOD, propertyNameExpr);
        if (graph.isPropertyValueConversionNeeded(attrType)) {
            GroovyExpression toConvert = new FunctionCallExpression(getItVariable(), GET_METHOD);
            GroovyExpression conversionFunction = graph.generatePersisentToLogicalConversionExpression(toConvert, attrType);
            return new FunctionCallExpression(TraversalStepType.MAP_TO_VALUE, unmapped, MAP_METHOD, new ClosureExpression(conversionFunction));
        } else {
            return unmapped;
        }
    }
}
Also used : AttributeInfo(org.apache.atlas.typesystem.types.AttributeInfo) LiteralExpression(org.apache.atlas.groovy.LiteralExpression) GroovyExpression(org.apache.atlas.groovy.GroovyExpression) ClosureExpression(org.apache.atlas.groovy.ClosureExpression) IDataType(org.apache.atlas.typesystem.types.IDataType) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) FunctionCallExpression(org.apache.atlas.groovy.FunctionCallExpression)

Example 13 with AtlasGraph

use of org.apache.atlas.repository.graphdb.AtlasGraph in project incubator-atlas by apache.

the class GraphRepoMapperScaleTest method searchWithOutIndex.

private void searchWithOutIndex(String key, String value) {
    AtlasGraph graph = TestUtils.getGraph();
    long start = System.currentTimeMillis();
    int count = 0;
    try {
        AtlasGraphQuery query = graph.query().has(key, ComparisionOperator.EQUAL, value);
        Iterable<AtlasVertex> result = query.vertices();
        for (AtlasVertex ignored : result) {
            count++;
        }
    } finally {
        System.out.println("Search on [" + key + "=" + value + "] returned results: " + count + ", took " + (System.currentTimeMillis() - start) + " ms");
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph)

Example 14 with AtlasGraph

use of org.apache.atlas.repository.graphdb.AtlasGraph in project incubator-atlas by apache.

the class GraphRepoMapperScaleTest method searchWithIndex.

private void searchWithIndex(String key, ComparisionOperator op, Object value, int expectedResults) {
    AtlasGraph graph = TestUtils.getGraph();
    long start = System.currentTimeMillis();
    int count = 0;
    try {
        AtlasGraphQuery query = graph.query().has(key, op, value);
        Iterable<AtlasVertex> itrble = query.vertices();
        for (AtlasVertex ignored : itrble) {
            count++;
        }
    } finally {
        System.out.println("Search on [" + key + "=" + value + "] returned results: " + count + ", took " + (System.currentTimeMillis() - start) + " ms");
        Assert.assertEquals(count, expectedResults);
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph)

Example 15 with AtlasGraph

use of org.apache.atlas.repository.graphdb.AtlasGraph in project incubator-atlas by apache.

the class AtlasEntityQueryTest method testExecute_Collection.

//todo: add tests for instance query and getInitialPipeline()
@Test
public void testExecute_Collection() throws Exception {
    AtlasGraph graph = createStrictMock(AtlasGraph.class);
    QueryExpression expression = createStrictMock(QueryExpression.class);
    ResourceDefinition resourceDefinition = createStrictMock(ResourceDefinition.class);
    Request request = createStrictMock(Request.class);
    GremlinPipeline initialPipeline = createStrictMock(GremlinPipeline.class);
    Pipe queryPipe = createStrictMock(Pipe.class);
    Pipe expressionPipe = createStrictMock(Pipe.class);
    Pipe notDeletedPipe = createStrictMock(Pipe.class);
    GremlinPipeline rootPipeline = createStrictMock(GremlinPipeline.class);
    GremlinPipeline queryPipeline = createStrictMock(GremlinPipeline.class);
    GremlinPipeline expressionPipeline = createStrictMock(GremlinPipeline.class);
    GremlinPipeline notDeletedPipeline = createStrictMock(GremlinPipeline.class);
    Vertex vertex1 = createStrictMock(Vertex.class);
    VertexWrapper vertex1Wrapper = createStrictMock(VertexWrapper.class);
    List<Vertex> results = new ArrayList<>();
    results.add(vertex1);
    Map<String, Object> vertex1PropertyMap = new HashMap<>();
    vertex1PropertyMap.put("prop1", "prop1.value1");
    vertex1PropertyMap.put("prop2", "prop2.value1");
    Map<String, Object> filteredVertex1PropertyMap = new HashMap<>();
    filteredVertex1PropertyMap.put("prop1", "prop1.value1");
    // mock expectations
    expect(initialPipeline.add(queryPipe)).andReturn(queryPipeline);
    expect(initialPipeline.add(notDeletedPipe)).andReturn(notDeletedPipeline);
    expect(initialPipeline.as("root")).andReturn(rootPipeline);
    expect(expression.asPipe()).andReturn(expressionPipe);
    expect(rootPipeline.add(expressionPipe)).andReturn(expressionPipeline);
    expect(expressionPipeline.back("root")).andReturn(rootPipeline);
    expect(rootPipeline.toList()).andReturn(results);
    graph.commit();
    expect(vertex1Wrapper.getPropertyMap()).andReturn(vertex1PropertyMap);
    expect(resourceDefinition.filterProperties(request, vertex1PropertyMap)).andReturn(filteredVertex1PropertyMap);
    expect(resourceDefinition.resolveHref(filteredVertex1PropertyMap)).andReturn("/foo/bar");
    expect(request.getCardinality()).andReturn(Request.Cardinality.COLLECTION);
    replay(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline, vertex1, vertex1Wrapper);
    // end mock expectations
    AtlasEntityQuery query = new TestAtlasEntityQuery(expression, resourceDefinition, request, initialPipeline, queryPipe, notDeletedPipe, graph, vertex1Wrapper);
    // invoke method being tested
    Collection<Map<String, Object>> queryResults = query.execute();
    assertEquals(queryResults.size(), 1);
    Map<String, Object> queryResultMap = queryResults.iterator().next();
    assertEquals(queryResultMap.size(), 2);
    assertEquals(queryResultMap.get("prop1"), "prop1.value1");
    assertEquals(queryResultMap.get("href"), "/foo/bar");
    verify(graph, expression, resourceDefinition, request, initialPipeline, queryPipe, expressionPipe, notDeletedPipe, rootPipeline, queryPipeline, expressionPipeline, notDeletedPipeline, vertex1, vertex1Wrapper);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) ResourceDefinition(org.apache.atlas.catalog.definition.ResourceDefinition) Request(org.apache.atlas.catalog.Request) Pipe(com.tinkerpop.pipes.Pipe) VertexWrapper(org.apache.atlas.catalog.VertexWrapper) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) Test(org.testng.annotations.Test)

Aggregations

AtlasGraph (org.apache.atlas.repository.graphdb.AtlasGraph)20 Test (org.testng.annotations.Test)9 AtlasGraphManagement (org.apache.atlas.repository.graphdb.AtlasGraphManagement)7 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)7 GremlinPipeline (com.tinkerpop.gremlin.java.GremlinPipeline)3 Pipe (com.tinkerpop.pipes.Pipe)3 Request (org.apache.atlas.catalog.Request)3 ResourceDefinition (org.apache.atlas.catalog.definition.ResourceDefinition)3 AtlasGraphQuery (org.apache.atlas.repository.graphdb.AtlasGraphQuery)3 Vertex (com.tinkerpop.blueprints.Vertex)2 ArrayList (java.util.ArrayList)2 VertexWrapper (org.apache.atlas.catalog.VertexWrapper)2 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)2 AtlasGraphIndex (org.apache.atlas.repository.graphdb.AtlasGraphIndex)2 AtlasPropertyKey (org.apache.atlas.repository.graphdb.AtlasPropertyKey)2 IDataType (org.apache.atlas.typesystem.types.IDataType)2 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)1 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)1 ClosureExpression (org.apache.atlas.groovy.ClosureExpression)1 FunctionCallExpression (org.apache.atlas.groovy.FunctionCallExpression)1