Example #1
0
//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));
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleRandomizedLoad() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleRandomizedLoad()
        {
            // Given
            DefaultConversationSPI conversationSPI = new DefaultConversationSPI(_locks, _scheduler);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ExposedConversationManager conversationManager = new ExposedConversationManager(conversationSPI, config, 100, 0);
            ExposedConversationManager conversationManager = new ExposedConversationManager(this, conversationSPI, _config, 100, 0);

            ConversationTestMasterSPI conversationTestMasterSPI = new ConversationTestMasterSPI();
            MasterImpl master = new MasterImpl(conversationTestMasterSPI, conversationManager, (new Monitors()).newMonitor(typeof(MasterImpl.Monitor)), _config);

            _life.add(conversationManager);
            _life.start();

            ConversationKiller conversationKiller = new ConversationKiller(conversationManager);

            _executor.submit(conversationKiller);
            IList <Callable <Void> > slaveWorkers = Workers(master, NUMBER_OF_WORKERS);
            IList <Future <Void> >   workers      = _executor.invokeAll(slaveWorkers);

            // Wait for all workers to complete
            foreach (Future <Void> future in workers)
            {
                future.get();
            }
            conversationKiller.Stop();

            assertTrue(_executionStatistic.SuccessfulExecution);
        }
Example #3
0
//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));
            }
        }
Example #4
0
//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);
        }
Example #5
0
//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();
            }
        }
Example #6
0
//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"));
            }
        }
Example #7
0
        private IList <Callable <Void> > Workers(MasterImpl master, int numWorkers)
        {
            LinkedList <Callable <Void> > workers = new LinkedList <Callable <Void> >();

            for (int i = 0; i < numWorkers; i++)
            {
                workers.AddLast(new SlaveEmulatorWorker(master, i));
            }
            return(workers);
        }
Example #8
0
        private MasterImpl NewMasterWithLocksClient(Locks_Client client)
        {
            SPI spi = MockedSpi();
            DefaultConversationSPI conversationSpi = MockedConversationSpi();

            when(spi.Accessible).thenReturn(true);
            when(conversationSpi.AcquireClient()).thenReturn(client);
            Config config = config();
            ConversationManager conversationManager = new ConversationManager(conversationSpi, config);

            MasterImpl master = new MasterImpl(spi, conversationManager, mock(typeof(Monitor)), config);

            master.Start();
            return(master);
        }
Example #9
0
//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);
        }
Example #10
0
//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())));
        }
Example #11
0
//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
            }
        }
Example #12
0
//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())));
        }
Example #13
0
//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);
            }
        }
Example #14
0
 internal SlaveEmulatorWorker(MasterImpl master, int clientNumber)
 {
     this.MachineId = clientNumber;
     this.Random    = new Random(MachineId);
     this.Master    = master;
 }
Example #15
0
        protected internal virtual RequestContext CreateRequestContext(MasterImpl master)
        {
            HandshakeResult handshake = master.Handshake(1, newStoreIdForCurrentVersion()).response();

            return(new RequestContext(handshake.Epoch(), 1, 2, 0, 0));
        }