Skip to content

Commit

Permalink
Remove custom IntFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegrohmann committed Dec 10, 2015
1 parent b6c12ef commit cbeed80
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 191 deletions.

This file was deleted.

Expand Up @@ -28,7 +28,6 @@


import org.neo4j.collection.primitive.PrimitiveIntIterator; import org.neo4j.collection.primitive.PrimitiveIntIterator;
import org.neo4j.cursor.Cursor; import org.neo4j.cursor.Cursor;
import org.neo4j.function.IntFunction;
import org.neo4j.graphdb.ConstraintViolationException; import org.neo4j.graphdb.ConstraintViolationException;
import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
Expand Down Expand Up @@ -64,7 +63,6 @@
import org.neo4j.kernel.impl.traversal.OldTraverserWrapper; import org.neo4j.kernel.impl.traversal.OldTraverserWrapper;


import static java.lang.String.format; import static java.lang.String.format;

import static org.neo4j.collection.primitive.PrimitiveIntCollections.map; import static org.neo4j.collection.primitive.PrimitiveIntCollections.map;
import static org.neo4j.graphdb.Label.label; import static org.neo4j.graphdb.Label.label;
import static org.neo4j.helpers.collection.IteratorUtil.asList; import static org.neo4j.helpers.collection.IteratorUtil.asList;
Expand All @@ -78,7 +76,7 @@ public class NodeProxy
public interface NodeActions public interface NodeActions
{ {
Statement statement(); Statement statement();

GraphDatabaseService getGraphDatabase(); GraphDatabaseService getGraphDatabase();


void assertInUnterminatedTransaction(); void assertInUnterminatedTransaction();
Expand Down Expand Up @@ -141,29 +139,24 @@ public ResourceIterable<Relationship> getRelationships()
public ResourceIterable<Relationship> getRelationships( final Direction dir ) public ResourceIterable<Relationship> getRelationships( final Direction dir )
{ {
assertInUnterminatedTransaction(); assertInUnterminatedTransaction();
return new ResourceIterable<Relationship>() return () -> {
{ Statement statement = actions.statement();
@Override try
public ResourceIterator<Relationship> iterator()
{ {
Statement statement = actions.statement(); RelationshipConversion result = new RelationshipConversion( actions );
try result.iterator = statement.readOperations().nodeGetRelationships( nodeId, dir );
{ result.statement = statement;
RelationshipConversion result = new RelationshipConversion( actions ); return result;
result.iterator = statement.readOperations().nodeGetRelationships( nodeId, dir ); }
result.statement = statement; catch ( EntityNotFoundException e )
return result; {
} statement.close();
catch ( EntityNotFoundException e ) throw new NotFoundException( format( "Node %d not found", nodeId ), e );
{ }
statement.close(); catch ( Throwable e )
throw new NotFoundException( format( "Node %d not found", nodeId ), e ); {
} statement.close();
catch ( Throwable e ) throw e;
{
statement.close();
throw e;
}
} }
}; };
} }
Expand Down Expand Up @@ -804,20 +797,15 @@ private int[] relTypeIds( RelationshipType[] types, Statement statement )


private Iterable<RelationshipType> map2relTypes( final Statement statement, PrimitiveIntIterator input ) private Iterable<RelationshipType> map2relTypes( final Statement statement, PrimitiveIntIterator input )
{ {
return asList( map( new IntFunction<RelationshipType>() return asList( map( id -> {
{ try
@Override
public RelationshipType apply( int id )
{ {
try return RelationshipType.withName( statement.readOperations().relationshipTypeGetName( id ) );
{ }
return RelationshipType.withName( statement.readOperations().relationshipTypeGetName( id ) ); catch ( RelationshipTypeIdNotFoundKernelException e )
} {
catch ( RelationshipTypeIdNotFoundKernelException e ) throw new ThisShouldNotHappenError( "Jake",
{ "Kernel API returned non-existent relationship type: " + id );
throw new ThisShouldNotHappenError( "Jake",
"Kernel API returned non-existent relationship type: " + id );
}
} }
}, input ) ); }, input ) );
} }
Expand Down
Expand Up @@ -22,6 +22,7 @@
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.function.IntFunction;
import java.util.function.IntPredicate; import java.util.function.IntPredicate;


import org.neo4j.collection.primitive.base.Empty; import org.neo4j.collection.primitive.base.Empty;
Expand Down Expand Up @@ -704,8 +705,7 @@ protected boolean fetchNext()
}; };
} }


public static <T> Iterator<T> map( final org.neo4j.function.IntFunction<T> mapFunction, public static <T> Iterator<T> map( final IntFunction<T> mapFunction, final PrimitiveIntIterator source )
final PrimitiveIntIterator source )
{ {
return new Iterator<T>() return new Iterator<T>()
{ {
Expand Down
Expand Up @@ -40,6 +40,7 @@
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.IntFunction;
import java.util.function.Predicate; import java.util.function.Predicate;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
Expand All @@ -56,8 +57,6 @@
import org.neo4j.cluster.member.ClusterMemberEvents; import org.neo4j.cluster.member.ClusterMemberEvents;
import org.neo4j.cluster.member.ClusterMemberListener; import org.neo4j.cluster.member.ClusterMemberListener;
import org.neo4j.cluster.protocol.election.NotElectableElectionCredentialsProvider; import org.neo4j.cluster.protocol.election.NotElectableElectionCredentialsProvider;
import org.neo4j.function.Function;
import org.neo4j.function.IntFunction;
import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.TransactionFailureException; import org.neo4j.graphdb.TransactionFailureException;
import org.neo4j.graphdb.config.Setting; import org.neo4j.graphdb.config.Setting;
Expand Down Expand Up @@ -141,14 +140,7 @@ public interface RepairKit


public static IntFunction<String> constant( final String value ) public static IntFunction<String> constant( final String value )
{ {
return new IntFunction<String>() return ignored -> value;
{
@Override
public String apply( int ignored )
{
return value;
}
};
} }


private final File root; private final File root;
Expand Down Expand Up @@ -186,15 +178,10 @@ private Map<String,IntFunction<String>> withDefaults( Map<String,IntFunction<Str
*/ */
public static Provider fromXml( final URI clustersXml ) public static Provider fromXml( final URI clustersXml )
{ {
return new Provider() return () -> {
{ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
@Override Document clustersXmlDoc = documentBuilder.parse( clustersXml.toURL().openStream() );
public Clusters clusters() throws Exception return new ClustersXMLSerializer( documentBuilder ).read( clustersXmlDoc );
{
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document clustersXmlDoc = documentBuilder.parse( clustersXml.toURL().openStream() );
return new ClustersXMLSerializer( documentBuilder ).read( clustersXmlDoc );
}
}; };
} }


Expand Down Expand Up @@ -264,14 +251,7 @@ public static Provider clusterWithAdditionalArbiters( int haMemberCount, int arb


public static Provider provided( final Clusters clusters ) public static Provider provided( final Clusters clusters )
{ {
return new Provider() return () -> clusters;
{
@Override
public Clusters clusters() throws Throwable
{
return clusters;
}
};
} }


/** /**
Expand Down Expand Up @@ -334,16 +314,9 @@ public static Predicate<ManagedCluster> masterAvailable( final HighlyAvailableGr
public boolean test( ManagedCluster cluster ) public boolean test( ManagedCluster cluster )
{ {
Predicate<HighlyAvailableGraphDatabase> filterMasterPredicate = Predicate<HighlyAvailableGraphDatabase> filterMasterPredicate =
new Predicate<HighlyAvailableGraphDatabase>() node -> !excludedNodes.contains( node ) &&
{ node.isAvailable( 0 ) &&
@Override node.isMaster();
public boolean test( HighlyAvailableGraphDatabase node )
{
return !excludedNodes.contains( node ) &&
node.isAvailable( 0 ) &&
node.isMaster();
}
};
return Iterables.filter( filterMasterPredicate, cluster.getAllMembers() ).iterator().hasNext(); return Iterables.filter( filterMasterPredicate, cluster.getAllMembers() ).iterator().hasNext();
} }


Expand Down Expand Up @@ -661,14 +634,7 @@ public Builder withRootDirectory( File root )
@Override @Override
public Builder withSeedDir( final File seedDir ) public Builder withSeedDir( final File seedDir )
{ {
return withStoreDirInitializer( new StoreDirInitializer() return withStoreDirInitializer( ( serverId, storeDir ) -> copyRecursively( seedDir, storeDir ) );
{
@Override
public void initializeStoreDir( int serverId, File storeDir ) throws IOException
{
copyRecursively( seedDir, storeDir );
}
} );
} }


@Override @Override
Expand Down Expand Up @@ -737,7 +703,7 @@ private static final class HighlyAvailableGraphDatabaseProxy


public HighlyAvailableGraphDatabaseProxy( final GraphDatabaseBuilder graphDatabaseBuilder ) public HighlyAvailableGraphDatabaseProxy( final GraphDatabaseBuilder graphDatabaseBuilder )
{ {
Callable<GraphDatabaseService> starter = () -> graphDatabaseBuilder.newGraphDatabase(); Callable<GraphDatabaseService> starter = graphDatabaseBuilder::newGraphDatabase;
executor = Executors.newFixedThreadPool( 1 ); executor = Executors.newFixedThreadPool( 1 );
untilThen = executor.submit( starter ); untilThen = executor.submit( starter );
} }
Expand Down Expand Up @@ -897,13 +863,8 @@ public void stop() throws Throwable
*/ */
public Iterable<HighlyAvailableGraphDatabase> getAllMembers() public Iterable<HighlyAvailableGraphDatabase> getAllMembers()
{ {
return Iterables.map( new Function<HighlyAvailableGraphDatabaseProxy,HighlyAvailableGraphDatabase>() return Iterables.map( from -> {
{ return from.get();
@Override
public HighlyAvailableGraphDatabase apply( HighlyAvailableGraphDatabaseProxy from )
{
return from.get();
}
}, members.values() ); }, members.values() );
} }


Expand Down
11 changes: 1 addition & 10 deletions enterprise/ha/src/test/java/org/neo4j/ha/BackupHaIT.java
Expand Up @@ -29,7 +29,6 @@
import java.util.List; import java.util.List;


import org.neo4j.backup.OnlineBackupSettings; import org.neo4j.backup.OnlineBackupSettings;
import org.neo4j.function.IntFunction;
import org.neo4j.kernel.configuration.Settings; import org.neo4j.kernel.configuration.Settings;
import org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster; import org.neo4j.kernel.impl.ha.ClusterManager.ManagedCluster;
import org.neo4j.test.DbRepresentation; import org.neo4j.test.DbRepresentation;
Expand All @@ -38,7 +37,6 @@


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;

import static org.neo4j.backup.BackupEmbeddedIT.createSomeData; import static org.neo4j.backup.BackupEmbeddedIT.createSomeData;
import static org.neo4j.backup.BackupEmbeddedIT.runBackupToolFromOtherJvmToGetExitCode; import static org.neo4j.backup.BackupEmbeddedIT.runBackupToolFromOtherJvmToGetExitCode;


Expand All @@ -47,14 +45,7 @@ public class BackupHaIT
@ClassRule @ClassRule
public static ClusterRule clusterRule = new ClusterRule( BackupHaIT.class ) public static ClusterRule clusterRule = new ClusterRule( BackupHaIT.class )
.withSharedSetting( OnlineBackupSettings.online_backup_enabled, Settings.TRUE ) .withSharedSetting( OnlineBackupSettings.online_backup_enabled, Settings.TRUE )
.withInstanceSetting( OnlineBackupSettings.online_backup_server, new IntFunction<String>() .withInstanceSetting( OnlineBackupSettings.online_backup_server, serverId -> (":" + (4444 + serverId)) );
{
@Override
public String apply( int serverId )
{
return (":" + (4444 + serverId));
}
} );
@Rule @Rule
public final SuppressOutput suppressOutput = SuppressOutput.suppressAll(); public final SuppressOutput suppressOutput = SuppressOutput.suppressAll();


Expand Down
18 changes: 5 additions & 13 deletions enterprise/ha/src/test/java/org/neo4j/ha/TestPullUpdates.java
Expand Up @@ -28,12 +28,12 @@
import java.net.URI; import java.net.URI;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.IntFunction;


import org.neo4j.cluster.ClusterSettings; import org.neo4j.cluster.ClusterSettings;
import org.neo4j.cluster.InstanceId; import org.neo4j.cluster.InstanceId;
import org.neo4j.cluster.client.ClusterClient; import org.neo4j.cluster.client.ClusterClient;
import org.neo4j.cluster.protocol.cluster.ClusterListener; import org.neo4j.cluster.protocol.cluster.ClusterListener;
import org.neo4j.function.IntFunction;
import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.NotFoundException; import org.neo4j.graphdb.NotFoundException;
Expand All @@ -51,11 +51,9 @@
import org.neo4j.shell.ShellSettings; import org.neo4j.shell.ShellSettings;
import org.neo4j.test.TargetDirectory; import org.neo4j.test.TargetDirectory;


import static java.lang.System.currentTimeMillis;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;

import static java.lang.System.currentTimeMillis;

import static org.neo4j.kernel.impl.ha.ClusterManager.allSeesAllAsAvailable; import static org.neo4j.kernel.impl.ha.ClusterManager.allSeesAllAsAvailable;
import static org.neo4j.kernel.impl.ha.ClusterManager.clusterOfSize; import static org.neo4j.kernel.impl.ha.ClusterManager.clusterOfSize;
import static org.neo4j.kernel.impl.ha.ClusterManager.masterAvailable; import static org.neo4j.kernel.impl.ha.ClusterManager.masterAvailable;
Expand Down Expand Up @@ -131,15 +129,9 @@ public void pullUpdatesShellAppPullsUpdates() throws Throwable
HaSettings.tx_push_factor.name(), "0" , HaSettings.tx_push_factor.name(), "0" ,
ShellSettings.remote_shell_enabled.name(), "true" ) ) ShellSettings.remote_shell_enabled.name(), "true" ) )
.withInstanceConfig( MapUtil.<String,IntFunction<String>>genericMap( .withInstanceConfig( MapUtil.<String,IntFunction<String>>genericMap(
ShellSettings.remote_shell_port.name(), new IntFunction<String>() ShellSettings.remote_shell_port.name(),
{ (IntFunction<String>) oneBasedServerId -> oneBasedServerId >= 1 && oneBasedServerId <= 2 ?
@Override "" + (SHELL_PORT + oneBasedServerId) : null ) ).build();
public String apply( int oneBasedServerId )
{
return oneBasedServerId >= 1 && oneBasedServerId <= 2 ?
"" + (SHELL_PORT + oneBasedServerId) : null;
}
} ) ).build();
clusterManager.start(); clusterManager.start();
cluster = clusterManager.getDefaultCluster(); cluster = clusterManager.getDefaultCluster();


Expand Down

0 comments on commit cbeed80

Please sign in to comment.