Exemplo n.º 1
0
        private void ConsecutiveAllocationFromSeparateIdGeneratorsForSameIdTypeShouldNotDuplicateForGivenInitialHighId(long initialHighId)
        {
            ISet <long> idAllocations = new HashSet <long>();
            int         idRangeLength = 8;

            FileSystemAbstraction fs = DefaultFileSystemRule.get();
            File generatorFile1      = TestDirectory.file("gen1");
            File generatorFile2      = TestDirectory.file("gen2");

            using (ReplicatedIdGenerator generatorOne = CreateForMemberWithInitialIdAndRangeLength(_memberA, initialHighId, idRangeLength, fs, generatorFile1), ReplicatedIdGenerator generatorTwo = CreateForMemberWithInitialIdAndRangeLength(_memberB, initialHighId, idRangeLength, fs, generatorFile2), )
            {
                // First iteration is bootstrapping the set, so we do it outside the loop to avoid an if check in there
                long newId = generatorOne.NextId();
                idAllocations.Add(newId);

                for (int i = 1; i < idRangeLength - initialHighId; i++)
                {
                    newId = generatorOne.NextId();
                    bool wasNew = idAllocations.Add(newId);
                    assertTrue("Id " + newId + " has already been returned", wasNew);
                    assertTrue("Detected gap in id generation, missing " + (newId - 1), idAllocations.Contains(newId - 1));
                }

                for (int i = 0; i < idRangeLength; i++)
                {
                    newId = generatorTwo.NextId();
                    bool wasNew = idAllocations.Add(newId);
                    assertTrue("Id " + newId + " has already been returned", wasNew);
                    assertTrue("Detected gap in id generation, missing " + (newId - 1), idAllocations.Contains(newId - 1));
                }
            }
        }
Exemplo n.º 2
0
        private ISet <long> CollectGeneratedIds(ReplicatedIdGenerator idGenerator, long expectedIds)
        {
            ISet <long> idsGenerated = new HashSet <long>();

            long nextId;

            for (int i = 0; i < expectedIds; i++)
            {
                nextId = idGenerator.NextId();
                assertThat(nextId, greaterThanOrEqualTo(0L));
                idsGenerated.Add(nextId);
            }

            try
            {
                idGenerator.NextId();
                fail("Too many ids produced, expected " + expectedIds);
            }
            catch (NoMoreIds)
            {
                // rock and roll!
            }

            return(idsGenerated);
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
        private IdGenerator OpenGenerator(File file, int grabSize, IdType idType, System.Func <long> highId, long maxId, bool aggressiveReuse)
        {
            ReplicatedIdGenerator other = _generators[idType];

            if (other != null)
            {
                other.Dispose();
            }
            ReplicatedIdGenerator replicatedIdGenerator = new ReplicatedIdGenerator(_fs, file, idType, highId, _idRangeAcquirer, _logProvider, grabSize, aggressiveReuse);

            _generators[idType] = replicatedIdGenerator;
            return(replicatedIdGenerator);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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());
        }
Exemplo n.º 8
0
 public override void Create(File fileName, long highId, bool throwIfFileExists)
 {
     ReplicatedIdGenerator.CreateGenerator(_fs, fileName, highId, throwIfFileExists);
 }
Exemplo n.º 9
0
        protected internal override IdGenerator OpenIdGenerator(int grabSize)
        {
            ReplicatedIdGenerator replicatedIdGenerator = GetReplicatedIdGenerator(grabSize, 0L, StubAcquirer());

            return(new FreeIdFilteredIdGenerator(replicatedIdGenerator, _idReusabilityCondition));
        }