//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 shouldStopLockSessionOnFailureWhereThereIsAnActiveLockAcquisition() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldStopLockSessionOnFailureWhereThereIsAnActiveLockAcquisition() { // GIVEN System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1); try { Locks_Client client = NewWaitingLocksClient(latch); MasterImpl master = NewMasterWithLocksClient(client); HandshakeResult handshake = master.Handshake(1, newStoreIdForCurrentVersion()).response(); // WHEN RequestContext context = new RequestContext(handshake.Epoch(), 1, 2, 0, 0); master.NewLockSession(context); Future <Void> acquireFuture = OtherThread.execute(state => { master.AcquireExclusiveLock(context, ResourceTypes.NODE, 1L); return(null); }); OtherThread.get().waitUntilWaiting(); master.EndLockSession(context, false); verify(client).stop(); verify(client, never()).close(); latch.Signal(); acquireFuture.get(); // THEN verify(client).close(); } finally { latch.Signal(); } }
//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 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); } }
protected internal virtual RequestContext CreateRequestContext(MasterImpl master) { HandshakeResult handshake = master.Handshake(1, newStoreIdForCurrentVersion()).response(); return(new RequestContext(handshake.Epoch(), 1, 2, 0, 0)); }