use of com.github.ambry.protocol.TtlUpdateResponse in project ambry by linkedin.
the class InMemoryCloudDestinationErrorSimulationTest method testTtlUpdateErrorSimulation.
/**
* test error simulation for TtlUpdateRequest
* @throws Exception
*/
@Test
public void testTtlUpdateErrorSimulation() throws Exception {
BlobId blobId = doPut(partitionId);
TtlUpdateRequest ttlUpdateRequest = new TtlUpdateRequest(1234, "clientId", blobId, Utils.Infinite_Time, SystemTime.getInstance().milliseconds());
RequestInfo requestInfo = new RequestInfo(hostname, port, ttlUpdateRequest, replica, null);
ResponseInfo responseInfo = sendAndWaitForResponses(requestInfo);
TtlUpdateResponse response = responseInfo.getError() == null ? (TtlUpdateResponse) RouterUtils.mapToReceivedResponse((Response) responseInfo.getResponse()) : null;
Assert.assertEquals("TtlUpdate should succeed.", response.getError(), ServerErrorCode.No_Error);
response.release();
// inject error for cloud colo.
cloudDestination.setServerErrorForAllRequests(StoreErrorCodes.TTL_Expired);
ttlUpdateRequest = new TtlUpdateRequest(1234, "clientId", blobId, Utils.Infinite_Time, SystemTime.getInstance().milliseconds());
requestInfo = new RequestInfo(hostname, port, ttlUpdateRequest, replica, null);
responseInfo = sendAndWaitForResponses(requestInfo);
response = responseInfo.getError() == null ? ((TtlUpdateResponse) RouterUtils.mapToReceivedResponse((Response) responseInfo.getResponse())) : null;
Assert.assertEquals("TtlUpdate should return Blob_Expired.", response.getError(), ServerErrorCode.Blob_Expired);
response.release();
}
use of com.github.ambry.protocol.TtlUpdateResponse in project ambry by linkedin.
the class TtlUpdateManager method handleResponse.
/**
* Handles responses received for each of the {@link TtlUpdateOperation} within this TtlUpdateManager.
* @param responseInfo the {@link ResponseInfo} containing the response.
*/
void handleResponse(ResponseInfo responseInfo) {
long startTime = time.milliseconds();
TtlUpdateResponse ttlUpdateResponse = RouterUtils.extractResponseAndNotifyResponseHandler(responseHandler, routerMetrics, responseInfo, TtlUpdateResponse::readFrom, TtlUpdateResponse::getError);
RequestInfo routerRequestInfo = responseInfo.getRequestInfo();
int correlationId = ((TtlUpdateRequest) routerRequestInfo.getRequest()).getCorrelationId();
TtlUpdateOperation ttlUpdateOperation = correlationIdToTtlUpdateOperation.remove(correlationId);
// If it is still an active operation, hand over the response. Otherwise, ignore.
if (ttlUpdateOperations.contains(ttlUpdateOperation)) {
boolean exceptionEncountered = false;
try {
ttlUpdateOperation.handleResponse(responseInfo, ttlUpdateResponse);
} catch (Exception e) {
exceptionEncountered = true;
ttlUpdateOperation.setOperationException(new RouterException("TTLUpdate handleResponse encountered unexpected error", e, RouterErrorCode.UnexpectedInternalError));
}
if (exceptionEncountered || ttlUpdateOperation.isOperationComplete()) {
if (ttlUpdateOperations.remove(ttlUpdateOperation)) {
onComplete(ttlUpdateOperation);
}
}
routerMetrics.ttlUpdateManagerHandleResponseTimeMs.update(time.milliseconds() - startTime);
} else {
routerMetrics.ignoredResponseCount.inc();
}
}
use of com.github.ambry.protocol.TtlUpdateResponse in project ambry by linkedin.
the class ServerTestUtil method updateBlobTtl.
/**
* Updates the TTL of the given {@code blobId}
* @param channel the {@link ConnectedChannel} to make the {@link GetRequest} on.
* @param blobId the ID of the blob to TTL update
* @param ts the operation time
* @throws IOException
*/
static void updateBlobTtl(ConnectedChannel channel, BlobId blobId, long ts) throws IOException {
TtlUpdateRequest ttlUpdateRequest = new TtlUpdateRequest(1, "updateBlobTtl", blobId, Utils.Infinite_Time, ts);
DataInputStream stream = channel.sendAndReceive(ttlUpdateRequest).getInputStream();
TtlUpdateResponse ttlUpdateResponse = TtlUpdateResponse.readFrom(stream);
releaseNettyBufUnderneathStream(stream);
assertEquals("Unexpected ServerErrorCode for TtlUpdateRequest", ServerErrorCode.No_Error, ttlUpdateResponse.getError());
}
Aggregations