use of com.facebook.buck.util.trace.BuildTraces in project buck by facebook.
the class TraceDataHandlerTest method testHandleGetWithMultipleTraceCallback.
@Test
public void testHandleGetWithMultipleTraceCallback() throws IOException, ServletException {
Request baseRequest = createMock(Request.class);
expect(baseRequest.getMethod()).andReturn("GET");
expect(baseRequest.getPathInfo()).andReturn("/abcdef");
expect(baseRequest.getParameter("callback")).andReturn("my.callback");
baseRequest.setHandled(true);
HttpServletRequest request = createMock(HttpServletRequest.class);
HttpServletResponse response = createMock(HttpServletResponse.class);
response.setStatus(200);
response.setContentType("application/javascript; charset=utf-8");
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
expect(response.getWriter()).andReturn(printWriter);
response.flushBuffer();
BuildTraces buildTraces = createMock(BuildTraces.class);
Iterable<InputStream> traces = Arrays.asList(new ByteArrayInputStream("{\"foo\":\"bar\"}".getBytes(Charsets.UTF_8)), new ByteArrayInputStream("{\"baz\":\"blech\"}".getBytes(Charsets.UTF_8)));
expect(buildTraces.getInputsForTraces("abcdef")).andReturn(traces);
TraceDataHandler traceDataHandler = new TraceDataHandler(buildTraces);
replayAll();
traceDataHandler.handle("/trace/abcdef?callback=my.callback", baseRequest, request, response);
verifyAll();
assertEquals("my.callback([{\"foo\":\"bar\"},{\"baz\":\"blech\"}]);\n", stringWriter.toString());
}
use of com.facebook.buck.util.trace.BuildTraces in project buck by facebook.
the class TraceDataHandlerTest method testHandleGet.
@Test
public void testHandleGet() throws IOException, ServletException {
Request baseRequest = createMock(Request.class);
expect(baseRequest.getMethod()).andReturn("GET");
expect(baseRequest.getPathInfo()).andReturn("/abcdef");
expect(baseRequest.getParameter("callback")).andReturn(null);
baseRequest.setHandled(true);
HttpServletRequest request = createMock(HttpServletRequest.class);
HttpServletResponse response = createMock(HttpServletResponse.class);
response.setStatus(200);
response.setContentType("application/javascript; charset=utf-8");
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
expect(response.getWriter()).andReturn(printWriter);
response.flushBuffer();
BuildTraces buildTraces = createMock(BuildTraces.class);
Iterable<InputStream> traces = Arrays.asList(new ByteArrayInputStream("{\"foo\":\"bar\"}".getBytes(Charsets.UTF_8)));
expect(buildTraces.getInputsForTraces("abcdef")).andReturn(traces);
TraceDataHandler traceDataHandler = new TraceDataHandler(buildTraces);
replayAll();
traceDataHandler.handle("/trace/abcdef", baseRequest, request, response);
verifyAll();
assertEquals("[{\"foo\":\"bar\"}]", stringWriter.toString());
}
use of com.facebook.buck.util.trace.BuildTraces in project buck by facebook.
the class TraceHandlerDelegateTest method testMalformedPathInfoReturnsError.
@Test
public void testMalformedPathInfoReturnsError() throws IOException {
Request baseRequest = createMock(Request.class);
expect(baseRequest.getPathInfo()).andReturn("/..upADirectory");
// Nothing on the helper should be invoked because the handler will error-out first.
BuildTraces buildTraces = createMock(BuildTraces.class);
replayAll();
TraceHandlerDelegate traceHandler = new TraceHandlerDelegate(buildTraces);
assertNull(traceHandler.getDataForRequest(baseRequest));
verifyAll();
}
use of com.facebook.buck.util.trace.BuildTraces in project buck by facebook.
the class TraceHandlerDelegateTest method testHandleGet.
@Test
public void testHandleGet() throws IOException, ServletException {
Request baseRequest = createMock(Request.class);
expect(baseRequest.getPathInfo()).andReturn("/abcdef");
baseRequest.setHandled(true);
HttpServletRequest request = createMock(HttpServletRequest.class);
HttpServletResponse response = createMock(HttpServletResponse.class);
response.setStatus(200);
response.setContentType("text/html; charset=utf-8");
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
expect(response.getWriter()).andReturn(printWriter);
response.flushBuffer();
BuildTraces buildTraces = createMock(BuildTraces.class);
expect(buildTraces.getTraceAttributesFor("abcdef")).andReturn(new TraceAttributes(Optional.of("buck build buck"), 2000L));
Handler traceHandler = new TemplateHandler(new TraceHandlerDelegate(buildTraces));
replayAll();
traceHandler.handle("/trace/abcdef", baseRequest, request, response);
verifyAll();
String expectedScriptTag = "<script src=\"/tracedata/abcdef?callback=onTracesLoaded\">";
String html = stringWriter.toString();
assertThat(html, containsString(expectedScriptTag));
assertThat(html, containsString("buck build buck"));
}
use of com.facebook.buck.util.trace.BuildTraces in project buck by facebook.
the class TracesHandlerTest method testHandleGet.
@Test
public void testHandleGet() throws IOException {
BuildTraces buildTraces = createMock(BuildTraces.class);
expect(buildTraces.getTraceAttributesFor(traceDir.resolve("build.a.trace"))).andReturn(new TraceAttributes(Optional.of("buck build buck"), 1000L));
expect(buildTraces.getTraceAttributesFor(traceDir.resolve("build.b.trace"))).andReturn(new TraceAttributes(Optional.of("buck test --all --code-coverage"), 4000L));
expect(buildTraces.getTraceAttributesFor(traceDir.resolve("build.c.trace"))).andReturn(new TraceAttributes(Optional.empty(), 2000L));
expect(buildTraces.getTraceAttributesFor(traceDir.resolve("build.d.trace"))).andReturn(new TraceAttributes(Optional.of("buck test //test/com/facebook/buck/cli:cli"), 3000L));
expect(buildTraces.listTraceFilesByLastModified()).andReturn(ImmutableList.of(traceDir.resolve("build.b.trace"), traceDir.resolve("build.d.trace"), traceDir.resolve("build.c.trace"), traceDir.resolve("build.a.trace")));
Request baseRequest = createMock(Request.class);
replayAll();
TracesHandlerDelegate delegate = new TracesHandlerDelegate(buildTraces);
TemplateHandler tracesHandler = new TemplateHandler(delegate);
String html = tracesHandler.createHtmlForResponse(baseRequest);
int indexB = html.indexOf("<a href=\"/trace/b\"><tt>build.b.trace</tt></a>");
assertTrue(indexB > 0);
int indexBCommand = html.indexOf("buck test --all --code-coverage");
assertTrue(indexBCommand > 0);
int indexD = html.indexOf("<a href=\"/trace/d\"><tt>build.d.trace</tt></a>");
assertTrue(indexD > indexB);
int indexDCommand = html.indexOf("buck test //test/com/facebook/buck/cli:cli");
assertTrue(indexDCommand > indexBCommand);
int indexC = html.indexOf("<a href=\"/trace/c\"><tt>build.c.trace</tt></a>");
assertTrue(indexC > indexD);
int indexA = html.indexOf("<a href=\"/trace/a\"><tt>build.a.trace</tt></a>");
assertTrue(indexA > indexC);
int indexACommand = html.indexOf("buck build buck");
assertTrue(indexACommand > indexDCommand);
verifyAll();
}
Aggregations