diff --git a/community/kernel/src/main/java/org/neo4j/kernel/configuration/Config.java b/community/kernel/src/main/java/org/neo4j/kernel/configuration/Config.java index bc99dc547b851..3ccc6a7a34581 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/configuration/Config.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/configuration/Config.java @@ -80,9 +80,9 @@ public static Config defaults() return new Config(); } - public Config() + private Config() { - this( new HashMap<>(), Collections.>emptyList() ); + this( new HashMap<>() ); } public Config( Map inputParams ) diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/pagecache/ConfiguringPageCacheFactoryTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/pagecache/ConfiguringPageCacheFactoryTest.java index 4e589db78b92e..a965d98241c24 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/pagecache/ConfiguringPageCacheFactoryTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/pagecache/ConfiguringPageCacheFactoryTest.java @@ -19,13 +19,13 @@ */ package org.neo4j.kernel.impl.pagecache; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.io.pagecache.PageCache; import org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory; @@ -37,6 +37,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; + import static org.neo4j.graphdb.factory.GraphDatabaseSettings.mapped_memory_page_size; import static org.neo4j.graphdb.factory.GraphDatabaseSettings.pagecache_memory; import static org.neo4j.graphdb.factory.GraphDatabaseSettings.pagecache_swapper; @@ -62,8 +63,7 @@ public void shouldUseConfiguredPageSizeAndFitAsManyPagesAsItCan() throws Throwab // Given final int pageSize = 4096; final int maxPages = 60; - Config config = new Config(); - config.applyChanges( stringMap( + Config config = new Config( stringMap( mapped_memory_page_size.name(), "" + pageSize, pagecache_memory.name(), Integer.toString( pageSize * maxPages ) ) ); @@ -83,8 +83,7 @@ public void shouldUseConfiguredPageSizeAndFitAsManyPagesAsItCan() throws Throwab public void mustUseConfiguredPageSwapper() throws Exception { // Given - Config config = new Config(); - config.applyChanges( stringMap( + Config config = new Config( stringMap( pagecache_memory.name(), "8m", pagecache_swapper.name(), "test" ) ); @@ -102,8 +101,7 @@ public void mustUsePageSwapperCachePageSizeHintAsDefault() throws Exception // Given int cachePageSizeHint = 16 * 1024; PageSwapperFactoryForTesting.cachePageSizeHint.set( cachePageSizeHint ); - Config config = new Config(); - config.applyChanges( stringMap( + Config config = new Config( stringMap( GraphDatabaseSettings.pagecache_swapper.name(), "test" ) ); // When @@ -124,8 +122,7 @@ public void mustIgnoreExplicitlySpecifiedCachePageSizeIfPageSwapperHintIsStrict( int cachePageSizeHint = 16 * 1024; PageSwapperFactoryForTesting.cachePageSizeHint.set( cachePageSizeHint ); PageSwapperFactoryForTesting.cachePageSizeHintIsStrict.set( true ); - Config config = new Config(); - config.applyChanges( stringMap( + Config config = new Config( stringMap( GraphDatabaseSettings.mapped_memory_page_size.name(), "4096", GraphDatabaseSettings.pagecache_swapper.name(), "test" ) ); diff --git a/community/server/src/main/java/org/neo4j/server/configuration/BaseServerConfigLoader.java b/community/server/src/main/java/org/neo4j/server/configuration/BaseServerConfigLoader.java index 4c1950f60d163..4ae55a4e67213 100644 --- a/community/server/src/main/java/org/neo4j/server/configuration/BaseServerConfigLoader.java +++ b/community/server/src/main/java/org/neo4j/server/configuration/BaseServerConfigLoader.java @@ -33,6 +33,8 @@ import org.neo4j.shell.ShellSettings; import static java.util.Arrays.asList; +import static java.util.Collections.emptyMap; + import static org.neo4j.kernel.configuration.Settings.TRUE; public class BaseServerConfigLoader @@ -44,7 +46,7 @@ public Config loadConfig( File configFile, File legacyConfigFile, Log log, Pair< throw new IllegalArgumentException( "log cannot be null "); } - Config config = new Config(); + Config config = new Config( emptyMap(), asList( ServerSettings.class, GraphDatabaseSettings.class ) ); config.setLogger( log ); // For now, don't print warnings if this file is not specified @@ -58,8 +60,6 @@ public Config loadConfig( File configFile, File legacyConfigFile, Log log, Pair< overrideEmbeddedDefaults( config ); applyUserOverrides( config, configOverrides ); - config.registerSettingsClasses( asList( ServerSettings.class, GraphDatabaseSettings.class ) ); - return config; } diff --git a/community/server/src/test/java/org/neo4j/server/rest/web/RestfulGraphDatabaseTest.java b/community/server/src/test/java/org/neo4j/server/rest/web/RestfulGraphDatabaseTest.java index 768c76adc9ff7..8d09b5b37ef0a 100644 --- a/community/server/src/test/java/org/neo4j/server/rest/web/RestfulGraphDatabaseTest.java +++ b/community/server/src/test/java/org/neo4j/server/rest/web/RestfulGraphDatabaseTest.java @@ -68,7 +68,7 @@ import org.neo4j.test.server.EntityOutputFormat; import static java.lang.Long.parseLong; -import static java.util.Arrays.asList; +import static java.util.Collections.emptyMap; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.greaterThanOrEqualTo; @@ -104,15 +104,15 @@ public static void doBefore() throws IOException database = new WrappedDatabase( graph ); helper = new GraphDbHelper( database ); output = new EntityOutputFormat( new JsonFormat(), URI.create( BASE_URI ), null ); - LeaseManager leaseManager = new LeaseManager( new FakeClock() ); - - Config config = new Config(); - config.registerSettingsClasses( asList( ServerSettings.class, GraphDatabaseSettings.class )); - - service = new RestfulGraphDatabase( new JsonFormat(), output, - new DatabaseActions( leaseManager, true, database.getGraph() ), new ConfigAdapter( - config ) ); - service = new TransactionWrappingRestfulGraphDatabase( graph, service ); + service = new TransactionWrappingRestfulGraphDatabase( + graph, + new RestfulGraphDatabase( + new JsonFormat(), + output, + new DatabaseActions( new LeaseManager( new FakeClock() ), true, database.getGraph() ), + new ConfigAdapter( new Config( emptyMap(), ServerSettings.class, GraphDatabaseSettings.class ) ) + ) + ); } @Before @@ -347,7 +347,7 @@ public void shouldRespondWith400WhenTransferringIncompatibleJsonPayload() throws public void shouldRespondWith200ForGetNodeProperties() throws Exception { long nodeId = helper.createNode(); - Map properties = new HashMap(); + Map properties = new HashMap<>(); properties.put( "foo", "bar" ); helper.setNodeProperties( nodeId, properties ); Response response = service.getAllNodeProperties( nodeId ); @@ -360,7 +360,7 @@ public void shouldRespondWith200ForGetNodeProperties() throws Exception public void shouldGetPropertiesForGetNodeProperties() throws Exception { long nodeId = helper.createNode(); - Map properties = new HashMap(); + Map properties = new HashMap<>(); properties.put( "foo", "bar" ); properties.put( "number", 15 ); properties.put( "double", 15.7 ); @@ -591,7 +591,7 @@ public void shouldRespondWith400WhenTryingToCreateRelationshipWithUnsupportedPro public void shouldRespondWith204ForRemoveNodeProperties() { long nodeId = helper.createNode(); - Map properties = new HashMap(); + Map properties = new HashMap<>(); properties.put( "foo", "bar" ); properties.put( "number", 15 ); helper.setNodeProperties( nodeId, properties ); @@ -603,7 +603,7 @@ public void shouldRespondWith204ForRemoveNodeProperties() public void shouldBeAbleToRemoveNodeProperties() { long nodeId = helper.createNode(); - Map properties = new HashMap(); + Map properties = new HashMap<>(); properties.put( "foo", "bar" ); properties.put( "number", 15 ); helper.setNodeProperties( nodeId, properties ); @@ -625,7 +625,7 @@ public void shouldRespondWith404ForRemoveNodePropertiesForNonExistingNode() thro public void shouldBeAbleToRemoveNodeProperty() { long nodeId = helper.createNode(); - Map properties = new HashMap(); + Map properties = new HashMap<>(); properties.put( "foo", "bar" ); properties.put( "number", 15 ); helper.setNodeProperties( nodeId, properties ); @@ -638,7 +638,7 @@ public void shouldBeAbleToRemoveNodeProperty() public void shouldGet404WhenRemovingNonExistingProperty() throws Exception { long nodeId = helper.createNode(); - Map properties = new HashMap(); + Map properties = new HashMap<>(); properties.put( "foo", "bar" ); properties.put( "number", 15 ); helper.setNodeProperties( nodeId, properties ); @@ -678,7 +678,7 @@ public void shouldGet404WhenRetrievingRelationshipThatDoesNotExist() throws Exce public void shouldRespondWith200AndDataForGetRelationshipProperties() throws Exception { long relationshipId = helper.createRelationship( "knows" ); - Map properties = new HashMap(); + Map properties = new HashMap<>(); properties.put( "foo", "bar" ); helper.setRelationshipProperties( relationshipId, properties ); Response response = service.getAllRelationshipProperties( relationshipId ); @@ -696,7 +696,7 @@ public void shouldGet200WhenSuccessfullyRetrievedPropertyOnRelationship() { long relationshipId = helper.createRelationship( "knows" ); - Map properties = new HashMap(); + Map properties = new HashMap<>(); properties.put( "some-key", "some-value" ); helper.setRelationshipProperties( relationshipId, properties ); @@ -828,7 +828,7 @@ public void shouldRespondWith204AndSetCorrectDataWhenSettingRelationshipProperti String json = "{\"name\": \"Mattias\", \"age\": 30}"; Response response = service.setAllRelationshipProperties( relationshipId, json ); assertEquals( 204, response.getStatus() ); - Map setProperties = new HashMap(); + Map setProperties = new HashMap<>(); setProperties.put( "name", "Mattias" ); setProperties.put( "age", 30 ); assertEquals( setProperties, helper.getRelationshipProperties( relationshipId ) ); @@ -980,7 +980,7 @@ public void shouldRespondWithAvailableIndexNodeRoots() throws BadInputException Response response = service.getNodeIndexRoot(); assertEquals( 200, response.getStatus() ); - try ( Transaction transaction = graph.beginTx() ) + try ( Transaction ignored = graph.beginTx() ) { Map resultAsMap = output.getResultAsMap(); assertThat( resultAsMap.size(), is( numberOfAutoIndexesWhichCouldNotBeDeletedAtTestSetup + 1 ) ); @@ -1003,7 +1003,7 @@ public void shouldRespondWithAvailableIndexRelationshipRoots() throws BadInputEx Response response = service.getRelationshipIndexRoot(); assertEquals( 200, response.getStatus() ); - try ( Transaction transaction = graph.beginTx() ) + try ( Transaction ignored = graph.beginTx() ) { Map resultAsMap = output.getResultAsMap(); assertThat( resultAsMap.size(), is( 1 ) ); @@ -1057,7 +1057,7 @@ public void shouldBeAbleToIndexNode() URI nodeUri = (URI) response.getMetadata() .getFirst( "Location" ); - Map postBody = new HashMap(); + Map postBody = new HashMap<>(); postBody.put( "key", "mykey" ); postBody.put( "value", "my/key" ); postBody.put( "uri", nodeUri.toString() ); @@ -1100,7 +1100,7 @@ public void shouldNotBeAbleToIndexANodePropertyThatsTooLarge() @Test public void shouldBeAbleToIndexNodeUniquely() { - Map postBody = new HashMap(); + Map postBody = new HashMap<>(); postBody.put( "key", "mykey" ); postBody.put( "value", "my/key" ); @@ -1120,7 +1120,7 @@ public void shouldBeAbleToIndexNodeUniquely() public void shouldNotBeAbleToIndexNodeUniquelyWithBothUriAndPropertiesInPayload() throws Exception { URI node = (URI) service.createNode( null ).getMetadata().getFirst( "Location" ); - Map postBody = new HashMap(); + Map postBody = new HashMap<>(); postBody.put( "key", "mykey" ); postBody.put( "value", "my/key" ); postBody.put( "uri", node.toString() ); @@ -1137,7 +1137,7 @@ public void uniquelyIndexedNodeGetsTheSpecifiedKeyAndValueAsPropertiesIfNoProper { final String key = "somekey", value = "somevalue"; - Map postBody = new HashMap(); + Map postBody = new HashMap<>(); postBody.put( "key", key ); postBody.put( "value", value ); @@ -1158,10 +1158,10 @@ public void specifiedPropertiesOverrideKeyAndValueForUniquelyIndexedNodes() thro { final String key = "a_key", value = "a value"; - Map postBody = new HashMap(); + Map postBody = new HashMap<>(); postBody.put( "key", key ); postBody.put( "value", value ); - Map properties = new HashMap(); + Map properties = new HashMap<>(); properties.put( "name", "Jürgen" ); properties.put( "age", "42" ); properties.put( "occupation", "crazy" ); @@ -1182,13 +1182,13 @@ public void shouldNotBeAbleToCreateAnIndexWithEmptyName() throws Exception { URI node = (URI) service.createNode( null ).getMetadata().getFirst( "Location" ); - Map createRel = new HashMap(); + Map createRel = new HashMap<>(); createRel.put( "to", node.toString() ); createRel.put( "type", "knows" ); URI rel = (URI) service.createRelationship( helper.createNode(), JsonHelper.createJsonFrom( createRel ) ).getMetadata().getFirst( "Location" ); - Map indexPostBody = new HashMap(); + Map indexPostBody = new HashMap<>(); indexPostBody.put( "key", "mykey" ); indexPostBody.put( "value", "myvalue" ); @@ -1200,7 +1200,7 @@ public void shouldNotBeAbleToCreateAnIndexWithEmptyName() throws Exception response = service.addToRelationshipIndex( "", "", "", JsonHelper.createJsonFrom( indexPostBody ) ); assertEquals( "http bad request when trying to create an index with empty name", 400, response.getStatus() ); - Map basicIndexCreation = new HashMap(); + Map basicIndexCreation = new HashMap<>(); basicIndexCreation.put( "name", "" ); response = service.jsonCreateNodeIndex( JsonHelper.createJsonFrom( basicIndexCreation ) ); @@ -1214,12 +1214,12 @@ public void shouldNotBeAbleToCreateAnIndexWithEmptyName() throws Exception public void shouldNotBeAbleToIndexNodeUniquelyWithRequiredParameterMissing() throws Exception { service.createNode( null ).getMetadata().getFirst( "Location" ); - Map body = new HashMap(); + Map body = new HashMap<>(); body.put( "key", "mykey" ); body.put( "value", "my/key" ); for ( String key : body.keySet() ) { - Map postBody = new HashMap( body ); + Map postBody = new HashMap<>( body ); postBody.remove( key ); Response response = service.addToNodeIndex( "unique-nodes", "", "", JsonHelper.createJsonFrom( postBody ) ); @@ -1233,7 +1233,7 @@ public void shouldBeAbleToIndexRelationshipUniquely() throws Exception { URI start = (URI) service.createNode( null ).getMetadata().getFirst( "Location" ); URI end = (URI) service.createNode( null ).getMetadata().getFirst( "Location" ); - Map postBody = new HashMap(); + Map postBody = new HashMap<>(); postBody.put( "key", "mykey" ); postBody.put( "value", "my/key" ); postBody.put( "start", start.toString() ); @@ -1260,7 +1260,7 @@ public void uniquelyIndexedRelationshipGetsTheSpecifiedKeyAndValueAsPropertiesIf URI start = (URI) service.createNode( null ).getMetadata().getFirst( "Location" ); URI end = (URI) service.createNode( null ).getMetadata().getFirst( "Location" ); - Map postBody = new HashMap(); + Map postBody = new HashMap<>(); postBody.put( "key", key ); postBody.put( "value", value ); postBody.put( "start", start.toString() ); @@ -1286,13 +1286,13 @@ public void specifiedPropertiesOverrideKeyAndValueForUniquelyIndexedRelationship URI start = (URI) service.createNode( null ).getMetadata().getFirst( "Location" ); URI end = (URI) service.createNode( null ).getMetadata().getFirst( "Location" ); - Map postBody = new HashMap(); + Map postBody = new HashMap<>(); postBody.put( "key", key ); postBody.put( "value", value ); postBody.put( "start", start.toString() ); postBody.put( "end", end.toString() ); postBody.put( "type", "knows" ); - Map properties = new HashMap(); + Map properties = new HashMap<>(); properties.put( "name", "Jürgen" ); properties.put( "age", "42" ); properties.put( "occupation", "crazy" ); @@ -1317,14 +1317,14 @@ public void shouldNotBeAbleToIndexRelationshipUniquelyWithBothUriAndCreationalDa URI rel = (URI) service.createRelationship( parseLong( path.substring( path.lastIndexOf( '/' ) + 1 ) ), "{\"to\":\"" + end + "\",\"type\":\"knows\"}" ).getMetadata() .getFirst( "Location" ); - Map unwanted = new HashMap(); + Map unwanted = new HashMap<>(); unwanted.put( "properties", new HashMap() ); unwanted.put( "start", start.toString() ); unwanted.put( "end", end.toString() ); unwanted.put( "type", "friend" ); for ( Map.Entry bad : unwanted.entrySet() ) { - Map postBody = new HashMap(); + Map postBody = new HashMap<>(); postBody.put( "key", "mykey" ); postBody.put( "value", "my/key" ); postBody.put( "uri", rel.toString() ); @@ -1341,7 +1341,7 @@ public void shouldNotBeAbleToIndexRelationshipUniquelyWithRequiredParameterMissi { URI start = (URI) service.createNode( null ).getMetadata().getFirst( "Location" ); URI end = (URI) service.createNode( null ).getMetadata().getFirst( "Location" ); - Map body = new HashMap(); + Map body = new HashMap<>(); body.put( "key", "mykey" ); body.put( "value", "my/key" ); body.put( "start", start.toString() ); @@ -1349,7 +1349,7 @@ public void shouldNotBeAbleToIndexRelationshipUniquelyWithRequiredParameterMissi body.put( "type", "knows" ); for ( String key : body.keySet() ) { - Map postBody = new HashMap( body ); + Map postBody = new HashMap<>( body ); postBody.remove( key ); Response response = service.addToRelationshipIndex( "unique-relationships", "", "", JsonHelper.createJsonFrom( postBody ) ); @@ -1730,7 +1730,7 @@ public void shouldGet200WhenNoHitsReturnedFromTraverse() { long startNode = helper.createNode(); - try ( Transaction transaction = graph.beginTx() ) + try ( Transaction ignored = graph.beginTx() ) { Response response = service.traverse( startNode, TraverserReturnType.node, "" ); assertEquals( Status.OK.getStatusCode(), response.getStatus() ); @@ -1838,10 +1838,10 @@ public void shouldBeAbleToFindSinglePathBetweenTwoNodes() throws Exception Response response = service.singlePath( n1, payload ); assertThat( response.getStatus(), is( 200 ) ); - try ( Transaction transaction = graph.beginTx() ) + try ( Transaction ignored = graph.beginTx() ) { Map resultAsMap = output.getResultAsMap(); - assertThat( (Integer) resultAsMap.get( "length" ), is( 1 ) ); + assertThat( resultAsMap.get( "length" ), is( 1 ) ); } } @@ -1858,7 +1858,7 @@ public void shouldBeAbleToFindSinglePathBetweenTwoNodesEvenWhenAskingForAllPaths Response response = service.allPaths( n1, payload ); assertThat( response.getStatus(), is( 200 ) ); - try ( Transaction transaction = graph.beginTx() ) + try ( Transaction ignored = graph.beginTx() ) { List resultAsList = output.getResultAsList(); assertThat( resultAsList.size(), is( 1 ) ); @@ -1961,7 +1961,7 @@ public void nodeAutoindexingSupposedToWork() throws JsonParseException service.createNode( "{\"myAutoIndexedProperty\" : \"value\"}" ); - try ( Transaction transaction = graph.beginTx() ) + try ( Transaction ignored = graph.beginTx() ) { IndexHits indexResult = database.getGraph().index().getNodeAutoIndexer().getAutoIndex().get( "myAutoIndexedProperty", "value" );