Search in sources :

Example 6 with AtlasGraph

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

the class GraphBackedMetadataRepositoryDeleteTestBase method getVertices.

protected List<AtlasVertex> getVertices(String propertyName, Object value) {
    AtlasGraph graph = TestUtils.getGraph();
    Iterable<AtlasVertex> vertices = graph.getVertices(propertyName, value);
    List<AtlasVertex> list = new ArrayList<>();
    for (AtlasVertex vertex : vertices) {
        list.add(vertex);
    }
    return list;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ArrayList(java.util.ArrayList) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph)

Example 7 with AtlasGraph

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

the class GraphBackedMetadataRepositoryTest method assertEdge.

private boolean assertEdge(String id, String typeName) throws Exception {
    AtlasGraph graph = TestUtils.getGraph();
    Iterable<AtlasVertex> vertices = graph.query().has(Constants.GUID_PROPERTY_KEY, id).vertices();
    AtlasVertex AtlasVertex = vertices.iterator().next();
    Iterable<AtlasEdge> edges = AtlasVertex.getEdges(AtlasEdgeDirection.OUT, Constants.INTERNAL_PROPERTY_KEY_PREFIX + typeName + ".ref");
    if (!edges.iterator().hasNext()) {
        ITypedReferenceableInstance entity = repositoryService.getEntityDefinition(id);
        assertNotNull(entity.get("ref"));
        return true;
    }
    return false;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Example 8 with AtlasGraph

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

the class AbstractGremlinQueryOptimizerTest method get.

@Override
public AtlasGraph get() throws RepositoryException {
    AtlasGraph graph = mock(AtlasGraph.class);
    when(graph.getSupportedGremlinVersion()).thenReturn(GremlinVersion.THREE);
    when(graph.isPropertyValueConversionNeeded(any(IDataType.class))).thenReturn(false);
    return graph;
}
Also used : IDataType(org.apache.atlas.typesystem.types.IDataType) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph)

Example 9 with AtlasGraph

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

the class Titan1DatabaseTest method getGraph.

private <V, E> AtlasGraph<V, E> getGraph() {
    GraphSandboxUtil.create();
    if (atlasGraph == null) {
        Titan1GraphDatabase db = new Titan1GraphDatabase();
        atlasGraph = db.getGraph();
        AtlasGraphManagement mgmt = atlasGraph.getManagementSystem();
        // many)
        for (String propertyName : new String[] { "__superTypeNames", "__traitNames" }) {
            AtlasPropertyKey propertyKey = mgmt.getPropertyKey(propertyName);
            if (propertyKey == null) {
                propertyKey = mgmt.makePropertyKey(propertyName, String.class, AtlasCardinality.SET);
                mgmt.createExactMatchIndex(propertyName, false, Collections.singletonList(propertyKey));
            }
        }
        mgmt.commit();
    }
    return (AtlasGraph<V, E>) atlasGraph;
}
Also used : AtlasGraphManagement(org.apache.atlas.repository.graphdb.AtlasGraphManagement) AtlasPropertyKey(org.apache.atlas.repository.graphdb.AtlasPropertyKey) AtlasGraph(org.apache.atlas.repository.graphdb.AtlasGraph)

Example 10 with AtlasGraph

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

the class AtlasEntityQueryTest method testExecute_Collection_update.

@Test
public void testExecute_Collection_update() 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);
    Capture<Long> modifiedTimestampCapture = newCapture();
    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");
    Map<String, Object> updateProperties = new HashMap<>();
    updateProperties.put("prop3", "newValue");
    // 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();
    vertex1Wrapper.setProperty("prop3", "newValue");
    vertex1Wrapper.setProperty(eq(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY), capture(modifiedTimestampCapture));
    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);
    long startTime = System.currentTimeMillis();
    // invoke method being tested
    Collection<Map<String, Object>> queryResults = query.execute(updateProperties);
    long endTime = System.currentTimeMillis();
    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");
    long modifiedTimestamp = modifiedTimestampCapture.getValue();
    assertTrue(modifiedTimestamp >= startTime && modifiedTimestamp <= endTime);
    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