@Test
  public void testRouterMetadataCacheFirstChunkOperationFlag() throws Exception {
    // Note that random() can return 0. So we add 1.
    // This _will_ generate a composite blob.
    blobSize = maxChunkSize + random.nextInt(maxChunkSize) + 1;
    int randomOne = random.nextInt(blobSize);
    int randomTwo = random.nextInt(blobSize);
    doPut();
    assertNull("BlobMetadata must not be cached after PUT request", this.blobMetadataCache.getObject(blobIdStr));
    options = new GetBlobOptionsInternal(new GetBlobOptionsBuilder().operationType(GetBlobOptions.OperationType.All)
        .range(ByteRanges.fromOffsetRange(Math.min(randomOne, randomTwo), Math.max(randomOne, randomTwo)))
        .resolveRangeOnEmptyBlob(true)
        .build(), false, routerMetrics.ageAtGet);
    // First range request gets the entire blob including blobInfo
    GetBlobOperation op1 = getAndAssertSuccess(false, false, (short) 0);
    assertEquals(String.format("Expected operation flag %s but received %s", MessageFormatFlags.All,
        op1.getFirstChunkOperationFlag()), op1.getFirstChunkOperationFlag(), MessageFormatFlags.All);
    // Subsequent range request gets only blobInfo to validate metadata cached by previous request
    GetBlobOperation op2 = getAndAssertSuccess(false, false, (short) 0);
    if (this.enableMetadataCache) {
      assertNotNull(
          String.format("Blobsize must be greater than maxChunkSize. maxChunkSize = %s, blobSize = %s", maxChunkSize,
              blobSize), this.blobMetadataCache.getObject(blobIdStr));
      assertEquals(String.format("Expected operation flag %s but received %s", MessageFormatFlags.BlobInfo,
          op2.getFirstChunkOperationFlag()), op2.getFirstChunkOperationFlag(), MessageFormatFlags.BlobInfo);
    } else {
      assertNull(String.format("maxChunkSize = %s, blobSize = %s", maxChunkSize, blobSize),
          this.blobMetadataCache.getObject(blobIdStr));
      assertEquals(String.format("Expected operation flag %s but received %s", MessageFormatFlags.All,
          op2.getFirstChunkOperationFlag()), op2.getFirstChunkOperationFlag(), MessageFormatFlags.All);
    }
  }
Test range requests on a composite blob and asserts that when the cache is enabled and metadata is found in the cache,
then we only issue a blobInfo to validate the metadata entry.
@throws Exception
ambry-router/src/test/java/com/github/ambry/router/GetBlobOperationTest.java