Package org.apache.flink.core.memory

Examples of org.apache.flink.core.memory.MemorySegment


      Set<DefaultMemorySegment> segsForOwner = null;

      // go over all segments
      while (segmentsIterator.hasNext()) {
       
        final MemorySegment seg = segmentsIterator.next();
        if (seg.isFreed()) {
          continue;
        }
       
        final DefaultMemorySegment defSeg = (DefaultMemorySegment) seg;
        final AbstractInvokable owner = defSeg.owner;
View Full Code Here


    Envelope env = new Envelope(random.nextInt(), new JobID(), new ChannelID());
    if (bufferSize > 0) {
      byte[] data = new byte[bufferSize];
      random.nextBytes(data);

      env.setBuffer(spy(new Buffer(new MemorySegment(data), bufferSize, RECYCLER)));
    }

    if (events != null && events.length > 0) {
      env.serializeEventList(Arrays.asList(events));
    }
View Full Code Here

  @Test
  public void testWrapAsByteBuffer() {
    SerializationTestType randomInt = Util.randomRecord(SerializationTestTypeFactory.INT);

    DataOutputSerializer serializer = new DataOutputSerializer(randomInt.length());
    MemorySegment segment = new MemorySegment(new byte[randomInt.length()]);

    try {
      // empty buffer, read buffer should be empty
      ByteBuffer wrapper = serializer.wrapAsByteBuffer();

      Assert.assertEquals(0, wrapper.position());
      Assert.assertEquals(0, wrapper.limit());

      // write to data output, read buffer should still be empty
      randomInt.write(serializer);

      Assert.assertEquals(0, wrapper.position());
      Assert.assertEquals(0, wrapper.limit());

      // get updated read buffer, read buffer should contain written data
      wrapper = serializer.wrapAsByteBuffer();

      Assert.assertEquals(0, wrapper.position());
      Assert.assertEquals(randomInt.length(), wrapper.limit());

      // clear data output, read buffer should still contain written data
      serializer.clear();

      Assert.assertEquals(0, wrapper.position());
      Assert.assertEquals(randomInt.length(), wrapper.limit());

      // get updated read buffer, should be empty
      wrapper = serializer.wrapAsByteBuffer();

      Assert.assertEquals(0, wrapper.position());
      Assert.assertEquals(0, wrapper.limit());

      // write to data output and read back to memory
      randomInt.write(serializer);
      wrapper = serializer.wrapAsByteBuffer();

      segment.put(0, wrapper, randomInt.length());

      Assert.assertEquals(randomInt.length(), wrapper.position());
      Assert.assertEquals(randomInt.length(), wrapper.limit());
    } catch (IOException e) {
      e.printStackTrace();
View Full Code Here

    private final List<SegmentWithPosition> segments = new ArrayList<SegmentWithPosition>();

    private final int segmentSize;

    private TestOutputView(int segmentSize) {
      super(new MemorySegment(new byte[segmentSize]), segmentSize, 0);

      this.segmentSize = segmentSize;
    }
View Full Code Here

    }

    @Override
    protected MemorySegment nextSegment(MemorySegment current, int positionInCurrent) throws IOException {
      segments.add(new SegmentWithPosition(current, positionInCurrent));
      return new MemorySegment(new byte[segmentSize]);
    }
View Full Code Here

  @Test
  public void testHasData() {
    final int SEGMENT_SIZE = 16;

    final SpanningRecordSerializer<SerializationTestType> serializer = new SpanningRecordSerializer<SerializationTestType>();
    final Buffer buffer = new Buffer(new MemorySegment(new byte[SEGMENT_SIZE]), SEGMENT_SIZE, null);
    final SerializationTestType randomIntRecord = Util.randomRecord(SerializationTestTypeFactory.INT);

    Assert.assertFalse(serializer.hasData());

    try {
View Full Code Here

  @Test
  public void testEmptyRecords() {
    final int SEGMENT_SIZE = 11;

    final SpanningRecordSerializer<SerializationTestType> serializer = new SpanningRecordSerializer<SerializationTestType>();
    final Buffer buffer = new Buffer(new MemorySegment(new byte[SEGMENT_SIZE]), SEGMENT_SIZE, null);

    try {
      Assert.assertEquals(SerializationResult.FULL_RECORD, serializer.setNextBuffer(buffer));
    } catch (IOException e) {
      e.printStackTrace();
View Full Code Here

   */
  private void test(Util.MockRecords records, int segmentSize) throws Exception {
    final int SERIALIZATION_OVERHEAD = 4; // length encoding

    final SpanningRecordSerializer<SerializationTestType> serializer = new SpanningRecordSerializer<SerializationTestType>();
    final Buffer buffer = new Buffer(new MemorySegment(new byte[segmentSize]), segmentSize, null);

    // -------------------------------------------------------------------------------------------------------------

    serializer.setNextBuffer(buffer);

View Full Code Here

  private static final int MAX_BUFFER_SIZE = 32768;

  @Test
  public void testEncodedSizeAndBufferRecycling() {
    final ByteBuffer events = ByteBuffer.allocate(MAX_EVENTS_SIZE);
    final MemorySegment segment = new MemorySegment(new byte[MAX_BUFFER_SIZE]);

    final Buffer buffer = mock(Buffer.class);
    when(buffer.getMemorySegment()).thenReturn(segment);

    final EmbeddedChannel channel = new EmbeddedChannel(new OutboundEnvelopeEncoder());
View Full Code Here

    final int SERIALIZATION_OVERHEAD = 4; // length encoding

    final RecordSerializer<SerializationTestType> serializer = new SpanningRecordSerializer<SerializationTestType>();
    final RecordDeserializer<SerializationTestType> deserializer = new AdaptiveSpanningRecordDeserializer<SerializationTestType>();

    final Buffer buffer = new Buffer(new MemorySegment(new byte[segmentSize]), segmentSize, null);

    final ArrayDeque<SerializationTestType> serializedRecords = new ArrayDeque<SerializationTestType>();

    // -------------------------------------------------------------------------------------------------------------
View Full Code Here

TOP

Related Classes of org.apache.flink.core.memory.MemorySegment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.