BlockwiseLayer extends AbstractLayer { @Override public void receiveRequest(final Exchange exchange, final Request request) { if (isTransparentBlockwiseHandlingEnabled()) { BlockOption block2 = request.getOptions().getBlock2(); if (request.getOptions().hasBlock1()) { handleInboundBlockwiseUpload(exchange, request); } else if (block2 != null && block2.getNum() > 0) { KeyUri key = getKey(exchange, request); Block2BlockwiseStatus status = getBlock2Status(key); if (status == null) { LOGGER.debug( "peer wants to retrieve individual block2 {} of {}, delivering request to application layer", block2, key); exchange.setRequest(request); upper().receiveRequest(exchange, request); } else { handleInboundRequestForNextBlock(exchange, request, key, status); } } else { exchange.setRequest(request); upper().receiveRequest(exchange, request); } } else { exchange.setRequest(request); upper().receiveRequest(exchange, request); } } BlockwiseLayer(final NetworkConfig config); @Override void start(); @Override void destroy(); @Override void sendRequest(final Exchange exchange, final Request request); @Override void receiveRequest(final Exchange exchange, final Request request); @Override void sendResponse(final Exchange exchange, final Response response); @Override void receiveResponse(final Exchange exchange, final Response response); boolean isEmpty();  }
@Test public void testReceiveRequestDelegatesToApplicationLayer() { NetworkConfig config = NetworkConfig.createStandardWithoutFile() .setInt(Keys.MAX_MESSAGE_SIZE, 128) .setInt(Keys.MAX_RESOURCE_BODY_SIZE, 0); Layer appLayer = mock(Layer.class); BlockwiseLayer blockwiseLayer = new BlockwiseLayer(config); blockwiseLayer.setUpperLayer(appLayer); Request request = newReceivedBlockwiseRequest(256, 64); Exchange exchange = new Exchange(request, Origin.REMOTE, MatcherTestUtils.TEST_EXCHANGE_EXECUTOR); blockwiseLayer.receiveRequest(exchange, request); verify(appLayer).receiveRequest(exchange, request); }