@Test
  public void testStitchBlobFailures() throws Exception {

    ThrowingConsumer<Pair<List<ChunkInfo>, RouterErrorCode>> runTest = chunksAndErrorCode -> {
      requestAndResultsList.clear();
      requestAndResultsList.add(new RequestAndResult(chunksAndErrorCode.getFirst()));
      submitPutsAndAssertFailure(new RouterException("", chunksAndErrorCode.getSecond()), true, false, true);
    };

    // chunk size issues
    if (metadataContentVersion <= 2) {
      // intermediate chunk sizes do not match
      runTest.accept(new Pair<>(
          RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.DATACHUNK, Utils.Infinite_Time,
              LongStream.of(200, 10, 200)), RouterErrorCode.InvalidPutArgument));

      // last chunk larger than intermediate chunks
      runTest.accept(new Pair<>(
          RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.DATACHUNK, Utils.Infinite_Time,
              LongStream.of(200, 201)), RouterErrorCode.InvalidPutArgument));
    }
    // last chunk is size 0 (0 not supported by current metadata format)
    runTest.accept(new Pair<>(
        RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.DATACHUNK, Utils.Infinite_Time,
            LongStream.of(200, 0)), RouterErrorCode.InvalidPutArgument));
    // intermediate chunk is size 0 (0 not supported by current metadata format)
    runTest.accept(new Pair<>(
        RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.DATACHUNK, Utils.Infinite_Time,
            LongStream.of(200, 0, 200)), RouterErrorCode.InvalidPutArgument));
    // invalid intermediate chunk size (0 not supported by current metadata format)
    runTest.accept(new Pair<>(
        RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.DATACHUNK, Utils.Infinite_Time,
            LongStream.of(0, 0)), RouterErrorCode.InvalidPutArgument));
    // chunks sizes must be less than or equal to put chunk size config
    runTest.accept(new Pair<>(
        RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.DATACHUNK, Utils.Infinite_Time,
            RouterTestHelpers.buildValidChunkSizeStream((chunkSize + 1) * 3, chunkSize + 1)),
        RouterErrorCode.InvalidPutArgument));

    // must provide at least 1 chunk for stitching
    runTest.accept(new Pair<>(
        RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.DATACHUNK, Utils.Infinite_Time,
            LongStream.empty()), RouterErrorCode.InvalidPutArgument));

    // TTL shorter than metadata blob TTL
    runTest.accept(new Pair<>(RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.DATACHUNK, 25,
        RouterTestHelpers.buildValidChunkSizeStream(chunkSize * 3, chunkSize)), RouterErrorCode.InvalidPutArgument));

    // Chunk IDs must all be DATACHUNK type
    runTest.accept(new Pair<>(
        RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.METADATA, Utils.Infinite_Time,
            RouterTestHelpers.buildValidChunkSizeStream(chunkSize * 3, chunkSize)), RouterErrorCode.InvalidBlobId));
    runTest.accept(new Pair<>(RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.SIMPLE, Utils.Infinite_Time,
        RouterTestHelpers.buildValidChunkSizeStream(chunkSize * 3, chunkSize)), RouterErrorCode.InvalidBlobId));
  }
Test different cases where a stitch operation should fail.
@throws Exception
ambry-router/src/test/java/com/github/ambry/router/PutManagerTest.java