Search in sources :

Example 6 with TypeDBException

use of com.vaticle.typedb.core.common.exception.TypeDBException in project grakn by graknlabs.

the class CoreConfigTest method config_file_missing_data_throws.

@Test
public void config_file_missing_data_throws() {
    Path configMissingLog = Util.getTypedbDir().resolve("server/test/config/config-missing-data.yml");
    try {
        CoreConfigFactory.config(configMissingLog, new HashSet<>(), new CoreConfigParser());
        fail();
    } catch (TypeDBException e) {
        assert e.code().isPresent();
        assertEquals(MISSING_CONFIG_OPTION.code(), e.code().get());
        assertEquals(MISSING_CONFIG_OPTION.message("storage.data"), e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) CoreConfigParser(com.vaticle.typedb.core.server.parameters.CoreConfigParser) Test(org.junit.Test)

Example 7 with TypeDBException

use of com.vaticle.typedb.core.common.exception.TypeDBException in project grakn by graknlabs.

the class CoreConfigTest method config_file_invalid_output_reference_throws.

@Test
public void config_file_invalid_output_reference_throws() {
    Path configInvalidOutput = Util.getTypedbDir().resolve("server/test/config/config-invalid-logger-output.yml");
    try {
        CoreConfigFactory.config(configInvalidOutput, new HashSet<>(), new CoreConfigParser());
        fail();
    } catch (TypeDBException e) {
        assert e.code().isPresent();
        assertEquals(CONFIG_OUTPUT_UNRECOGNISED.code(), e.code().get());
    }
}
Also used : Path(java.nio.file.Path) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) CoreConfigParser(com.vaticle.typedb.core.server.parameters.CoreConfigParser) Test(org.junit.Test)

Example 8 with TypeDBException

use of com.vaticle.typedb.core.common.exception.TypeDBException in project grakn by graknlabs.

the class ReiterationTest method test_first_iteration_exhausts_and_second_iteration_recurses_infinitely.

@Test
public void test_first_iteration_exhausts_and_second_iteration_recurses_infinitely() throws InterruptedException {
    try (CoreSession session = schemaSession()) {
        try (CoreTransaction transaction = singleThreadElgTransaction(session)) {
            transaction.query().define(TypeQL.parseQuery("define " + "X sub relation, relates item, plays Y:item;" + "Y sub relation, relates item, plays X:item;" + "object sub entity, plays X:item, plays Y:item;" + "rule rule-b: when {" + "$r(item:$x) isa X;" + "} then {" + "(item:$r) isa Y;" + "};" + "rule rule-a: when {" + "$r(item:$x) isa Y;" + "} then {" + "(item:$r) isa X;" + "};" + "rule rule-c: when {" + "$o isa object;" + "} then {" + "(item:$o) isa X;" + "};"));
            transaction.commit();
        }
    }
    try (CoreSession session = dataSession()) {
        try (CoreTransaction transaction = singleThreadElgTransaction(session)) {
            transaction.query().insert(TypeQL.parseQuery("insert $o isa object;"));
            transaction.commit();
        }
    }
    try (CoreSession session = dataSession()) {
        try (CoreTransaction transaction = singleThreadElgTransaction(session)) {
            Conjunction conjunction = resolvedConjunction("{ $y isa Y; }", transaction.logic());
            Set<Identifier.Variable.Retrievable> filter = new HashSet<>();
            iterate(conjunction.variables()).map(Variable::id).filter(Identifier::isName).map(Identifier.Variable::asName).forEachRemaining(filter::add);
            ResolverRegistry registry = transaction.reasoner().resolverRegistry();
            LinkedBlockingQueue<Match.Finished> responses = new LinkedBlockingQueue<>();
            LinkedBlockingQueue<Integer> failed = new LinkedBlockingQueue<>();
            int[] iteration = { 0 };
            int[] doneInIteration = { 0 };
            boolean[] receivedInferredAnswer = { false };
            ResolutionTracer.get().start();
            Actor.Driver<RootResolver.Conjunction> root = registry.root(conjunction, answer -> {
                if (iterate(answer.conceptMap().concepts().entrySet()).map(e -> e.getValue().asThing().isInferred()).first().isPresent()) {
                    receivedInferredAnswer[0] = true;
                }
                responses.add(answer);
            }, iterDone -> {
                assert iteration[0] == iterDone;
                doneInIteration[0]++;
                failed.add(iterDone);
            }, throwable -> fail());
            Set<Match.Finished> answers = new HashSet<>();
            // iteration 0
            sendRootRequest(root, filter, iteration[0]);
            answers.add(responses.take());
            ResolutionTracer.get().finish();
            ResolutionTracer.get().start();
            sendRootRequest(root, filter, iteration[0]);
            // Block and wait for an failed message
            failed.take();
            ResolutionTracer.get().finish();
            assertTrue(receivedInferredAnswer[0]);
            assertEquals(1, doneInIteration[0]);
            // iteration 1 onwards
            for (int j = 0; j <= 100; j++) {
                ResolutionTracer.get().start();
                sendRootRequest(root, filter, iteration[0]);
                Match.Finished re = responses.poll(100, MILLISECONDS);
                if (re == null) {
                    Integer ex = failed.poll(100, MILLISECONDS);
                    if (ex == null) {
                        ResolutionTracer.get().finish();
                        fail();
                    }
                    // Reset the iteration
                    iteration[0]++;
                    receivedInferredAnswer[0] = false;
                    doneInIteration[0] = 0;
                }
                ResolutionTracer.get().finish();
            }
        } catch (TypeDBException e) {
            e.printStackTrace();
            fail();
        }
    }
}
Also used : LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) CoreTransaction(com.vaticle.typedb.core.database.CoreTransaction) Match(com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Top.Match) Identifier(com.vaticle.typedb.core.traversal.common.Identifier) Actor(com.vaticle.typedb.core.concurrent.actor.Actor) Util.resolvedConjunction(com.vaticle.typedb.core.reasoner.resolution.Util.resolvedConjunction) Conjunction(com.vaticle.typedb.core.pattern.Conjunction) CoreSession(com.vaticle.typedb.core.database.CoreSession) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with TypeDBException

use of com.vaticle.typedb.core.common.exception.TypeDBException in project grakn by graknlabs.

the class ReasonerTest method test_exception_kills_query.

@Test
public void test_exception_kills_query() {
    try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.SCHEMA)) {
        try (CoreTransaction txn = singleThreadElgTransaction(session, Arguments.Transaction.Type.WRITE)) {
            ConceptManager conceptMgr = txn.concepts();
            LogicManager logicMgr = txn.logic();
            EntityType milk = conceptMgr.putEntityType("milk");
            AttributeType ageInDays = conceptMgr.putAttributeType("age-in-days", AttributeType.ValueType.LONG);
            AttributeType isStillGood = conceptMgr.putAttributeType("is-still-good", AttributeType.ValueType.BOOLEAN);
            milk.setOwns(ageInDays);
            milk.setOwns(isStillGood);
            logicMgr.putRule("old-milk-is-not-good", TypeQL.parsePattern("{ $x isa milk, has age-in-days >= 10; }").asConjunction(), TypeQL.parseVariable("$x has is-still-good false").asThing());
            txn.commit();
        }
    }
    try (CoreSession session = databaseMgr.session(database, Arguments.Session.Type.DATA)) {
        try (CoreTransaction txn = singleThreadElgTransaction(session, Arguments.Transaction.Type.WRITE)) {
            txn.query().insert(TypeQL.parseQuery("insert $x isa milk, has age-in-days 5;").asInsert());
            txn.query().insert(TypeQL.parseQuery("insert $x isa milk, has age-in-days 10;").asInsert());
            txn.commit();
        }
        try (CoreTransaction txn = singleThreadElgTransaction(session, Arguments.Transaction.Type.READ)) {
            txn.reasoner().resolverRegistry().terminateResolvers(new RuntimeException());
            try {
                List<ConceptMap> ans = txn.query().match(TypeQL.parseQuery("match $x isa is-still-good;").asMatch()).toList();
            } catch (TypeDBException e) {
                assertEquals(e.code().get(), RESOLUTION_TERMINATED.code());
                return;
            }
            fail();
        }
    }
}
Also used : ConceptManager(com.vaticle.typedb.core.concept.ConceptManager) EntityType(com.vaticle.typedb.core.concept.type.EntityType) LogicManager(com.vaticle.typedb.core.logic.LogicManager) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) CoreSession(com.vaticle.typedb.core.database.CoreSession) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) CoreTransaction(com.vaticle.typedb.core.database.CoreTransaction) Test(org.junit.Test)

Example 10 with TypeDBException

use of com.vaticle.typedb.core.common.exception.TypeDBException in project grakn by graknlabs.

the class ResolutionTest method createRootAndAssertResponses.

private void createRootAndAssertResponses(CoreTransaction transaction, Disjunction disjunction, Set<Identifier.Variable.Retrievable> filter, long answerCount, long explainableAnswers) throws InterruptedException {
    ResolverRegistry registry = transaction.reasoner().resolverRegistry();
    LinkedBlockingQueue<Match.Finished> responses = new LinkedBlockingQueue<>();
    AtomicLong doneReceived = new AtomicLong(0L);
    Actor.Driver<RootResolver.Disjunction> root;
    try {
        root = registry.root(disjunction, responses::add, iterDone -> doneReceived.incrementAndGet(), (throwable) -> fail());
    } catch (TypeDBException e) {
        fail();
        return;
    }
    assertResponses(root, filter, responses, doneReceived, answerCount, explainableAnswers);
}
Also used : Util.resolvedConjunction(com.vaticle.typedb.core.reasoner.resolution.Util.resolvedConjunction) Collections.set(com.vaticle.typedb.common.collection.Collections.set) Variable(com.vaticle.typedb.core.pattern.variable.Variable) Identifier(com.vaticle.typedb.core.traversal.common.Identifier) MB(com.vaticle.typedb.core.common.collection.Bytes.MB) Arguments(com.vaticle.typedb.core.common.parameters.Arguments) HashSet(java.util.HashSet) Root(com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Partial.Compound.Root) Util.resolvedDisjunction(com.vaticle.typedb.core.reasoner.resolution.Util.resolvedDisjunction) After(org.junit.After) InitialImpl(com.vaticle.typedb.core.reasoner.resolution.answer.AnswerStateImpl.TopImpl.MatchImpl.InitialImpl) Assert.fail(org.junit.Assert.fail) Path(java.nio.file.Path) Before(org.junit.Before) Conjunction(com.vaticle.typedb.core.pattern.Conjunction) TypeQL(com.vaticle.typeql.lang.TypeQL) CoreDatabaseManager(com.vaticle.typedb.core.database.CoreDatabaseManager) Set(java.util.Set) ConceptMap(com.vaticle.typedb.core.concept.answer.ConceptMap) Test(org.junit.Test) IOException(java.io.IOException) RootResolver(com.vaticle.typedb.core.reasoner.resolution.resolver.RootResolver) Actor(com.vaticle.typedb.core.concurrent.actor.Actor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Disjunction(com.vaticle.typedb.core.pattern.Disjunction) TimeUnit(java.util.concurrent.TimeUnit) CoreSession(com.vaticle.typedb.core.database.CoreSession) AtomicLong(java.util.concurrent.atomic.AtomicLong) Stream(java.util.stream.Stream) NamedThreadFactory(com.vaticle.typedb.common.concurrent.NamedThreadFactory) Paths(java.nio.file.Paths) TestCase.assertTrue(junit.framework.TestCase.assertTrue) ActorExecutorGroup(com.vaticle.typedb.core.concurrent.actor.ActorExecutorGroup) Database(com.vaticle.typedb.core.common.parameters.Options.Database) Iterators.iterate(com.vaticle.typedb.core.common.iterator.Iterators.iterate) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) Request(com.vaticle.typedb.core.reasoner.resolution.framework.Request) CoreTransaction(com.vaticle.typedb.core.database.CoreTransaction) Match(com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Top.Match) Resolver(com.vaticle.typedb.core.reasoner.resolution.framework.Resolver) Util(com.vaticle.typedb.core.test.integration.util.Util) TestCase.assertEquals(junit.framework.TestCase.assertEquals) AtomicLong(java.util.concurrent.atomic.AtomicLong) Util.resolvedDisjunction(com.vaticle.typedb.core.reasoner.resolution.Util.resolvedDisjunction) Disjunction(com.vaticle.typedb.core.pattern.Disjunction) Actor(com.vaticle.typedb.core.concurrent.actor.Actor) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Aggregations

TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)16 Test (org.junit.Test)11 Path (java.nio.file.Path)9 CoreConfigParser (com.vaticle.typedb.core.server.parameters.CoreConfigParser)7 CoreSession (com.vaticle.typedb.core.database.CoreSession)5 CoreTransaction (com.vaticle.typedb.core.database.CoreTransaction)5 ConceptMap (com.vaticle.typedb.core.concept.answer.ConceptMap)4 Actor (com.vaticle.typedb.core.concurrent.actor.Actor)4 Conjunction (com.vaticle.typedb.core.pattern.Conjunction)4 Disjunction (com.vaticle.typedb.core.pattern.Disjunction)4 Util.resolvedConjunction (com.vaticle.typedb.core.reasoner.resolution.Util.resolvedConjunction)4 Match (com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Top.Match)4 Identifier (com.vaticle.typedb.core.traversal.common.Identifier)4 IOException (java.io.IOException)4 Collections.set (com.vaticle.typedb.common.collection.Collections.set)3 NamedThreadFactory (com.vaticle.typedb.common.concurrent.NamedThreadFactory)3 MB (com.vaticle.typedb.core.common.collection.Bytes.MB)3 Iterators.iterate (com.vaticle.typedb.core.common.iterator.Iterators.iterate)3 Arguments (com.vaticle.typedb.core.common.parameters.Arguments)3 Database (com.vaticle.typedb.core.common.parameters.Options.Database)3