private static IndexEntryConflictException BuildCauseChain(ISet <IndexEntryConflictException> conflicts) { IndexEntryConflictException chainedConflicts = null; foreach (IndexEntryConflictException conflict in conflicts) { chainedConflicts = Exceptions.chain(chainedConflicts, conflict); } return(chainedConflicts); }
private static void MarkAsFailed <T1>(DatabaseIndex <T1> index, IndexEntryConflictException conflict) where T1 : Org.Neo4j.Storageengine.Api.schema.IndexReader { try { index.MarkAsFailed(conflict.Message); } catch (IOException ioe) { ioe.addSuppressed(conflict); throw new UncheckedIOException(ioe); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void verifyDeferredConstraints(org.neo4j.storageengine.api.NodePropertyAccessor accessor) throws org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException, java.io.IOException public override void VerifyDeferredConstraints(NodePropertyAccessor accessor) { // If we've seen constraint violation failures in here when updates came in then fail immediately with those if (_failures.Count > 0) { IEnumerator <IndexEntryConflictException> failureIterator = _failures.GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: IndexEntryConflictException conflict = failureIterator.next(); failureIterator.forEachRemaining(conflict.addSuppressed); throw conflict; } // Otherwise consolidate the usual verification base.VerifyDeferredConstraints(accessor); }
//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); }
public override string GetUserMessage(TokenNameLookup tokenNameLookup) { SchemaDescriptor schema = ConstraintConflict.schema(); StringBuilder message = new StringBuilder(); for (IEnumerator <IndexEntryConflictException> iterator = _conflicts.GetEnumerator(); iterator.MoveNext();) { IndexEntryConflictException conflict = iterator.Current; message.Append(conflict.EvidenceMessage(tokenNameLookup, schema)); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: if (iterator.hasNext()) { message.Append(Environment.NewLine); } } return(message.ToString()); }
/* verifyDeferredConstraints */ //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void verifyDeferredConstraintsMustThrowIfAnyThrow() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void VerifyDeferredConstraintsMustThrowIfAnyThrow() { foreach (IndexPopulator alivePopulator in _alivePopulators) { // given IndexEntryConflictException failure = mock(typeof(IndexEntryConflictException)); doThrow(failure).when(alivePopulator).verifyDeferredConstraints(any()); verifyCallFail(failure, () => { _fusionIndexPopulator.verifyDeferredConstraints(null); return(null); }); // reset throw for testing of next populator doAnswer(invocation => null).when(alivePopulator).verifyDeferredConstraints(any()); } }
/// <summary> /// This is also checked by the UniqueConstraintCompatibility test, only not on this abstraction level. /// </summary> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldProvidePopulatorThatEnforcesUniqueConstraints() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldProvidePopulatorThatEnforcesUniqueConstraints() { // when Value value = Values.of("value1"); int nodeId1 = 1; int nodeId2 = 2; WithPopulator(IndexProvider.getPopulator(Descriptor, IndexSamplingConfig, heapBufferFactory(1024)), p => { try { p.add(Arrays.asList(add(nodeId1, Descriptor.schema(), value), add(nodeId2, Descriptor.schema(), value))); TestNodePropertyAccessor propertyAccessor = new TestNodePropertyAccessor(nodeId1, Descriptor.schema(), value); propertyAccessor.AddNode(nodeId2, Descriptor.schema(), value); p.scanCompleted(PhaseTracker.nullInstance); p.verifyDeferredConstraints(propertyAccessor); fail("expected exception"); } // then catch (Exception e) { Exception root = Exceptions.rootCause(e); if (root is IndexEntryConflictException) { IndexEntryConflictException conflict = ( IndexEntryConflictException )root; assertEquals(nodeId1, conflict.ExistingNodeId); assertEquals(ValueTuple.of(value), conflict.PropertyValues); assertEquals(nodeId2, conflict.AddedNodeId); } else { throw e; } } }, false); }
public UniquePropertyValueValidationException(IndexBackedConstraintDescriptor constraint, ConstraintValidationException.Phase phase, IndexEntryConflictException conflict) : this(constraint, phase, Collections.singleton(conflict)) { }