use of com.facebook.buck.distributed.thrift.FrontendRequest 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.FrontendRequest 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.FrontendRequest 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.FrontendRequest 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()));
}
}
use of com.facebook.buck.distributed.thrift.FrontendRequest 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);
}
Aggregations