Skip to content

Commit

Permalink
Add additional IT tests for new api methods.
Browse files Browse the repository at this point in the history
Cleanup.
  • Loading branch information
MishaDemianenko committed Sep 7, 2016
1 parent ef9d6d8 commit 8a1a071
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 31 deletions.
@@ -0,0 +1,96 @@
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.factory;


import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;

import java.util.HashMap;

import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.kernel.GraphDatabaseQueryService;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.security.AccessMode;
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class GraphDatabaseFacadeTest
{

private GraphDatabaseFacade.SPI spi = Mockito.mock( GraphDatabaseFacade.SPI.class, Mockito.RETURNS_DEEP_STUBS );
private GraphDatabaseFacade graphDatabaseFacade = new GraphDatabaseFacade();
private GraphDatabaseQueryService queryService;
private DependencyResolver dependencyResolver;

@Before
public void setUp()
{
queryService = mock( GraphDatabaseQueryService.class );
dependencyResolver = mock( DependencyResolver.class );
ThreadToStatementContextBridge contextBridge = mock( ThreadToStatementContextBridge.class );

when( spi.queryService() ).thenReturn( queryService );
when( queryService.getDependencyResolver() ).thenReturn( dependencyResolver );
when( dependencyResolver.resolveDependency( ThreadToStatementContextBridge.class ) ).thenReturn( contextBridge );

graphDatabaseFacade.init( spi );
}

@Test
public void beginTransactionWithCustomTimeout() throws Exception
{
graphDatabaseFacade.beginTx( 10L );

verify( spi ).beginTransaction( KernelTransaction.Type.explicit, AccessMode.Static.FULL, 10L );
}

@Test
public void beginTransaction()
{
graphDatabaseFacade.beginTx();

verify( spi ).beginTransaction( KernelTransaction.Type.explicit, AccessMode.Static.FULL );
}

@Test
public void executeQueryWithCustomTimeoutShouldStartTransactionWithRequestedTimeout()
{
graphDatabaseFacade.execute( "create (n)", 157L );
verify( spi ).beginTransaction( KernelTransaction.Type.implicit, AccessMode.Static.FULL, 157L );

graphDatabaseFacade.execute( "create (n)", new HashMap<>(), 247L );
verify( spi ).beginTransaction( KernelTransaction.Type.implicit, AccessMode.Static.FULL, 247L );
}

@Test
public void executeQueryStartDefaultTransaction()
{
graphDatabaseFacade.execute( "create (n)" );
graphDatabaseFacade.execute( "create (n)", new HashMap<>() );

verify( spi, times( 2 ) ).beginTransaction( KernelTransaction.Type.implicit, AccessMode.Static.FULL );
}
}
Expand Up @@ -201,7 +201,7 @@ public void start() throws ServerStartupException


transactionFacade = createTransactionalActions(); transactionFacade = createTransactionalActions();


cypherExecutor = new CypherExecutor( database, config, logProvider ); cypherExecutor = new CypherExecutor( database, logProvider );


configureWebServer(); configureWebServer();


Expand Down
Expand Up @@ -27,7 +27,6 @@
import org.neo4j.kernel.GraphDatabaseQueryService; import org.neo4j.kernel.GraphDatabaseQueryService;
import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.security.AccessMode; import org.neo4j.kernel.api.security.AccessMode;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
import org.neo4j.kernel.impl.coreapi.InternalTransaction; import org.neo4j.kernel.impl.coreapi.InternalTransaction;
import org.neo4j.kernel.impl.coreapi.PropertyContainerLocker; import org.neo4j.kernel.impl.coreapi.PropertyContainerLocker;
Expand All @@ -52,7 +51,7 @@ public class CypherExecutor extends LifecycleAdapter
private static final PropertyContainerLocker locker = new PropertyContainerLocker(); private static final PropertyContainerLocker locker = new PropertyContainerLocker();
private final Log log; private final Log log;


public CypherExecutor( Database database, Config config, LogProvider logProvider ) public CypherExecutor( Database database, LogProvider logProvider )
{ {
this.database = database; this.database = database;
log = logProvider.getLog( getClass() ); log = logProvider.getLog( getClass() );
Expand Down
Expand Up @@ -26,13 +26,10 @@


import org.neo4j.cypher.internal.javacompat.ExecutionEngine; import org.neo4j.cypher.internal.javacompat.ExecutionEngine;
import org.neo4j.graphdb.DependencyResolver; import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.kernel.GraphDatabaseQueryService; import org.neo4j.kernel.GraphDatabaseQueryService;
import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.Statement; import org.neo4j.kernel.api.Statement;
import org.neo4j.kernel.api.security.AccessMode; import org.neo4j.kernel.api.security.AccessMode;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
import org.neo4j.kernel.impl.coreapi.InternalTransaction; import org.neo4j.kernel.impl.coreapi.InternalTransaction;
import org.neo4j.kernel.impl.coreapi.TopLevelTransaction; import org.neo4j.kernel.impl.coreapi.TopLevelTransaction;
Expand Down Expand Up @@ -70,8 +67,7 @@ public void setUp()
@Test @Test
public void startDefaultTransaction() throws Throwable public void startDefaultTransaction() throws Throwable
{ {
Config config = getConfiguredGuardConfig(); CypherExecutor cypherExecutor = new CypherExecutor( database, logProvider );
CypherExecutor cypherExecutor = new CypherExecutor( database, config, logProvider );
cypherExecutor.start(); cypherExecutor.start();


cypherExecutor.createSession( request ); cypherExecutor.createSession( request );
Expand All @@ -86,8 +82,7 @@ public void startTransactionWithCustomTimeout() throws Throwable
when( request.getHeader( CypherExecutor.MAX_EXECUTION_TIME_HEADER ) ) when( request.getHeader( CypherExecutor.MAX_EXECUTION_TIME_HEADER ) )
.thenReturn( String.valueOf( CUSTOM_TRANSACTION_TIMEOUT ) ); .thenReturn( String.valueOf( CUSTOM_TRANSACTION_TIMEOUT ) );


Config config = getConfiguredGuardConfig(); CypherExecutor cypherExecutor = new CypherExecutor( database, logProvider );
CypherExecutor cypherExecutor = new CypherExecutor( database, config, logProvider );
cypherExecutor.start(); cypherExecutor.start();


cypherExecutor.createSession( request ); cypherExecutor.createSession( request );
Expand All @@ -103,8 +98,7 @@ public void startDefaultTransactionWhenHeaderHasIncorrectValue() throws Throwabl
when( request.getHeader( CypherExecutor.MAX_EXECUTION_TIME_HEADER ) ) when( request.getHeader( CypherExecutor.MAX_EXECUTION_TIME_HEADER ) )
.thenReturn( "not a number" ); .thenReturn( "not a number" );


Config config = getConfiguredGuardConfig(); CypherExecutor cypherExecutor = new CypherExecutor( database, logProvider );
CypherExecutor cypherExecutor = new CypherExecutor( database, config, logProvider );
cypherExecutor.start(); cypherExecutor.start();


cypherExecutor.createSession( request ); cypherExecutor.createSession( request );
Expand All @@ -120,8 +114,7 @@ public void startDefaultTransactionIfTimeoutIsNegative() throws Throwable
when( request.getHeader( CypherExecutor.MAX_EXECUTION_TIME_HEADER ) ) when( request.getHeader( CypherExecutor.MAX_EXECUTION_TIME_HEADER ) )
.thenReturn( "-2" ); .thenReturn( "-2" );


Config config = getConfiguredGuardConfig(); CypherExecutor cypherExecutor = new CypherExecutor( database, logProvider );
CypherExecutor cypherExecutor = new CypherExecutor( database, config, logProvider );
cypherExecutor.start(); cypherExecutor.start();


cypherExecutor.createSession( request ); cypherExecutor.createSession( request );
Expand All @@ -136,7 +129,7 @@ public void startDefaultTransactionIfExecutionGuardDisabled() throws Throwable
when( request.getHeader( CypherExecutor.MAX_EXECUTION_TIME_HEADER ) ) when( request.getHeader( CypherExecutor.MAX_EXECUTION_TIME_HEADER ) )
.thenReturn( String.valueOf( CUSTOM_TRANSACTION_TIMEOUT ) ); .thenReturn( String.valueOf( CUSTOM_TRANSACTION_TIMEOUT ) );


CypherExecutor cypherExecutor = new CypherExecutor( database, Config.defaults(), logProvider ); CypherExecutor cypherExecutor = new CypherExecutor( database, logProvider );
cypherExecutor.start(); cypherExecutor.start();


cypherExecutor.createSession( request ); cypherExecutor.createSession( request );
Expand All @@ -150,11 +143,6 @@ private void initLogProvider()
logProvider = new AssertableLogProvider( true ); logProvider = new AssertableLogProvider( true );
} }


private Config getConfiguredGuardConfig()
{
return new Config( MapUtil.stringMap( GraphDatabaseSettings.transaction_timeout.name(), "60s" ) );
}

private void setUpMocks() private void setUpMocks()
{ {
database = mock( Database.class ); database = mock( Database.class );
Expand Down
Expand Up @@ -24,7 +24,6 @@
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;


import org.neo4j.helpers.collection.Pair; import org.neo4j.helpers.collection.Pair;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacade; import org.neo4j.kernel.impl.factory.GraphDatabaseFacade;
import org.neo4j.logging.NullLogProvider; import org.neo4j.logging.NullLogProvider;
import org.neo4j.server.database.CypherExecutor; import org.neo4j.server.database.CypherExecutor;
Expand All @@ -44,7 +43,7 @@ public void shouldReturnASingleNode() throws Throwable
{ {
GraphDatabaseFacade graphdb = (GraphDatabaseFacade) new TestGraphDatabaseFactory().newImpermanentDatabase(); GraphDatabaseFacade graphdb = (GraphDatabaseFacade) new TestGraphDatabaseFactory().newImpermanentDatabase();
Database database = new WrappedDatabase( graphdb ); Database database = new WrappedDatabase( graphdb );
CypherExecutor executor = new CypherExecutor( database, Config.defaults(), NullLogProvider.getInstance() ); CypherExecutor executor = new CypherExecutor( database, NullLogProvider.getInstance() );
executor.start(); executor.start();
try try
{ {
Expand Down

0 comments on commit 8a1a071

Please sign in to comment.