use of com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Partial.Compound.Root in project grakn by graknlabs.
the class ResolutionTest method test_exceptions_are_propagated.
@Test
public void test_exceptions_are_propagated() throws InterruptedException {
try (CoreSession session = schemaSession()) {
try (CoreTransaction transaction = singleThreadElgTransaction(session)) {
transaction.query().define(TypeQL.parseQuery("define person sub entity, owns age, plays twins:twin1, plays twins:twin2;" + "age sub attribute, value long;" + "twins sub relation, relates twin1, relates twin2;"));
transaction.commit();
}
}
try (CoreSession session = dataSession()) {
try (CoreTransaction transaction = singleThreadElgTransaction(session)) {
transaction.query().insert(TypeQL.parseQuery("insert $p1 isa person, has age 24; $t(twin1: $p1, twin2: $p2) isa twins; $p2 isa person;"));
transaction.query().insert(TypeQL.parseQuery("insert $p1 isa person, has age 24; $t(twin1: $p1, twin2: $p2) isa twins; $p2 isa person;"));
transaction.query().insert(TypeQL.parseQuery("insert $p1 isa person, has age 24; $t(twin1: $p1, twin2: $p2) isa twins; $p2 isa person;"));
transaction.commit();
}
}
try (CoreSession session = dataSession()) {
try (CoreTransaction transaction = singleThreadElgTransaction(session)) {
Conjunction conjunctionPattern = resolvedConjunction("{ $t(twin1: $p1, twin2: $p2) isa twins; $p1 has age $a; }", transaction.logic());
ResolverRegistry registry = transaction.reasoner().resolverRegistry();
LinkedBlockingQueue<Match.Finished> responses = new LinkedBlockingQueue<>();
AtomicLong doneReceived = new AtomicLong(0L);
LinkedBlockingQueue<Throwable> exceptions = new LinkedBlockingQueue<>();
Actor.Driver<RootResolver.Conjunction> root;
try {
root = registry.root(conjunctionPattern, responses::add, iterDone -> doneReceived.incrementAndGet(), exceptions::add);
} catch (TypeDBException e) {
fail();
}
Exception e = new RuntimeException();
registry.terminateResolvers(e);
Throwable receivedException = exceptions.poll(100, TimeUnit.MILLISECONDS);
assertEquals(e, receivedException);
}
}
}
use of com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Partial.Compound.Root in project grakn by graknlabs.
the class ResolutionTest method createRootAndAssertResponses.
private void createRootAndAssertResponses(CoreTransaction transaction, Conjunction conjunction, long answerCount, long explainableAnswers) throws InterruptedException {
ResolverRegistry registry = transaction.reasoner().resolverRegistry();
LinkedBlockingQueue<Match.Finished> responses = new LinkedBlockingQueue<>();
AtomicLong doneReceived = new AtomicLong(0L);
Set<Identifier.Variable.Retrievable> filter = new HashSet<>();
iterate(conjunction.variables()).map(Variable::id).filter(Identifier::isName).map(Identifier.Variable::asName).forEachRemaining(filter::add);
Actor.Driver<RootResolver.Conjunction> root;
try {
root = registry.root(conjunction, responses::add, iterDone -> doneReceived.incrementAndGet(), (throwable) -> fail());
} catch (TypeDBException e) {
fail();
return;
}
assertResponses(root, filter, responses, doneReceived, answerCount, explainableAnswers);
}
use of com.vaticle.typedb.core.reasoner.resolution.answer.AnswerState.Partial.Compound.Root 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);
}
Aggregations