Пример #1
0
        private ReplicatedIdGenerator CreateForMemberWithInitialIdAndRangeLength(MemberId member, long initialHighId, int idRangeLength, FileSystemAbstraction fs, File file)
        {
            IDictionary <IdType, int> allocationSizes = java.util.Enum.GetValues(typeof(IdType)).ToDictionary(idType => idType, idType => idRangeLength);
            ReplicatedIdRangeAcquirer acquirer        = new ReplicatedIdRangeAcquirer(_replicator, _idAllocationStateMachine, allocationSizes, member, NullLogProvider.Instance);

            return(new ReplicatedIdGenerator(fs, file, IdType.ARRAY_BLOCK, () => initialHighId, acquirer, NullLogProvider.Instance, 10, true));
        }
Пример #2
0
 public ReplicatedIdGeneratorFactory(FileSystemAbstraction fs, ReplicatedIdRangeAcquirer idRangeAcquirer, LogProvider logProvider, IdTypeConfigurationProvider idTypeConfigurationProvider)
 {
     this._fs = fs;
     this._idRangeAcquirer             = idRangeAcquirer;
     this._logProvider                 = logProvider;
     this._idTypeConfigurationProvider = idTypeConfigurationProvider;
 }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void freeIdOnlyWhenReusabilityConditionAllows()
        public virtual void FreeIdOnlyWhenReusabilityConditionAllows()
        {
            ReplicatedIdRangeAcquirer rangeAcquirer = SimpleRangeAcquirer(IdType.NODE, 0, 1024);

            IdReusabilityCondition idReusabilityCondition = IdReusabilityCondition;

            long burnedIds = 23L;

            using (FreeIdFilteredIdGenerator idGenerator = new FreeIdFilteredIdGenerator(GetReplicatedIdGenerator(10, burnedIds, rangeAcquirer), idReusabilityCondition))
            {
                idGenerator.FreeId(10);
                assertEquals(0, idGenerator.DefragCount);
                assertEquals(23, idGenerator.NextId());

                when(_commandIndexTracker.AppliedCommandIndex).thenReturn(4L, 6L);                             // gap-free
                when(_state.lastLogIndexBeforeWeBecameLeader()).thenReturn(5L);
                idReusabilityCondition.OnLeaderSwitch(new LeaderInfo(_myself, 1));

                assertEquals(24, idGenerator.NextId());
                idGenerator.FreeId(11);
                assertEquals(25, idGenerator.NextId());
                idGenerator.FreeId(6);
                assertEquals(6, idGenerator.NextId());
            }
        }
Пример #4
0
        private ReplicatedIdRangeAcquirer SimpleRangeAcquirer(IdType idType, long start, int length)
        {
            ReplicatedIdRangeAcquirer rangeAcquirer = mock(typeof(ReplicatedIdRangeAcquirer));

            //noinspection unchecked
            when(rangeAcquirer.AcquireIds(idType)).thenReturn(Allocation(start, length, -1)).thenThrow(typeof(NoMoreIds));
            return(rangeAcquirer);
        }
Пример #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateIdFileForPersistence()
        public virtual void ShouldCreateIdFileForPersistence()
        {
            ReplicatedIdRangeAcquirer rangeAcquirer = SimpleRangeAcquirer(IdType.NODE, 0, 1024);

            _idGenerator = GetReplicatedIdGenerator(10, 0L, rangeAcquirer);

            assertTrue(_fs.fileExists(_file));
        }
Пример #6
0
        private ReplicatedIdRangeAcquirer StubAcquirer()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ReplicatedIdRangeAcquirer rangeAcquirer = mock(ReplicatedIdRangeAcquirer.class);
            ReplicatedIdRangeAcquirer rangeAcquirer = mock(typeof(ReplicatedIdRangeAcquirer));

            when(rangeAcquirer.AcquireIds(IdType.NODE)).thenReturn(Allocation(0, 1024, -1)).thenReturn(Allocation(1024, 1024, 1023)).thenReturn(Allocation(2048, 1024, 2047)).thenReturn(Allocation(3072, 1024, 3071)).thenReturn(Allocation(4096, 1024, 4095)).thenReturn(Allocation(5120, 1024, 5119)).thenReturn(Allocation(6144, 1024, 6143)).thenReturn(Allocation(7168, 1024, 7167)).thenReturn(Allocation(8192, 1024, 8191)).thenReturn(Allocation(9216, 1024, 9215)).thenReturn(Allocation(-1, 0, 9216 + 1024));
            return(rangeAcquirer);
        }
Пример #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = IllegalStateException.class) public void shouldThrowIfAdjustmentFailsDueToInconsistentValues()
        public virtual void ShouldThrowIfAdjustmentFailsDueToInconsistentValues()
        {
            ReplicatedIdRangeAcquirer rangeAcquirer = mock(typeof(ReplicatedIdRangeAcquirer));

            when(rangeAcquirer.AcquireIds(IdType.NODE)).thenReturn(Allocation(3, 21, 21));
            _idGenerator = GetReplicatedIdGenerator(10, 42L, rangeAcquirer);

            _idGenerator.nextId();
        }
Пример #8
0
 internal ReplicatedIdGenerator(FileSystemAbstraction fs, File file, IdType idType, System.Func <long> highId, ReplicatedIdRangeAcquirer acquirer, LogProvider logProvider, int grabSize, bool aggressiveReuse)
 {
     this._idType   = idType;
     this._highId   = highId();
     this._acquirer = acquirer;
     this._log      = logProvider.getLog(this.GetType());
     _idContainer   = new IdContainer(fs, file, grabSize, aggressiveReuse);
     _idContainer.init();
 }
Пример #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotStepBeyondAllocationBoundaryWithoutBurnedId()
        public virtual void ShouldNotStepBeyondAllocationBoundaryWithoutBurnedId()
        {
            ReplicatedIdRangeAcquirer rangeAcquirer = SimpleRangeAcquirer(IdType.NODE, 0, 1024);

            _idGenerator = GetReplicatedIdGenerator(10, 0L, rangeAcquirer);

            ISet <long> idsGenerated = CollectGeneratedIds(_idGenerator, 1024);

            long minId = min(idsGenerated);
            long maxId = max(idsGenerated);

            assertEquals(0L, minId);
            assertEquals(1023L, maxId);
        }
Пример #10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReuseIdBeforeHighId()
        public virtual void ShouldReuseIdBeforeHighId()
        {
            ReplicatedIdRangeAcquirer rangeAcquirer = SimpleRangeAcquirer(IdType.NODE, 0, 1024);

            long burnedIds = 23L;

            _idGenerator = GetReplicatedIdGenerator(10, burnedIds, rangeAcquirer);

            assertEquals(23, _idGenerator.nextId());

            _idGenerator.freeId(10);
            _idGenerator.freeId(5);

            assertEquals(10, _idGenerator.nextId());
            assertEquals(5, _idGenerator.nextId());
            assertEquals(24, _idGenerator.nextId());
        }
Пример #11
0
 private ReplicatedIdGenerator GetReplicatedIdGenerator(int grabSize, long l, ReplicatedIdRangeAcquirer replicatedIdRangeAcquirer)
 {
     return(new ReplicatedIdGenerator(_fs, _file, IdType.NODE, () => l, replicatedIdRangeAcquirer, _logProvider, grabSize, true));
 }