Search in sources :

Example 1 with CASContainsResponse

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

the class DistBuildServiceTest method canUploadFiles.

@Test
public void canUploadFiles() throws Exception {
    final List<Boolean> fileExistence = Arrays.asList(true, false, true);
    Capture<FrontendRequest> containsRequest = EasyMock.newCapture();
    FrontendResponse containsResponse = new FrontendResponse();
    containsResponse.setType(FrontendRequestType.CAS_CONTAINS);
    CASContainsResponse casContainsResponse = new CASContainsResponse();
    casContainsResponse.setExists(fileExistence);
    containsResponse.setCasContainsResponse(casContainsResponse);
    containsResponse.setWasSuccessful(true);
    EasyMock.expect(frontendService.makeRequest(EasyMock.capture(containsRequest))).andReturn(containsResponse).once();
    Capture<FrontendRequest> storeRequest = EasyMock.newCapture();
    FrontendResponse storeResponse = new FrontendResponse();
    storeResponse.setType(FrontendRequestType.STORE_LOCAL_CHANGES);
    storeResponse.setWasSuccessful(true);
    EasyMock.expect(frontendService.makeRequest(EasyMock.capture(storeRequest))).andReturn(storeResponse).once();
    EasyMock.replay(frontendService);
    BuildJobStateFileHashEntry[] files = new BuildJobStateFileHashEntry[3];
    for (int i = 0; i < 3; i++) {
        files[i] = new BuildJobStateFileHashEntry();
        files[i].setHashCode(Integer.toString(i));
        files[i].setContents(("content" + Integer.toString(i)).getBytes());
        files[i].setPath(new PathWithUnixSeparators("/tmp/" + i));
    }
    List<BuildJobStateFileHashes> fileHashes = new ArrayList<>();
    fileHashes.add(new BuildJobStateFileHashes());
    fileHashes.get(0).setCellIndex(0);
    fileHashes.get(0).setEntries(new ArrayList<BuildJobStateFileHashEntry>());
    fileHashes.get(0).getEntries().add(files[0]);
    fileHashes.get(0).getEntries().add(files[1]);
    fileHashes.add(new BuildJobStateFileHashes());
    fileHashes.get(1).setCellIndex(1);
    fileHashes.get(1).setEntries(new ArrayList<BuildJobStateFileHashEntry>());
    fileHashes.get(1).getEntries().add(files[2]);
    distBuildService.uploadMissingFiles(fileHashes, executor).get();
    Assert.assertEquals(containsRequest.getValue().getType(), FrontendRequestType.CAS_CONTAINS);
    Assert.assertTrue(containsRequest.getValue().isSetCasContainsRequest());
    Assert.assertTrue(containsRequest.getValue().getCasContainsRequest().isSetContentSha1s());
    Assert.assertEquals(new HashSet<String>(containsRequest.getValue().getCasContainsRequest().getContentSha1s()), new HashSet<String>(Arrays.asList("0", "1", "2")));
    Assert.assertEquals(storeRequest.getValue().getType(), FrontendRequestType.STORE_LOCAL_CHANGES);
    Assert.assertTrue(storeRequest.getValue().isSetStoreLocalChangesRequest());
    Assert.assertTrue(storeRequest.getValue().getStoreLocalChangesRequest().isSetFiles());
    Assert.assertEquals(storeRequest.getValue().getStoreLocalChangesRequest().getFiles().size(), 1);
    Assert.assertEquals(storeRequest.getValue().getStoreLocalChangesRequest().getFiles().get(0).getContentHash(), "1");
    Assert.assertTrue(Arrays.equals(storeRequest.getValue().getStoreLocalChangesRequest().getFiles().get(0).getContent(), "content1".getBytes()));
}
Also used : ArrayList(java.util.ArrayList) PathWithUnixSeparators(com.facebook.buck.distributed.thrift.PathWithUnixSeparators) BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) CASContainsResponse(com.facebook.buck.distributed.thrift.CASContainsResponse) Test(org.junit.Test)

Aggregations

BuildJobStateFileHashEntry (com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry)1 BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)1 CASContainsResponse (com.facebook.buck.distributed.thrift.CASContainsResponse)1 FrontendRequest (com.facebook.buck.distributed.thrift.FrontendRequest)1 FrontendResponse (com.facebook.buck.distributed.thrift.FrontendResponse)1 PathWithUnixSeparators (com.facebook.buck.distributed.thrift.PathWithUnixSeparators)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1