@Test public void shouldAcquireSchemaWriteLockBeforeDroppingConstraint() throws Exception { // given SchemaWriteOperations delegate = mock(SchemaWriteOperations.class); UniquenessConstraint constraint = mock(UniquenessConstraint.class); LockingStatementOperations context = new LockingStatementOperations(null, null, delegate, null); // when context.constraintDrop(state, constraint); // then InOrder order = inOrder(lockHolder, delegate); order.verify(lockHolder).acquireSchemaWriteLock(); order.verify(delegate).constraintDrop(state, constraint); verifyNoMoreInteractions(lockHolder, delegate); }
@Test public void shouldAcquireSchemaWriteLockBeforeRemovingIndexRule() throws Exception { // given SchemaWriteOperations delegate = mock(SchemaWriteOperations.class); IndexDescriptor rule = mock(IndexDescriptor.class); LockingStatementOperations context = new LockingStatementOperations(null, null, delegate, null); // when context.indexDrop(state, rule); // then InOrder order = inOrder(lockHolder, delegate); order.verify(lockHolder).acquireSchemaWriteLock(); order.verify(delegate).indexDrop(state, rule); verifyNoMoreInteractions(lockHolder, delegate); }
@Test public void shouldAcquireSchemaWriteLockBeforeAddingIndexRule() throws Exception { // given SchemaWriteOperations delegate = mock(SchemaWriteOperations.class); IndexDescriptor rule = mock(IndexDescriptor.class); when(delegate.indexCreate(state, 123, 456)).thenReturn(rule); LockingStatementOperations context = new LockingStatementOperations(null, null, delegate, null); // when IndexDescriptor result = context.indexCreate(state, 123, 456); // then assertSame(rule, result); InOrder order = inOrder(lockHolder, delegate); order.verify(lockHolder).acquireSchemaWriteLock(); order.verify(delegate).indexCreate(state, 123, 456); verifyNoMoreInteractions(lockHolder, delegate); }
@Test public void shouldGrabWriteLocksBeforeDeleting() throws Exception { // GIVEN EntityWriteOperations inner = mock(EntityWriteOperations.class); NodeProxy.NodeLookup lookup = mock(NodeProxy.NodeLookup.class); NodeImpl node = mock(NodeImpl.class); int nodeId = 0; when(lookup.lookup(anyLong(), any(LockType.class))).thenReturn(node); LockingStatementOperations statementContext = new LockingStatementOperations(inner, null, null, null); // WHEN statementContext.nodeDelete(state, nodeId); // THEN verify(lockHolder).acquireNodeWriteLock(nodeId); }
@Test public void shouldAcquireSchemaWriteLockBeforeAddingUniquenessConstraint() throws Exception { // given SchemaWriteOperations delegate = mock(SchemaWriteOperations.class); UniquenessConstraint constraint = mock(UniquenessConstraint.class); when(delegate.uniquenessConstraintCreate(state, 123, 456)).thenReturn(constraint); LockingStatementOperations context = new LockingStatementOperations(null, null, delegate, null); // when UniquenessConstraint result = context.uniquenessConstraintCreate(state, 123, 456); // then assertEquals(constraint, result); InOrder order = inOrder(lockHolder, delegate); order.verify(lockHolder).acquireSchemaWriteLock(); order.verify(delegate).uniquenessConstraintCreate(state, 123, 456); verifyNoMoreInteractions(lockHolder, delegate); }
@Test public void shouldAcquireSchemaReadLockBeforeRetrievingAllConstraintsl() throws Exception { // given SchemaReadOperations delegate = mock(SchemaReadOperations.class); @SuppressWarnings("unchecked") Iterator<UniquenessConstraint> constraints = mock(Iterator.class); when(delegate.constraintsGetAll(state)).thenReturn(constraints); LockingStatementOperations context = new LockingStatementOperations(null, delegate, null, null); // when Iterator<UniquenessConstraint> result = context.constraintsGetAll(state); // then assertEquals(constraints, result); InOrder order = inOrder(lockHolder, delegate); order.verify(lockHolder).acquireSchemaReadLock(); order.verify(delegate).constraintsGetAll(state); verifyNoMoreInteractions(lockHolder, delegate); }
@Test public void shouldAcquireSchemaReadLockBeforeRetrievingIndexRule() throws Exception { // given SchemaReadOperations delegate = mock(SchemaReadOperations.class); @SuppressWarnings("unchecked") Iterator<IndexDescriptor> rules = mock(Iterator.class); when(delegate.indexesGetAll(state)).thenReturn(rules); LockingStatementOperations context = new LockingStatementOperations(null, delegate, null, null); // when Iterator<IndexDescriptor> result = context.indexesGetAll(state); // then assertSame(rules, result); InOrder order = inOrder(lockHolder, delegate); order.verify(lockHolder).acquireSchemaReadLock(); order.verify(delegate).indexesGetAll(state); verifyNoMoreInteractions(lockHolder, delegate); }