Skip to content

Commit

Permalink
General cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Jul 25, 2017
1 parent 194d51e commit 737d177
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 65 deletions.
Expand Up @@ -229,8 +229,8 @@ public Result runFullConsistencyCheck( final File storeDir, Config config, Progr
try ( NeoStores neoStores = factory.openAllNeoStores() )
{
life.start();
SchemaIndexProvider indexes = new LuceneSchemaIndexProvider( fileSystem, DirectoryFactory.PERSISTENT,
storeDir, logProvider, config, operationalMode );
SchemaIndexProvider indexes = life.add( new LuceneSchemaIndexProvider( fileSystem, DirectoryFactory.PERSISTENT,
storeDir, logProvider, config, operationalMode ) );

LabelScanStore labelScanStore =
new NativeLabelScanStore( pageCache, storeDir, FullStoreChangeStream.EMPTY, true, new Monitors(),
Expand Down
Expand Up @@ -25,10 +25,6 @@

/**
* Node id iterator used during index population when we go over node ids indexed in label scan store.
* Before each iteration check if data in current reader can be expired because of concurrent updates that came from
* other transactions.
* In that case will reopen corresponding lucene reader and will reposition itself into the same position of matched
* node ids.
*/
class LabelScanViewIdIterator implements PrimitiveLongResourceIterator
{
Expand Down
Expand Up @@ -1134,12 +1134,6 @@ NeoStores getNeoStores()
return neoStores;
}

// test-access
LabelScanStore getLabelScanStore()
{
return labelScanStore;
}

void forceFlushChanges()
{
flushStrategy.forceFlush();
Expand Down
Expand Up @@ -176,7 +176,7 @@ public void retrieveNodeIdsInAscendingOrder()
public void shouldHandleLargeAmountsOfNodesAddedAndRemovedInSameTx() throws Exception
{
// Given
GraphDatabaseService db = db();
GraphDatabaseService db = dbRule;
int labelsToAdd = 80;
int labelsToRemove = 40;

Expand Down Expand Up @@ -214,16 +214,11 @@ public void shouldHandleLargeAmountsOfNodesAddedAndRemovedInSameTx() throws Exce
}
}

protected GraphDatabaseService db()
{
return dbRule;
}

private void verifyFoundNodes( Label label, String sizeMismatchMessage, long... expectedNodeIds )
{
try ( Transaction ignored = db().beginTx() )
try ( Transaction ignored = dbRule.beginTx() )
{
ResourceIterator<Node> nodes = db().findNodes( label );
ResourceIterator<Node> nodes = dbRule.findNodes( label );
List<Node> nodeList = Iterators.asList( nodes );
assertThat( sizeMismatchMessage, nodeList, Matchers.hasSize( expectedNodeIds.length ) );
int index = 0;
Expand All @@ -236,7 +231,7 @@ private void verifyFoundNodes( Label label, String sizeMismatchMessage, long...

private void removeLabels( Node node, Label... labels )
{
try ( Transaction tx = db().beginTx() )
try ( Transaction tx = dbRule.beginTx() )
{
for ( Label label : labels )
{
Expand All @@ -248,7 +243,7 @@ private void removeLabels( Node node, Label... labels )

private void deleteNode( Node node )
{
try ( Transaction tx = db().beginTx() )
try ( Transaction tx = dbRule.beginTx() )
{
node.delete();
tx.success();
Expand All @@ -257,25 +252,25 @@ private void deleteNode( Node node )

private Set<Node> getAllNodesWithLabel( Label label )
{
try ( Transaction ignored = db().beginTx() )
try ( Transaction ignored = dbRule.beginTx() )
{
return asSet( db().findNodes( label ) );
return asSet( dbRule.findNodes( label ) );
}
}

private Node createLabeledNode( Label... labels )
{
try ( Transaction tx = db().beginTx() )
try ( Transaction tx = dbRule.beginTx() )
{
Node node = db().createNode( labels );
Node node = dbRule.createNode( labels );
tx.success();
return node;
}
}

private void addLabels( Node node, Label... labels )
{
try ( Transaction tx = db().beginTx() )
try ( Transaction tx = dbRule.beginTx() )
{
for ( Label label : labels )
{
Expand All @@ -287,9 +282,9 @@ private void addLabels( Node node, Label... labels )

private Node getNodeById( long id )
{
try ( Transaction ignored = db().beginTx() )
try ( Transaction ignored = dbRule.beginTx() )
{
return db().getNodeById( id );
return dbRule.getNodeById( id );
}
}

Expand Down
Expand Up @@ -102,6 +102,7 @@

import static java.lang.Integer.parseInt;
import static java.lang.String.format;
import static java.util.Collections.singletonList;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.arrayContaining;
import static org.hamcrest.Matchers.emptyArray;
Expand Down Expand Up @@ -236,7 +237,7 @@ private BatchInserter newBatchInserter() throws Exception

private BatchInserter newBatchInserterWithSchemaIndexProvider( KernelExtensionFactory<?> provider ) throws Exception
{
return BatchInserters.inserter( storeDir.absolutePath(), fileSystemRule.get(), configuration(), Arrays.asList( provider ) );
return BatchInserters.inserter( storeDir.absolutePath(), fileSystemRule.get(), configuration(), singletonList( provider ) );
}

private GraphDatabaseService switchToEmbeddedGraphDatabaseService( BatchInserter inserter )
Expand Down Expand Up @@ -653,7 +654,7 @@ public void createEntitiesWithDynamicPropertiesMap() throws Exception
BatchInserter inserter = globalInserter;

setAndGet( inserter, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" );
setAndGet( inserter, intArray( 20 ) );
setAndGet( inserter, intArray() );
}

@Test
Expand Down Expand Up @@ -1035,32 +1036,6 @@ public void shouldPopulateLabelScanStoreOnShutdown() throws Exception
labelScanStore.shutdown();
}

private LabelScanStore getLabelScanStore()
{
return new NativeLabelScanStore( pageCacheRule.getPageCache( fileSystemRule.get() ), storeDir.absolutePath(),
FullStoreChangeStream.EMPTY, true, new Monitors(), RecoveryCleanupWorkCollector.IMMEDIATE );
}

private void assertLabelScanStoreContains( LabelScanStore labelScanStore, int labelId, long... nodes )
{
try ( LabelScanReader labelScanReader = labelScanStore.newReader() )
{
List<Long> actualNodeIds = extractPrimitiveLongIteratorAsList( labelScanReader.nodesWithLabel( labelId ) );
List<Long> expectedNodeIds = Arrays.stream( nodes ).boxed().collect( Collectors.toList() );
assertEquals( expectedNodeIds, actualNodeIds );
}
}

private List<Long> extractPrimitiveLongIteratorAsList( PrimitiveLongIterator primitiveLongIterator )
{
List<Long> actualNodeIds = new ArrayList<>();
while ( primitiveLongIterator.hasNext() )
{
actualNodeIds.add( primitiveLongIterator.next() );
}
return actualNodeIds;
}

@Test
public void propertiesCanBeReSetUsingBatchInserter() throws Exception
{
Expand Down Expand Up @@ -1092,7 +1067,6 @@ public void propertiesCanBeReSetUsingBatchInserter() throws Exception
* During first update email property will be migrated to dynamic property and last property record will become
* empty. That record should be deleted form property chain or otherwise on next node load user will get an
* property record not in use exception.
* @throws Exception
*/
@Test
public void testCleanupEmptyPropertyRecords() throws Exception
Expand Down Expand Up @@ -1192,8 +1166,8 @@ public void shouldGetRelationships() throws Exception
// GIVEN
BatchInserter inserter = globalInserter;
long node = inserter.createNode( null );
createRelationships( inserter, node, RelTypes.REL_TYPE1, 3, 2, 1 );
createRelationships( inserter, node, RelTypes.REL_TYPE2, 4, 5, 6 );
createRelationships( inserter, node, RelTypes.REL_TYPE1, 3 );
createRelationships( inserter, node, RelTypes.REL_TYPE2, 4 );

// WHEN
Set<Long> gottenRelationships = Iterables.asSet( inserter.getRelationshipIds( node ) );
Expand Down Expand Up @@ -1412,7 +1386,7 @@ public void shouldIgnoreRemovingNonExistentNodeProperty() throws Exception
{
// given
BatchInserter inserter = globalInserter;
long id = inserter.createNode( Collections.<String,Object>emptyMap() );
long id = inserter.createNode( Collections.emptyMap() );

// when
inserter.removeNodeProperty( id, "non-existent" );
Expand All @@ -1425,7 +1399,7 @@ public void shouldIgnoreRemovingNonExistentRelationshipProperty() throws Excepti
{
// given
BatchInserter inserter = globalInserter;
Map<String,Object> noProperties = Collections.<String,Object>emptyMap();
Map<String,Object> noProperties = Collections.emptyMap();
long nodeId1 = inserter.createNode( noProperties );
long nodeId2 = inserter.createNode( noProperties );
long id = inserter.createRelationship( nodeId1, nodeId2, MyRelTypes.TEST, noProperties );
Expand All @@ -1436,8 +1410,33 @@ public void shouldIgnoreRemovingNonExistentRelationshipProperty() throws Excepti
// then no exception should be thrown, this mimics GraphDatabaseService behaviour
}

private void createRelationships( BatchInserter inserter, long node, RelationshipType relType,
int out, int in, int loop )
private LabelScanStore getLabelScanStore()
{
return new NativeLabelScanStore( pageCacheRule.getPageCache( fileSystemRule.get() ), storeDir.absolutePath(),
FullStoreChangeStream.EMPTY, true, new Monitors(), RecoveryCleanupWorkCollector.IMMEDIATE );
}

private void assertLabelScanStoreContains( LabelScanStore labelScanStore, int labelId, long... nodes )
{
try ( LabelScanReader labelScanReader = labelScanStore.newReader() )
{
List<Long> actualNodeIds = extractPrimitiveLongIteratorAsList( labelScanReader.nodesWithLabel( labelId ) );
List<Long> expectedNodeIds = Arrays.stream( nodes ).boxed().collect( Collectors.toList() );
assertEquals( expectedNodeIds, actualNodeIds );
}
}

private List<Long> extractPrimitiveLongIteratorAsList( PrimitiveLongIterator primitiveLongIterator )
{
List<Long> actualNodeIds = new ArrayList<>();
while ( primitiveLongIterator.hasNext() )
{
actualNodeIds.add( primitiveLongIterator.next() );
}
return actualNodeIds;
}

private void createRelationships( BatchInserter inserter, long node, RelationshipType relType, int out )
{
for ( int i = 0; i < out; i++ )
{
Expand Down Expand Up @@ -1478,8 +1477,9 @@ private void setAndGet( BatchInserter inserter, Object value )
assertEquals( Values.of( value ), readValue );
}

private int[] intArray( int length )
private int[] intArray()
{
int length = 20;
int[] array = new int[length];
for ( int i = 0, startValue = (int)Math.pow( 2, 30 ); i < length; i++ )
{
Expand Down

0 comments on commit 737d177

Please sign in to comment.