private void assertLocksHeld( final Long... expectedResourceIds ) { final List<Long> expectedLockedIds = Arrays.asList( expectedResourceIds ); final List<Long> seenLockedIds = new ArrayList<>(); locks.accept( ( resourceType, resourceId, description, estimatedWaitTime, lockIdentityHashCode ) -> seenLockedIds.add( resourceId ) ); Collections.sort( expectedLockedIds ); Collections.sort( seenLockedIds ); assertEquals( "unexpected locked resource ids", expectedLockedIds, seenLockedIds ); }
@Override public StatementLocks newInstance() { if ( locks == null ) { throw new IllegalStateException( "Factory has not been initialized" ); } return new SimpleStatementLocks( locks.newClient() ); } }
@Test public void shouldNotBeAbleToHandOutClientsIfClosed() { // GIVEN a lock manager and working clients try ( Client client = locks.newClient() ) { client.acquireExclusive( LockTracer.NONE, ResourceTypes.NODE, 0 ); } // WHEN locks.close(); // THEN try { locks.newClient(); fail( "Should fail" ); } catch ( IllegalStateException e ) { // Good } }
@After public void after() { clientA.close(); clientB.close(); clientC.close(); locks.close(); clientToThreadMap.clear(); }
@After public void tearDown() { client2.close(); client.close(); lockManager.close(); }
private void assertNoLocksHeld() { locks.accept( ( resourceType, resourceId, description, estimatedWaitTime, lockIdentityHashCode ) -> fail( "Unexpected lock on " + resourceType + " " + resourceId ) ); }
LockWorkerState( Locks locks ) { this.grabber = locks; this.client = locks.newClient(); }
@Override public void close() { localLocks.close(); }
private int lockCount() { LockCountVisitor lockVisitor = new LockCountVisitor(); locks.accept( lockVisitor ); return lockVisitor.getLockCount(); } }
StressThread( String name, int numberOfIterations, int depthCount, float readWriteRatio, long nodeId, CountDownLatch startSignal ) { super(); this.nodeId = nodeId; this.client = locks.newClient(); this.name = name; this.numberOfIterations = numberOfIterations; this.depthCount = depthCount; this.readWriteRatio = readWriteRatio; this.startSignal = startSignal; }
@Override public void close() { localLocks.close(); }
private static int lockCount( Locks locks ) { LockCountVisitor lockCountVisitor = new LockCountVisitor(); locks.accept( lockCountVisitor ); return lockCountVisitor.getLockCount(); }
@Before public void setUp() { client = locks.newClient(); }
public File dumpState( Locks lm, LockWorker... workers ) throws IOException { FileOutputStream out = new FileOutputStream( file, false ); FormattedLogProvider logProvider = FormattedLogProvider.withoutAutoFlush().toOutputStream( out ); try { // * locks held by the lock manager lm.accept( new DumpLocksVisitor( logProvider.getLog( LockWorkFailureDump.class ) ) ); // * rag manager state; // * workers state Log log = logProvider.getLog( getClass() ); for ( LockWorker worker : workers ) { // - what each is doing and have up to now log.info( "Worker %s", worker ); } return file; } finally { out.flush(); out.close(); } } }
private Locks.Client newLockClient( LockAcquisition lockAcquisition ) { Locks.Client client = locks.newClient(); lockAcquisition.setClient( client ); return client; }
@Test public void mustReleaseUnpreparedLocksOnStop() { // Given clientA.acquireShared( TRACER, NODE, 1L ); clientA.acquireExclusive( TRACER, NODE, 2L ); // When clientA.stop(); // The client was stopped before it could enter the prepare phase, so all of its locks are released LockCountVisitor lockCountVisitor = new LockCountVisitor(); locks.accept( lockCountVisitor ); assertEquals( 0, lockCountVisitor.getLockCount() ); }
@Before public void before() { this.locks = suite.createLockManager( Config.defaults(), Clocks.systemClock() ); clientA = this.locks.newClient(); clientB = this.locks.newClient(); clientC = this.locks.newClient(); clientToThreadMap.put( clientA, threadA ); clientToThreadMap.put( clientB, threadB ); clientToThreadMap.put( clientC, threadC ); }
@Test public void mustNotReleaseLocksAfterPrepareOnStop() { // Given clientA.acquireShared( TRACER, NODE, 1L ); clientA.acquireExclusive( TRACER, NODE, 2L ); clientA.prepare(); // When clientA.stop(); // The client entered the prepare phase, so it gets to keep its locks LockCountVisitor lockCountVisitor = new LockCountVisitor(); locks.accept( lockCountVisitor ); assertEquals( 2, lockCountVisitor.getLockCount() ); }
@Before public void setUp() { customConfig = Config.defaults( GraphDatabaseSettings.lock_acquisition_timeout, "100ms" ); clock = Clocks.fakeClock(100000, TimeUnit.MINUTES); lockManager = suite.createLockManager( customConfig, clock ); client = lockManager.newClient(); client2 = lockManager.newClient(); }
@Test public void prepareMustAllowAcquiringNewLocksAfterStop() { // Given clientA.prepare(); clientA.stop(); // When clientA.acquireShared( TRACER, NODE, 1 ); clientA.acquireExclusive( TRACER, NODE, 2 ); // Stopped essentially has no effect when it comes after the client has entered the prepare phase LockCountVisitor lockCountVisitor = new LockCountVisitor(); locks.accept( lockCountVisitor ); assertEquals( 2, lockCountVisitor.getLockCount() ); }