@Test
  public void serdeTest() throws IOException {
    short version = 0;
    Random random = new Random();
    long lastBlobUpdateTime = random.nextLong();
    long bytesRead = random.nextLong();
    Set<String> lastReadBlobIds = new HashSet<>();
    lastReadBlobIds.add("blobid1");
    lastReadBlobIds.add("blobid2");

    //Deserialization test

    //token with invalid version
    CosmosUpdateTimeFindToken invalidToken =
        new CosmosUpdateTimeFindToken((short) 1, lastBlobUpdateTime, bytesRead, lastReadBlobIds);
    DataInputStream tokenStream = getSerializedStream(invalidToken);
    try {
      CosmosUpdateTimeFindToken.fromBytes(tokenStream);
      fail("deserialization of token with invalid version should have failed");
    } catch (IllegalStateException ise) {
    }

    //valid token
    CosmosUpdateTimeFindToken token =
        new CosmosUpdateTimeFindToken(version, lastBlobUpdateTime, bytesRead, lastReadBlobIds);
    tokenStream = getSerializedStream(token);
    CosmosUpdateTimeFindToken deSerToken = CosmosUpdateTimeFindToken.fromBytes(tokenStream);
    assertEquals("Stream should have ended ", 0, tokenStream.available());
    assertEquals(token, deSerToken);

    //Serialization test

    //token with invalid version
    DataInputStream serializedStream = getSerializedStream(invalidToken);
    try {
      CosmosUpdateTimeFindToken.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 = CosmosUpdateTimeFindToken.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/CosmosUpdateTimeFindTokenTest.java