@Test
  public void testStitchBlobSuccess() throws Exception {
    ThrowingConsumer<List<ChunkInfo>> runTest = chunksToStitch -> {
      requestAndResultsList.clear();
      requestAndResultsList.add(new RequestAndResult(chunksToStitch));
      mockClusterMap.clearLastNRequestedPartitionClasses();
      submitPutsAndAssertSuccess(true);
      // since the puts are processed one at a time, it is fair to check the last partition class set
      checkLastRequestPartitionClasses(1, MockClusterMap.DEFAULT_PARTITION_CLASS, true);
    };

    for (int i = 1; i < 10; i++) {
      // Chunks are all the same size.
      runTest.accept(RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.DATACHUNK, Utils.Infinite_Time,
          RouterTestHelpers.buildValidChunkSizeStream(chunkSize * i, chunkSize)));
      // All intermediate chunks are the same size. Last is smaller.
      runTest.accept(RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.DATACHUNK, Utils.Infinite_Time,
          RouterTestHelpers.buildValidChunkSizeStream(chunkSize * i + random.nextInt(chunkSize - 1) + 1, chunkSize)));
      // Chunks are all the same size but smaller than routerMaxPutChunkSizeBytes.
      int dataChunkSize = 1 + random.nextInt(chunkSize - 1);
      runTest.accept(RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.DATACHUNK, Utils.Infinite_Time,
          RouterTestHelpers.buildValidChunkSizeStream(dataChunkSize * i, dataChunkSize)));
      // All intermediate chunks are the same size but smaller than routerMaxPutChunkSizeBytes. Last is smaller.
      runTest.accept(RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.DATACHUNK, Utils.Infinite_Time,
          RouterTestHelpers.buildValidChunkSizeStream(dataChunkSize * i + random.nextInt(dataChunkSize - 1) + 1,
              dataChunkSize)));
    }

    if (metadataContentVersion > 2) {
      // intermediate chunk sizes do not match
      runTest.accept(RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.DATACHUNK, Utils.Infinite_Time,
          LongStream.of(200, 10, 200)));

      // last chunk larger than intermediate chunks
      runTest.accept(RouterTestHelpers.buildChunkList(mockClusterMap, BlobDataType.DATACHUNK, Utils.Infinite_Time,
          LongStream.of(200, 201)));
    }
    Assert.assertEquals("Metrics should show creation of metadata chunk", 1,
        metrics.metadataChunkCreationCount.getCount());
  }
Test different cases where a stitch operation should succeed.
ambry-router/src/test/java/com/github/ambry/router/PutManagerTest.java