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());
}
}
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());
}
}
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();
}
}
}
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();
}
}
}
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);
}
Aggregations