Search in sources :

Example 11 with FrontendRequest

use of com.facebook.buck.distributed.thrift.FrontendRequest 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);
}
Also used : StartBuildResponse(com.facebook.buck.distributed.thrift.StartBuildResponse) StampedeId(com.facebook.buck.distributed.thrift.StampedeId) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) BuildJob(com.facebook.buck.distributed.thrift.BuildJob) Test(org.junit.Test)

Example 12 with FrontendRequest

use of com.facebook.buck.distributed.thrift.FrontendRequest in project buck by facebook.

the class DistBuildServiceTest method testRequestContainsStampedeId.

@Test
public void testRequestContainsStampedeId() {
    StampedeId stampedeId = createStampedeId("topspin");
    FrontendRequest request = DistBuildService.createFrontendBuildStatusRequest(stampedeId);
    Assert.assertEquals(stampedeId, request.getBuildStatusRequest().getStampedeId());
}
Also used : StampedeId(com.facebook.buck.distributed.thrift.StampedeId) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) Test(org.junit.Test)

Example 13 with FrontendRequest

use of com.facebook.buck.distributed.thrift.FrontendRequest 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);
}
Also used : FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) Request(okhttp3.Request) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with FrontendRequest

use of com.facebook.buck.distributed.thrift.FrontendRequest 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);
}
Also used : TSerializer(org.apache.thrift.TSerializer) ByteArrayInputStream(java.io.ByteArrayInputStream) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) Test(org.junit.Test)

Example 15 with FrontendRequest

use of com.facebook.buck.distributed.thrift.FrontendRequest in project buck by facebook.

the class DistBuildService method setBuckDotFiles.

public void setBuckDotFiles(StampedeId id, List<PathInfo> dotFiles) throws IOException {
    SetBuckDotFilePathsRequest storeBuckDotFilesRequest = new SetBuckDotFilePathsRequest();
    storeBuckDotFilesRequest.setStampedeId(id);
    storeBuckDotFilesRequest.setDotFiles(dotFiles);
    FrontendRequest request = new FrontendRequest();
    request.setType(FrontendRequestType.SET_DOTFILE_PATHS);
    request.setSetBuckDotFilePathsRequest(storeBuckDotFilesRequest);
    makeRequestChecked(request);
}
Also used : SetBuckDotFilePathsRequest(com.facebook.buck.distributed.thrift.SetBuckDotFilePathsRequest) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest)

Aggregations

FrontendRequest (com.facebook.buck.distributed.thrift.FrontendRequest)25 FrontendResponse (com.facebook.buck.distributed.thrift.FrontendResponse)18 Test (org.junit.Test)9 BuildJob (com.facebook.buck.distributed.thrift.BuildJob)5 StampedeId (com.facebook.buck.distributed.thrift.StampedeId)5 IOException (java.io.IOException)4 BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)3 Announcement (com.facebook.buck.distributed.thrift.Announcement)2 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)2 BuildJobStateFileHashEntry (com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry)2 BuildStatusRequest (com.facebook.buck.distributed.thrift.BuildStatusRequest)2 FileInfo (com.facebook.buck.distributed.thrift.FileInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 BuckConfig (com.facebook.buck.cli.BuckConfig)1 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)1 FrontendService (com.facebook.buck.distributed.FrontendService)1 AnnouncementRequest (com.facebook.buck.distributed.thrift.AnnouncementRequest)1 AnnouncementResponse (com.facebook.buck.distributed.thrift.AnnouncementResponse)1 BuildJobStateTargetGraph (com.facebook.buck.distributed.thrift.BuildJobStateTargetGraph)1