use of com.github.ambry.protocol.GetRequest in project ambry by linkedin.
the class ServerTestUtil method checkTtlUpdateStatus.
/**
* Checks the TTL update status of the given {@code blobId} based on the args provided
* @param channel the {@link ConnectedChannel} to make the {@link GetRequest} on.
* @param clusterMap the {@link ClusterMap} to use
* @param storeKeyFactory the {@link StoreKeyFactory} to use
* @param blobId the ID of the blob to check
* @param expectedBlobData the expected blob data
* @param ttlUpdated {@code true} if the blob has been ttl updated
* @param expectedExpiryTimeMs the expected expiry time (in ms)
* @throws IOException
* @throws MessageFormatException
*/
static void checkTtlUpdateStatus(ConnectedChannel channel, ClusterMap clusterMap, StoreKeyFactory storeKeyFactory, BlobId blobId, byte[] expectedBlobData, boolean ttlUpdated, long expectedExpiryTimeMs) throws IOException, MessageFormatException {
PartitionRequestInfo requestInfo = new PartitionRequestInfo(blobId.getPartition(), Collections.singletonList(blobId));
List<PartitionRequestInfo> requestInfos = Collections.singletonList(requestInfo);
// blob properties
GetRequest request = new GetRequest(1, "checkTtlUpdateStatus", MessageFormatFlags.BlobProperties, requestInfos, GetOption.None);
DataInputStream stream = channel.sendAndReceive(request).getInputStream();
GetResponse response = GetResponse.readFrom(stream, clusterMap);
BlobProperties blobProperties = MessageFormatRecord.deserializeBlobProperties(response.getInputStream());
if (!ttlUpdated) {
assertEquals("TTL does not match", expectedExpiryTimeMs, getExpiryTimeMs(blobProperties));
}
MessageInfo messageInfo = response.getPartitionResponseInfoList().get(0).getMessageInfoList().get(0);
assertEquals("Blob ID not as expected", blobId, messageInfo.getStoreKey());
assertEquals("TTL update state not as expected", ttlUpdated, messageInfo.isTtlUpdated());
assertEquals("Expiry time is not as expected", expectedExpiryTimeMs, messageInfo.getExpirationTimeInMs());
releaseNettyBufUnderneathStream(stream);
// blob all
request = new GetRequest(1, "checkTtlUpdateStatus", MessageFormatFlags.All, requestInfos, GetOption.None);
stream = channel.sendAndReceive(request).getInputStream();
response = GetResponse.readFrom(stream, clusterMap);
InputStream responseStream = response.getInputStream();
BlobAll blobAll = MessageFormatRecord.deserializeBlobAll(responseStream, storeKeyFactory);
byte[] actualBlobData = getBlobDataAndRelease(blobAll.getBlobData());
assertArrayEquals("Content mismatch.", expectedBlobData, actualBlobData);
messageInfo = response.getPartitionResponseInfoList().get(0).getMessageInfoList().get(0);
assertEquals("Blob ID not as expected", blobId, messageInfo.getStoreKey());
assertEquals("TTL update state not as expected", ttlUpdated, messageInfo.isTtlUpdated());
assertEquals("Expiry time is not as expected", expectedExpiryTimeMs, messageInfo.getExpirationTimeInMs());
releaseNettyBufUnderneathStream(stream);
}
Aggregations