Skip to content

Commit

Permalink
Allow most modules to be compiled with java 9
Browse files Browse the repository at this point in the history
Compilations is not possible so far for
procedure-compiler modules because of dependencies that rely on tools.jar
and all scala modules. All other modules are compilable.
Introduce java 9 profile with disabled cypher, java.xml.bind and corba dependency
Switch to asm 6 and update some mockito tests. See mockito issue #357 for details
  • Loading branch information
MishaDemianenko committed Nov 17, 2017
1 parent 9a93b55 commit b55fe4d
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 37 deletions.
Expand Up @@ -57,7 +57,7 @@ static UTF8Encoder fastestAvailableEncoder()
.getConstructor()
.newInstance();
}
catch ( Exception e )
catch ( Throwable e )
{
return new VanillaUTF8Encoder();
}
Expand Down
Expand Up @@ -19,6 +19,7 @@
*/
package org.neo4j.bolt.v1.transport.integration;

import org.hamcrest.CoreMatchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -27,6 +28,7 @@
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -158,20 +160,20 @@ private void createAndRollback( TransportConnection client ) throws Exception
{
client.send( createAndRollback );
assertThat( client, eventuallyReceives(
msgSuccess( allOf( hasEntry( is( "fields" ), equalTo( emptyList() ) ),
msgSuccess( CoreMatchers.<Map<? extends String,?>>allOf( hasEntry( is( "fields" ), equalTo( emptyList() ) ),
hasKey( "result_available_after" ) ) ),
msgSuccess(),
msgSuccess( allOf( hasEntry( is( "fields" ), equalTo( emptyList() ) ),
msgSuccess( CoreMatchers.<Map<? extends String,?>>allOf( hasEntry( is( "fields" ), equalTo( emptyList() ) ),
hasKey( "result_available_after" ) ) ),
msgSuccess(),
msgSuccess( allOf( hasEntry( is( "fields" ), equalTo( emptyList() ) ),
msgSuccess( CoreMatchers.<Map<? extends String,?>>allOf( hasEntry( is( "fields" ), equalTo( emptyList() ) ),
hasKey( "result_available_after" ) ) ),
msgSuccess() ) );

// Verify no visible data
client.send( matchAll );
assertThat( client, eventuallyReceives(
msgSuccess(allOf( hasEntry( is( "fields" ), equalTo( singletonList( "n" ) ) ),
msgSuccess(CoreMatchers.<Map<? extends String,?>>allOf( hasEntry( is( "fields" ), equalTo( singletonList( "n" ) ) ),
hasKey( "result_available_after" ) ) ),
msgSuccess() ) );

Expand Down
Expand Up @@ -19,6 +19,7 @@
*/
package org.neo4j.bolt.v1.transport.integration;

import org.apache.commons.lang3.SystemUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -70,8 +71,9 @@ public static Collection<Object[]> transports()
new IOException( "Failed to connect to the server within 10 seconds" )
},
new Object[]{
(Factory<TransportConnection>) SecureSocketConnection::new,
new IOException( "Remote host closed connection during handshake" )
(Factory<TransportConnection>) SecureSocketConnection::new, new IOException(
SystemUtils.IS_JAVA_9 ? "Remote host terminated the handshake"
: "Remote host closed connection during handshake" )

} );
}
Expand Down
Expand Up @@ -19,6 +19,7 @@
*/
package org.neo4j.bolt.v1.transport.integration;

import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
Expand All @@ -29,6 +30,7 @@

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.neo4j.bolt.v1.transport.socket.client.SecureSocketConnection;
import org.neo4j.bolt.v1.transport.socket.client.SecureWebSocketConnection;
Expand Down Expand Up @@ -143,13 +145,12 @@ public void shouldRunSimpleStatement() throws Throwable
assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
assertThat( client, eventuallyReceives(
msgSuccess(),
msgSuccess(
allOf( hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ),
hasKey( "result_available_after" ) ) ),
msgSuccess( CoreMatchers.<Map<? extends String,?>>allOf( hasEntry( is( "fields" ),
equalTo( asList( "a", "a_squared" ) ) ), hasKey( "result_available_after" ) ) ),
msgRecord( eqRecord( equalTo( longValue( 1L ) ), equalTo( longValue( 1L ) ) ) ),
msgRecord( eqRecord( equalTo( longValue( 2L ) ), equalTo( longValue( 4L ) ) ) ),
msgRecord( eqRecord( equalTo( longValue( 3L ) ), equalTo( longValue( 9L ) ) ) ),
msgSuccess( allOf( hasEntry( is( "type" ), equalTo( "r" ) ),
msgSuccess( CoreMatchers.<Map<? extends String,?>>allOf( hasEntry( is( "type" ), equalTo( "r" ) ),
hasKey( "result_consumed_after" ) ) ) ) );
}

Expand All @@ -169,9 +170,9 @@ public void shouldRespondWithMetadataToDiscardAll() throws Throwable
assertThat( client, eventuallyReceives(
msgSuccess(),
msgSuccess(
allOf( hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ),
CoreMatchers.<Map<? extends String,?>>allOf( hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ),
hasKey( "result_available_after" ) ) ),
msgSuccess( allOf( hasEntry( is( "type" ), equalTo( "r" ) ),
msgSuccess( CoreMatchers.<Map<? extends String,?>>allOf( hasEntry( is( "type" ), equalTo( "r" ) ),
hasKey( "result_consumed_after" ) ) ) ) );
}

Expand Down Expand Up @@ -219,7 +220,7 @@ public void shouldRunProcedure() throws Throwable
assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
assertThat( client, eventuallyReceives(
msgSuccess(),
msgSuccess( allOf( hasEntry( is( "fields" ), equalTo( singletonList( "age" ) ) ),
msgSuccess( CoreMatchers.<Map<? extends String,?>>allOf( hasEntry( is( "fields" ), equalTo( singletonList( "age" ) ) ),
hasKey( "result_available_after" ) ) ),
msgRecord( eqRecord( equalTo( longValue( 2L ) ) ) ),
msgSuccess() ) );
Expand All @@ -231,7 +232,7 @@ public void shouldRunProcedure() throws Throwable

// Then
assertThat( client, eventuallyReceives(
msgSuccess( allOf( hasEntry( is( "fields" ), equalTo( singletonList( "label" ) ) ),
msgSuccess( CoreMatchers.<Map<? extends String,?>>allOf( hasEntry( is( "fields" ), equalTo( singletonList( "label" ) ) ),
hasKey( "result_available_after" ) ) ),
msgRecord( eqRecord( Matchers.equalTo( stringValue( "Test" ) ) ) ),
msgSuccess()
Expand All @@ -253,7 +254,7 @@ public void shouldHandleDeletedNodes() throws Throwable
assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
assertThat( client, eventuallyReceives(
msgSuccess(),
msgSuccess( allOf( hasEntry( is( "fields" ), equalTo( singletonList( "n" ) ) ),
msgSuccess( CoreMatchers.<Map<? extends String,?>>allOf( hasEntry( is( "fields" ), equalTo( singletonList( "n" ) ) ),
hasKey( "result_available_after" ) ) ) ) );

//
Expand Down Expand Up @@ -284,7 +285,7 @@ public void shouldHandleDeletedRelationships() throws Throwable
assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
assertThat( client, eventuallyReceives(
msgSuccess(),
msgSuccess( allOf( hasEntry( is( "fields" ), equalTo( singletonList( "r" ) ) ),
msgSuccess( CoreMatchers.<Map<? extends String,?>>allOf( hasEntry( is( "fields" ), equalTo( singletonList( "r" ) ) ),
hasKey( "result_available_after" ) ) ) ) );

//
Expand Down Expand Up @@ -328,7 +329,7 @@ public void shouldNotLeakStatsToNextStatement() throws Throwable
assertThat( client, eventuallyReceives(
msgSuccess(),
msgRecord( eqRecord( equalTo( longValue( 1L ) ) ) ),
msgSuccess( allOf( hasEntry( is( "type" ), equalTo( "r" ) ),
msgSuccess( CoreMatchers.<Map<? extends String,?>>allOf( hasEntry( is( "type" ), equalTo( "r" ) ),
hasKey( "result_consumed_after" ) ) ) ) );
}

Expand Down Expand Up @@ -374,7 +375,7 @@ public void shouldFailNicelyOnPoints() throws Throwable
assertThat( client, eventuallyReceives( new byte[]{0, 0, 0, 1} ) );
assertThat( client, eventuallyReceives(
msgSuccess(),
msgSuccess( allOf( hasEntry( is( "fields" ), equalTo( singletonList( "p" ) ) ),
msgSuccess( CoreMatchers.<Map<? extends String,?>>allOf( hasEntry( is( "fields" ), equalTo( singletonList( "p" ) ) ),
hasKey( "result_available_after" ) ) ),
msgRecord( eqRecord( equalTo( NO_VALUE ) ) ),
msgFailure( Status.Request.Invalid, "Point is not yet supported as a return type in Bolt" ) ) );
Expand Down
1 change: 1 addition & 0 deletions community/cypher/pom.xml
Expand Up @@ -32,6 +32,7 @@
<profile>
<id>include-cypher</id>
<activation>
<jdk>!9</jdk>
<property>
<name>!skipCypher</name>
</property>
Expand Down
5 changes: 3 additions & 2 deletions community/kernel/src/main/java/org/neo4j/helpers/Format.java
Expand Up @@ -22,6 +22,7 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -110,11 +111,11 @@ public static String bytes( long bytes )
{
if ( size < KB )
{
return String.format( "%.2f %s", Double.valueOf( size ), suffix );
return String.format( Locale.ROOT, "%.2f %s", Double.valueOf( size ), suffix );
}
size /= KB;
}
return String.format( "%.2f TB", Double.valueOf( size ) );
return String.format( Locale.ROOT, "%.2f TB", Double.valueOf( size ) );
}

public static String duration( long durationMillis )
Expand Down
Expand Up @@ -91,10 +91,18 @@ public void setup()
StoreReadLayer storeReadLayer = mock( StoreReadLayer.class );
when( storeReadLayer.indexesGetAll() ).thenAnswer( x -> indexes.iterator() );
when( storeReadLayer.indexesGetForLabel(anyInt() ) )
.thenAnswer( x -> filter( hasLabel( x.getArgument( 0 ) ), indexes.iterator() ) );
.thenAnswer( x ->
{
Integer argument = x.getArgument( 0 );
return filter( hasLabel( argument ), indexes.iterator() );
} );

when( storeReadLayer.indexesGetRelatedToProperty( anyInt() ) )
.thenAnswer( x -> filter( hasProperty( x.getArgument( 0 ) ), indexes.iterator() ) );
.thenAnswer( x ->
{
Integer argument = x.getArgument( 0 );
return filter( hasProperty( argument ), indexes.iterator() );
} );

PrimitiveIntSet labels = Primitive.intSet();
labels.add( labelId1 );
Expand Down
Expand Up @@ -189,7 +189,7 @@ private static boolean awaitParked( ThreadRepository.ThreadInfo thread, long tim
for ( long end = System.currentTimeMillis() + unit.toMillis( timeout ); System.currentTimeMillis() < end; )
{
StackTraceElement frame = thread.getStackTrace()[0];
if ( "park".equals( frame.getMethodName() ) && "sun.misc.Unsafe".equals( frame.getClassName() ) )
if ( "park".equals( frame.getMethodName() ) && frame.getClassName().endsWith( "Unsafe" ) )
{
if ( thread.getState().name().endsWith( "WAITING" ) )
{
Expand Down
Expand Up @@ -23,6 +23,7 @@

import java.io.File;
import java.net.URL;
import java.nio.file.Paths;

import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.graphdb.security.URLAccessValidationError;
Expand All @@ -32,6 +33,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;

public class FileURLAccessRuleTest
{
Expand Down Expand Up @@ -83,6 +85,7 @@ public void shouldThrowWhenFileAccessIsDisabled() throws Exception
@Test
public void shouldThrowWhenRelativePathIsOutsideImportDirectory() throws Exception
{
assumeFalse( Paths.get( "/" ).relativize( Paths.get( "/../baz.csv" ) ).toString().equals( "baz.csv" ) );
File importDir = new File( "/tmp/neo4jtest" ).getAbsoluteFile();
final Config config = Config.defaults( GraphDatabaseSettings.load_csv_file_url_root, importDir.toString() );
try
Expand Down
1 change: 1 addition & 0 deletions community/pom.xml
Expand Up @@ -85,6 +85,7 @@ the relevant Commercial Agreement.
<profile>
<id>include-cypher</id>
<activation>
<jdk>!9</jdk>
<property>
<name>!skipCypher</name>
</property>
Expand Down
Expand Up @@ -21,7 +21,7 @@

import java.util.Arrays;

import static javax.xml.bind.DatatypeConverter.printHexBinary;
import org.neo4j.string.HexString;

/**
* This is a concurrent data structure used to track
Expand Down Expand Up @@ -174,7 +174,7 @@ public String asHex()
(bit( i + 6 ) << 1) |
(bit( i + 7 )) ) ;
}
return printHexBinary( bits );
return HexString.encodeHexString( bits );
}

private int bit( int idx )
Expand Down
1 change: 0 additions & 1 deletion community/procedure-compiler/processor/pom.xml
Expand Up @@ -60,7 +60,6 @@
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<goals>
Expand Down
Expand Up @@ -29,6 +29,7 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.AdvertisedSocketAddress;
import org.neo4j.helpers.HostnamePort;
Expand All @@ -55,7 +56,7 @@ public class DiscoveryServiceTest
private AdvertisedSocketAddress boltAddress;
private URI dataUri;
private URI managementUri;
private final NeoServer neoServer = mock( NeoServer.class, Answers.RETURNS_DEEP_STUBS.get() );
private final NeoServer neoServer = mock( NeoServer.class, Answers.RETURNS_DEEP_STUBS );

@Before
public void setUp() throws URISyntaxException
Expand All @@ -68,7 +69,9 @@ public void setUp() throws URISyntaxException
// Setup NeoServer
ConnectorPortRegister portRegister = mock( ConnectorPortRegister.class );
when( portRegister.getLocalAddress( "bolt" ) ).thenReturn( new HostnamePort( "localhost", 7687 ) );
when( neoServer.getDatabase().getGraph().getDependencyResolver().resolveDependency( ConnectorPortRegister.class ) ).thenReturn( portRegister );
DependencyResolver dependencyResolver = mock( DependencyResolver.class );
when( neoServer.getDatabase().getGraph().getDependencyResolver() ).thenReturn( dependencyResolver );
when( dependencyResolver.resolveDependency( ConnectorPortRegister.class ) ).thenReturn( portRegister );
}

private Config mockConfig() throws URISyntaxException
Expand Down
Expand Up @@ -22,7 +22,6 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.omg.CORBA.SystemException;

import java.io.Serializable;
import java.rmi.RemoteException;
Expand Down Expand Up @@ -122,12 +121,12 @@ public void rollback_outside_of_transaction_fails() throws Exception
executeCommandExpectingException( "rollback", "Not in a transaction" );
}

private void assertWeAreNotInATransaction() throws SystemException
private void assertWeAreNotInATransaction()
{
assertTrue( "Expected to not be in a transaction", shellServer.getActiveTransactionCount() == 0 );
}

private void assertWeAreInATransaction() throws SystemException
private void assertWeAreInATransaction()
{

assertTrue( "Expected to be in a transaction", shellServer.getActiveTransactionCount() > 0 );
Expand Down
1 change: 1 addition & 0 deletions enterprise/cypher/pom.xml
Expand Up @@ -32,6 +32,7 @@
<profile>
<id>include-cypher</id>
<activation>
<jdk>!9</jdk>
<property>
<name>!skipCypher</name>
</property>
Expand Down
1 change: 1 addition & 0 deletions enterprise/pom.xml
Expand Up @@ -48,6 +48,7 @@
<profile>
<id>include-cypher</id>
<activation>
<jdk>!9</jdk>
<property>
<name>!skipCypher</name>
</property>
Expand Down
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.server.security.enterprise.auth.integration.bolt;

import org.hamcrest.BaseMatcher;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Description;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -365,7 +366,7 @@ private static Map<String, Long> collectConnectionResult( TransportConnection cl

// Then
assertThat( client, eventuallyReceives(
msgSuccess( allOf( hasEntry(is("fields"), equalTo(asList( "username", "connectionCount" ) )),
msgSuccess( CoreMatchers.<Map<? extends String,?>>allOf( hasEntry(is("fields"), equalTo(asList( "username", "connectionCount" ) )),
hasKey( "result_available_after" ) ) )
) );

Expand Down

0 comments on commit b55fe4d

Please sign in to comment.