Search in sources :

Example 1 with AnnouncementResponse

use of com.facebook.buck.distributed.thrift.AnnouncementResponse 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.");
    }
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) RemoteLogBuckConfig(com.facebook.buck.util.network.RemoteLogBuckConfig) DefaultExecutionEnvironment(com.facebook.buck.util.environment.DefaultExecutionEnvironment) ExecutionEnvironment(com.facebook.buck.util.environment.ExecutionEnvironment) Announcement(com.facebook.buck.distributed.thrift.Announcement) AnnouncementResponse(com.facebook.buck.distributed.thrift.AnnouncementResponse) DataOutputStream(java.io.DataOutputStream) DefaultClock(com.facebook.buck.timing.DefaultClock) Clock(com.facebook.buck.timing.Clock) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) RemoteLogBuckConfig(com.facebook.buck.util.network.RemoteLogBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) DefaultClock(com.facebook.buck.timing.DefaultClock) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) HttpdForTests(com.facebook.buck.testutil.integration.HttpdForTests) DefaultExecutionEnvironment(com.facebook.buck.util.environment.DefaultExecutionEnvironment) Request(org.eclipse.jetty.server.Request) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Aggregations

BuckConfig (com.facebook.buck.cli.BuckConfig)1 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)1 Announcement (com.facebook.buck.distributed.thrift.Announcement)1 AnnouncementResponse (com.facebook.buck.distributed.thrift.AnnouncementResponse)1 FrontendRequest (com.facebook.buck.distributed.thrift.FrontendRequest)1 FrontendResponse (com.facebook.buck.distributed.thrift.FrontendResponse)1 BuckEventBus (com.facebook.buck.event.BuckEventBus)1 TestConsole (com.facebook.buck.testutil.TestConsole)1 HttpdForTests (com.facebook.buck.testutil.integration.HttpdForTests)1 Clock (com.facebook.buck.timing.Clock)1 DefaultClock (com.facebook.buck.timing.DefaultClock)1 DefaultExecutionEnvironment (com.facebook.buck.util.environment.DefaultExecutionEnvironment)1 ExecutionEnvironment (com.facebook.buck.util.environment.ExecutionEnvironment)1 RemoteLogBuckConfig (com.facebook.buck.util.network.RemoteLogBuckConfig)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1