示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") private org.neo4j.com.Response<IdAllocation> response(IdAllocation firstValue, IdAllocation... additionalValues)
        private Response <IdAllocation> Response(IdAllocation firstValue, params IdAllocation[] additionalValues)
        {
            Response <IdAllocation> response = mock(typeof(Response));

            when(response.ResponseConflict()).thenReturn(firstValue, additionalValues);
            return(response);
        }
示例#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));
        }
示例#3
0
 internal virtual void AskForNextRangeFromMaster()
 {
     // If we don't have anymore grabbed ids from master, grab a bunch
     try
     {
         using (Response <IdAllocation> response = Master.allocateIds(RequestContextFactory.newRequestContext(), IdType))
         {
             IdAllocation allocation = response.ResponseConflict();
             Log.info("Received id allocation " + allocation + " from master " + Master + " for " + IdType);
             StoreLocally(allocation);
         }
     }
     catch (ComException e)
     {
         throw new TransientTransactionFailureException("Cannot allocate new entity ids from the cluster master. " + "The master instance is either down, or we have network connectivity problems", e);
     }
 }
示例#4
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));
        }
示例#5
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());
            }
        }
示例#6
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);
        }
示例#7
0
 internal virtual void StoreLocally(IdAllocation allocation)
 {
     HighId = allocation.HighestIdInUse;
     this.DefragCountConflict = allocation.DefragCount;
     this.IdQueue             = allocation.IdRange.GetEnumerator();
 }