Search in sources :

Example 16 with BuckEvent

use of com.facebook.buck.event.BuckEvent in project buck by facebook.

the class WorkerShellStepTest method testWarningIsPrintedForIdenticalWorkerToolsWithDifferentCapacity.

@Test
public void testWarningIsPrintedForIdenticalWorkerToolsWithDifferentCapacity() throws InterruptedException {
    int existingPoolSize = 2;
    int stepPoolSize = 4;
    ExecutionContext context = createExecutionContextWith(ImmutableMap.of("jobArgs", WorkerJobResult.of(0, Optional.of(""), Optional.of(""))), existingPoolSize);
    FakeBuckEventListener listener = new FakeBuckEventListener();
    context.getBuckEventBus().register(listener);
    WorkerJobParams params = createJobParams(ImmutableList.of(startupCommand), startupArgs, ImmutableMap.of(), "jobArgs", stepPoolSize);
    WorkerShellStep step = createWorkerShellStep(params, null, null);
    step.execute(context);
    BuckEvent firstEvent = listener.getEvents().get(0);
    assertThat(firstEvent, Matchers.instanceOf(ConsoleEvent.class));
    ConsoleEvent consoleEvent = (ConsoleEvent) firstEvent;
    assertThat(consoleEvent.getLevel(), Matchers.is(Level.WARNING));
    assertThat(consoleEvent.getMessage(), Matchers.is(String.format("There are two 'worker_tool' targets declared with the same command (%s), but different " + "'max_worker' settings (%d and %d). Only the first capacity is applied. Consolidate " + "these workers to avoid this warning.", fakeWorkerStartupCommand, existingPoolSize, stepPoolSize)));
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) FakeBuckEventListener(com.facebook.buck.event.FakeBuckEventListener) BuckEvent(com.facebook.buck.event.BuckEvent) Test(org.junit.Test)

Example 17 with BuckEvent

use of com.facebook.buck.event.BuckEvent in project buck by facebook.

the class WorkerShellStepTest method testJobIsExecutedAndResultIsReceived.

@Test
public void testJobIsExecutedAndResultIsReceived() throws IOException, InterruptedException {
    String stdout = "my stdout";
    String stderr = "my stderr";
    ExecutionContext context = createExecutionContextWith(0, stdout, stderr);
    WorkerShellStep step = createWorkerShellStep(createJobParams(ImmutableList.of(startupCommand), startupArgs, ImmutableMap.of(), "myJobArgs"), null, null);
    FakeBuckEventListener listener = new FakeBuckEventListener();
    context.getBuckEventBus().register(listener);
    int exitCode = step.execute(context).getExitCode();
    assertThat(exitCode, Matchers.equalTo(0));
    // assert that the job's stdout and stderr were written to the console
    BuckEvent firstEvent = listener.getEvents().get(0);
    assertTrue(firstEvent instanceof ConsoleEvent);
    assertThat(((ConsoleEvent) firstEvent).getLevel(), Matchers.is(Level.INFO));
    assertThat(((ConsoleEvent) firstEvent).getMessage(), Matchers.is(stdout));
    BuckEvent secondEvent = listener.getEvents().get(1);
    assertTrue(secondEvent instanceof ConsoleEvent);
    assertThat(((ConsoleEvent) secondEvent).getLevel(), Matchers.is(Level.WARNING));
    assertThat(((ConsoleEvent) secondEvent).getMessage(), Matchers.is(stderr));
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) FakeBuckEventListener(com.facebook.buck.event.FakeBuckEventListener) BuckEvent(com.facebook.buck.event.BuckEvent) Test(org.junit.Test)

Example 18 with BuckEvent

use of com.facebook.buck.event.BuckEvent in project buck by facebook.

the class PerfStatsTrackingTest method probingMemoryPostsToTheEventBus.

@Test
public void probingMemoryPostsToTheEventBus() throws Exception {
    BuckEventBus eventBus = BuckEventBusFactory.newInstance();
    final BlockingQueue<BuckEvent> events = new LinkedBlockingQueue<>();
    eventBus.register(new Object() {

        @Subscribe
        public void event(BuckEvent event) {
            events.add(event);
        }
    });
    try (PerfStatsTrackingForTest perfStatsTracking = new PerfStatsTrackingForTest(eventBus, FakeInvocationInfoFactory.create())) {
        perfStatsTracking.runOneIteration();
        // The BuckEventBus runs on a separate thread, give it a moment to push the event.
        BuckEvent event = events.poll(100, TimeUnit.MILLISECONDS);
        assertThat(event, Matchers.notNullValue());
        assertThat(event, Matchers.instanceOf(PerfStatsTracking.MemoryPerfStatsEvent.class));
        PerfStatsTracking.MemoryPerfStatsEvent memoryEvent = (PerfStatsTracking.MemoryPerfStatsEvent) event;
        assertThat(memoryEvent.getTotalMemoryBytes(), Matchers.greaterThan(0L));
        assertThat(memoryEvent.getCurrentMemoryBytesUsageByPool().size(), Matchers.greaterThan(0));
    }
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) Subscribe(com.google.common.eventbus.Subscribe) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) BuckEvent(com.facebook.buck.event.BuckEvent) Test(org.junit.Test)

Example 19 with BuckEvent

use of com.facebook.buck.event.BuckEvent in project buck by facebook.

the class WatchmanWatcherTest method whenWatchmanReportsZeroFilesChangedThenPostEvent.

@Test
public void whenWatchmanReportsZeroFilesChangedThenPostEvent() throws IOException, InterruptedException {
    ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of());
    WatchmanWatcher watcher = createWatcher(new EventBus("watchman test"), watchmanOutput);
    final Set<BuckEvent> events = Sets.newHashSet();
    BuckEventBus bus = BuckEventBusFactory.newInstance(new FakeClock(0));
    bus.register(new Object() {

        @Subscribe
        public void listen(WatchmanStatusEvent event) {
            events.add(event);
        }
    });
    watcher.postEvents(bus, WatchmanWatcher.FreshInstanceAction.POST_OVERFLOW_EVENT);
    boolean zeroFilesChangedSeen = false;
    System.err.println(String.format("Events: %d", events.size()));
    for (BuckEvent event : events) {
        zeroFilesChangedSeen |= event.getEventName().equals("WatchmanZeroFileChanges");
    }
    assertTrue(zeroFilesChangedSeen);
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) WatchmanStatusEvent(com.facebook.buck.event.WatchmanStatusEvent) FakeClock(com.facebook.buck.timing.FakeClock) EasyMock.anyObject(org.easymock.EasyMock.anyObject) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) Subscribe(com.google.common.eventbus.Subscribe) BuckEvent(com.facebook.buck.event.BuckEvent) Test(org.junit.Test)

Aggregations

BuckEvent (com.facebook.buck.event.BuckEvent)19 Test (org.junit.Test)16 AbstractBuckEvent (com.facebook.buck.event.AbstractBuckEvent)12 BuckEventBus (com.facebook.buck.event.BuckEventBus)5 ConsoleEvent (com.facebook.buck.event.ConsoleEvent)4 Subscribe (com.google.common.eventbus.Subscribe)4 FakeBuckEventListener (com.facebook.buck.event.FakeBuckEventListener)3 ExecutionContext (com.facebook.buck.step.ExecutionContext)3 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)3 FakeClock (com.facebook.buck.timing.FakeClock)3 WatchmanStatusEvent (com.facebook.buck.event.WatchmanStatusEvent)2 BuildId (com.facebook.buck.model.BuildId)2 EventBus (com.google.common.eventbus.EventBus)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 FakeWatchmanClient (com.facebook.buck.io.FakeWatchmanClient)1 LazyPath (com.facebook.buck.io.LazyPath)1 WatchmanCursor (com.facebook.buck.io.WatchmanCursor)1 RuleKey (com.facebook.buck.rules.RuleKey)1 HttpResponse (com.facebook.buck.slb.HttpResponse)1 HttpService (com.facebook.buck.slb.HttpService)1