Ejemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testOffsetFileChannel() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestOffsetFileChannel()
        {
            using (JumpingFileSystemAbstraction offsetFileSystem = new JumpingFileSystemAbstraction(10))
            {
                File fileName = new File("target/var/neostore.nodestore.db");
                offsetFileSystem.DeleteFile(fileName);
                offsetFileSystem.Mkdirs(fileName.ParentFile);
                IdGenerator idGenerator = (new JumpingIdGeneratorFactory(10)).Get(IdType.NODE);

                using (JumpingFileChannel channel = ( JumpingFileChannel )offsetFileSystem.Open(fileName, OpenMode.READ_WRITE))
                {
                    for (int i = 0; i < 16; i++)
                    {
                        WriteSomethingLikeNodeRecord(channel, idGenerator.NextId(), i);
                    }
                }
                using (JumpingFileChannel channel = ( JumpingFileChannel )offsetFileSystem.Open(fileName, OpenMode.READ_WRITE))
                {
                    idGenerator = (new JumpingIdGeneratorFactory(10)).Get(IdType.NODE);

                    for (int i = 0; i < 16; i++)
                    {
                        assertEquals(i, ReadSomethingLikeNodeRecord(channel, idGenerator.NextId()));
                    }
                }
            }
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void slaveIdGeneratorShouldAskForMoreWhenRangeIsOver()
        public virtual void SlaveIdGeneratorShouldAskForMoreWhenRangeIsOver()
        {
            // GIVEN
            IdAllocation            firstResult  = new IdAllocation(new IdRange(new long[] {}, 42, 123), 42 + 123, 0);
            IdAllocation            secondResult = new IdAllocation(new IdRange(new long[] {}, 1042, 223), 1042 + 223, 0);
            Response <IdAllocation> response     = response(firstResult, secondResult);

            when(_master.allocateIds(Null, any(typeof(IdType)))).thenReturn(response);

            // WHEN
            IdGenerator gen = SwitchToSlave();

            // THEN
            long startAt     = firstResult.IdRange.RangeStart;
            long forThatMany = firstResult.IdRange.RangeLength;

            for (long i = startAt; i < startAt + forThatMany; i++)
            {
                assertEquals(i, gen.NextId());
            }
            verify(_master, times(1)).allocateIds(Null, eq(IdType.NODE));

            startAt     = secondResult.IdRange.RangeStart;
            forThatMany = secondResult.IdRange.RangeLength;
            for (long i = startAt; i < startAt + forThatMany; i++)
            {
                assertEquals(i, gen.NextId());
            }

            verify(_master, times(2)).allocateIds(Null, eq(IdType.NODE));
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testIt()
        public virtual void TestIt()
        {
            int sizePerJump              = 1000;
            IdGeneratorFactory factory   = new JumpingIdGeneratorFactory(sizePerJump);
            IdGenerator        generator = factory.Get(IdType.NODE);

            for (int i = 0; i < sizePerJump / 2; i++)
            {
                assertEquals(i, generator.NextId());
            }

            for (int i = 0; i < sizePerJump - 1; i++)
            {
                long expected = 0x100000000L - sizePerJump / 2 + i;
                if (expected >= 0xFFFFFFFFL)
                {
                    expected++;
                }
                assertEquals(expected, generator.NextId());
            }

            for (int i = 0; i < sizePerJump; i++)
            {
                assertEquals(0x200000000L - sizePerJump / 2 + i, generator.NextId());
            }

            for (int i = 0; i < sizePerJump; i++)
            {
                assertEquals(0x300000000L - sizePerJump / 2 + i, generator.NextId());
            }
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = org.neo4j.graphdb.TransientTransactionFailureException.class) public void shouldTranslateComExceptionsIntoTransientTransactionFailures()
        public virtual void ShouldTranslateComExceptionsIntoTransientTransactionFailures()
        {
            when(_master.allocateIds(Null, any(typeof(IdType)))).thenThrow(new ComException());
            IdGenerator generator = SwitchToSlave();

            generator.NextId();
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReportCorrectHighId()
        public virtual void ShouldReportCorrectHighId()
        {
            // given
            using (IdGenerator idGenerator = CreateIdGenerator(2))
            {
                assertEquals(0, idGenerator.HighId);
                assertEquals(-1, idGenerator.HighestPossibleIdInUse);

                // when
                idGenerator.NextId();

                // then
                assertEquals(1, idGenerator.HighId);
                assertEquals(0, idGenerator.HighestPossibleIdInUse);
            }
        }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void slaveIdGeneratorShouldReturnFromAssignedRange()
        public virtual void SlaveIdGeneratorShouldReturnFromAssignedRange()
        {
            // GIVEN
            IdAllocation            firstResult = new IdAllocation(new IdRange(new long[] {}, 42, 123), 123, 0);
            Response <IdAllocation> response    = response(firstResult);

            when(_master.allocateIds(Null, any(typeof(IdType)))).thenReturn(response);

            // WHEN
            IdGenerator gen = SwitchToSlave();

            // THEN
            for (long i = firstResult.IdRange.RangeStart; i < firstResult.IdRange.RangeLength; i++)
            {
                assertEquals(i, gen.NextId());
            }
            verify(_master, times(1)).allocateIds(Null, eq(IdType.NODE));
        }
Ejemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldMoveFromDefraggedToRange()
        public virtual void ShouldMoveFromDefraggedToRange()
        {
            // GIVEN
            long[]                  defragIds   = new long[] { 42, 27172828, 314159 };
            IdAllocation            firstResult = new IdAllocation(new IdRange(defragIds, 0, 10), 100, defragIds.Length);
            Response <IdAllocation> response    = response(firstResult);

            when(_master.allocateIds(Null, any(typeof(IdType)))).thenReturn(response);

            // WHEN
            IdGenerator gen = SwitchToSlave();

            // THEN
            foreach (long defragId in defragIds)
            {
                assertEquals(defragId, gen.NextId());
            }
        }
Ejemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void slaveShouldNeverAllowReducingHighId()
        public virtual void SlaveShouldNeverAllowReducingHighId()
        {
            // GIVEN
            const int               highIdFromAllocation = 123;
            IdAllocation            firstResult          = new IdAllocation(new IdRange(new long[] {}, 42, highIdFromAllocation), highIdFromAllocation, 0);
            Response <IdAllocation> response             = response(firstResult);

            when(_master.allocateIds(Null, any(typeof(IdType)))).thenReturn(response);

            // WHEN
            IdGenerator gen = SwitchToSlave();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int highIdFromUpdatedRecord = highIdFromAllocation + 1;
            int highIdFromUpdatedRecord = highIdFromAllocation + 1;

            gen.HighId = highIdFromUpdatedRecord; // Assume this is from a received transaction
            gen.NextId();                         // that will ask the master for an IdRange

            // THEN
            assertEquals(highIdFromUpdatedRecord, gen.HighId);
        }