use of com.github.ambry.clustermap.PartitionId in project ambry by linkedin.
the class RequestResponseTest method doReplicationControlAdminRequestTest.
/**
* Does the actual test of ser/de of {@link ReplicationControlAdminRequest} and checks for equality of fields with
* reference data.
* @param origins the origins list to use in {@link ReplicationControlAdminRequest}.
* @param enable the value for the enable field in {@link ReplicationControlAdminRequest}.
* @throws IOException
*/
private void doReplicationControlAdminRequestTest(List<String> origins, boolean enable) throws IOException {
MockClusterMap clusterMap = new MockClusterMap();
PartitionId id = clusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0);
int correlationId = 1234;
String clientId = "client";
AdminRequest adminRequest = new AdminRequest(AdminRequestOrResponseType.ReplicationControl, id, correlationId, clientId);
ReplicationControlAdminRequest controlRequest = new ReplicationControlAdminRequest(origins, enable, adminRequest);
DataInputStream requestStream = serAndPrepForRead(controlRequest, -1, true);
AdminRequest deserializedAdminRequest = deserAdminRequestAndVerify(requestStream, clusterMap, correlationId, clientId, AdminRequestOrResponseType.ReplicationControl, id);
ReplicationControlAdminRequest deserializedControlRequest = ReplicationControlAdminRequest.readFrom(requestStream, deserializedAdminRequest);
Assert.assertEquals(origins, deserializedControlRequest.getOrigins());
Assert.assertEquals(enable, deserializedControlRequest.shouldEnable());
controlRequest.release();
}
use of com.github.ambry.clustermap.PartitionId in project ambry by linkedin.
the class RequestResponseTest method adminRequestResponseTest.
/**
* Tests the ser/de of {@link AdminRequest} and {@link AdminResponse} and checks for equality of fields with
* reference data.
* @throws IOException
*/
@Test
public void adminRequestResponseTest() throws IOException {
int correlationId = 1234;
String clientId = "client";
for (AdminRequestOrResponseType type : AdminRequestOrResponseType.values()) {
MockClusterMap clusterMap = new MockClusterMap();
PartitionId id = clusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0);
// with a valid partition id
AdminRequest adminRequest = new AdminRequest(type, id, correlationId, clientId);
DataInputStream requestStream = serAndPrepForRead(adminRequest, -1, true);
deserAdminRequestAndVerify(requestStream, clusterMap, correlationId, clientId, type, id);
adminRequest.release();
// with a null partition id
adminRequest = new AdminRequest(type, null, correlationId, clientId);
requestStream = serAndPrepForRead(adminRequest, -1, true);
deserAdminRequestAndVerify(requestStream, clusterMap, correlationId, clientId, type, null);
adminRequest.release();
// response
ServerErrorCode[] values = ServerErrorCode.values();
int indexToPick = TestUtils.RANDOM.nextInt(values.length);
ServerErrorCode responseErrorCode = values[indexToPick];
AdminResponse response = new AdminResponse(correlationId, clientId, responseErrorCode);
DataInputStream responseStream = serAndPrepForRead(response, -1, false);
AdminResponse deserializedAdminResponse = AdminResponse.readFrom(responseStream);
Assert.assertEquals(deserializedAdminResponse.getCorrelationId(), correlationId);
Assert.assertEquals(deserializedAdminResponse.getClientId(), clientId);
Assert.assertEquals(deserializedAdminResponse.getError(), responseErrorCode);
response.release();
}
}
use of com.github.ambry.clustermap.PartitionId in project ambry by linkedin.
the class ReplicaMetadataRequestInfo method readFrom.
public static ReplicaMetadataRequestInfo readFrom(DataInputStream stream, ClusterMap clusterMap, FindTokenHelper findTokenHelper, short requestVersion) throws IOException {
String hostName = Utils.readIntString(stream);
String replicaPath = Utils.readIntString(stream);
ReplicaType replicaType;
if (requestVersion == ReplicaMetadataRequest.Replica_Metadata_Request_Version_V2) {
replicaType = ReplicaType.values()[stream.readShort()];
} else {
// before version 2 we only have disk based replicas
replicaType = ReplicaType.DISK_BACKED;
}
PartitionId partitionId = clusterMap.getPartitionIdFromStream(stream);
FindTokenFactory findTokenFactory = findTokenHelper.getFindTokenFactoryFromReplicaType(replicaType);
FindToken token = findTokenFactory.getFindToken(stream);
return new ReplicaMetadataRequestInfo(partitionId, token, hostName, replicaPath, replicaType, requestVersion);
}
use of com.github.ambry.clustermap.PartitionId in project ambry by linkedin.
the class PartitionRequestInfo method readFrom.
public static PartitionRequestInfo readFrom(DataInputStream stream, ClusterMap clusterMap) throws IOException {
int blobCount = stream.readInt();
ArrayList<BlobId> ids = new ArrayList<BlobId>(blobCount);
PartitionId partitionId = null;
while (blobCount > 0) {
BlobId id = new BlobId(stream, clusterMap);
if (partitionId == null) {
partitionId = id.getPartition();
}
ids.add(id);
blobCount--;
}
return new PartitionRequestInfo(partitionId, ids);
}
use of com.github.ambry.clustermap.PartitionId in project ambry by linkedin.
the class ReplicaMetadataResponseInfo method readFrom.
public static ReplicaMetadataResponseInfo readFrom(DataInputStream stream, FindTokenHelper helper, ClusterMap clusterMap, short replicaMetadataResponseVersion) throws IOException {
PartitionId partitionId = clusterMap.getPartitionIdFromStream(stream);
ReplicaType replicaType;
if (replicaMetadataResponseVersion == ReplicaMetadataResponse.REPLICA_METADATA_RESPONSE_VERSION_V_6) {
replicaType = ReplicaType.values()[stream.readShort()];
} else {
// before REPLICA_METADATA_RESPONSE_VERSION_V_6 there were only disk based replicas
replicaType = ReplicaType.DISK_BACKED;
}
ServerErrorCode error = ServerErrorCode.values()[stream.readShort()];
if (error != ServerErrorCode.No_Error) {
return new ReplicaMetadataResponseInfo(partitionId, replicaType, error, replicaMetadataResponseVersion);
} else {
FindTokenFactory findTokenFactory = helper.getFindTokenFactoryFromReplicaType(replicaType);
FindToken token = findTokenFactory.getFindToken(stream);
MessageInfoAndMetadataListSerde messageInfoAndMetadataList = MessageInfoAndMetadataListSerde.deserializeMessageInfoAndMetadataList(stream, clusterMap, getMessageInfoAndMetadataListSerDeVersion(replicaMetadataResponseVersion));
long remoteReplicaLag = stream.readLong();
return new ReplicaMetadataResponseInfo(partitionId, replicaType, token, messageInfoAndMetadataList.getMessageInfoList(), remoteReplicaLag, replicaMetadataResponseVersion);
}
}
Aggregations