//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void addingUniqueNodeWithUnrelatedValueShouldNotAffectLookup() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void AddingUniqueNodeWithUnrelatedValueShouldNotAffectLookup() { // given CreateConstraint("Person", "id"); long ourNode; { Transaction transaction = NewTransaction(AnonymousContext.writeToken()); ourNode = CreateLabeledNode(transaction, "Person", "id", 1); Commit(); } Transaction transaction = NewTransaction(AnonymousContext.writeToken()); TokenRead tokenRead = transaction.TokenRead(); int person = tokenRead.NodeLabel("Person"); int propId = tokenRead.PropertyKey("id"); IndexReference idx = transaction.SchemaRead().index(person, propId); // when CreateLabeledNode(transaction, "Person", "id", 2); // then I should find the original node assertThat(transaction.DataRead().lockingNodeUniqueIndexSeek(idx, exact(propId, Values.of(1))), equalTo(ourNode)); Commit(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void dropIndex(org.neo4j.internal.kernel.api.IndexReference reference) throws org.neo4j.internal.kernel.api.exceptions.KernelException private void DropIndex(IndexReference reference) { using (Transaction transaction = _kernel.beginTransaction(@implicit, AUTH_DISABLED)) { transaction.SchemaWrite().indexDrop(reference); transaction.Success(); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static void assertOnIndexCounts(int expectedIndexUpdates, int expectedIndexSize, int expectedUniqueValues, int expectedSampleSize, org.neo4j.storageengine.api.schema.IndexDescriptor indexDescriptor, HighlyAvailableGraphDatabase db) throws org.neo4j.internal.kernel.api.exceptions.TransactionFailureException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException private static void AssertOnIndexCounts(int expectedIndexUpdates, int expectedIndexSize, int expectedUniqueValues, int expectedSampleSize, IndexDescriptor indexDescriptor, HighlyAvailableGraphDatabase db) { using ([email protected] tx = Db.DependencyResolver.resolveDependency(typeof(Kernel)).beginTransaction(@explicit, AUTH_DISABLED)) { IndexReference indexReference = tx.SchemaRead().index(indexDescriptor.Schema()); AssertDoubleLongEquals(expectedIndexUpdates, expectedIndexSize, tx.SchemaRead().indexUpdatesAndSize(indexReference, newDoubleLongRegister())); AssertDoubleLongEquals(expectedUniqueValues, expectedSampleSize, tx.SchemaRead().indexSample(indexReference, newDoubleLongRegister())); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void awaitIndexOnline(org.neo4j.internal.kernel.api.IndexReference descriptor, String keyForProbing) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException, org.neo4j.internal.kernel.api.exceptions.TransactionFailureException private void AwaitIndexOnline(IndexReference descriptor, string keyForProbing) { using (Transaction transaction = _kernel.beginTransaction(@implicit, AUTH_DISABLED)) { SchemaIndexTestHelper.awaitIndexOnline(transaction.SchemaRead(), descriptor); transaction.Success(); } AwaitSchemaStateCleared(keyForProbing); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private org.neo4j.internal.kernel.api.IndexReference createIndex() throws org.neo4j.internal.kernel.api.exceptions.KernelException private IndexReference CreateIndex() { using (Transaction transaction = _kernel.beginTransaction(@implicit, AUTH_DISABLED)) { IndexReference reference = transaction.SchemaWrite().indexCreate(SchemaDescriptorFactory.forLabel(1, 1)); transaction.Success(); return(reference); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static org.neo4j.storageengine.api.schema.IndexDescriptor createAnIndex(HighlyAvailableGraphDatabase db, org.neo4j.graphdb.Label label, String propertyName) throws org.neo4j.internal.kernel.api.exceptions.KernelException private static IndexDescriptor CreateAnIndex(HighlyAvailableGraphDatabase db, Label label, string propertyName) { using (Transaction tx = Db.beginTx()) { KernelTransaction ktx = KernelTransaction(db); int labelId = ktx.TokenWrite().labelGetOrCreateForName(label.Name()); int propertyKeyId = ktx.TokenWrite().propertyKeyGetOrCreateForName(propertyName); IndexReference index = ktx.SchemaWrite().indexCreate(SchemaDescriptorFactory.forLabel(labelId, propertyKeyId)); tx.Success(); return(( IndexDescriptor )index); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCallIndexSeek() throws org.neo4j.internal.kernel.api.exceptions.KernelException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldCallIndexSeek() { // GIVEN Read read = mock(typeof(Read)); IndexReference index = mock(typeof(IndexReference)); when(index.Properties()).thenReturn(new int[] { 42 }); // WHEN CompiledIndexUtils.IndexSeek(read, mock(typeof(CursorFactory)), index, "hello"); // THEN verify(read, times(1)).nodeIndexSeek(any(), any(), any(), anyBoolean(), any()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleNullInIndexSeek() throws org.neo4j.internal.kernel.api.exceptions.KernelException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleNullInIndexSeek() { // GIVEN Read read = mock(typeof(Read)); IndexReference index = mock(typeof(IndexReference)); when(index.Properties()).thenReturn(new int[] { 42 }); // WHEN NodeValueIndexCursor cursor = CompiledIndexUtils.IndexSeek(mock(typeof(Read)), mock(typeof(CursorFactory)), index, null); // THEN verify(read, never()).nodeIndexSeek(any(), any(), any(), anyBoolean()); assertFalse(cursor.Next()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void visitsIndexes() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void VisitsIndexes() { DbStructureVisitor visitor = mock(typeof(DbStructureVisitor)); int labelId = CreateLabel("Person"); int pkId = CreatePropertyKey("name"); CommitAndReOpen(); IndexReference reference = CreateSchemaIndex(labelId, pkId); // WHEN Accept(visitor); // THEN verify(visitor).visitIndex(( IndexDescriptor )reference, ":Person(name)", 1.0d, 0L); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static void lockNodeUsingUniqueIndexSeek(org.neo4j.kernel.internal.GraphDatabaseAPI database, org.neo4j.graphdb.Label label, String nameProperty) throws org.neo4j.internal.kernel.api.exceptions.KernelException private static void LockNodeUsingUniqueIndexSeek(GraphDatabaseAPI database, Label label, string nameProperty) { using (Transaction transaction = database.BeginTx()) { ThreadToStatementContextBridge contextBridge = database.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)); KernelTransaction kernelTransaction = contextBridge.GetKernelTransactionBoundToThisThread(true); TokenRead tokenRead = kernelTransaction.TokenRead(); Read dataRead = kernelTransaction.DataRead(); int labelId = tokenRead.NodeLabel(label.Name()); int propertyId = tokenRead.PropertyKey(nameProperty); IndexReference indexReference = kernelTransaction.SchemaRead().index(labelId, propertyId); dataRead.LockingNodeUniqueIndexSeek(indexReference, IndexQuery.ExactPredicate.exact(propertyId, "value")); transaction.Success(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldInvalidateSchemaStateOnDropIndex() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldInvalidateSchemaStateOnDropIndex() { IndexReference @ref = CreateIndex(); AwaitIndexOnline(@ref, "test"); CommitToSchemaState("test", "before"); DropIndex(@ref); // when string after = CommitToSchemaState("test", "after"); // then assertEquals("after", after); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void schemaStateShouldBeEvictedOnIndexDropped() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void SchemaStateShouldBeEvictedOnIndexDropped() { // GIVEN IndexReference idx = CreateIndex(NewTransaction(AUTH_DISABLED)); Commit(); using (Transaction tx = Db.beginTx()) { Db.schema().awaitIndexesOnline(20, SECONDS); GetOrCreateSchemaState("my key", "some state"); tx.Success(); } // WHEN SchemaWriteInNewTransaction().indexDrop(idx); Commit(); // THEN schema state should be immediately updated (this works because the schema cache is updated during // transaction apply, while the schema lock is held). assertFalse(SchemaStateContains("my key")); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void verifyThatThereAreExactlyOneIndexEntryPerNodeInTheIndexes(int i, org.neo4j.helpers.collection.Pair<long[],long[]> data) throws Exception private void VerifyThatThereAreExactlyOneIndexEntryPerNodeInTheIndexes(int i, Pair <long[], long[]> data) { Kernel kernel = Db.DependencyResolver.resolveDependency(typeof(Kernel)); using ([email protected] tx = kernel.BeginTransaction(@implicit, AnonymousContext.read())) { int labelAId = tx.TokenRead().nodeLabel(LabelA(i).name()); int keyAId = tx.TokenRead().propertyKey(KeyA(i)); int labelBId = tx.TokenRead().nodeLabel(LabelB(i).name()); int keyBId = tx.TokenRead().propertyKey(KeyB(i)); IndexReference indexA = TestIndexDescriptorFactory.forLabel(labelAId, keyAId); IndexReference indexB = TestIndexDescriptorFactory.forLabel(labelBId, keyBId); for (int j = 0; j < NODES_PER_INDEX; j++) { long nodeAId = data.First()[j]; assertEquals(1, tx.SchemaRead().nodesCountIndexed(indexA, nodeAId, keyAId, Values.of(nodeAId))); long nodeBId = data.Other()[j]; assertEquals(1, tx.SchemaRead().nodesCountIndexed(indexB, nodeBId, keyBId, Values.of(nodeBId))); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static <CURSOR extends org.neo4j.internal.kernel.api.NodeValueIndexCursor> long apply(org.neo4j.kernel.impl.locking.Locks_Client locks, org.neo4j.storageengine.api.lock.LockTracer lockTracer, System.Func<CURSOR> cursors, UniqueNodeIndexSeeker<CURSOR> nodeIndexSeeker, Read read, org.neo4j.internal.kernel.api.IndexReference index, org.neo4j.internal.kernel.api.IndexQuery.ExactPredicate... predicates) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException public static long Apply <CURSOR>(Org.Neo4j.Kernel.impl.locking.Locks_Client locks, LockTracer lockTracer, System.Func <CURSOR> cursors, UniqueNodeIndexSeeker <CURSOR> nodeIndexSeeker, Read read, IndexReference index, params IndexQuery.ExactPredicate[] predicates) where CURSOR : [email protected] { int[] entityTokenIds = index.Schema().EntityTokenIds; if (entityTokenIds.Length != 1) { throw new IndexNotApplicableKernelException("Multi-token index " + index + " does not support uniqueness."); } long indexEntryId = indexEntryResourceId(entityTokenIds[0], predicates); //First try to find node under a shared lock //if not found upgrade to exclusive and try again locks.AcquireShared(lockTracer, INDEX_ENTRY, indexEntryId); using (CURSOR cursor = cursors(), IndexReaders readers = new IndexReaders(index, read)) { nodeIndexSeeker.NodeIndexSeekWithFreshIndexReader(cursor, readers.CreateReader(), predicates); if (!cursor.next()) { locks.ReleaseShared(INDEX_ENTRY, indexEntryId); locks.AcquireExclusive(lockTracer, INDEX_ENTRY, indexEntryId); nodeIndexSeeker.NodeIndexSeekWithFreshIndexReader(cursor, readers.CreateReader(), predicates); if (cursor.next()) // we found it under the exclusive lock { // downgrade to a shared lock locks.AcquireShared(lockTracer, INDEX_ENTRY, indexEntryId); locks.ReleaseExclusive(INDEX_ENTRY, indexEntryId); } } return(cursor.nodeReference()); } }