use of com.github.ambry.protocol.Response in project ambry by linkedin.
the class AmbryServerRequestsTest method doScheduleCompactionTest.
// scheduleCompactionSuccessTest() and scheduleCompactionFailuresTest() helpers
/**
* Schedules a compaction for {@code id} and checks that the {@link ServerErrorCode} returned matches
* {@code expectedServerErrorCode}.
* @param id the {@link PartitionId} to schedule compaction for.
* @param expectedServerErrorCode the {@link ServerErrorCode} expected when the request is processed.
* @throws InterruptedException
* @throws IOException
*/
private void doScheduleCompactionTest(PartitionId id, ServerErrorCode expectedServerErrorCode) throws InterruptedException, IOException {
int correlationId = TestUtils.RANDOM.nextInt();
String clientId = TestUtils.getRandomString(10);
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.TriggerCompaction, id, correlationId, clientId);
Response response = sendRequestGetResponse(adminRequest, expectedServerErrorCode);
assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
}
use of com.github.ambry.protocol.Response in project ambry by linkedin.
the class AmbryServerRequestsTest method sendAndVerifyReplicationControlRequest.
/**
* Sends and verifies that a {@link AdminRequestOrResponseType#ReplicationControl} request received the error code
* expected and that {@link AmbryRequests} sent the right details to {@link ReplicationManager}.
* @param origins the list of datacenters from which replication should be enabled/disabled.
* @param enable {@code true} if replication needs to be enabled. {@code false} otherwise.
* @param id the {@link PartitionId} to send the request for. Can be {@code null}.
* @param expectedServerErrorCode the {@link ServerErrorCode} expected in the response.
* @throws InterruptedException
* @throws IOException
*/
private void sendAndVerifyReplicationControlRequest(List<String> origins, boolean enable, PartitionId id, ServerErrorCode expectedServerErrorCode) throws InterruptedException, IOException {
int correlationId = TestUtils.RANDOM.nextInt();
String clientId = TestUtils.getRandomString(10);
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.ReplicationControl, id, correlationId, clientId);
ReplicationControlAdminRequest controlRequest = new ReplicationControlAdminRequest(origins, enable, adminRequest);
Response response = sendRequestGetResponse(controlRequest, expectedServerErrorCode);
assertTrue("Response not of type AdminResponse", response instanceof AdminResponse);
List<PartitionId> idsVal;
if (id == null) {
idsVal = clusterMap.getAllPartitionIds(null);
} else {
idsVal = Collections.singletonList(id);
}
if (!expectedServerErrorCode.equals(ServerErrorCode.Unknown_Error)) {
assertEquals("Origins not as provided in request", origins, replicationManager.originsVal);
assertEquals("Enable not as provided in request", enable, replicationManager.enableVal);
assertEquals("Ids not as provided in request", idsVal.size(), replicationManager.idsVal.size());
assertTrue("Ids not as provided in request", replicationManager.idsVal.containsAll(idsVal));
}
response.release();
}
use of com.github.ambry.protocol.Response in project ambry by linkedin.
the class AmbryServerRequestsTest method crossColoMetricsUpdateTest.
/**
* Test that cross-colo metrics are updated correctly when {@link AmbryRequests} handles {@link GetRequest} and
* {@link ReplicaMetadataRequest}
* @throws Exception
*/
@Test
public void crossColoMetricsUpdateTest() throws Exception {
// find a node in remote dc
DataNodeId remoteNode = clusterMap.getDataNodeIds().stream().filter(node -> !node.getDatacenterName().equals(localDc)).findFirst().get();
PartitionId id = clusterMap.getReplicaIds(remoteNode).get(0).getPartitionId();
// send cross-colo metadata request and verify
String clientId = "replication-metadata-" + remoteNode.getHostname() + "[" + remoteNode.getDatacenterName() + "]";
List<Response> responseList = sendAndVerifyOperationRequest(RequestOrResponseType.ReplicaMetadataRequest, Collections.singletonList(id), ServerErrorCode.No_Error, null, clientId);
assertEquals("cross-colo metadata exchange bytes are not expected", responseList.get(0).sizeInBytes(), serverMetrics.crossColoMetadataExchangeBytesRate.get(remoteNode.getDatacenterName()).getCount());
responseList.forEach(Response::release);
// send cross-colo get request and verify
clientId = GetRequest.Replication_Client_Id_Prefix + remoteNode.getHostname() + "[" + remoteNode.getDatacenterName() + "]";
responseList = sendAndVerifyOperationRequest(RequestOrResponseType.GetRequest, Collections.singletonList(id), ServerErrorCode.No_Error, null, clientId);
assertEquals("cross-colo fetch bytes are not expected", responseList.get(0).sizeInBytes(), serverMetrics.crossColoFetchBytesRate.get(remoteNode.getDatacenterName()).getCount());
responseList.forEach(Response::release);
}
Aggregations