use of com.facebook.buck.distributed.thrift.FrontendResponse in project buck by facebook.
the class DistBuildServiceTest method canPollBuild.
@Test
public void canPollBuild() throws Exception {
final String idString = "poll id";
Capture<FrontendRequest> request = EasyMock.newCapture();
FrontendResponse response = new FrontendResponse();
response.setType(FrontendRequestType.BUILD_STATUS);
BuildStatusResponse buildStatusResponse = new BuildStatusResponse();
BuildJob buildJob = new BuildJob();
StampedeId stampedeId = new StampedeId();
stampedeId.setId(idString);
buildJob.setStampedeId(stampedeId);
buildStatusResponse.setBuildJob(buildJob);
response.setBuildStatusResponse(buildStatusResponse);
response.setWasSuccessful(true);
EasyMock.expect(frontendService.makeRequest(EasyMock.capture(request))).andReturn(response).once();
EasyMock.replay(frontendService);
StampedeId id = new StampedeId();
id.setId(idString);
BuildJob job = distBuildService.getCurrentBuildJobState(id);
Assert.assertEquals(request.getValue().getType(), FrontendRequestType.BUILD_STATUS);
Assert.assertTrue(request.getValue().isSetBuildStatusRequest());
Assert.assertTrue(request.getValue().getBuildStatusRequest().isSetStampedeId());
Assert.assertEquals(request.getValue().getBuildStatusRequest().getStampedeId(), id);
Assert.assertTrue(job.isSetStampedeId());
Assert.assertEquals(job.getStampedeId(), id);
}
use of com.facebook.buck.distributed.thrift.FrontendResponse in project buck by facebook.
the class DistBuildServiceTest method canStartBuild.
@Test
public void canStartBuild() throws Exception {
final String idString = "start id";
Capture<FrontendRequest> request = EasyMock.newCapture();
FrontendResponse response = new FrontendResponse();
response.setType(FrontendRequestType.START_BUILD);
StartBuildResponse startBuildResponse = new StartBuildResponse();
BuildJob buildJob = new BuildJob();
StampedeId stampedeId = new StampedeId();
stampedeId.setId(idString);
buildJob.setStampedeId(stampedeId);
startBuildResponse.setBuildJob(buildJob);
response.setStartBuildResponse(startBuildResponse);
response.setWasSuccessful(true);
EasyMock.expect(frontendService.makeRequest(EasyMock.capture(request))).andReturn(response).once();
EasyMock.replay(frontendService);
StampedeId id = new StampedeId();
id.setId(idString);
BuildJob job = distBuildService.startBuild(id);
Assert.assertEquals(request.getValue().getType(), FrontendRequestType.START_BUILD);
Assert.assertTrue(request.getValue().isSetStartBuildRequest());
Assert.assertTrue(request.getValue().getStartBuildRequest().isSetStampedeId());
Assert.assertEquals(request.getValue().getStartBuildRequest().getStampedeId(), id);
Assert.assertTrue(job.isSetStampedeId());
Assert.assertEquals(job.getStampedeId(), id);
}
use of com.facebook.buck.distributed.thrift.FrontendResponse in project buck by facebook.
the class ThriftOverHttpServiceTest method testSendValidMessageAndReturnError.
@Test
public void testSendValidMessageAndReturnError() throws IOException {
// TODO(ruibm): Add jetty end to end integration tests for this API.
FrontendRequest request = new FrontendRequest();
request.setType(FrontendRequestType.BUILD_STATUS);
FrontendResponse response = new FrontendResponse();
response.setType(FrontendRequestType.START_BUILD);
Capture<Request.Builder> requestBuilder = EasyMock.newCapture();
HttpResponse httpResponse = EasyMock.createMock(HttpResponse.class);
EasyMock.expect(httpResponse.statusCode()).andReturn(404).atLeastOnce();
EasyMock.expect(httpResponse.statusMessage()).andReturn("topspin").atLeastOnce();
EasyMock.expect(httpResponse.requestUrl()).andReturn("super url").atLeastOnce();
EasyMock.expect(httpService.makeRequest(EasyMock.eq("/thrift"), EasyMock.capture(requestBuilder))).andReturn(httpResponse).times(1);
EasyMock.replay(httpResponse, httpService);
try {
service.makeRequest(request, response);
Assert.fail("This should've thrown an IOException.");
} catch (IOException e) {
Assert.assertNotNull(e);
}
Request actualHttpRequest = requestBuilder.getValue().url("http://localhost").build();
Assert.assertEquals(ThriftOverHttpService.THRIFT_CONTENT_TYPE, actualHttpRequest.body().contentType());
EasyMock.verify(httpResponse, httpService);
}
use of com.facebook.buck.distributed.thrift.FrontendResponse in project buck by facebook.
the class ThriftOverHttpServiceTest method testSendValidMessageAndReturnValidResponse.
@Test
public void testSendValidMessageAndReturnValidResponse() throws IOException, TException {
FrontendRequest request = new FrontendRequest();
request.setType(FrontendRequestType.BUILD_STATUS);
FrontendResponse expectedResponse = new FrontendResponse();
expectedResponse.setType(FrontendRequestType.START_BUILD);
Capture<Request.Builder> requestBuilder = EasyMock.newCapture();
TSerializer serializer = new TSerializer(config.getThriftProtocol().getFactory());
final byte[] responseBuffer = serializer.serialize(expectedResponse);
HttpResponse httpResponse = new HttpResponse() {
@Override
public int statusCode() {
return 200;
}
@Override
public String statusMessage() {
return "super cool msg";
}
@Override
public long contentLength() throws IOException {
return responseBuffer.length;
}
@Override
public InputStream getBody() {
return new ByteArrayInputStream(responseBuffer);
}
@Override
public String requestUrl() {
return "super url";
}
@Override
public void close() throws IOException {
// do nothing.
}
};
EasyMock.expect(httpService.makeRequest(EasyMock.eq("/thrift"), EasyMock.capture(requestBuilder))).andReturn(httpResponse).times(1);
EasyMock.replay(httpService);
FrontendResponse actualResponse = new FrontendResponse();
service.makeRequest(request, actualResponse);
Assert.assertEquals(expectedResponse, actualResponse);
EasyMock.verify(httpService);
}
use of com.facebook.buck.distributed.thrift.FrontendResponse in project buck by facebook.
the class DistBuildService method fetchBuildSlaveLogDir.
public MultiGetBuildSlaveLogDirResponse fetchBuildSlaveLogDir(final StampedeId stampedeId, final List<RunId> runIds) throws IOException {
MultiGetBuildSlaveLogDirRequest getBuildSlaveLogDirRequest = new MultiGetBuildSlaveLogDirRequest();
getBuildSlaveLogDirRequest.setStampedeId(stampedeId);
getBuildSlaveLogDirRequest.setRunIds(runIds);
FrontendRequest request = new FrontendRequest();
request.setType(FrontendRequestType.GET_BUILD_SLAVE_LOG_DIR);
request.setMultiGetBuildSlaveLogDirRequest(getBuildSlaveLogDirRequest);
FrontendResponse response = makeRequestChecked(request);
return response.getMultiGetBuildSlaveLogDirResponse();
}
Aggregations