//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: public static org.neo4j.kernel.ha.com.master.MasterImpl.SPI mockedSpi(final org.neo4j.storageengine.api.StoreId storeId) public static SPI MockedSpi(StoreId storeId) { MasterImpl.SPI mock = mock(typeof(MasterImpl.SPI)); when(mock.StoreId()).thenReturn(storeId); when(mock.PackEmptyResponse(any())).thenAnswer(invocation => new TransactionObligationResponse <>(invocation.getArgument(0), storeId, Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.BASE_TX_ID, Org.Neo4j.com.ResourceReleaser_Fields.NoOp)); return(mock); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAllowStartNewTransactionAfterClientSessionWasRemovedOnTimeout() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAllowStartNewTransactionAfterClientSessionWasRemovedOnTimeout() { //Given MasterImpl.SPI spi = MockedSpi(); DefaultConversationSPI conversationSpi = MockedConversationSpi(); Monitor monitor = mock(typeof(Monitor)); Config config = config(); Locks_Client client = mock(typeof(Locks_Client)); ConversationManager conversationManager = new ConversationManager(conversationSpi, config); int machineId = 1; MasterImpl master = new MasterImpl(spi, conversationManager, monitor, config); when(spi.Accessible).thenReturn(true); when(conversationSpi.AcquireClient()).thenReturn(client); master.Start(); HandshakeResult handshake = master.Handshake(1, newStoreIdForCurrentVersion()).response(); RequestContext requestContext = new RequestContext(handshake.Epoch(), machineId, 0, 0, 0); // When master.NewLockSession(requestContext); master.AcquireSharedLock(requestContext, ResourceTypes.NODE, 1L); conversationManager.Stop(requestContext); master.NewLockSession(requestContext); //Then IDictionary <int, ICollection <RequestContext> > transactions = master.OngoingTransactions; assertEquals(1, transactions.Count); assertThat(transactions[machineId], org.hamcrest.Matchers.hasItem(requestContext)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAllowCommitIfClientHoldsNoLocks() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAllowCommitIfClientHoldsNoLocks() { // Given MasterImpl.SPI spi = mock(typeof(MasterImpl.SPI)); Config config = config(); DefaultConversationSPI conversationSpi = MockedConversationSpi(); ConversationManager conversationManager = new ConversationManager(conversationSpi, config); when(spi.Accessible).thenReturn(true); when(spi.GetTransactionChecksum(anyLong())).thenReturn(1L); MockEmptyResponse(spi); MasterImpl master = new MasterImpl(spi, conversationManager, mock(typeof(MasterImpl.Monitor)), config); master.Start(); HandshakeResult handshake = master.Handshake(1, newStoreIdForCurrentVersion()).response(); const int noLockSession = -1; RequestContext ctx = new RequestContext(handshake.Epoch(), 1, noLockSession, 0, 0); TransactionRepresentation tx = mock(typeof(TransactionRepresentation)); // When master.Commit(ctx, tx); // Then verify(spi).applyPreparedTransaction(tx); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotAllowCommitIfThereIsNoMatchingLockSession() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotAllowCommitIfThereIsNoMatchingLockSession() { // Given MasterImpl.SPI spi = mock(typeof(MasterImpl.SPI)); DefaultConversationSPI conversationSpi = MockedConversationSpi(); Config config = config(); ConversationManager conversationManager = new ConversationManager(conversationSpi, config); when(spi.Accessible).thenReturn(true); when(spi.GetTransactionChecksum(anyLong())).thenReturn(1L); MockEmptyResponse(spi); MasterImpl master = new MasterImpl(spi, conversationManager, mock(typeof(MasterImpl.Monitor)), config); master.Start(); HandshakeResult handshake = master.Handshake(1, newStoreIdForCurrentVersion()).response(); RequestContext ctx = new RequestContext(handshake.Epoch(), 1, 2, 0, 0); // When try { master.Commit(ctx, mock(typeof(TransactionRepresentation))); fail("Should have failed."); } catch (TransactionNotPresentOnMasterException e) { // Then assertThat(e.Message, equalTo((new TransactionNotPresentOnMasterException(ctx)).Message)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void failingToStartTxShouldNotLeadToNPE() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void FailingToStartTxShouldNotLeadToNPE() { // Given MasterImpl.SPI spi = MockedSpi(); DefaultConversationSPI conversationSpi = MockedConversationSpi(); Config config = config(); ConversationManager conversationManager = new ConversationManager(conversationSpi, config); when(spi.Accessible).thenReturn(true); when(conversationSpi.AcquireClient()).thenThrow(new Exception("Nope")); when(spi.GetTransactionChecksum(anyLong())).thenReturn(1L); MockEmptyResponse(spi); MasterImpl instance = new MasterImpl(spi, conversationManager, mock(typeof(MasterImpl.Monitor)), config); instance.Start(); Response <HandshakeResult> response = instance.Handshake(1, newStoreIdForCurrentVersion()); HandshakeResult handshake = response.ResponseConflict(); // When try { instance.NewLockSession(new RequestContext(handshake.Epoch(), 1, 2, 0, 0)); fail("Should have failed."); } catch (Exception e) { // Then assertThat(e, instanceOf(typeof(Exception))); assertThat(e.Message, equalTo("Nope")); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldStartStopConversationManager() public virtual void ShouldStartStopConversationManager() { MasterImpl.SPI spi = MockedSpi(); ConversationManager conversationManager = mock(typeof(ConversationManager)); Config config = config(); MasterImpl master = new MasterImpl(spi, conversationManager, null, config); master.Start(); master.Stop(); InOrder order = inOrder(conversationManager); order.verify(conversationManager).start(); order.verify(conversationManager).stop(); verifyNoMoreInteractions(conversationManager); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void lockResultMustHaveMessageWhenAcquiringSharedLockWithoutConversation() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void LockResultMustHaveMessageWhenAcquiringSharedLockWithoutConversation() { MasterImpl.SPI spi = MockedSpi(); ConversationManager conversationManager = mock(typeof(ConversationManager)); Config config = config(); MasterImpl master = new MasterImpl(spi, conversationManager, null, config); RequestContext context = CreateRequestContext(master); when(conversationManager.Acquire(context)).thenThrow(new NoSuchEntryException("")); master.AcquireSharedLock(context, ResourceTypes.NODE, 1); ArgumentCaptor <LockResult> captor = ArgumentCaptor.forClass(typeof(LockResult)); verify(spi).packTransactionObligationResponse(MockitoHamcrest.argThat(@is(context)), captor.capture()); assertThat(captor.Value.Message, @is(not(nullValue()))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void givenStartedAndInaccessibleWhenNewLockSessionThrowException() public virtual void GivenStartedAndInaccessibleWhenNewLockSessionThrowException() { // Given MasterImpl.SPI spi = mock(typeof(MasterImpl.SPI)); Config config = config(); when(spi.Accessible).thenReturn(false); MasterImpl instance = new MasterImpl(spi, mock(typeof(ConversationManager)), mock(typeof(MasterImpl.Monitor)), config); instance.Start(); // When try { instance.NewLockSession(new RequestContext(0, 1, 2, 0, 0)); fail(); } catch (TransactionFailureException) { // Ok } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void lockResultMustHaveMessageWhenAcquiringSharedLockThrowsIllegalResource() public virtual void LockResultMustHaveMessageWhenAcquiringSharedLockThrowsIllegalResource() { MasterImpl.SPI spi = MockedSpi(); DefaultConversationSPI conversationSpi = MockedConversationSpi(); Config config = config(); ConversationManager conversationManager = new ConversationManager(conversationSpi, config); conversationManager.Start(); Locks_Client locks = mock(typeof(Locks_Client)); MasterImpl master = new MasterImpl(spi, conversationManager, null, config); RequestContext context = CreateRequestContext(master); when(conversationSpi.AcquireClient()).thenReturn(locks); ResourceTypes type = ResourceTypes.NODE; doThrow(new IllegalResourceException("")).when(locks).acquireExclusive(LockTracer.NONE, type, 1); master.AcquireSharedLock(context, type, 1); ArgumentCaptor <LockResult> captor = ArgumentCaptor.forClass(typeof(LockResult)); verify(spi).packTransactionObligationResponse(MockitoHamcrest.argThat(@is(context)), captor.capture()); assertThat(captor.Value.Message, @is(not(nullValue()))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void givenStartedAndAccessibleWhenNewLockSessionThenSucceeds() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void GivenStartedAndAccessibleWhenNewLockSessionThenSucceeds() { // Given MasterImpl.SPI spi = MockedSpi(); Config config = config(); when(spi.Accessible).thenReturn(true); when(spi.GetTransactionChecksum(anyLong())).thenReturn(1L); MasterImpl instance = new MasterImpl(spi, mock(typeof(ConversationManager)), mock(typeof(MasterImpl.Monitor)), config); instance.Start(); HandshakeResult handshake = instance.Handshake(1, newStoreIdForCurrentVersion()).response(); // When try { instance.NewLockSession(new RequestContext(handshake.Epoch(), 1, 2, 0, 0)); } catch (Exception e) { fail(e.Message); } }