Skip to content

Commit

Permalink
Fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusmelke committed Mar 15, 2018
1 parent f04f648 commit 832369f
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 30 deletions.
Expand Up @@ -798,7 +798,7 @@ sealed class TransactionBoundQueryContext(val transactionalContext: Transactiona
transactionalContext.statement.readOperations().schemaStateGetOrCreate(key, javaCreator) transactionalContext.statement.readOperations().schemaStateGetOrCreate(key, javaCreator)
} }


override def addIndexRule(descriptor: IndexDescriptor): IdempotentResult[CapableIndexReference] = { override def addIndexRule(descriptor: IndexDescriptor): IdempotentResult[IndexReference] = {
val kernelDescriptor = cypherToKernelSchema(descriptor) val kernelDescriptor = cypherToKernelSchema(descriptor)
try { try {
IdempotentResult(transactionalContext.kernelTransaction.schemaWrite().indexCreate(kernelDescriptor)) IdempotentResult(transactionalContext.kernelTransaction.schemaWrite().indexCreate(kernelDescriptor))
Expand Down
Expand Up @@ -27,8 +27,8 @@ import org.neo4j.cypher.internal.runtime._
import org.neo4j.cypher.internal.v3_4.expressions.SemanticDirection import org.neo4j.cypher.internal.v3_4.expressions.SemanticDirection
import org.neo4j.cypher.internal.v3_4.logical.plans.QualifiedName import org.neo4j.cypher.internal.v3_4.logical.plans.QualifiedName
import org.neo4j.graphdb.{Node, Path, PropertyContainer} import org.neo4j.graphdb.{Node, Path, PropertyContainer}
import org.neo4j.internal.kernel.api.IndexReference
import org.neo4j.internal.kernel.api.helpers.RelationshipSelectionCursor import org.neo4j.internal.kernel.api.helpers.RelationshipSelectionCursor
import org.neo4j.internal.kernel.api.{CapableIndexReference, IndexReference}
import org.neo4j.kernel.impl.api.store.RelationshipIterator import org.neo4j.kernel.impl.api.store.RelationshipIterator
import org.neo4j.kernel.impl.core.EmbeddedProxySPI import org.neo4j.kernel.impl.core.EmbeddedProxySPI
import org.neo4j.values.AnyValue import org.neo4j.values.AnyValue
Expand Down Expand Up @@ -181,7 +181,7 @@ trait QueryContextAdaptation {


override def nodeCountByCountStore(labelId: Int): Long = ??? override def nodeCountByCountStore(labelId: Int): Long = ???


override def addIndexRule(descriptor: IndexDescriptor): IdempotentResult[CapableIndexReference] = ??? override def addIndexRule(descriptor: IndexDescriptor): IdempotentResult[IndexReference] = ???


override def getOptRelTypeId(relType: String): Option[Int] = ??? override def getOptRelTypeId(relType: String): Option[Int] = ???


Expand Down
Expand Up @@ -27,7 +27,7 @@ import org.neo4j.cypher.internal.planner.v3_4.spi.{IdempotentResult, IndexDescri
import org.neo4j.cypher.internal.runtime.{Operations, QueryContext, QueryStatistics} import org.neo4j.cypher.internal.runtime.{Operations, QueryContext, QueryStatistics}
import org.neo4j.cypher.internal.util.v3_4.test_helpers.CypherFunSuite import org.neo4j.cypher.internal.util.v3_4.test_helpers.CypherFunSuite
import org.neo4j.graphdb.{Node, Relationship} import org.neo4j.graphdb.{Node, Relationship}
import org.neo4j.internal.kernel.api.CapableIndexReference import org.neo4j.internal.kernel.api.IndexReference
import org.neo4j.values.storable.Values import org.neo4j.values.storable.Values
import org.neo4j.values.virtual.{NodeValue, RelationshipValue} import org.neo4j.values.virtual.{NodeValue, RelationshipValue}


Expand Down Expand Up @@ -68,7 +68,7 @@ class UpdateCountingQueryContextTest extends CypherFunSuite {
when( inner.createRelationshipPropertyExistenceConstraint(anyInt(), anyInt()) ).thenReturn(true) when( inner.createRelationshipPropertyExistenceConstraint(anyInt(), anyInt()) ).thenReturn(true)


when(inner.addIndexRule(any())) when(inner.addIndexRule(any()))
.thenReturn(IdempotentResult(mock[CapableIndexReference])) .thenReturn(IdempotentResult(mock[IndexReference]))


var context: UpdateCountingQueryContext = null var context: UpdateCountingQueryContext = null


Expand Down
Expand Up @@ -95,7 +95,7 @@ trait QueryContext extends TokenContext {


def getOrCreatePropertyKeyId(propertyKey: String): Int def getOrCreatePropertyKeyId(propertyKey: String): Int


def addIndexRule(descriptor: IndexDescriptor): IdempotentResult[CapableIndexReference] def addIndexRule(descriptor: IndexDescriptor): IdempotentResult[IndexReference]


def dropIndexRule(descriptor: IndexDescriptor) def dropIndexRule(descriptor: IndexDescriptor)


Expand Down
Expand Up @@ -35,7 +35,7 @@ public interface SchemaWrite
* @param descriptor description of the index * @param descriptor description of the index
* @return the newly created index * @return the newly created index
*/ */
CapableIndexReference indexCreate( LabelSchemaDescriptor descriptor ) throws SchemaKernelException; IndexReference indexCreate( LabelSchemaDescriptor descriptor ) throws SchemaKernelException;


/** /**
* Drop the given index * Drop the given index
Expand Down
Expand Up @@ -81,7 +81,7 @@ public void setUp() throws Exception
@Test @Test
public void shouldCreateIndex() throws Exception public void shouldCreateIndex() throws Exception
{ {
CapableIndexReference index; IndexReference index;
try ( Transaction transaction = session.beginTransaction() ) try ( Transaction transaction = session.beginTransaction() )
{ {
index = transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) ); index = transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) );
Expand All @@ -98,7 +98,7 @@ public void shouldCreateIndex() throws Exception
@Test @Test
public void shouldDropIndex() throws Exception public void shouldDropIndex() throws Exception
{ {
CapableIndexReference index; IndexReference index;
try ( Transaction transaction = session.beginTransaction() ) try ( Transaction transaction = session.beginTransaction() )
{ {
index = transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) ); index = transaction.schemaWrite().indexCreate( labelDescriptor( label, prop1 ) );
Expand Down Expand Up @@ -161,7 +161,7 @@ public void shouldSeeIndexFromTransaction() throws Exception
@Test @Test
public void shouldNotSeeDroppedIndexFromTransaction() throws Exception public void shouldNotSeeDroppedIndexFromTransaction() throws Exception
{ {
CapableIndexReference index; IndexReference index;
try ( Transaction transaction = session.beginTransaction() ) try ( Transaction transaction = session.beginTransaction() )
{ {
index = index =
Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.neo4j.internal.kernel.api.CapableIndexReference; import org.neo4j.internal.kernel.api.CapableIndexReference;
import org.neo4j.internal.kernel.api.IndexCapability; import org.neo4j.internal.kernel.api.IndexCapability;
import org.neo4j.internal.kernel.api.IndexOrder; import org.neo4j.internal.kernel.api.IndexOrder;
import org.neo4j.internal.kernel.api.IndexReference;
import org.neo4j.internal.kernel.api.IndexValueCapability; import org.neo4j.internal.kernel.api.IndexValueCapability;
import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.kernel.api.index.IndexProvider; import org.neo4j.kernel.api.index.IndexProvider;
Expand Down Expand Up @@ -97,14 +98,14 @@ public boolean equals( Object o )
{ {
return true; return true;
} }
if ( o == null || getClass() != o.getClass() ) if ( o == null || !(o instanceof IndexReference) )
{ {
return false; return false;
} }


DefaultCapableIndexReference that = (DefaultCapableIndexReference) o; IndexReference that = (IndexReference) o;


return label == that.label && unique == that.unique && Arrays.equals( properties, that.properties ); return label == that.label() && unique == that.isUnique() && Arrays.equals( properties, that.properties() );
} }


@Override @Override
Expand Down
Expand Up @@ -80,13 +80,13 @@ public boolean equals( Object o )
{ {
return true; return true;
} }
if ( o == null || getClass() != o.getClass() ) if ( o == null || !( o instanceof IndexReference ) )
{ {
return false; return false;
} }


DefaultIndexReference that = (DefaultIndexReference) o; IndexReference that = (IndexReference) o;
return unique == that.unique && label == that.label && Arrays.equals( properties, that.properties ); return unique == that.isUnique() && label == that.label() && Arrays.equals( properties, that.properties() );
} }


@Override @Override
Expand All @@ -97,4 +97,11 @@ public int hashCode()
result = 31 * result + Arrays.hashCode( properties ); result = 31 * result + Arrays.hashCode( properties );
return result; return result;
} }

@Override
public String toString()
{
return String.format( "Index(%d:%s)", label, Arrays.toString( properties ) );
}

} }
Expand Up @@ -80,6 +80,7 @@
import org.neo4j.kernel.api.txstate.TransactionState; import org.neo4j.kernel.api.txstate.TransactionState;
import org.neo4j.kernel.impl.api.KernelTransactionImplementation; import org.neo4j.kernel.impl.api.KernelTransactionImplementation;
import org.neo4j.kernel.impl.api.state.ConstraintIndexCreator; import org.neo4j.kernel.impl.api.state.ConstraintIndexCreator;
import org.neo4j.kernel.impl.api.store.DefaultIndexReference;
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.ResourceTypes; import org.neo4j.kernel.impl.locking.ResourceTypes;
Expand All @@ -92,12 +93,12 @@
import static java.lang.Math.max; import static java.lang.Math.max;
import static java.lang.Math.min; import static java.lang.Math.min;
import static org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException.Phase.VALIDATION; import static org.neo4j.internal.kernel.api.exceptions.schema.ConstraintValidationException.Phase.VALIDATION;
import static org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException.OperationContext.CONSTRAINT_CREATION; import static org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException.OperationContext
.CONSTRAINT_CREATION;
import static org.neo4j.internal.kernel.api.schema.SchemaDescriptorPredicates.hasProperty; import static org.neo4j.internal.kernel.api.schema.SchemaDescriptorPredicates.hasProperty;
import static org.neo4j.kernel.api.StatementConstants.NO_SUCH_NODE; import static org.neo4j.kernel.api.StatementConstants.NO_SUCH_NODE;
import static org.neo4j.kernel.api.StatementConstants.NO_SUCH_PROPERTY_KEY; import static org.neo4j.kernel.api.StatementConstants.NO_SUCH_PROPERTY_KEY;
import static org.neo4j.kernel.api.schema.index.SchemaIndexDescriptor.Type.UNIQUE; import static org.neo4j.kernel.api.schema.index.SchemaIndexDescriptor.Type.UNIQUE;
import static org.neo4j.kernel.impl.api.store.DefaultCapableIndexReference.fromDescriptor;
import static org.neo4j.kernel.impl.locking.ResourceTypes.INDEX_ENTRY; import static org.neo4j.kernel.impl.locking.ResourceTypes.INDEX_ENTRY;
import static org.neo4j.kernel.impl.locking.ResourceTypes.indexEntryResourceId; import static org.neo4j.kernel.impl.locking.ResourceTypes.indexEntryResourceId;
import static org.neo4j.kernel.impl.newapi.IndexTxStateUpdater.LabelChangeType.ADDED_LABEL; import static org.neo4j.kernel.impl.newapi.IndexTxStateUpdater.LabelChangeType.ADDED_LABEL;
Expand Down Expand Up @@ -781,7 +782,7 @@ public DefaultPropertyCursor propertyCursor()
} }


@Override @Override
public CapableIndexReference indexCreate( LabelSchemaDescriptor descriptor ) throws SchemaKernelException public IndexReference indexCreate( LabelSchemaDescriptor descriptor ) throws SchemaKernelException
{ {
acquireExclusiveLabelLock( descriptor.getLabelId() ); acquireExclusiveLabelLock( descriptor.getLabelId() );
ktx.assertOpen(); ktx.assertOpen();
Expand All @@ -790,7 +791,7 @@ public CapableIndexReference indexCreate( LabelSchemaDescriptor descriptor ) thr


SchemaIndexDescriptor indexDescriptor = SchemaIndexDescriptorFactory.forSchema( descriptor ); SchemaIndexDescriptor indexDescriptor = SchemaIndexDescriptorFactory.forSchema( descriptor );
ktx.txState().indexRuleDoAdd( indexDescriptor ); ktx.txState().indexRuleDoAdd( indexDescriptor );
return fromDescriptor( indexDescriptor ); return DefaultIndexReference.fromDescriptor( indexDescriptor );
} }


@Override @Override
Expand Down
Expand Up @@ -35,7 +35,6 @@
import org.neo4j.graphdb.schema.IndexDefinition; import org.neo4j.graphdb.schema.IndexDefinition;
import org.neo4j.helpers.collection.Iterables; import org.neo4j.helpers.collection.Iterables;
import org.neo4j.helpers.collection.Iterators; import org.neo4j.helpers.collection.Iterators;
import org.neo4j.internal.kernel.api.CapableIndexReference;
import org.neo4j.internal.kernel.api.IndexReference; import org.neo4j.internal.kernel.api.IndexReference;
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.SchemaWrite;
Expand Down Expand Up @@ -130,7 +129,7 @@ public void addIndexRuleInATransaction() throws Exception
SchemaWrite schemaWriteOperations = schemaWriteInNewTransaction(); SchemaWrite schemaWriteOperations = schemaWriteInNewTransaction();


// WHEN // WHEN
CapableIndexReference expectedRule = schemaWriteOperations.indexCreate( descriptor ); IndexReference expectedRule = schemaWriteOperations.indexCreate( descriptor );
commit(); commit();


// THEN // THEN
Expand All @@ -145,7 +144,7 @@ public void committedAndTransactionalIndexRulesShouldBeMerged() throws Exception
{ {
// GIVEN // GIVEN
SchemaWrite schemaWriteOperations = schemaWriteInNewTransaction(); SchemaWrite schemaWriteOperations = schemaWriteInNewTransaction();
CapableIndexReference existingRule = schemaWriteOperations.indexCreate( descriptor ); IndexReference existingRule = schemaWriteOperations.indexCreate( descriptor );
commit(); commit();


// WHEN // WHEN
Expand Down Expand Up @@ -204,7 +203,7 @@ public void shouldBeAbleToRemoveAConstraintIndexWithoutOwner() throws Exception
public void shouldDisallowDroppingIndexThatDoesNotExist() throws Exception public void shouldDisallowDroppingIndexThatDoesNotExist() throws Exception
{ {
// given // given
CapableIndexReference index; IndexReference index;
{ {
SchemaWrite statement = schemaWriteInNewTransaction(); SchemaWrite statement = schemaWriteInNewTransaction();
index = statement.indexCreate( descriptor ); index = statement.indexCreate( descriptor );
Expand Down Expand Up @@ -307,7 +306,7 @@ public void shouldListAll() throws Exception
{ {
// given // given
SchemaWrite schemaWrite = schemaWriteInNewTransaction(); SchemaWrite schemaWrite = schemaWriteInNewTransaction();
CapableIndexReference index1 = schemaWrite.indexCreate( descriptor ); IndexReference index1 = schemaWrite.indexCreate( descriptor );
IndexReference index2 = fromDescriptor( IndexReference index2 = fromDescriptor(
((IndexBackedConstraintDescriptor) schemaWrite.uniquePropertyConstraintCreate( descriptor2 )).ownedIndexDescriptor()) ; ((IndexBackedConstraintDescriptor) schemaWrite.uniquePropertyConstraintCreate( descriptor2 )).ownedIndexDescriptor()) ;
commit(); commit();
Expand Down
Expand Up @@ -37,7 +37,7 @@
import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.TransactionFailureException; import org.neo4j.graphdb.TransactionFailureException;
import org.neo4j.internal.kernel.api.CapableIndexReference; import org.neo4j.internal.kernel.api.IndexReference;
import org.neo4j.internal.kernel.api.SchemaWrite; import org.neo4j.internal.kernel.api.SchemaWrite;
import org.neo4j.internal.kernel.api.TokenWrite; import org.neo4j.internal.kernel.api.TokenWrite;
import org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException; import org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException;
Expand All @@ -47,7 +47,6 @@
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.exceptions.Status; import org.neo4j.kernel.api.exceptions.Status;
import org.neo4j.kernel.api.security.AnonymousContext;
import org.neo4j.kernel.impl.transaction.log.TransactionIdStore; import org.neo4j.kernel.impl.transaction.log.TransactionIdStore;
import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.storageengine.api.NodeItem; import org.neo4j.storageengine.api.NodeItem;
Expand Down Expand Up @@ -519,7 +518,7 @@ public void schemaStateShouldBeEvictedOnIndexComingOnline() throws Exception
public void schemaStateShouldBeEvictedOnIndexDropped() throws Exception public void schemaStateShouldBeEvictedOnIndexDropped() throws Exception
{ {
// GIVEN // GIVEN
CapableIndexReference idx = createIndex( newTransaction( AUTH_DISABLED ) ); IndexReference idx = createIndex( newTransaction( AUTH_DISABLED ) );
commit(); commit();


try ( Transaction tx = db.beginTx() ) try ( Transaction tx = db.beginTx() )
Expand Down Expand Up @@ -638,7 +637,7 @@ private static long lastCommittedTxId( GraphDatabaseAPI db )
return txIdStore.getLastCommittedTransactionId(); return txIdStore.getLastCommittedTransactionId();
} }


private CapableIndexReference createIndex( KernelTransaction transaction ) private IndexReference createIndex( KernelTransaction transaction )
throws SchemaKernelException, InvalidTransactionTypeKernelException throws SchemaKernelException, InvalidTransactionTypeKernelException
{ {
TokenWrite tokenWrite = transaction.tokenWrite(); TokenWrite tokenWrite = transaction.tokenWrite();
Expand Down
Expand Up @@ -62,7 +62,7 @@
import static org.neo4j.graphdb.Label.label; import static org.neo4j.graphdb.Label.label;
import static org.neo4j.helpers.collection.Iterators.asSet; import static org.neo4j.helpers.collection.Iterators.asSet;
import static org.neo4j.helpers.collection.Iterators.single; import static org.neo4j.helpers.collection.Iterators.single;
import static org.neo4j.kernel.impl.api.store.DefaultCapableIndexReference.fromDescriptor; import static org.neo4j.kernel.impl.api.store.DefaultIndexReference.fromDescriptor;


public class UniquenessConstraintCreationIT public class UniquenessConstraintCreationIT
extends AbstractConstraintCreationIT<ConstraintDescriptor,LabelSchemaDescriptor> extends AbstractConstraintCreationIT<ConstraintDescriptor,LabelSchemaDescriptor>
Expand Down

0 comments on commit 832369f

Please sign in to comment.