Skip to content

Commit

Permalink
Couple of more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Jun 26, 2017
1 parent 017dcc3 commit 5b2a368
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 25 deletions.
Expand Up @@ -34,8 +34,12 @@
import org.neo4j.kernel.api.index.IndexUpdater;
import org.neo4j.kernel.api.index.PropertyAccessor;
import org.neo4j.kernel.impl.api.index.IndexUpdateMode;
import org.neo4j.kernel.impl.index.GBPTreeUtil;
import org.neo4j.storageengine.api.schema.IndexReader;

import static org.neo4j.helpers.collection.Iterators.asResourceIterator;
import static org.neo4j.helpers.collection.Iterators.iterator;

public class NativeSchemaNumberIndexAccessor<KEY extends NumberKey, VALUE extends NumberValue>
extends NativeSchemaNumberIndex<KEY,VALUE> implements IndexAccessor
{
Expand All @@ -52,7 +56,8 @@ public class NativeSchemaNumberIndexAccessor<KEY extends NumberKey, VALUE extend
@Override
public void drop() throws IOException
{
throw new UnsupportedOperationException( "Implement me" );
closeTree();
GBPTreeUtil.delete( pageCache, storeFile );
}

@Override
Expand Down Expand Up @@ -96,7 +101,7 @@ public BoundedIterable<Long> newAllEntriesReader()
@Override
public ResourceIterator<File> snapshotFiles() throws IOException
{
throw new UnsupportedOperationException( "Implement me" );
return asResourceIterator( iterator( storeFile ) );
}

@Override
Expand Down
Expand Up @@ -42,7 +42,7 @@
import static org.neo4j.kernel.impl.index.schema.FullScanNonUniqueIndexSamplerTest.countUniqueValues;

public class NativeNonUniqueSchemaNumberIndexPopulatorTest
extends NativeSchemaIndexPopulatorTest<NumberKey,NumberValue>
extends NativeSchemaNumberIndexPopulatorTest<NumberKey,NumberValue>
{
@Override
NativeSchemaNumberIndexPopulator<NumberKey,NumberValue> createPopulator( PageCache pageCache, File indexFile,
Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
Expand All @@ -33,6 +34,7 @@
import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.graphdb.ResourceIterator;
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.IndexUpdater;
Expand All @@ -43,6 +45,8 @@

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import static org.neo4j.collection.primitive.PrimitiveLongCollections.EMPTY_LONG_ARRAY;
Expand Down Expand Up @@ -469,11 +473,56 @@ public void requestForSecondUpdaterMustThrow() throws Exception
@Test
public void dropShouldDeleteAndCloseIndex() throws Exception
{
// GIVEN
// given
assertFilePresent();

// when
accessor.drop();

// then
assertFileNotPresent();
}

@Test
public void forceShouldCheckpointTree() throws Exception
{
// given
IndexEntryUpdate<IndexDescriptor>[] data = layoutUtil.someUpdates();
processAll( data );

// when
accessor.force();
accessor.close();

// then
verifyUpdates( data );
}

// WHEN
// THEN
fail( "Test not fully implemented yet" );
@SuppressWarnings( "unchecked" )
@Test
public void closeShouldCloseTreeWithoutCheckpoint() throws Exception
{
// given
IndexEntryUpdate<IndexDescriptor>[] data = layoutUtil.someUpdates();
processAll( data );

// when
accessor.close();

// then
verifyUpdates( new IndexEntryUpdate[0] );
}

@Test
public void snapshotFilesShouldReturnIndexFile() throws Exception
{
// when
ResourceIterator<File> files = accessor.snapshotFiles();

// then
assertTrue( files.hasNext() );
assertEquals( indexFile, files.next() );
assertFalse( files.hasNext() );
}

private static Predicate<Object> lessThan( Double value )
Expand Down Expand Up @@ -629,24 +678,24 @@ private IndexEntryUpdate<IndexDescriptor> simpleUpdate()
// shouldReturnNoEntriesForRangePredicateOutsideAnyMatch
// TODO: multiple query predicates... actually Lucene SimpleIndexReader only supports single predicate
// so perhaps we should wait with this until we know exactly how this works and which combinations
// that should be optimized.
// that should be supported/optimized for.

// TODO: SAMPLER

// long countIndexedNodes( long nodeId, Object... propertyValues )
// IndexSampler createSampler()
// PrimitiveLongIterator query( IndexQuery... predicates )
// close
// close()

// ACCESSOR
// shouldHandleMultipleConsecutiveUpdaters
// requestForSecondUpdaterMustThrow
// TODO: dropShouldDeleteAndCloseIndex
// dropShouldDeleteAndCloseIndex
// TODO: anyUsageAfterDropShouldThrow
// TODO: forceShouldCheckpointTree
// TODO: closeShouldCloseTreeWithoutCheckpoint
// forceShouldCheckpointTree
// closeShouldCloseTreeWithoutCheckpoint
// TODO: anyUsageAfterCloseShouldThrow
// TODO: snapshotFilesShouldReturnIndexFile
// snapshotFilesShouldReturnIndexFile

// void drop()
// IndexUpdater newUpdater( IndexUpdateMode mode )
Expand Down
Expand Up @@ -58,7 +58,7 @@
import static org.neo4j.kernel.impl.index.schema.NativeSchemaNumberIndexPopulator.BYTE_FAILED;
import static org.neo4j.kernel.impl.index.schema.NativeSchemaNumberIndexPopulator.BYTE_ONLINE;

public abstract class NativeSchemaIndexPopulatorTest<KEY extends NumberKey,VALUE extends NumberValue>
public abstract class NativeSchemaNumberIndexPopulatorTest<KEY extends NumberKey,VALUE extends NumberValue>
extends SchemaNumberIndexTestUtil<KEY,VALUE>
{
static final int LARGE_AMOUNT_OF_UPDATES = 1_000;
Expand Down Expand Up @@ -484,16 +484,6 @@ public void unsuccessfulCloseMustThrowAfterDrop() throws Exception
}
}

private void assertFilePresent()
{
assertTrue( fs.fileExists( indexFile ) );
}

private void assertFileNotPresent()
{
assertFalse( fs.fileExists( indexFile ) );
}

int interleaveLargeAmountOfUpdates( Random updaterRandom,
Iterator<IndexEntryUpdate<IndexDescriptor>> updates ) throws IOException, IndexEntryConflictException
{
Expand Down
Expand Up @@ -37,7 +37,7 @@
import static org.junit.Assert.fail;
import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE;

public class NativeUniqueSchemaNumberIndexPopulatorTest extends NativeSchemaIndexPopulatorTest<NumberKey,NumberValue>
public class NativeUniqueSchemaNumberIndexPopulatorTest extends NativeSchemaNumberIndexPopulatorTest<NumberKey,NumberValue>
{
@Override
NativeSchemaNumberIndexPopulator<NumberKey,NumberValue> createPopulator(
Expand Down
Expand Up @@ -47,6 +47,7 @@

import static java.lang.String.format;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.rules.RuleChain.outerRule;

Expand Down Expand Up @@ -183,6 +184,16 @@ private Hit<KEY,VALUE> hit( final KEY key, final VALUE value )
return new SimpleHit( key, value );
}

protected void assertFilePresent()
{
assertTrue( fs.fileExists( indexFile ) );
}

protected void assertFileNotPresent()
{
assertFalse( fs.fileExists( indexFile ) );
}

private class SimpleHit implements Hit<KEY,VALUE>
{
private final KEY key;
Expand Down

0 comments on commit 5b2a368

Please sign in to comment.