@Test
  public void serdeTest() throws IOException {
    Random random = new Random();
    long bytesRead = random.nextLong();
    String startContinuationToken = "start";
    String endContinuationToken = "end";
    int totalItems = random.nextInt();
    int index = random.nextInt() % totalItems;
    String azureRequestId = UUID.randomUUID().toString();

    //Deserialization test

    //token with invalid version
    CosmosChangeFeedFindToken invalidToken =
        new CosmosChangeFeedFindToken(bytesRead, startContinuationToken, endContinuationToken, index, totalItems,
            azureRequestId, (short) 1);
    DataInputStream tokenStream = getSerializedStream(invalidToken);
    try {
      CosmosChangeFeedFindToken.fromBytes(tokenStream);
      fail("deserialization of token with invalid version should have failed");
    } catch (IllegalStateException ise) {
    }

    //valid token
    CosmosChangeFeedFindToken token =
        new CosmosChangeFeedFindToken(bytesRead, startContinuationToken, endContinuationToken, index, totalItems,
            azureRequestId);
    tokenStream = new DataInputStream(new ByteArrayInputStream(token.toBytes()));
    CosmosChangeFeedFindToken deSerToken = CosmosChangeFeedFindToken.fromBytes(tokenStream);
    assertEquals("Stream should have ended ", 0, tokenStream.available());
    assertEquals(token, deSerToken);

    //Serialization test

    //token with invalid version
    DataInputStream serializedStream = getSerializedStream(invalidToken);
    try {
      CosmosChangeFeedFindToken.fromBytes(serializedStream);
      fail("serialization of token with invalid version should have failed");
    } catch (IllegalStateException ise) {
    }

    //valid token
    serializedStream = new DataInputStream(new ByteArrayInputStream(token.toBytes()));
    deSerToken = CosmosChangeFeedFindToken.fromBytes(serializedStream);
    assertEquals("Stream should have ended ", 0, serializedStream.available());
    assertEquals(token, deSerToken);
  }
Test for serialization and deserialization of cloud token
@throws IOException if an IO exception happens during deserialization
ambry-cloud/src/test/java/com/github/ambry/cloud/azure/CosmosChangeFeedFindTokenTest.java