Package org.apache.flink.runtime.io.network

Examples of org.apache.flink.runtime.io.network.Buffer


    // 2. failure: buffer is available
    // --------------------------------------------------------------------
    registration = bufferPool.registerBufferAvailabilityListener(listener);
    Assert.assertEquals(BufferAvailabilityRegistration.FAILED_BUFFER_AVAILABLE, registration);

    Buffer buffer = bufferPool.requestBuffer(BUFFER_SIZE);
    Assert.assertNotNull(buffer);

    buffer.recycleBuffer();

    // --------------------------------------------------------------------
    // 3. failure: buffer pool destroyed
    // --------------------------------------------------------------------
    bufferPool.destroy();
View Full Code Here


    ByteBuf buf = encode(ch, envelopes);

    when(this.bufferProvider.registerBufferAvailabilityListener(Matchers.<BufferAvailabilityListener>anyObject()))
        .thenReturn(BufferAvailabilityRegistration.SUCCEEDED_REGISTERED);

    Buffer buffer = allocBuffer(envelopes[2].getBuffer().size());

    when(this.bufferProvider.requestBuffer(anyInt()))
        .thenReturn(null, null, buffer, null);

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

  private static Buffer allocBuffer() {
    return allocBuffer(MAX_BUFFER_SIZE);
  }

  private static Buffer allocBuffer(int bufferSize) {
    return spy(new Buffer(new MemorySegment(new byte[bufferSize]), bufferSize, RECYCLER));
  }
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

  private static class RecyclingBufferAvailableAnswer implements Answer<Void> {

    @Override
    public Void answer(InvocationOnMock invocation) throws Throwable {
      Buffer buffer = (Buffer) invocation.getArguments()[0];
      buffer.recycleBuffer();

      return null;
    }
View Full Code Here

    }

    @Override
    public Buffer answer(InvocationOnMock invocation) throws Throwable {
      if (this.forced) {
        Buffer toReturn = allocBuffer((Integer) invocation.getArguments()[0]);
        this.forced = false;

        return toReturn;
      }
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

  @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());

    int numBuffers = 0;
    for (int i = 0; i < NUM_RANDOM_ENVELOPES; i++) {
      Envelope env = new Envelope(i, new JobID(), new ChannelID());
      int expectedEncodedMsgSize = OutboundEnvelopeEncoder.HEADER_SIZE;

      if (random.nextBoolean()) {
        int eventsSize = random.nextInt(MAX_EVENTS_SIZE + 1);
        expectedEncodedMsgSize += eventsSize;

        events.clear();
        events.limit(eventsSize);

        env.setEventsSerialized(events);
      }

      if (random.nextBoolean()) {
        numBuffers++;

        int bufferSize = random.nextInt(MAX_BUFFER_SIZE + 1);
        when(buffer.size()).thenReturn(bufferSize);
        env.setBuffer(buffer);

        expectedEncodedMsgSize += bufferSize;
      }
View Full Code Here

TOP

Related Classes of org.apache.flink.runtime.io.network.Buffer

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.