use of com.facebook.buck.distributed.thrift.FrontendResponse 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()));
}
use of com.facebook.buck.distributed.thrift.FrontendResponse in project buck by facebook.
the class DistBuildServiceTest method canCreateBuild.
@Test
public void canCreateBuild() throws Exception {
final String idString = "create id";
Capture<FrontendRequest> request = EasyMock.newCapture();
FrontendResponse response = new FrontendResponse();
response.setType(FrontendRequestType.CREATE_BUILD);
CreateBuildResponse createBuildResponse = new CreateBuildResponse();
BuildJob buildJob = new BuildJob();
StampedeId stampedeId = new StampedeId();
stampedeId.setId(idString);
buildJob.setStampedeId(stampedeId);
createBuildResponse.setBuildJob(buildJob);
response.setCreateBuildResponse(createBuildResponse);
response.setWasSuccessful(true);
EasyMock.expect(frontendService.makeRequest(EasyMock.capture(request))).andReturn(response).once();
EasyMock.replay(frontendService);
BuildJob job = distBuildService.createBuild();
Assert.assertEquals(request.getValue().getType(), FrontendRequestType.CREATE_BUILD);
Assert.assertTrue(request.getValue().isSetCreateBuildRequest());
Assert.assertTrue(request.getValue().getCreateBuildRequest().isSetCreateTimestampMillis());
Assert.assertTrue(job.isSetStampedeId());
Assert.assertTrue(job.getStampedeId().isSetId());
Assert.assertEquals(job.getStampedeId().getId(), idString);
}
use of com.facebook.buck.distributed.thrift.FrontendResponse in project buck by facebook.
the class DistBuildServiceTest method canUploadTargetGraph.
@Test
public void canUploadTargetGraph() throws IOException, ExecutionException, InterruptedException {
Capture<FrontendRequest> request = EasyMock.newCapture();
FrontendResponse response = new FrontendResponse();
response.setType(FrontendRequestType.STORE_BUILD_GRAPH);
response.setWasSuccessful(true);
EasyMock.expect(frontendService.makeRequest(EasyMock.capture(request))).andReturn(response).once();
EasyMock.replay(frontendService);
BuildJobState buildJobState = new BuildJobState();
List<BuildJobStateFileHashes> fileHashes = new ArrayList<>();
buildJobState.setFileHashes(fileHashes);
BuildJobStateTargetGraph graph = new BuildJobStateTargetGraph();
graph.setNodes(new ArrayList<BuildJobStateTargetNode>());
BuildJobStateTargetNode node1 = new BuildJobStateTargetNode();
node1.setRawNode("node1");
BuildJobStateTargetNode node2 = new BuildJobStateTargetNode();
node2.setRawNode("node1");
graph.addToNodes(node1);
graph.addToNodes(node2);
buildJobState.setTargetGraph(graph);
StampedeId stampedeId = new StampedeId();
stampedeId.setId("check-id");
distBuildService.uploadTargetGraph(buildJobState, stampedeId, executor).get();
Assert.assertTrue(request.getValue().isSetType());
Assert.assertEquals(request.getValue().getType(), FrontendRequestType.STORE_BUILD_GRAPH);
Assert.assertTrue(request.getValue().isSetStoreBuildGraphRequest());
Assert.assertTrue(request.getValue().getStoreBuildGraphRequest().isSetStampedeId());
Assert.assertEquals(request.getValue().getStoreBuildGraphRequest().getStampedeId(), stampedeId);
Assert.assertTrue(request.getValue().getStoreBuildGraphRequest().isSetBuildGraph());
BuildJobState sentState = BuildJobStateSerializer.deserialize(request.getValue().getStoreBuildGraphRequest().getBuildGraph());
Assert.assertTrue(buildJobState.equals(sentState));
}
use of com.facebook.buck.distributed.thrift.FrontendResponse in project buck by facebook.
the class PublicAnnouncementManagerIntegrationTest method testAnnouncementsWork.
@Test
public void testAnnouncementsWork() throws Exception {
final AtomicReference<byte[]> requestBody = new AtomicReference<>();
try (HttpdForTests httpd = new HttpdForTests()) {
httpd.addHandler(new AbstractHandler() {
@Override
public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException {
httpServletResponse.setStatus(200);
request.setHandled(true);
if (request.getUri().getPath().equals("/status.php")) {
return;
}
requestBody.set(ByteStreams.toByteArray(httpServletRequest.getInputStream()));
FrontendRequest thriftRequest = new FrontendRequest();
ThriftUtil.deserialize(ThriftProtocol.BINARY, requestBody.get(), thriftRequest);
assertTrue("Request should contain the repository.", thriftRequest.getAnnouncementRequest().getRepository().equals(REPOSITORY));
try (DataOutputStream out = new DataOutputStream(httpServletResponse.getOutputStream())) {
Announcement announcement = new Announcement();
announcement.setErrorMessage(ERROR_MSG);
announcement.setSolutionMessage(SOLUTION_MSG);
AnnouncementResponse announcementResponse = new AnnouncementResponse();
announcementResponse.setAnnouncements(ImmutableList.of(announcement));
FrontendResponse frontendResponse = new FrontendResponse();
frontendResponse.setType(FrontendRequestType.ANNOUNCEMENT);
frontendResponse.setAnnouncementResponse(announcementResponse);
out.write(ThriftUtil.serialize(ThriftProtocol.BINARY, frontendResponse));
}
}
});
httpd.start();
Clock clock = new DefaultClock();
BuckEventBus eventBus = BuckEventBusFactory.newInstance(clock);
ExecutionEnvironment executionEnvironment = new DefaultExecutionEnvironment(ImmutableMap.copyOf(System.getenv()), System.getProperties());
BuckConfig buckConfig = new FakeBuckConfig.Builder().setSections(ImmutableMap.of("log", ImmutableMap.of("slb_server_pool", "http://localhost:" + httpd.getRootUri().getPort()))).build();
TestConsole console = new TestConsole();
SuperConsoleEventBusListener listener = new SuperConsoleEventBusListener(new SuperConsoleConfig(FakeBuckConfig.builder().build()), console, clock, /* verbosity */
TestResultSummaryVerbosity.of(false, false), executionEnvironment, Optional.empty(), Locale.US, logPath, TimeZone.getTimeZone("UTC"));
eventBus.register(listener);
PublicAnnouncementManager manager = new PublicAnnouncementManager(clock, eventBus, listener, REPOSITORY, new RemoteLogBuckConfig(buckConfig), MoreExecutors.newDirectExecutorService());
manager.getAndPostAnnouncements();
Optional<String> announcements = listener.getPublicAnnouncements();
assertEquals("The header and the message", announcements.get(), "**-------------------------------**\n" + "**- Sticky Public Announcements -**\n" + "**-------------------------------**\n" + "** This is the error message. This is the solution message.");
}
}
use of com.facebook.buck.distributed.thrift.FrontendResponse in project buck by facebook.
the class ThriftScribeLogger method sendViaThrift.
private void sendViaThrift(String category, Iterable<String> lines) throws IOException {
//Prepare log request.
ScribeData scribeData = new ScribeData();
scribeData.setCategory(category);
copyLinesWithoutNulls(lines, scribeData);
LogRequest logRequest = new LogRequest();
logRequest.setType(LogRequestType.SCRIBE_DATA);
logRequest.setScribeData(scribeData);
// Wrap in high-level request & response.
FrontendRequest request = new FrontendRequest();
request.setType(FrontendRequestType.LOG);
request.setLogRequest(logRequest);
FrontendResponse response = new FrontendResponse();
thriftService.makeRequest(request, response);
if (!response.isWasSuccessful()) {
throw new IOException(String.format("Log request failed. Error from response: %s", response.getErrorMessage()));
}
}
Aggregations