Search in sources :

Example 31 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class DatabaseCompositeIndexAccessorTest method multipleIndexReadersFromDifferentPointsInTimeCanSeeDifferentResults.

@Test
public void multipleIndexReadersFromDifferentPointsInTimeCanSeeDifferentResults() throws Exception {
    // WHEN
    updateAndCommit(asList(add(nodeId, values)));
    IndexReader firstReader = accessor.newReader();
    updateAndCommit(asList(add(nodeId2, values2)));
    IndexReader secondReader = accessor.newReader();
    // THEN
    assertEquals(asSet(nodeId), PrimitiveLongCollections.toSet(firstReader.query(IndexQuery.exact(PROP_ID1, values[0]), IndexQuery.exact(PROP_ID2, values[1]))));
    assertEquals(asSet(), PrimitiveLongCollections.toSet(firstReader.query(IndexQuery.exact(PROP_ID1, values2[0]), IndexQuery.exact(PROP_ID2, values2[1]))));
    assertEquals(asSet(nodeId), PrimitiveLongCollections.toSet(secondReader.query(IndexQuery.exact(PROP_ID1, values[0]), IndexQuery.exact(PROP_ID2, values[1]))));
    assertEquals(asSet(nodeId2), PrimitiveLongCollections.toSet(secondReader.query(IndexQuery.exact(PROP_ID1, values2[0]), IndexQuery.exact(PROP_ID2, values2[1]))));
    firstReader.close();
    secondReader.close();
}
Also used : IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 32 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class DatabaseIndexAccessorTest method multipleIndexReadersFromDifferentPointsInTimeCanSeeDifferentResults.

@Test
public void multipleIndexReadersFromDifferentPointsInTimeCanSeeDifferentResults() throws Exception {
    // WHEN
    updateAndCommit(asList(add(nodeId, value)));
    IndexReader firstReader = accessor.newReader();
    updateAndCommit(asList(add(nodeId2, value2)));
    IndexReader secondReader = accessor.newReader();
    // THEN
    assertEquals(asSet(nodeId), PrimitiveLongCollections.toSet(firstReader.query(exact(PROP_ID, value))));
    assertEquals(asSet(), PrimitiveLongCollections.toSet(firstReader.query(exact(PROP_ID, value2))));
    assertEquals(asSet(nodeId), PrimitiveLongCollections.toSet(secondReader.query(exact(PROP_ID, value))));
    assertEquals(asSet(nodeId2), PrimitiveLongCollections.toSet(secondReader.query(exact(PROP_ID, value2))));
    firstReader.close();
    secondReader.close();
}
Also used : IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 33 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class DatabaseIndexAccessorTest method indexReaderShouldSupportScan.

@Test
public void indexReaderShouldSupportScan() throws Exception {
    // GIVEN
    updateAndCommit(asList(add(nodeId, value), add(nodeId2, value2)));
    IndexReader reader = accessor.newReader();
    // WHEN
    PrimitiveLongIterator results = reader.query(IndexQuery.exists(PROP_ID));
    // THEN
    assertEquals(asSet(nodeId, nodeId2), PrimitiveLongCollections.toSet(results));
    assertEquals(asSet(nodeId), PrimitiveLongCollections.toSet(reader.query(IndexQuery.exact(PROP_ID, value))));
    reader.close();
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 34 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class DatabaseIndexAccessorTest method indexStringRangeQuery.

@Test
public void indexStringRangeQuery() throws Exception {
    updateAndCommit(asList(add(PROP_ID, "A"), add(2, "B"), add(3, "C"), add(4, "")));
    IndexReader reader = accessor.newReader();
    PrimitiveLongIterator rangeFromBInclusive = reader.query(range(PROP_ID, "B", true, null, false));
    assertThat(PrimitiveLongCollections.asArray(rangeFromBInclusive), LongArrayMatcher.of(2, 3));
    PrimitiveLongIterator rangeFromANonInclusive = reader.query(range(PROP_ID, "A", false, null, false));
    assertThat(PrimitiveLongCollections.asArray(rangeFromANonInclusive), LongArrayMatcher.of(2, 3));
    PrimitiveLongIterator emptyLowInclusive = reader.query(range(PROP_ID, "", true, null, false));
    assertThat(PrimitiveLongCollections.asArray(emptyLowInclusive), LongArrayMatcher.of(PROP_ID, 2, 3, 4));
    PrimitiveLongIterator emptyUpperNonInclusive = reader.query(range(PROP_ID, "B", true, "", false));
    assertThat(PrimitiveLongCollections.asArray(emptyUpperNonInclusive), LongArrayMatcher.emptyArrayMatcher());
    PrimitiveLongIterator emptyInterval = reader.query(range(PROP_ID, "", true, "", true));
    assertThat(PrimitiveLongCollections.asArray(emptyInterval), LongArrayMatcher.of(4));
    PrimitiveLongIterator emptyAllNonInclusive = reader.query(range(PROP_ID, "", false, null, false));
    assertThat(PrimitiveLongCollections.asArray(emptyAllNonInclusive), LongArrayMatcher.of(PROP_ID, 2, 3));
    PrimitiveLongIterator nullNonInclusive = reader.query(range(PROP_ID, (String) null, false, null, false));
    assertThat(PrimitiveLongCollections.asArray(nullNonInclusive), LongArrayMatcher.of(PROP_ID, 2, 3, 4));
    PrimitiveLongIterator nullInclusive = reader.query(range(PROP_ID, (String) null, false, null, false));
    assertThat(PrimitiveLongCollections.asArray(nullInclusive), LongArrayMatcher.of(PROP_ID, 2, 3, 4));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 35 with IndexReader

use of org.neo4j.storageengine.api.schema.IndexReader in project neo4j by neo4j.

the class DatabaseIndexAccessorTest method canAddNewData.

@Test
public void canAddNewData() throws Exception {
    // WHEN
    updateAndCommit(asList(add(nodeId, value), add(nodeId2, value2)));
    IndexReader reader = accessor.newReader();
    // THEN
    assertEquals(asSet(nodeId), PrimitiveLongCollections.toSet(reader.query(exact(PROP_ID, value))));
    reader.close();
}
Also used : IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Aggregations

IndexReader (org.neo4j.storageengine.api.schema.IndexReader)50 Test (org.junit.Test)38 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)19 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)11 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)10 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)10 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)9 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)9 DocValuesCollector (org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)6 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)5 IndexSampler (org.neo4j.storageengine.api.schema.IndexSampler)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Arrays (java.util.Arrays)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 TermQuery (org.apache.lucene.search.TermQuery)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.fail (org.junit.Assert.fail)2 Before (org.junit.Before)2