Skip to content

Commit

Permalink
Fix ConstraintIndexCreatorTest
Browse files Browse the repository at this point in the history
  • Loading branch information
ragadeeshu committed May 21, 2018
1 parent 64ce85e commit 2c2d458
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
Expand Up @@ -236,7 +236,7 @@ private void removeFromLookup(


private static Map<SchemaDescriptor, IndexProxy> indexesByDescriptor( LongObjectMap<IndexProxy> indexesById ) private static Map<SchemaDescriptor, IndexProxy> indexesByDescriptor( LongObjectMap<IndexProxy> indexesById )
{ {
return indexesById.toMap( IndexProxy::schema, Functions.identity() ); return indexesById.toMap( indexProxy -> indexProxy.getDescriptor().schema(), Functions.identity() );
} }


private static MutableObjectLongMap<SchemaDescriptor> indexIdsByDescriptor( LongObjectMap<IndexProxy> indexesById ) private static MutableObjectLongMap<SchemaDescriptor> indexIdsByDescriptor( LongObjectMap<IndexProxy> indexesById )
Expand Down
Expand Up @@ -28,9 +28,11 @@
import org.neo4j.internal.kernel.api.Kernel; import org.neo4j.internal.kernel.api.Kernel;
import org.neo4j.internal.kernel.api.Modes; import org.neo4j.internal.kernel.api.Modes;
import org.neo4j.internal.kernel.api.SchemaRead; import org.neo4j.internal.kernel.api.SchemaRead;
import org.neo4j.internal.kernel.api.SchemaWrite;
import org.neo4j.internal.kernel.api.Session; import org.neo4j.internal.kernel.api.Session;
import org.neo4j.internal.kernel.api.TokenRead; import org.neo4j.internal.kernel.api.TokenRead;
import org.neo4j.internal.kernel.api.Transaction; import org.neo4j.internal.kernel.api.Transaction;
import org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException;
import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException; import org.neo4j.internal.kernel.api.exceptions.TransactionFailureException;
import org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException; import org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException;
import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor;
Expand Down Expand Up @@ -65,6 +67,7 @@
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
Expand All @@ -84,6 +87,7 @@ public class ConstraintIndexCreatorTest
private final IndexDescriptor index = TestIndexDescriptorFactory.uniqueForLabel( LABEL_ID, PROPERTY_KEY_ID ); private final IndexDescriptor index = TestIndexDescriptorFactory.uniqueForLabel( LABEL_ID, PROPERTY_KEY_ID );
private final IndexReference indexReference = TestIndexDescriptorFactory.uniqueForLabel( LABEL_ID, PROPERTY_KEY_ID ); private final IndexReference indexReference = TestIndexDescriptorFactory.uniqueForLabel( LABEL_ID, PROPERTY_KEY_ID );
private final SchemaRead schemaRead = schemaRead(); private final SchemaRead schemaRead = schemaRead();
private final SchemaWrite schemaWrite = mock( SchemaWrite.class );
private final TokenRead tokenRead = mock( TokenRead.class ); private final TokenRead tokenRead = mock( TokenRead.class );


@Test @Test
Expand Down Expand Up @@ -122,6 +126,7 @@ public void shouldDropIndexIfPopulationFails() throws Exception
IndexProxy indexProxy = mock( IndexProxy.class ); IndexProxy indexProxy = mock( IndexProxy.class );
when( indexingService.getIndexProxy( INDEX_ID ) ).thenReturn( indexProxy ); when( indexingService.getIndexProxy( INDEX_ID ) ).thenReturn( indexProxy );
when( indexingService.getIndexProxy( descriptor ) ).thenReturn( indexProxy ); when( indexingService.getIndexProxy( descriptor ) ).thenReturn( indexProxy );
when( indexProxy.getDescriptor() ).thenReturn( index.withId( INDEX_ID ).withoutCapabilities() );


IndexEntryConflictException cause = new IndexEntryConflictException( 2, 1, Values.of( "a" ) ); IndexEntryConflictException cause = new IndexEntryConflictException( 2, 1, Values.of( "a" ) );
doThrow( new IndexPopulationFailedKernelException( descriptor, "some index", cause ) ) doThrow( new IndexPopulationFailedKernelException( descriptor, "some index", cause ) )
Expand Down Expand Up @@ -150,15 +155,14 @@ public void shouldDropIndexIfPopulationFails() throws Exception
"ASSERT label[123].property[456] IS UNIQUE.", e.getMessage() ); "ASSERT label[123].property[456] IS UNIQUE.", e.getMessage() );
} }
assertEquals( 2, kernel.transactions.size() ); assertEquals( 2, kernel.transactions.size() );
TransactionState tx1 = kernel.transactions.get( 0 ).txState(); KernelTransactionImplementation tx1 = kernel.transactions.get( 0 );
IndexDescriptor newIndex = TestIndexDescriptorFactory.uniqueForLabel( 123, 456 ); SchemaDescriptor newIndex = index.schema();
verify( tx1 ).indexRuleDoAdd( newIndex ); verify( tx1 ).indexUniqueCreate( eq( newIndex ) );
verifyNoMoreInteractions( tx1 );
verify( schemaRead ).indexGetCommittedId( indexReference ); verify( schemaRead ).indexGetCommittedId( indexReference );
verify( schemaRead, times( 2 ) ).index( LABEL_ID, PROPERTY_KEY_ID ); verify( schemaRead, times( 2 ) ).index( LABEL_ID, PROPERTY_KEY_ID );
verifyNoMoreInteractions( schemaRead ); verifyNoMoreInteractions( schemaRead );
TransactionState tx2 = kernel.transactions.get( 1 ).txState(); TransactionState tx2 = kernel.transactions.get( 1 ).txState();
verify( tx2 ).indexDoDrop( newIndex ); verify( tx2 ).indexDoDrop( index );
verifyNoMoreInteractions( tx2 ); verifyNoMoreInteractions( tx2 );
} }


Expand Down Expand Up @@ -346,22 +350,28 @@ private SchemaRead schemaRead()


private KernelTransactionImplementation createTransaction() private KernelTransactionImplementation createTransaction()
{ {
TransactionHeaderInformation headerInformation = new TransactionHeaderInformation( -1, -1, new byte[0] ); KernelTransactionImplementation transaction = mock( KernelTransactionImplementation.class );
try
{TransactionHeaderInformation headerInformation = new TransactionHeaderInformation( -1, -1, new byte[0] );
TransactionHeaderInformationFactory headerInformationFactory = TransactionHeaderInformationFactory headerInformationFactory =
mock( TransactionHeaderInformationFactory.class ); mock( TransactionHeaderInformationFactory.class );
when( headerInformationFactory.create() ).thenReturn( headerInformation ); when( headerInformationFactory.create() ).thenReturn( headerInformation );
StorageEngine storageEngine = mock( StorageEngine.class ); StorageEngine storageEngine = mock( StorageEngine.class );
StorageReader storageReader = mock( StorageReader.class ); StorageReader storageReader = mock( StorageReader.class );
when( storageEngine.newReader() ).thenReturn( storageReader ); when( storageEngine.newReader() ).thenReturn( storageReader );
KernelTransactionImplementation transaction = mock( KernelTransactionImplementation.class );
SimpleStatementLocks locks = SimpleStatementLocks locks =
new SimpleStatementLocks( mock( org.neo4j.kernel.impl.locking.Locks.Client.class ) ); new SimpleStatementLocks( mock( org.neo4j.kernel.impl.locking.Locks.Client.class ) );
when( transaction.statementLocks() ).thenReturn( locks ); when( transaction.statementLocks() ).thenReturn( locks );
when( transaction.tokenRead() ).thenReturn( tokenRead ); when( transaction.tokenRead() ).thenReturn( tokenRead );
when( transaction.schemaRead() ).thenReturn( schemaRead ); when( transaction.schemaRead() ).thenReturn( schemaRead );when( transaction.schemaWrite() ).thenReturn( schemaWrite );
TransactionState transactionState = mock( TransactionState.class ); TransactionState transactionState = mock( TransactionState.class );
when( transaction.txState() ).thenReturn( transactionState ); when( transaction.txState() ).thenReturn( transactionState );
when( transaction.indexUniqueCreate( any(SchemaDescriptor.class ) ) ).thenAnswer( i-> IndexDescriptorFactory.uniqueForSchema( i.getArgument( 0 ) ) ); when( transaction.indexUniqueCreate( any(SchemaDescriptor.class ) ) ).thenAnswer( i-> IndexDescriptorFactory.uniqueForSchema( i.getArgument( 0 ) ) );}
catch ( InvalidTransactionTypeKernelException e )
{
e.printStackTrace();
}
return transaction; return transaction;
} }
} }

0 comments on commit 2c2d458

Please sign in to comment.