use of ai.grakn.graql.internal.reasoner.cache.LazyQueryCache in project grakn by graknlabs.
the class QueryCacheTest method lazilyGetRetrieveAnswers.
@Test
public void lazilyGetRetrieveAnswers() {
LazyQueryCache<ReasonerAtomicQuery> cache = new LazyQueryCache<>();
cache.record(recordQuery, recordQuery.getQuery().stream());
LazyAnswerIterator retrieveIterator = cache.getAnswers(retrieveQuery);
LazyAnswerIterator recordIterator = cache.getAnswers(recordQuery);
Set<Answer> record = recordIterator.stream().collect(toSet());
Set<Answer> retrieve = retrieveIterator.stream().map(ans -> ans.unify(retrieveToRecordUnifier)).collect(toSet());
assertTrue(!retrieve.isEmpty());
assertEquals(record, retrieve);
}
use of ai.grakn.graql.internal.reasoner.cache.LazyQueryCache in project grakn by graknlabs.
the class QueryCacheTest method lazilyGetUpdateRetrieveAnswers.
@Test
public void lazilyGetUpdateRetrieveAnswers() {
LazyQueryCache<ReasonerAtomicQuery> cache = new LazyQueryCache<>();
Answer retrieveSingleAnswer = singleAnswer.unify(recordToRetrieveUnifier);
cache.record(recordQuery, recordQuery.getQuery().stream());
LazyAnswerIterator retrieveIterator = cache.getAnswers(retrieveQuery);
LazyAnswerIterator recordIterator = cache.getAnswers(recordQuery);
cache.record(recordQuery, Stream.of(singleAnswer));
Set<Answer> record = recordIterator.stream().collect(toSet());
Set<Answer> retrieve = retrieveIterator.stream().map(ans -> ans.unify(retrieveToRecordUnifier)).collect(toSet());
assertTrue(!retrieve.isEmpty());
assertTrue(!retrieve.contains(singleAnswer));
assertEquals(record, retrieve);
assertTrue(cache.getAnswers(recordQuery).stream().anyMatch(ans -> ans.equals(singleAnswer)));
assertTrue(cache.getAnswers(retrieveQuery).stream().anyMatch(ans -> ans.equals(retrieveSingleAnswer)));
}
Aggregations