Search in sources :

Example 81 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class RemoteGraknTxTest method whenExecutingAQueryWithAVoidResult_GetANullBack.

@Test
public void whenExecutingAQueryWithAVoidResult_GetANullBack() {
    Query<?> query = match(var("x").isa("person")).delete("x");
    String queryString = query.toString();
    server.setResponse(GrpcUtil.execQueryRequest(query), GrpcUtil.doneResponse());
    try (GraknTx tx = RemoteGraknTx.create(session, GrpcUtil.openRequest(KEYSPACE, GraknTxType.WRITE))) {
        // The open request
        verify(server.requests()).onNext(any());
        assertNull(tx.graql().parse(queryString).execute());
    }
}
Also used : GraknTx(ai.grakn.GraknTx) Test(org.junit.Test)

Example 82 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class InsertQueryImpl method getSchemaConcepts.

@Override
public Set<SchemaConcept> getSchemaConcepts() {
    GraknTx theGraph = getTx().orElseThrow(GraqlQueryException::noTx);
    Set<SchemaConcept> types = allVarPatterns().map(VarPatternAdmin::getTypeLabel).flatMap(CommonUtil::optionalToStream).map(theGraph::<Type>getSchemaConcept).collect(Collectors.toSet());
    match().ifPresent(mq -> types.addAll(mq.admin().getSchemaConcepts()));
    return types;
}
Also used : GraknTx(ai.grakn.GraknTx) CommonUtil(ai.grakn.util.CommonUtil) Type(ai.grakn.concept.Type) GraqlQueryException(ai.grakn.exception.GraqlQueryException) SchemaConcept(ai.grakn.concept.SchemaConcept)

Example 83 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class GraknKeyspaceStoreTest method whenClearingGraphsUsingExternalFactory_EnsureKeyspacesAreDeletedFromSystemGraph.

@Test
public void whenClearingGraphsUsingExternalFactory_EnsureKeyspacesAreDeletedFromSystemGraph() {
    String[] keyspaces = { "g1", "g2", "g3" };
    // Create transactions to begin with
    Set<GraknTx> txs = buildTxs(externalFactoryGraphProvider, keyspaces);
    txs.forEach(GraknTx::close);
    // Delete a tx entirely
    GraknTx deletedGraph = txs.iterator().next();
    deletedGraph.admin().delete();
    txs.remove(deletedGraph);
    // Get system keyspaces
    Set<String> systemKeyspaces = getSystemKeyspaces();
    // Check only 2 graphs have been built
    for (GraknTx tx : txs) {
        assertTrue("Contains correct keyspace", systemKeyspaces.contains(tx.keyspace().getValue()));
    }
    assertFalse(graknKeyspaceStore.containsKeyspace(deletedGraph.keyspace()));
}
Also used : GraknTx(ai.grakn.GraknTx) Test(org.junit.Test)

Example 84 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class GraknKeyspaceStoreTest method whenClearingGraphsUsingEngineFactory_EnsureKeyspacesAreDeletedFromSystemGraph.

@Test
public void whenClearingGraphsUsingEngineFactory_EnsureKeyspacesAreDeletedFromSystemGraph() {
    String[] keyspaces = { "g4", "g5", "g6" };
    // Create transactions to begin with
    Set<GraknTx> txs = buildTxs(engineFactoryKBProvider, keyspaces);
    txs.forEach(GraknTx::close);
    // Delete a tx entirely
    GraknTx deletedGraph = txs.iterator().next();
    deletedGraph.admin().delete();
    txs.remove(deletedGraph);
    // Get system keyspaces
    Set<String> systemKeyspaces = getSystemKeyspaces();
    // Check only 2 graphs have been built
    for (GraknTx tx : txs) {
        assertTrue("Contains correct keyspace", systemKeyspaces.contains(tx.keyspace().getValue()));
    }
    assertFalse(graknKeyspaceStore.containsKeyspace(deletedGraph.keyspace()));
}
Also used : GraknTx(ai.grakn.GraknTx) Test(org.junit.Test)

Example 85 with GraknTx

use of ai.grakn.GraknTx in project grakn by graknlabs.

the class GrpcGraknService method delete.

@Override
public void delete(DeleteRequest request, StreamObserver<DeleteResponse> responseObserver) {
    try {
        runAndConvertGraknExceptions(() -> {
            try (GraknTx tx = executor.execute(request.getOpen())) {
                tx.admin().delete();
            }
            responseObserver.onNext(GrpcUtil.deleteResponse());
            responseObserver.onCompleted();
        });
    } catch (StatusRuntimeException e) {
        responseObserver.onError(e);
    }
}
Also used : GraknTx(ai.grakn.GraknTx) StatusRuntimeException(io.grpc.StatusRuntimeException)

Aggregations

GraknTx (ai.grakn.GraknTx)243 Test (org.junit.Test)189 EntityType (ai.grakn.concept.EntityType)54 GetQuery (ai.grakn.graql.GetQuery)52 Entity (ai.grakn.concept.Entity)51 QueryBuilder (ai.grakn.graql.QueryBuilder)49 Role (ai.grakn.concept.Role)48 RelationshipType (ai.grakn.concept.RelationshipType)46 Answer (ai.grakn.graql.admin.Answer)44 Set (java.util.Set)44 EmbeddedGraknTx (ai.grakn.kb.internal.EmbeddedGraknTx)33 Label (ai.grakn.concept.Label)28 Attribute (ai.grakn.concept.Attribute)27 Concept (ai.grakn.concept.Concept)27 HashSet (java.util.HashSet)26 GraknSession (ai.grakn.GraknSession)22 AttributeType (ai.grakn.concept.AttributeType)22 ConceptId (ai.grakn.concept.ConceptId)22 List (java.util.List)19 GraknTxType (ai.grakn.GraknTxType)17