//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCreateConstraintIndexForSpecifiedProvider() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldCreateConstraintIndexForSpecifiedProvider() { // given IndexingService indexingService = mock(typeof(IndexingService)); StubKernel kernel = new StubKernel(this); when(_schemaRead.indexGetCommittedId(_indexReference)).thenReturn(INDEX_ID); IndexProxy indexProxy = mock(typeof(IndexProxy)); when(indexingService.GetIndexProxy(INDEX_ID)).thenReturn(indexProxy); when(indexingService.getIndexProxy(_descriptor)).thenReturn(indexProxy); NodePropertyAccessor nodePropertyAccessor = mock(typeof(NodePropertyAccessor)); ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider); IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("Groovy", "1.2"); // when KernelTransactionImplementation transaction = CreateTransaction(); creator.CreateUniquenessConstraintIndex(transaction, _descriptor, providerDescriptor.Name()); // then assertEquals(1, kernel.Transactions.Count); KernelTransactionImplementation transactionInstance = kernel.Transactions[0]; verify(transactionInstance).indexUniqueCreate(eq(_descriptor), eq(providerDescriptor.Name())); verify(_schemaRead).index(_descriptor); verify(_schemaRead).indexGetCommittedId(any()); verifyNoMoreInteractions(_schemaRead); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReuseExistingOrphanedConstraintIndex() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReuseExistingOrphanedConstraintIndex() { // given IndexingService indexingService = mock(typeof(IndexingService)); StubKernel kernel = new StubKernel(this); long orphanedConstraintIndexId = 111; when(_schemaRead.indexGetCommittedId(_indexReference)).thenReturn(orphanedConstraintIndexId); IndexProxy indexProxy = mock(typeof(IndexProxy)); when(indexingService.GetIndexProxy(orphanedConstraintIndexId)).thenReturn(indexProxy); NodePropertyAccessor nodePropertyAccessor = mock(typeof(NodePropertyAccessor)); when(_schemaRead.index(_descriptor)).thenReturn(_indexReference); when(_schemaRead.indexGetOwningUniquenessConstraintId(_indexReference)).thenReturn(null); // which means it has no owner ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider); // when KernelTransactionImplementation transaction = CreateTransaction(); long indexId = creator.CreateUniquenessConstraintIndex(transaction, _descriptor, DefaultProvider); // then assertEquals(orphanedConstraintIndexId, indexId); assertEquals("There should have been no need to acquire a statement to create the constraint index", 0, kernel.Transactions.Count); verify(_schemaRead).indexGetCommittedId(_indexReference); verify(_schemaRead).index(_descriptor); verify(_schemaRead).indexGetOwningUniquenessConstraintId(_indexReference); verifyNoMoreInteractions(_schemaRead); verify(indexProxy).awaitStoreScanCompleted(anyLong(), any()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReleaseLabelLockWhileAwaitingIndexPopulation() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReleaseLabelLockWhileAwaitingIndexPopulation() { // given StubKernel kernel = new StubKernel(this); IndexingService indexingService = mock(typeof(IndexingService)); NodePropertyAccessor nodePropertyAccessor = mock(typeof(NodePropertyAccessor)); when(_schemaRead.indexGetCommittedId(_indexReference)).thenReturn(INDEX_ID); IndexProxy indexProxy = mock(typeof(IndexProxy)); when(indexingService.getIndexProxy(anyLong())).thenReturn(indexProxy); when(indexingService.getIndexProxy(_descriptor)).thenReturn(indexProxy); when(_schemaRead.index(LABEL_ID, PROPERTY_KEY_ID)).thenReturn(IndexReference.NO_INDEX); ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider); // when KernelTransactionImplementation transaction = CreateTransaction(); creator.CreateUniquenessConstraintIndex(transaction, _descriptor, DefaultProvider); // then verify(transaction.StatementLocks().pessimistic()).releaseExclusive(ResourceTypes.LABEL, _descriptor.LabelId); verify(transaction.StatementLocks().pessimistic()).acquireExclusive(transaction.LockTracer(), ResourceTypes.LABEL, _descriptor.LabelId); }
public void RegisterServices_DoesNotRegisterSameServiceTwice() { // arrange var kernel = new StubKernel(); // act NinjectMVC3.RegisterServices(kernel); // assert Assert.GreaterThan(kernel.Types.Count, 1); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDropIndexIfPopulationFails() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldDropIndexIfPopulationFails() { // given StubKernel kernel = new StubKernel(this); IndexingService indexingService = mock(typeof(IndexingService)); IndexProxy indexProxy = mock(typeof(IndexProxy)); when(indexingService.GetIndexProxy(INDEX_ID)).thenReturn(indexProxy); when(indexingService.getIndexProxy(_descriptor)).thenReturn(indexProxy); when(indexProxy.Descriptor).thenReturn(_index.withId(INDEX_ID).withoutCapabilities()); IndexEntryConflictException cause = new IndexEntryConflictException(2, 1, Values.of("a")); doThrow(new IndexPopulationFailedKernelException("some index", cause)).when(indexProxy).awaitStoreScanCompleted(anyLong(), any()); NodePropertyAccessor nodePropertyAccessor = mock(typeof(NodePropertyAccessor)); when(_schemaRead.index(any(typeof(SchemaDescriptor)))).thenReturn(IndexReference.NO_INDEX).thenReturn(_indexReference); // then after it failed claim it does exist ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider); // when KernelTransactionImplementation transaction = CreateTransaction(); try { creator.CreateUniquenessConstraintIndex(transaction, _descriptor, DefaultProvider); fail("expected exception"); } // then catch (UniquePropertyValueValidationException e) { assertEquals("Existing data does not satisfy CONSTRAINT ON ( label[123]:label[123] ) " + "ASSERT label[123].property[456] IS UNIQUE: Both node 2 and node 1 share the property value ( String(\"a\") )", e.Message); } assertEquals(2, kernel.Transactions.Count); KernelTransactionImplementation tx1 = kernel.Transactions[0]; SchemaDescriptor newIndex = _index.schema(); verify(tx1).indexUniqueCreate(eq(newIndex), eq(DefaultProvider)); verify(_schemaRead).indexGetCommittedId(_indexReference); verify(_schemaRead, times(2)).index(_descriptor); verifyNoMoreInteractions(_schemaRead); TransactionState tx2 = kernel.Transactions[1].txState(); verify(tx2).indexDoDrop(_index); verifyNoMoreInteractions(tx2); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDropIndexInAnotherTransaction() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldDropIndexInAnotherTransaction() { // given StubKernel kernel = new StubKernel(this); IndexingService indexingService = mock(typeof(IndexingService)); NodePropertyAccessor nodePropertyAccessor = mock(typeof(NodePropertyAccessor)); ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider); // when creator.DropUniquenessConstraintIndex(_index); // then assertEquals(1, kernel.Transactions.Count); verify(kernel.Transactions[0].txState()).indexDoDrop(_index); verifyZeroInteractions(indexingService); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void logMessagesAboutConstraintCreation() throws org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException, org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException, org.neo4j.internal.kernel.api.exceptions.TransactionFailureException, org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void LogMessagesAboutConstraintCreation() { StubKernel kernel = new StubKernel(this); IndexProxy indexProxy = mock(typeof(IndexProxy)); IndexingService indexingService = mock(typeof(IndexingService)); when(indexingService.GetIndexProxy(INDEX_ID)).thenReturn(indexProxy); when(indexingService.getIndexProxy(_descriptor)).thenReturn(indexProxy); when(indexProxy.Descriptor).thenReturn(_index.withId(INDEX_ID).withoutCapabilities()); NodePropertyAccessor propertyAccessor = mock(typeof(NodePropertyAccessor)); ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, propertyAccessor, _logProvider); KernelTransactionImplementation transaction = CreateTransaction(); creator.CreateUniquenessConstraintIndex(transaction, _descriptor, "indexProviderByName-1.0"); _logProvider.rawMessageMatcher().assertContains("Starting constraint creation: %s."); _logProvider.rawMessageMatcher().assertContains("Constraint %s populated, starting verification."); _logProvider.rawMessageMatcher().assertContains("Constraint %s verified."); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFailOnExistingOwnedConstraintIndex() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldFailOnExistingOwnedConstraintIndex() { // given IndexingService indexingService = mock(typeof(IndexingService)); StubKernel kernel = new StubKernel(this); long constraintIndexId = 111; long constraintIndexOwnerId = 222; when(_schemaRead.indexGetCommittedId(_indexReference)).thenReturn(constraintIndexId); IndexProxy indexProxy = mock(typeof(IndexProxy)); when(indexingService.GetIndexProxy(constraintIndexId)).thenReturn(indexProxy); NodePropertyAccessor nodePropertyAccessor = mock(typeof(NodePropertyAccessor)); when(_schemaRead.index(_descriptor)).thenReturn(_indexReference); when(_schemaRead.indexGetOwningUniquenessConstraintId(_indexReference)).thenReturn(constraintIndexOwnerId); // which means there's an owner when(_tokenRead.nodeLabelName(LABEL_ID)).thenReturn("MyLabel"); when(_tokenRead.propertyKeyName(PROPERTY_KEY_ID)).thenReturn("MyKey"); ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider); // when try { KernelTransactionImplementation transaction = CreateTransaction(); creator.CreateUniquenessConstraintIndex(transaction, _descriptor, DefaultProvider); fail("Should've failed"); } catch (AlreadyConstrainedException) { // THEN good } // then assertEquals("There should have been no need to acquire a statement to create the constraint index", 0, kernel.Transactions.Count); verify(_schemaRead).index(_descriptor); verify(_schemaRead).indexGetOwningUniquenessConstraintId(_indexReference); verifyNoMoreInteractions(_schemaRead); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCreateIndexInAnotherTransaction() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldCreateIndexInAnotherTransaction() { // given StubKernel kernel = new StubKernel(this); IndexProxy indexProxy = mock(typeof(IndexProxy)); IndexingService indexingService = mock(typeof(IndexingService)); when(indexingService.GetIndexProxy(INDEX_ID)).thenReturn(indexProxy); when(indexingService.getIndexProxy(_descriptor)).thenReturn(indexProxy); when(indexProxy.Descriptor).thenReturn(_index.withId(INDEX_ID).withoutCapabilities()); NodePropertyAccessor nodePropertyAccessor = mock(typeof(NodePropertyAccessor)); ConstraintIndexCreator creator = new ConstraintIndexCreator(() => kernel, indexingService, nodePropertyAccessor, _logProvider); // when long indexId = creator.CreateUniquenessConstraintIndex(CreateTransaction(), _descriptor, DefaultProvider); // then assertEquals(INDEX_ID, indexId); verify(_schemaRead).indexGetCommittedId(_indexReference); verify(_schemaRead).index(_descriptor); verifyNoMoreInteractions(_schemaRead); verify(indexProxy).awaitStoreScanCompleted(anyLong(), any()); }