コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIgnoreNotContiguousRequestAndAlreadySeenIndex()
        public virtual void ShouldIgnoreNotContiguousRequestAndAlreadySeenIndex()
        {
            ReplicatedIdAllocationStateMachine stateMachine = new ReplicatedIdAllocationStateMachine(new InMemoryStateStorage <IdAllocationState>(new IdAllocationState()));

            stateMachine.ApplyCommand(new ReplicatedIdAllocationRequest(_me, _someType, 0L, 10), 0L, r =>
            {
            });
            assertEquals(10L, stateMachine.FirstUnallocated(_someType));

            // apply command that doesn't consume ids because the requested range is non-contiguous
            stateMachine.ApplyCommand(new ReplicatedIdAllocationRequest(_me, _someType, 20L, 10), 1L, r =>
            {
            });
            assertEquals(10L, stateMachine.FirstUnallocated(_someType));

            stateMachine.ApplyCommand(new ReplicatedIdAllocationRequest(_me, _someType, 10L, 10), 2L, r =>
            {
            });
            assertEquals(20L, stateMachine.FirstUnallocated(_someType));

            // try applying the same command again. The requested range is now contiguous, but the log index
            // has already been exceeded
            stateMachine.ApplyCommand(new ReplicatedIdAllocationRequest(_me, _someType, 20L, 10), 1L, r =>
            {
            });
            assertEquals(20L, stateMachine.FirstUnallocated(_someType));
        }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotHaveAnyIdsInitially()
        public virtual void ShouldNotHaveAnyIdsInitially()
        {
            // given
            ReplicatedIdAllocationStateMachine stateMachine = new ReplicatedIdAllocationStateMachine(new InMemoryStateStorage <IdAllocationState>(new IdAllocationState()));

            // then
            assertEquals(0, stateMachine.FirstUnallocated(_someType));
        }
コード例 #3
0
 public ReplicatedIdRangeAcquirer(Replicator replicator, ReplicatedIdAllocationStateMachine idAllocationStateMachine, IDictionary <IdType, int> allocationSizes, MemberId me, LogProvider logProvider)
 {
     this._replicator = replicator;
     this._idAllocationStateMachine = idAllocationStateMachine;
     this._allocationSizes          = allocationSizes;
     this._me  = me;
     this._log = logProvider.getLog(this.GetType());
 }
コード例 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldUpdateStateOnlyForTypeRequested()
        public virtual void ShouldUpdateStateOnlyForTypeRequested()
        {
            // given
            ReplicatedIdAllocationStateMachine stateMachine        = new ReplicatedIdAllocationStateMachine(new InMemoryStateStorage <IdAllocationState>(new IdAllocationState()));
            ReplicatedIdAllocationRequest      idAllocationRequest = new ReplicatedIdAllocationRequest(_me, _someType, 0, 1024);

            // when
            stateMachine.ApplyCommand(idAllocationRequest, 0, r =>
            {
            });

            // then
            assertEquals(1024, stateMachine.FirstUnallocated(_someType));
            assertEquals(0, stateMachine.FirstUnallocated(_someOtherType));
        }
コード例 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void outOfOrderRequestShouldBeIgnored()
        public virtual void OutOfOrderRequestShouldBeIgnored()
        {
            // given
            ReplicatedIdAllocationStateMachine stateMachine = new ReplicatedIdAllocationStateMachine(new InMemoryStateStorage <IdAllocationState>(new IdAllocationState()));

            // when
            stateMachine.ApplyCommand(new ReplicatedIdAllocationRequest(_me, _someType, 0, 1024), 0, r =>
            {
            });
            // apply command that doesn't consume ids because the requested range is non-contiguous
            stateMachine.ApplyCommand(new ReplicatedIdAllocationRequest(_me, _someType, 2048, 1024), 0, r =>
            {
            });

            // then
            assertEquals(1024, stateMachine.FirstUnallocated(_someType));
        }
コード例 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void severalEqualRequestsShouldOnlyUpdateOnce()
        public virtual void SeveralEqualRequestsShouldOnlyUpdateOnce()
        {
            // given
            ReplicatedIdAllocationStateMachine stateMachine = new ReplicatedIdAllocationStateMachine(new InMemoryStateStorage <IdAllocationState>(new IdAllocationState()));

            // when
            stateMachine.ApplyCommand(new ReplicatedIdAllocationRequest(_me, _someType, 0, 1024), 0, r =>
            {
            });
            stateMachine.ApplyCommand(new ReplicatedIdAllocationRequest(_me, _someType, 0, 1024), 0, r =>
            {
            });
            stateMachine.ApplyCommand(new ReplicatedIdAllocationRequest(_me, _someType, 0, 1024), 0, r =>
            {
            });

            // then
            assertEquals(1024, stateMachine.FirstUnallocated(_someType));
        }
コード例 #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void severalDistinctRequestsShouldIncrementallyUpdate()
        public virtual void SeveralDistinctRequestsShouldIncrementallyUpdate()
        {
            // given
            ReplicatedIdAllocationStateMachine stateMachine = new ReplicatedIdAllocationStateMachine(new InMemoryStateStorage <IdAllocationState>(new IdAllocationState()));
            long index = 0;

            // when
            stateMachine.ApplyCommand(new ReplicatedIdAllocationRequest(_me, _someType, 0, 1024), index++, r =>
            {
            });
            stateMachine.ApplyCommand(new ReplicatedIdAllocationRequest(_me, _someType, 1024, 1024), index++, r =>
            {
            });
            stateMachine.ApplyCommand(new ReplicatedIdAllocationRequest(_me, _someType, 2048, 1024), index, r =>
            {
            });

            // then
            assertEquals(3072, stateMachine.FirstUnallocated(_someType));
        }