Examples of InboundEnvelopeDecoder


Examples of org.apache.flink.runtime.io.network.netty.InboundEnvelopeDecoder

    MockitoAnnotations.initMocks(this);
  }

  @Test
  public void testBufferStaging() throws Exception {
    final InboundEnvelopeDecoder decoder = new InboundEnvelopeDecoder(this.bufferProviderBroker);
    final EmbeddedChannel ch = new EmbeddedChannel(
        new OutboundEnvelopeEncoder(),
        decoder);

    when(this.bufferProviderBroker.getBufferProvider(anyJobId(), anyChannelId()))
        .thenReturn(this.bufferProvider);

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

    Envelope[] envelopes = nextEnvelopes(3, true);

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

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

    // slices: [0] => full envelope, [1] => half envelope, [2] => remaining half + full envelope
    ByteBuf[] slices = slice(buf,
        OutboundEnvelopeEncoder.HEADER_SIZE + envelopes[0].getBuffer().size(),
        OutboundEnvelopeEncoder.HEADER_SIZE + envelopes[1].getBuffer().size() / 2);

    // 1. no buffer available, incoming slice contains all data
    int refCount = slices[0].refCnt();

    decodeAndVerify(ch, slices[0]);

    Assert.assertEquals(refCount + 1, slices[0].refCnt());
    Assert.assertFalse(ch.config().isAutoRead());

    // notify of available buffer (=> bufferAvailable() callback does return a buffer
    // of the current network buffer size; the decoder needs to adjust its size to the
    // requested size
    decoder.bufferAvailable(allocBuffer(envelopes[0].getBuffer().size() * 2));
    ch.runPendingTasks();

    Assert.assertEquals(refCount - 1, slices[0].refCnt());
    Assert.assertTrue(ch.config().isAutoRead());

    decodeAndVerify(ch, envelopes[0]);

    // 2. no buffer available, incoming slice does NOT contain all data
    refCount = slices[1].refCnt();

    decodeAndVerify(ch, slices[1]);

    Assert.assertEquals(refCount + 1, slices[1].refCnt());
    Assert.assertFalse(ch.config().isAutoRead());

    decoder.bufferAvailable(allocBuffer());
    ch.runPendingTasks();

    Assert.assertEquals(refCount - 1, slices[1].refCnt());
    Assert.assertTrue(ch.config().isAutoRead());

View Full Code Here

Examples of org.apache.flink.runtime.io.network.netty.InboundEnvelopeDecoder

  @Test
  public void testBufferStagingStagedBufferException() throws Exception {
    final EmbeddedChannel ch = new EmbeddedChannel(
        new OutboundEnvelopeEncoder(),
        new InboundEnvelopeDecoder(this.bufferProviderBroker));

    when(this.bufferProviderBroker.getBufferProvider(anyJobId(), anyChannelId()))
        .thenReturn(this.bufferProvider);

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

Examples of org.apache.flink.runtime.io.network.netty.InboundEnvelopeDecoder

  @Test
  public void testBufferAvailabilityRegistrationBufferAvailable() throws Exception {
    final EmbeddedChannel ch = new EmbeddedChannel(
        new OutboundEnvelopeEncoder(),
        new InboundEnvelopeDecoder(this.bufferProviderBroker));

    when(this.bufferProviderBroker.getBufferProvider(anyJobId(), anyChannelId()))
        .thenReturn(this.bufferProvider);

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

Examples of org.apache.flink.runtime.io.network.netty.InboundEnvelopeDecoder

  @Test
  public void testBufferAvailabilityRegistrationBufferPoolDestroyedSkipBytes() throws Exception {
    final EmbeddedChannel ch = new EmbeddedChannel(
        new OutboundEnvelopeEncoder(),
        new InboundEnvelopeDecoder(this.bufferProviderBroker));

    when(this.bufferProviderBroker.getBufferProvider(anyJobId(), anyChannelId()))
        .thenReturn(this.bufferProvider);

    when(this.bufferProvider.requestBuffer(anyInt()))
View Full Code Here

Examples of org.apache.flink.runtime.io.network.netty.InboundEnvelopeDecoder

  }

  @Test
  public void testEncodeDecode() throws Exception {
    final EmbeddedChannel ch = new EmbeddedChannel(
        new OutboundEnvelopeEncoder(), new InboundEnvelopeDecoder(this.bufferProviderBroker));

    when(this.bufferProviderBroker.getBufferProvider(anyJobId(), anyChannelId()))
        .thenReturn(this.bufferProvider);

    when(this.bufferProvider.requestBuffer(anyInt())).thenAnswer(new Answer<Object>() {
View Full Code Here

Examples of org.apache.flink.runtime.io.network.netty.InboundEnvelopeDecoder

    buf.release();
  }

  @Test
  public void testEncodeDecodeRandomEnvelopes() throws Exception {
    final InboundEnvelopeDecoder decoder = new InboundEnvelopeDecoder(this.bufferProviderBroker);
    final EmbeddedChannel ch = new EmbeddedChannel(
        new OutboundEnvelopeEncoder(), decoder);

    when(this.bufferProviderBroker.getBufferProvider(anyJobId(), anyChannelId()))
        .thenReturn(this.bufferProvider);

    when(this.bufferProvider.requestBuffer(anyInt())).thenAnswer(new Answer<Object>() {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable {
        // fulfill the buffer request with the requested size
        return allocBuffer((Integer) invocation.getArguments()[0]);
      }
    });

    Random randomAnswerSource = new Random(RANDOM_SEED);

    RandomBufferRequestAnswer randomBufferRequestAnswer = new RandomBufferRequestAnswer(randomAnswerSource);

    RandomBufferAvailabilityRegistrationAnswer randomBufferAvailabilityRegistrationAnswer =
        new RandomBufferAvailabilityRegistrationAnswer(randomAnswerSource, randomBufferRequestAnswer);

    when(this.bufferProvider.requestBuffer(anyInt())).thenAnswer(randomBufferRequestAnswer);

    when(this.bufferProvider.registerBufferAvailabilityListener(Matchers.<BufferAvailabilityListener>anyObject()))
        .thenAnswer(randomBufferAvailabilityRegistrationAnswer);

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

    Envelope[] envelopes = nextRandomEnvelopes(1024);

    ByteBuf buf = encode(ch, envelopes);

    ByteBuf[] slices = randomSlices(buf);

    for (ByteBuf slice : slices) {
      int refCount = slice.refCnt();
      ch.writeInbound(slice);

      // registered BufferAvailabilityListener => call bufferAvailable(buffer)
      while (randomBufferAvailabilityRegistrationAnswer.isRegistered()) {
        randomBufferAvailabilityRegistrationAnswer.unregister();

        Assert.assertFalse(ch.config().isAutoRead());
        Assert.assertEquals(refCount + 1, slice.refCnt());

        // return a buffer of max size => decoder needs to limit buffer size
        decoder.bufferAvailable(allocBuffer(MAX_BUFFER_SIZE));
        ch.runPendingTasks();
      }

      Assert.assertEquals(refCount - 1, slice.refCnt());
      Assert.assertTrue(ch.config().isAutoRead());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.