Ejemplo n.º 1
0
        public static void AllocateRecordsFromBytes(ICollection <DynamicRecord> recordList, sbyte[] src, DynamicRecordAllocator dynamicRecordAllocator)
        {
            Debug.Assert(src != null, "Null src argument");
            DynamicRecord nextRecord = dynamicRecordAllocator.NextRecord();
            int           srcOffset  = 0;
            int           dataSize   = dynamicRecordAllocator.RecordDataSize;

            do
            {
                DynamicRecord record = nextRecord;
                record.StartRecord = srcOffset == 0;
                if (src.Length - srcOffset > dataSize)
                {
                    sbyte[] data = new sbyte[dataSize];
                    Array.Copy(src, srcOffset, data, 0, dataSize);
                    record.Data      = data;
                    nextRecord       = dynamicRecordAllocator.NextRecord();
                    record.NextBlock = nextRecord.Id;
                    srcOffset       += dataSize;
                }
                else
                {
                    sbyte[] data = new sbyte[src.Length - srcOffset];
                    Array.Copy(src, srcOffset, data, 0, data.Length);
                    record.Data      = data;
                    nextRecord       = null;
                    record.NextBlock = Record.NO_NEXT_BLOCK.intValue();
                }
                recordList.Add(record);
                Debug.Assert(record.Data != null);
            } while (nextRecord != null);
        }
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 allocateReusableRecordsAndSwitchToDefaultWhenExhausted()
        public virtual void AllocateReusableRecordsAndSwitchToDefaultWhenExhausted()
        {
            DynamicRecord          dynamicRecord1  = new DynamicRecord(1);
            DynamicRecord          dynamicRecord2  = new DynamicRecord(2);
            DynamicRecordAllocator recordAllocator = mock(typeof(DynamicRecordAllocator));

            Mockito.when(recordAllocator.NextRecord()).thenReturn(dynamicRecord2);
            ReusableRecordsCompositeAllocator compositeAllocator = new ReusableRecordsCompositeAllocator(singletonList(dynamicRecord1), recordAllocator);

            assertSame("Same as pre allocated record.", dynamicRecord1, compositeAllocator.NextRecord());
            assertSame("Same as expected allocated record.", dynamicRecord2, compositeAllocator.NextRecord());
        }