Skip to content

Commit

Permalink
Merge pull request #9271 from MishaDemianenko/3.2-no-more-warnings-on…
Browse files Browse the repository at this point in the history
…-widnows

Close open channels can be cleaned up on windows without any warnings.
  • Loading branch information
MishaDemianenko committed May 21, 2017
2 parents e5ea526 + 4daec16 commit c3a5cbf
Show file tree
Hide file tree
Showing 59 changed files with 1,049 additions and 659 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
import org.neo4j.io.fs.DefaultFileSystemAbstraction;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.StoreLockException;
import org.neo4j.kernel.internal.StoreLocker;
import org.neo4j.kernel.internal.locker.GlobalStoreLocker;
import org.neo4j.kernel.internal.locker.StoreLocker;

import static java.lang.String.format;

Expand Down Expand Up @@ -65,7 +66,7 @@ public static Path canonicalPath( File file ) throws IllegalArgumentException
public static void checkLock( Path databaseDirectory ) throws CommandFailed
{
try ( FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
StoreLocker storeLocker = new StoreLocker( fileSystem, databaseDirectory.toFile() ) )
StoreLocker storeLocker = new GlobalStoreLocker( fileSystem, databaseDirectory.toFile() ) )
{
storeLocker.checkLock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,14 @@ public void init()
catch ( Throwable e )
{
currentStatus = changedStatus( instance, currentStatus, LifecycleStatus.NONE );
try
{
instance.shutdown();
}
catch ( Throwable se )
{
e.addSuppressed( se );
}
if ( e instanceof LifecycleException )
{
throw (LifecycleException) e;
Expand Down Expand Up @@ -437,6 +445,14 @@ public void start()
catch ( Throwable e )
{
currentStatus = changedStatus( instance, currentStatus, LifecycleStatus.STOPPED );
try
{
instance.stop();
}
catch ( Throwable se )
{
e.addSuppressed( se );
}
if ( e instanceof LifecycleException )
{
throw (LifecycleException) e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
import static org.junit.Assert.fail;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

/**
* Test LifeSupport lifecycle transitions
*/
public class LifeSupportTest
{
@Test
Expand Down Expand Up @@ -103,7 +101,7 @@ public void testFailingInit()
}
assertEquals( LifecycleStatus.SHUTDOWN, lifeSupport.getStatus() );
assertEquals( LifecycleStatus.SHUTDOWN, instance1.getStatus() );
assertEquals( LifecycleStatus.NONE, instance2.getStatus() );
assertEquals( LifecycleStatus.SHUTDOWN, instance2.getStatus() );
assertEquals( LifecycleStatus.NONE, instance3.getStatus() );
}

Expand Down Expand Up @@ -230,50 +228,6 @@ public void testFailingShutdown()
assertEquals( LifecycleStatus.SHUTDOWN, instance3.getStatus() );
}

@Test
public void testRestartOk()
throws LifecycleException
{
LifeSupport lifeSupport = newLifeSupport();

LifecycleMock instance1 = new LifecycleMock( null, null, null, null );
lifeSupport.add( instance1 );
LifecycleMock instance2 = new LifecycleMock( null, null, null, null );
lifeSupport.add( instance2 );
LifecycleMock instance3 = new LifecycleMock( null, null, null, null );
lifeSupport.add( instance3 );

lifeSupport.init();
assertEquals( LifecycleStatus.STOPPED, lifeSupport.getStatus() );
assertEquals( LifecycleStatus.STOPPED, instance1.getStatus() );
assertEquals( LifecycleStatus.STOPPED, instance2.getStatus() );
assertEquals( LifecycleStatus.STOPPED, instance3.getStatus() );

lifeSupport.start();
assertEquals( LifecycleStatus.STARTED, lifeSupport.getStatus() );
assertEquals( LifecycleStatus.STARTED, instance1.getStatus() );
assertEquals( LifecycleStatus.STARTED, instance2.getStatus() );
assertEquals( LifecycleStatus.STARTED, instance3.getStatus() );

lifeSupport.stop();
assertEquals( LifecycleStatus.STOPPED, lifeSupport.getStatus() );
assertEquals( LifecycleStatus.STOPPED, instance1.getStatus() );
assertEquals( LifecycleStatus.STOPPED, instance2.getStatus() );
assertEquals( LifecycleStatus.STOPPED, instance3.getStatus() );

lifeSupport.start();
assertEquals( LifecycleStatus.STARTED, lifeSupport.getStatus() );
assertEquals( LifecycleStatus.STARTED, instance1.getStatus() );
assertEquals( LifecycleStatus.STARTED, instance2.getStatus() );
assertEquals( LifecycleStatus.STARTED, instance3.getStatus() );

lifeSupport.shutdown();
assertEquals( LifecycleStatus.SHUTDOWN, lifeSupport.getStatus() );
assertEquals( LifecycleStatus.SHUTDOWN, instance1.getStatus() );
assertEquals( LifecycleStatus.SHUTDOWN, instance2.getStatus() );
assertEquals( LifecycleStatus.SHUTDOWN, instance3.getStatus() );
}

@Test
public void testAddInstanceWhenInitInitsInstance()
throws LifecycleException
Expand Down Expand Up @@ -504,6 +458,48 @@ public void testStopFailsShutdownFails() throws Throwable

}

@Test
public void tryToStopComponentOnStartFailure() throws Throwable
{
LifeSupport lifeSupport = newLifeSupport();
Lifecycle component = mock( Lifecycle.class );
doThrow( new RuntimeException( "Start exceptions" ) ).when( component ).start();
lifeSupport.add( component );

try
{
lifeSupport.start();
}
catch ( Exception e )
{
// expected start failure
}

assertEquals( LifecycleStatus.STOPPED, lifeSupport.getStatus() );
verify( component ).stop();
}

@Test
public void tryToShutdownComponentOnStartFailure() throws Throwable
{
LifeSupport lifeSupport = newLifeSupport();
Lifecycle component = mock( Lifecycle.class );
doThrow( new RuntimeException( "Init exceptions" ) ).when( component ).init();
lifeSupport.add( component );

try
{
lifeSupport.init();
}
catch ( Exception e )
{
// expected start failure
}

assertEquals( LifecycleStatus.SHUTDOWN, lifeSupport.getStatus() );
verify( component ).shutdown();
}

public class LifecycleMock implements Lifecycle
{
Throwable initThrowable;
Expand All @@ -513,15 +509,15 @@ public class LifecycleMock implements Lifecycle

List<LifecycleStatus> transitions;

public LifecycleMock( Throwable initThrowable, Throwable startThrowable, Throwable stopThrowable,
LifecycleMock( Throwable initThrowable, Throwable startThrowable, Throwable stopThrowable,
Throwable shutdownThrowable )
{
this.initThrowable = initThrowable;
this.startThrowable = startThrowable;
this.stopThrowable = stopThrowable;
this.shutdownThrowable = shutdownThrowable;

transitions = new LinkedList<LifecycleStatus>();
transitions = new LinkedList<>();
transitions.add( LifecycleStatus.NONE );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.neo4j.cypher;

import org.junit.After;
import org.junit.Rule;
import org.junit.Test;

Expand Down Expand Up @@ -52,6 +53,12 @@ protected void configure( GraphDatabaseBuilder builder )

private final ExecutorService executorService = Executors.newFixedThreadPool( 10 );

@After
public void tearDown()
{
executorService.shutdown();
}

@Test
public void shouldHandleConcurrentIndexCreationAndUsage() throws InterruptedException
{
Expand Down Expand Up @@ -88,7 +95,6 @@ private void executeInThread( final String query, Map<String,Object> params )
}
catch ( Exception e )
{
e.printStackTrace();
hasFailed.set( true );
}
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.neo4j.cypher;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -43,6 +44,7 @@
public class DeleteRelationshipStressIT
{
private final AtomicBoolean hasFailed = new AtomicBoolean( false );
private final ExecutorService executorService = Executors.newFixedThreadPool( 10 );

@Rule
public ImpermanentDatabaseRule db = new ImpermanentDatabaseRule();
Expand Down Expand Up @@ -72,7 +74,11 @@ public void setup()
}
}

private final ExecutorService executorService = Executors.newFixedThreadPool( 10 );
@After
public void tearDown()
{
executorService.shutdown();
}

@Test
public void shouldBeAbleToReturnRelsWhileDeletingRelationship() throws IOException, ExecutionException, InterruptedException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
package org.neo4j.cypher;

import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Result;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.spatial.CRS;
Expand All @@ -39,7 +39,8 @@
import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.procedure.Name;
import org.neo4j.procedure.Procedure;
import org.neo4j.test.TestGraphDatabaseFactory;
import org.neo4j.test.rule.DatabaseRule;
import org.neo4j.test.rule.ImpermanentDatabaseRule;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -48,11 +49,14 @@

public class GraphDatabaseServiceExecuteTest
{

@Rule
public final DatabaseRule graphDb = new ImpermanentDatabaseRule();

@Test
public void shouldExecuteCypher() throws Exception
{
// given
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
final long before;
final long after;
try ( Transaction tx = graphDb.beginTx() )
Expand All @@ -76,9 +80,6 @@ public void shouldExecuteCypher() throws Exception
@Test
public void shouldNotReturnInternalGeographicPointType() throws Exception
{
// given
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();

// when
Result execute = graphDb.execute( "RETURN point({longitude: 144.317718, latitude: -37.031738}) AS p" );

Expand All @@ -98,9 +99,6 @@ public void shouldNotReturnInternalGeographicPointType() throws Exception
@Test
public void shouldNotReturnInternalCartesianPointType() throws Exception
{
// given
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();

// when
Result execute = graphDb.execute( "RETURN point({x: 13.37, y: 13.37, crs:'cartesian'}) AS p" );

Expand All @@ -121,9 +119,6 @@ public void shouldNotReturnInternalCartesianPointType() throws Exception
@Test
public void shouldNotReturnInternalPointWhenInArray() throws Exception
{
// given
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();

// when
Result execute = graphDb.execute( "RETURN [point({longitude: 144.317718, latitude: -37.031738})] AS ps" );

Expand All @@ -136,9 +131,6 @@ public void shouldNotReturnInternalPointWhenInArray() throws Exception
@Test
public void shouldNotReturnInternalPointWhenInMap() throws Exception
{
// given
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();

// when
Result execute = graphDb.execute( "RETURN {p: point({longitude: 144.317718, latitude: -37.031738})} AS m" );

Expand All @@ -151,7 +143,6 @@ public void shouldNotReturnInternalPointWhenInMap() throws Exception
public void shouldBeAbleToUseResultingPointFromOneQueryAsParameterToNext() throws Exception
{
// given a point create by one cypher query
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
Result execute = graphDb.execute( "RETURN point({longitude: 144.317718, latitude: -37.031738}) AS p" );
Point point = (Point) execute.next().get( "p" );

Expand All @@ -169,7 +160,6 @@ public void shouldBeAbleToUseResultingPointFromOneQueryAsParameterToNext() throw
public void shouldBeAbleToUseExternalPointAsParameterToQuery() throws Exception
{
// given a point created from public interface
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
Point point = makeFakePoint( 144.317718, -37.031738, makeWGS84() );

// when passing as params to a distance function
Expand All @@ -186,7 +176,6 @@ public void shouldBeAbleToUseExternalPointAsParameterToQuery() throws Exception
public void shouldBeAbleToUseExternalGeometryAsParameterToQuery() throws Exception
{
// given a point created from public interface
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
Geometry geometry = makeFakePointAsGeometry( 144.317718, -37.031738, makeWGS84() );

// when passing as params to a distance function
Expand All @@ -203,7 +192,6 @@ public void shouldBeAbleToUseExternalGeometryAsParameterToQuery() throws Excepti
public void shouldBeAbleToUseExternalPointArrayAsParameterToQuery() throws Exception
{
// given a point created from public interface
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
Point point = makeFakePoint( 144.317718, -37.031738, makeWGS84() );
Point[] points = new Point[]{point, point};

Expand All @@ -221,7 +209,6 @@ public void shouldBeAbleToUseExternalPointArrayAsParameterToQuery() throws Excep
public void shouldBeAbleToUseResultsOfPointProcedureAsInputToDistanceFunction() throws Exception
{
// given procedure that produces a point
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
Procedures procedures =
((GraphDatabaseAPI) graphDb).getDependencyResolver().resolveDependency( Procedures.class );
procedures.registerProcedure( PointProcs.class );
Expand All @@ -241,7 +228,6 @@ public void shouldBeAbleToUseResultsOfPointProcedureAsInputToDistanceFunction()
public void shouldBeAbleToUseResultsOfPointGeometryProcedureAsInputToDistanceFunction() throws Exception
{
// given procedure that produces a point
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
Procedures procedures =
((GraphDatabaseAPI) graphDb).getDependencyResolver().resolveDependency( Procedures.class );
procedures.registerProcedure( PointProcs.class );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ class QueryExecutionMonitorTest extends CypherFunSuite with GraphIcing with Grap
var engine: ExecutionEngine = null

override protected def beforeEach(): Unit = {
super.beforeEach()
db = new GraphDatabaseCypherService(new TestGraphDatabaseFactory().newImpermanentDatabase())
monitor = mock[QueryExecutionMonitor]
val monitors = db.getDependencyResolver.resolveDependency(classOf[org.neo4j.kernel.monitoring.Monitors])
Expand All @@ -321,6 +320,8 @@ class QueryExecutionMonitorTest extends CypherFunSuite with GraphIcing with Grap

override protected def afterEach(): Unit = {
super.afterEach()
if (db != null) db.shutdown()
if (db != null) {
db.shutdown()
}
}
}

0 comments on commit c3a5cbf

Please sign in to comment.