Skip to content

Commit

Permalink
Add config to enable/disable deferred locks
Browse files Browse the repository at this point in the history
Also simplified StatementLocks creation in KTI - now it only requires
StatementLocksFactory and does not require Locks.
  • Loading branch information
lutovich committed Jul 28, 2016
1 parent f8b91fa commit 9a3e987
Show file tree
Hide file tree
Showing 15 changed files with 326 additions and 41 deletions.
Expand Up @@ -99,7 +99,6 @@
import org.neo4j.kernel.impl.index.IndexConfigStore; import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.kernel.impl.index.LegacyIndexStore; import org.neo4j.kernel.impl.index.LegacyIndexStore;
import org.neo4j.kernel.impl.locking.LockService; import org.neo4j.kernel.impl.locking.LockService;
import org.neo4j.kernel.impl.locking.Locks;
import org.neo4j.kernel.impl.locking.ReentrantLockService; import org.neo4j.kernel.impl.locking.ReentrantLockService;
import org.neo4j.kernel.impl.locking.StatementLocksFactory; import org.neo4j.kernel.impl.locking.StatementLocksFactory;
import org.neo4j.kernel.impl.store.MetaDataStore; import org.neo4j.kernel.impl.store.MetaDataStore;
Expand Down Expand Up @@ -359,7 +358,6 @@ boolean applicable( DiagnosticsPhase phase )
private final PropertyKeyTokenHolder propertyKeyTokenHolder; private final PropertyKeyTokenHolder propertyKeyTokenHolder;
private final LabelTokenHolder labelTokens; private final LabelTokenHolder labelTokens;
private final RelationshipTypeTokenHolder relationshipTypeTokens; private final RelationshipTypeTokenHolder relationshipTypeTokens;
private final Locks locks;
private final StatementLocksFactory statementLocksFactory; private final StatementLocksFactory statementLocksFactory;
private final SchemaWriteGuard schemaWriteGuard; private final SchemaWriteGuard schemaWriteGuard;
private final TransactionEventHandlers transactionEventHandlers; private final TransactionEventHandlers transactionEventHandlers;
Expand Down Expand Up @@ -425,7 +423,7 @@ public NeoStoreDataSource( File storeDir, Config config, StoreFactory sf, LogPro
JobScheduler scheduler, TokenNameLookup tokenNameLookup, DependencyResolver dependencyResolver, JobScheduler scheduler, TokenNameLookup tokenNameLookup, DependencyResolver dependencyResolver,
PropertyKeyTokenHolder propertyKeyTokens, LabelTokenHolder labelTokens, PropertyKeyTokenHolder propertyKeyTokens, LabelTokenHolder labelTokens,
RelationshipTypeTokenHolder relationshipTypeTokens, RelationshipTypeTokenHolder relationshipTypeTokens,
Locks locks, StatementLocksFactory statementLocksFactory, StatementLocksFactory statementLocksFactory,
SchemaWriteGuard schemaWriteGuard, TransactionEventHandlers transactionEventHandlers, SchemaWriteGuard schemaWriteGuard, TransactionEventHandlers transactionEventHandlers,
IndexingService.Monitor indexingServiceMonitor, FileSystemAbstraction fs, IndexingService.Monitor indexingServiceMonitor, FileSystemAbstraction fs,
StoreUpgrader storeMigrationProcess, TransactionMonitor transactionMonitor, StoreUpgrader storeMigrationProcess, TransactionMonitor transactionMonitor,
Expand All @@ -451,7 +449,6 @@ public NeoStoreDataSource( File storeDir, Config config, StoreFactory sf, LogPro
this.propertyKeyTokenHolder = propertyKeyTokens; this.propertyKeyTokenHolder = propertyKeyTokens;
this.labelTokens = labelTokens; this.labelTokens = labelTokens;
this.relationshipTypeTokens = relationshipTypeTokens; this.relationshipTypeTokens = relationshipTypeTokens;
this.locks = locks;
this.statementLocksFactory = statementLocksFactory; this.statementLocksFactory = statementLocksFactory;
this.schemaWriteGuard = schemaWriteGuard; this.schemaWriteGuard = schemaWriteGuard;
this.transactionEventHandlers = transactionEventHandlers; this.transactionEventHandlers = transactionEventHandlers;
Expand Down Expand Up @@ -1101,7 +1098,7 @@ public KernelAPI get()
final TransactionHooks hooks = new TransactionHooks(); final TransactionHooks hooks = new TransactionHooks();
final KernelTransactions kernelTransactions = final KernelTransactions kernelTransactions =
life.add( new KernelTransactions( neoStoreTxContextFactory, life.add( new KernelTransactions( neoStoreTxContextFactory,
neoStores, locks, statementLocksFactory, integrityValidator, constraintIndexCreator, neoStores, statementLocksFactory, integrityValidator, constraintIndexCreator,
indexingService, labelScanStore, statementOperations, updateableSchemaState, indexingService, labelScanStore, statementOperations, updateableSchemaState,
schemaWriteGuard, schemaIndexProviderMap, transactionHeaderInformationFactory, storeLayer, schemaWriteGuard, schemaIndexProviderMap, transactionHeaderInformationFactory, storeLayer,
transactionCommitProcess, indexConfigStore, legacyIndexProviderLookup, hooks, transactionCommitProcess, indexConfigStore, legacyIndexProviderLookup, hooks,
Expand Down
Expand Up @@ -70,7 +70,6 @@
import org.neo4j.kernel.impl.constraints.ConstraintSemantics; import org.neo4j.kernel.impl.constraints.ConstraintSemantics;
import org.neo4j.kernel.impl.index.IndexEntityType; import org.neo4j.kernel.impl.index.IndexEntityType;
import org.neo4j.kernel.impl.locking.LockGroup; import org.neo4j.kernel.impl.locking.LockGroup;
import org.neo4j.kernel.impl.locking.Locks;
import org.neo4j.kernel.impl.locking.StatementLocks; import org.neo4j.kernel.impl.locking.StatementLocks;
import org.neo4j.kernel.impl.locking.StatementLocksFactory; import org.neo4j.kernel.impl.locking.StatementLocksFactory;
import org.neo4j.kernel.impl.store.NeoStores; import org.neo4j.kernel.impl.store.NeoStores;
Expand Down Expand Up @@ -160,7 +159,6 @@ TransactionType upgradeToSchemaTransaction() throws InvalidTransactionTypeKernel
private final TransactionMonitor transactionMonitor; private final TransactionMonitor transactionMonitor;
private final StoreReadLayer storeLayer; private final StoreReadLayer storeLayer;
private final ProcedureCache procedureCache; private final ProcedureCache procedureCache;
private final Locks locks;
private final StatementLocksFactory statementLocksFactory; private final StatementLocksFactory statementLocksFactory;
private final Clock clock; private final Clock clock;
private final TransactionToRecordStateVisitor txStateToRecordStateVisitor = new TransactionToRecordStateVisitor(); private final TransactionToRecordStateVisitor txStateToRecordStateVisitor = new TransactionToRecordStateVisitor();
Expand Down Expand Up @@ -221,7 +219,6 @@ public KernelTransactionImplementation( StatementOperationParts operations,
Clock clock, Clock clock,
TransactionTracer tracer, TransactionTracer tracer,
ProcedureCache procedureCache, ProcedureCache procedureCache,
Locks locks,
StatementLocksFactory statementLocksFactory, StatementLocksFactory statementLocksFactory,
NeoStoreTransactionContext context, NeoStoreTransactionContext context,
boolean txTerminationAwareLocks ) boolean txTerminationAwareLocks )
Expand All @@ -241,7 +238,6 @@ public KernelTransactionImplementation( StatementOperationParts operations,
this.transactionMonitor = transactionMonitor; this.transactionMonitor = transactionMonitor;
this.storeLayer = storeLayer; this.storeLayer = storeLayer;
this.procedureCache = procedureCache; this.procedureCache = procedureCache;
this.locks = locks;
this.statementLocksFactory = statementLocksFactory; this.statementLocksFactory = statementLocksFactory;
this.context = context; this.context = context;
this.legacyIndexTransactionState = new CachingLegacyIndexTransactionState( legacyIndexTransactionState ); this.legacyIndexTransactionState = new CachingLegacyIndexTransactionState( legacyIndexTransactionState );
Expand All @@ -257,7 +253,7 @@ public KernelTransactionImplementation( StatementOperationParts operations,
*/ */
public KernelTransactionImplementation initialize( long lastCommittedTx, long lastTimeStamp ) public KernelTransactionImplementation initialize( long lastCommittedTx, long lastTimeStamp )
{ {
this.statementLocks = statementLocksFactory.newInstance( locks.newClient() ); this.statementLocks = statementLocksFactory.newInstance();
this.terminationReason = null; this.terminationReason = null;
this.closing = closed = failure = success = false; this.closing = closed = failure = success = false;
this.transactionType = TransactionType.ANY; this.transactionType = TransactionType.ANY;
Expand Down
Expand Up @@ -46,7 +46,6 @@
import org.neo4j.kernel.impl.api.store.StoreReadLayer; import org.neo4j.kernel.impl.api.store.StoreReadLayer;
import org.neo4j.kernel.impl.constraints.ConstraintSemantics; import org.neo4j.kernel.impl.constraints.ConstraintSemantics;
import org.neo4j.kernel.impl.index.IndexConfigStore; import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.kernel.impl.locking.Locks;
import org.neo4j.kernel.impl.locking.StatementLocksFactory; import org.neo4j.kernel.impl.locking.StatementLocksFactory;
import org.neo4j.kernel.impl.store.NeoStores; import org.neo4j.kernel.impl.store.NeoStores;
import org.neo4j.kernel.impl.store.TransactionId; import org.neo4j.kernel.impl.store.TransactionId;
Expand Down Expand Up @@ -83,7 +82,6 @@ public class KernelTransactions extends LifecycleAdapter
private final NeoStoreTransactionContextFactory neoStoreTransactionContextFactory; private final NeoStoreTransactionContextFactory neoStoreTransactionContextFactory;
private final NeoStores neoStores; private final NeoStores neoStores;
private final StatementLocksFactory statementLocksFactory; private final StatementLocksFactory statementLocksFactory;
private final Locks locks;
private final boolean txTerminationAwareLocks; private final boolean txTerminationAwareLocks;
private final IntegrityValidator integrityValidator; private final IntegrityValidator integrityValidator;
private final ConstraintIndexCreator constraintIndexCreator; private final ConstraintIndexCreator constraintIndexCreator;
Expand Down Expand Up @@ -125,7 +123,7 @@ public class KernelTransactions extends LifecycleAdapter


public KernelTransactions( NeoStoreTransactionContextFactory neoStoreTransactionContextFactory, public KernelTransactions( NeoStoreTransactionContextFactory neoStoreTransactionContextFactory,
NeoStores neoStores, NeoStores neoStores,
Locks locks, StatementLocksFactory statementLocksFactory, StatementLocksFactory statementLocksFactory,
IntegrityValidator integrityValidator, IntegrityValidator integrityValidator,
ConstraintIndexCreator constraintIndexCreator, ConstraintIndexCreator constraintIndexCreator,
IndexingService indexingService, LabelScanStore labelScanStore, IndexingService indexingService, LabelScanStore labelScanStore,
Expand All @@ -146,7 +144,6 @@ public KernelTransactions( NeoStoreTransactionContextFactory neoStoreTransaction
{ {
this.neoStoreTransactionContextFactory = neoStoreTransactionContextFactory; this.neoStoreTransactionContextFactory = neoStoreTransactionContextFactory;
this.neoStores = neoStores; this.neoStores = neoStores;
this.locks = locks;
this.statementLocksFactory = statementLocksFactory; this.statementLocksFactory = statementLocksFactory;
this.txTerminationAwareLocks = config.get( tx_termination_aware_locks ); this.txTerminationAwareLocks = config.get( tx_termination_aware_locks );
this.integrityValidator = integrityValidator; this.integrityValidator = integrityValidator;
Expand Down Expand Up @@ -189,7 +186,7 @@ public KernelTransactionImplementation newInstance()
labelScanStore, indexingService, updateableSchemaState, recordState, providerMap, labelScanStore, indexingService, updateableSchemaState, recordState, providerMap,
neoStores, hooks, constraintIndexCreator, transactionHeaderInformationFactory, neoStores, hooks, constraintIndexCreator, transactionHeaderInformationFactory,
transactionCommitProcess, transactionMonitor, storeLayer, legacyIndexTransactionState, transactionCommitProcess, transactionMonitor, storeLayer, legacyIndexTransactionState,
localTxPool, constraintSemantics, clock, tracers.transactionTracer, procedureCache, locks, localTxPool, constraintSemantics, clock, tracers.transactionTracer, procedureCache,
statementLocksFactory, context, txTerminationAwareLocks ); statementLocksFactory, context, txTerminationAwareLocks );


allTransactions.add( tx ); allTransactions.add( tx );
Expand Down
Expand Up @@ -66,6 +66,7 @@
import org.neo4j.kernel.impl.coreapi.RelationshipAutoIndexerImpl; import org.neo4j.kernel.impl.coreapi.RelationshipAutoIndexerImpl;
import org.neo4j.kernel.impl.coreapi.schema.SchemaImpl; import org.neo4j.kernel.impl.coreapi.schema.SchemaImpl;
import org.neo4j.kernel.impl.index.IndexConfigStore; import org.neo4j.kernel.impl.index.IndexConfigStore;
import org.neo4j.kernel.impl.locking.Locks;
import org.neo4j.kernel.impl.locking.SimpleStatementLocksFactory; import org.neo4j.kernel.impl.locking.SimpleStatementLocksFactory;
import org.neo4j.kernel.impl.locking.StatementLocksFactory; import org.neo4j.kernel.impl.locking.StatementLocksFactory;
import org.neo4j.kernel.impl.logging.LogService; import org.neo4j.kernel.impl.logging.LogService;
Expand All @@ -81,6 +82,7 @@
import org.neo4j.kernel.info.DiagnosticsManager; import org.neo4j.kernel.info.DiagnosticsManager;
import org.neo4j.kernel.lifecycle.LifeSupport; import org.neo4j.kernel.lifecycle.LifeSupport;
import org.neo4j.kernel.lifecycle.LifecycleAdapter; import org.neo4j.kernel.lifecycle.LifecycleAdapter;
import org.neo4j.logging.Log;


import static org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.Configuration.execution_guard_enabled; import static org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.Configuration.execution_guard_enabled;


Expand Down Expand Up @@ -113,12 +115,15 @@ public class DataSourceModule


public final Supplier<StoreId> storeId; public final Supplier<StoreId> storeId;


private final Log log;

public DataSourceModule( final GraphDatabaseFacadeFactory.Dependencies dependencies, public DataSourceModule( final GraphDatabaseFacadeFactory.Dependencies dependencies,
final PlatformModule platformModule, EditionModule editionModule ) final PlatformModule platformModule, EditionModule editionModule )
{ {
final org.neo4j.kernel.impl.util.Dependencies deps = platformModule.dependencies; final org.neo4j.kernel.impl.util.Dependencies deps = platformModule.dependencies;
Config config = platformModule.config; Config config = platformModule.config;
LogService logging = platformModule.logging; LogService logging = platformModule.logging;
this.log = logging.getInternalLog( DataSourceModule.class );
FileSystemAbstraction fileSystem = platformModule.fileSystem; FileSystemAbstraction fileSystem = platformModule.fileSystem;
DataSourceManager dataSourceManager = platformModule.dataSourceManager; DataSourceManager dataSourceManager = platformModule.dataSourceManager;
LifeSupport life = platformModule.life; LifeSupport life = platformModule.life;
Expand Down Expand Up @@ -195,14 +200,14 @@ public GraphDatabaseService getGraphDatabaseService()
KernelHealth kernelHealth = deps.satisfyDependency( new KernelHealth( kernelPanicEventGenerator, KernelHealth kernelHealth = deps.satisfyDependency( new KernelHealth( kernelPanicEventGenerator,
logging.getInternalLog( KernelHealth.class ) ) ); logging.getInternalLog( KernelHealth.class ) ) );


StatementLocksFactory statementLocksFactory = createStatementLocksFactory(); StatementLocksFactory locksFactory = createStatementLocksFactory( editionModule.lockManager, config, log );


neoStoreDataSource = deps.satisfyDependency( new NeoStoreDataSource( storeDir, config, neoStoreDataSource = deps.satisfyDependency( new NeoStoreDataSource( storeDir, config,
storeFactory, logging.getInternalLogProvider(), platformModule.jobScheduler, storeFactory, logging.getInternalLogProvider(), platformModule.jobScheduler,
new NonTransactionalTokenNameLookup( editionModule.labelTokenHolder, new NonTransactionalTokenNameLookup( editionModule.labelTokenHolder,
editionModule.relationshipTypeTokenHolder, editionModule.propertyKeyTokenHolder ), editionModule.relationshipTypeTokenHolder, editionModule.propertyKeyTokenHolder ),
deps, editionModule.propertyKeyTokenHolder, editionModule.labelTokenHolder, relationshipTypeTokenHolder, deps, editionModule.propertyKeyTokenHolder, editionModule.labelTokenHolder, relationshipTypeTokenHolder,
editionModule.lockManager, statementLocksFactory, schemaWriteGuard, transactionEventHandlers, locksFactory, schemaWriteGuard, transactionEventHandlers,
platformModule.monitors.newMonitor( IndexingService.Monitor.class ), fileSystem, platformModule.monitors.newMonitor( IndexingService.Monitor.class ), fileSystem,
storeMigrationProcess, platformModule.transactionMonitor, kernelHealth, storeMigrationProcess, platformModule.transactionMonitor, kernelHealth,
platformModule.monitors.newMonitor( PhysicalLogFile.Monitor.class ), platformModule.monitors.newMonitor( PhysicalLogFile.Monitor.class ),
Expand Down Expand Up @@ -384,21 +389,35 @@ public Relationship newRelationshipProxy( long id, long startNodeId, int typeId,
}; };
} }


private static StatementLocksFactory createStatementLocksFactory() private static StatementLocksFactory createStatementLocksFactory( Locks locks, Config config, Log log )
{ {
StatementLocksFactory statementLocksFactory;

String serviceName = StatementLocksFactory.class.getSimpleName();
List<StatementLocksFactory> factories = Iterables.toList( Service.load( StatementLocksFactory.class ) ); List<StatementLocksFactory> factories = Iterables.toList( Service.load( StatementLocksFactory.class ) );
if ( factories.isEmpty() ) if ( factories.isEmpty() )
{ {
return new SimpleStatementLocksFactory(); statementLocksFactory = new SimpleStatementLocksFactory( locks );

log.info( "No services implementing " + serviceName + " found. " +
"Using " + SimpleStatementLocksFactory.class.getSimpleName() );
} }
else if ( factories.size() == 1 ) else if ( factories.size() == 1 )
{ {
return factories.get( 0 ); statementLocksFactory = factories.get( 0 );

log.info( "Found single implementation of " + serviceName +
". Namely " + statementLocksFactory.getClass().getSimpleName() );
} }
else else
{ {
throw new IllegalStateException( "Found more than one implementation: " + factories ); throw new IllegalStateException(
"Found more than one implementation of " + serviceName + ": " + factories );
} }

statementLocksFactory.initialize( locks, config );

return statementLocksFactory;
} }


/** /**
Expand Down
Expand Up @@ -19,11 +19,36 @@
*/ */
package org.neo4j.kernel.impl.locking; package org.neo4j.kernel.impl.locking;


import org.neo4j.kernel.configuration.Config;

import static java.util.Objects.requireNonNull;

/**
* A {@link StatementLocksFactory} that creates {@link SimpleStatementLocks}.
*/
public class SimpleStatementLocksFactory implements StatementLocksFactory public class SimpleStatementLocksFactory implements StatementLocksFactory
{ {
private final Locks locks;

public SimpleStatementLocksFactory( Locks locks )
{
this.locks = requireNonNull( locks );
}

/**
* Inherited from the {@link StatementLocksFactory} interface but does nothing for this factory.
*
* @param locks will not be used.
* @param config will not be used.
*/
@Override
public void initialize( Locks locks, Config config )
{
}

@Override @Override
public StatementLocks newInstance( Locks.Client locksClient ) public StatementLocks newInstance()
{ {
return new SimpleStatementLocks( locksClient ); return new SimpleStatementLocks( locks.newClient() );
} }
} }
Expand Up @@ -19,7 +19,26 @@
*/ */
package org.neo4j.kernel.impl.locking; package org.neo4j.kernel.impl.locking;


import org.neo4j.kernel.configuration.Config;

/**
* Factory to create {@link StatementLocks} instances.
*/
public interface StatementLocksFactory public interface StatementLocksFactory
{ {
StatementLocks newInstance( Locks.Client locksClient ); /**
* Initialize this factory with the given {@code locks} and {@code config}. Callers should ensure this method
* is called once during database startup.
*
* @param locks the locks to use.
* @param config the database config that can contain settings interesting for factory implementations.
*/
void initialize( Locks locks, Config config );

/**
* Create new {@link StatementLocks} instance.
*
* @return new statement locks.
*/
StatementLocks newInstance();
} }
Expand Up @@ -65,7 +65,7 @@ null, mock( NeoStores.class ),
Clock.SYSTEM_CLOCK, Clock.SYSTEM_CLOCK,
TransactionTracer.NULL, TransactionTracer.NULL,
new ProcedureCache(), new ProcedureCache(),
new NoOpLocks(), new SimpleStatementLocksFactory(), new SimpleStatementLocksFactory( new NoOpLocks() ),
mock( NeoStoreTransactionContext.class ), mock( NeoStoreTransactionContext.class ),
false ); false );
} }
Expand Down
Expand Up @@ -635,7 +635,7 @@ private KernelTransactionImplementation newTransaction( boolean txTerminationAwa
return new KernelTransactionImplementation( null, null, null, null, null, recordState, null, neoStores, return new KernelTransactionImplementation( null, null, null, null, null, recordState, null, neoStores,
hooks, null, headerInformationFactory, commitProcess, hooks, null, headerInformationFactory, commitProcess,
transactionMonitor, storeReadLayer, legacyIndexState, pool, new StandardConstraintSemantics(), clock, transactionMonitor, storeReadLayer, legacyIndexState, pool, new StandardConstraintSemantics(), clock,
TransactionTracer.NULL, new ProcedureCache(), locks, new SimpleStatementLocksFactory(), TransactionTracer.NULL, new ProcedureCache(), new SimpleStatementLocksFactory( locks ),
mock( NeoStoreTransactionContext.class ), txTerminationAware ); mock( NeoStoreTransactionContext.class ), txTerminationAware );
} }


Expand Down
Expand Up @@ -397,7 +397,7 @@ private static class TestKernelTransaction extends KernelTransactionImplementati
mock( TransactionCommitProcess.class ), monitor, mock( TransactionCommitProcess.class ), monitor,
mock( StoreReadLayer.class, RETURNS_MOCKS ), mock( LegacyIndexTransactionState.class ), mock( StoreReadLayer.class, RETURNS_MOCKS ), mock( LegacyIndexTransactionState.class ),
mock( Pool.class ), new StandardConstraintSemantics(), new FakeClock(), TransactionTracer.NULL, mock( Pool.class ), new StandardConstraintSemantics(), new FakeClock(), TransactionTracer.NULL,
new ProcedureCache(), new NoOpLocks(), new SimpleStatementLocksFactory(), new ProcedureCache(), new SimpleStatementLocksFactory( new NoOpLocks() ),
mock( NeoStoreTransactionContext.class ), true ); mock( NeoStoreTransactionContext.class ), true );


this.monitor = monitor; this.monitor = monitor;
Expand Down
Expand Up @@ -339,7 +339,7 @@ private static KernelTransactions newKernelTransactions( TransactionCommitProces
MetaDataStore metaDataStore = mock( MetaDataStore.class ); MetaDataStore metaDataStore = mock( MetaDataStore.class );
when( metaDataStore.getLastCommittedTransaction() ).thenReturn( new TransactionId( 2, 3, 4 ) ); when( metaDataStore.getLastCommittedTransaction() ).thenReturn( new TransactionId( 2, 3, 4 ) );
when( neoStores.getMetaDataStore() ).thenReturn( metaDataStore ); when( neoStores.getMetaDataStore() ).thenReturn( metaDataStore );
return new KernelTransactions( contextSupplier, neoStores, locks, new SimpleStatementLocksFactory(), return new KernelTransactions( contextSupplier, neoStores, new SimpleStatementLocksFactory( locks ),
mock( IntegrityValidator.class ), null, null, null, null, null, null, null, mock( IntegrityValidator.class ), null, null, null, null, null, null, null,
TransactionHeaderInformationFactory.DEFAULT, readLayer, commitProcess, null, TransactionHeaderInformationFactory.DEFAULT, readLayer, commitProcess, null,
null, new TransactionHooks(), mock( ConstraintSemantics.class ), mock( TransactionMonitor.class ), null, new TransactionHooks(), mock( ConstraintSemantics.class ), mock( TransactionMonitor.class ),
Expand Down
@@ -0,0 +1,62 @@
/*
* 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.locking;

import org.junit.Test;

import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class SimpleStatementLocksFactoryTest
{
@Test
public void throwsForNullLocks()
{
try
{
new SimpleStatementLocksFactory( null );
fail( "Exception expected" );
}
catch ( Exception e )
{
assertThat( e, instanceOf( NullPointerException.class ) );
}
}

@Test
public void createSimpleStatementLocks()
{
Locks locks = mock( Locks.class );
Locks.Client client = mock( Locks.Client.class );
when( locks.newClient() ).thenReturn( client );

SimpleStatementLocksFactory factory = new SimpleStatementLocksFactory( locks );

StatementLocks statementLocks = factory.newInstance();

assertThat( statementLocks, instanceOf( SimpleStatementLocks.class ) );
assertSame( client, statementLocks.optimistic() );
assertSame( client, statementLocks.pessimistic() );
}
}
Expand Up @@ -102,8 +102,8 @@ public NeoStoreDataSource getDataSource( File storeDir, FileSystemAbstraction fs
dataSource = new NeoStoreDataSource( storeDir, config, storeFactory, logProvider, dataSource = new NeoStoreDataSource( storeDir, config, storeFactory, logProvider,
mock( JobScheduler.class, RETURNS_MOCKS ), mock( TokenNameLookup.class ), mock( JobScheduler.class, RETURNS_MOCKS ), mock( TokenNameLookup.class ),
dependencyResolverForNoIndexProvider(), mock( PropertyKeyTokenHolder.class ), dependencyResolverForNoIndexProvider(), mock( PropertyKeyTokenHolder.class ),
mock( LabelTokenHolder.class ), mock( RelationshipTypeTokenHolder.class ), locks, mock( LabelTokenHolder.class ), mock( RelationshipTypeTokenHolder.class ),
new SimpleStatementLocksFactory(), new SimpleStatementLocksFactory( locks ),
mock( SchemaWriteGuard.class ), mock( TransactionEventHandlers.class ), IndexingService.NO_MONITOR, mock( SchemaWriteGuard.class ), mock( TransactionEventHandlers.class ), IndexingService.NO_MONITOR,
fs, mock( StoreUpgrader.class ), mock( TransactionMonitor.class ), kernelHealth, fs, mock( StoreUpgrader.class ), mock( TransactionMonitor.class ), kernelHealth,
mock( PhysicalLogFile.Monitor.class ), TransactionHeaderInformationFactory.DEFAULT, mock( PhysicalLogFile.Monitor.class ), TransactionHeaderInformationFactory.DEFAULT,
Expand Down

0 comments on commit 9a3e987

Please sign in to comment.