Search in sources :

Example 6 with BuckEvent

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

the class BuckEventOrdererTest method testMergesSingleEventAtStartCorrectly.

@Test
public void testMergesSingleEventAtStartCorrectly() {
    BuckEvent first = createUniqueEvent(0, TimeUnit.MILLISECONDS, THREAD_ONE);
    BuckEvent second = createUniqueEvent(1, TimeUnit.MILLISECONDS, THREAD_TWO);
    BuckEvent third = createUniqueEvent(2, TimeUnit.MILLISECONDS, THREAD_ONE);
    try (BuckEventOrderer<BuckEvent> orderer = new BuckEventOrderer<>(addToSerializedEventsFunction, MAX_SKEW, TimeUnit.MILLISECONDS)) {
        orderer.add(second);
        orderer.add(first);
        orderer.add(third);
    }
    assertThat(serializedEvents, Matchers.contains(first, second, third));
}
Also used : BuckEvent(com.facebook.buck.event.BuckEvent) AbstractBuckEvent(com.facebook.buck.event.AbstractBuckEvent) Test(org.junit.Test)

Example 7 with BuckEvent

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

the class BuckEventOrdererTest method testMergesTwoInterleavedEventSeries.

@Test
public void testMergesTwoInterleavedEventSeries() {
    BuckEvent first = createUniqueEvent(0, TimeUnit.MILLISECONDS, THREAD_ONE);
    BuckEvent second = createUniqueEvent(1, TimeUnit.MILLISECONDS, THREAD_TWO);
    BuckEvent third = createUniqueEvent(2, TimeUnit.MILLISECONDS, THREAD_ONE);
    BuckEvent fourth = createUniqueEvent(3, TimeUnit.MILLISECONDS, THREAD_TWO);
    try (BuckEventOrderer<BuckEvent> orderer = new BuckEventOrderer<>(addToSerializedEventsFunction, MAX_SKEW, TimeUnit.MILLISECONDS)) {
        orderer.add(second);
        orderer.add(first);
        orderer.add(fourth);
        orderer.add(third);
    }
    assertThat(serializedEvents, Matchers.contains(first, second, third, fourth));
}
Also used : BuckEvent(com.facebook.buck.event.BuckEvent) AbstractBuckEvent(com.facebook.buck.event.AbstractBuckEvent) Test(org.junit.Test)

Example 8 with BuckEvent

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

the class UnskippedRulesTrackerTest method assertReceivedEvent.

private void assertReceivedEvent(int numRules) throws InterruptedException {
    BuckEvent event = events.take();
    assertThat(event, is(instanceOf(BuildEvent.UnskippedRuleCountUpdated.class)));
    BuildEvent.UnskippedRuleCountUpdated countEvent = (BuildEvent.UnskippedRuleCountUpdated) event;
    assertThat(countEvent.getNumRules(), is(equalTo(numRules)));
}
Also used : BuckEvent(com.facebook.buck.event.BuckEvent) AbstractBuckEvent(com.facebook.buck.event.AbstractBuckEvent)

Example 9 with BuckEvent

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

the class WorkerShellStepTest method testStdErrIsPrintedAsErrorIfJobFails.

@Test
public void testStdErrIsPrintedAsErrorIfJobFails() throws IOException, InterruptedException {
    String stderr = "my stderr";
    ExecutionContext context = createExecutionContextWith(1, "", 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(1));
    // assert that the job's stderr was written to the console as error, not as warning
    BuckEvent firstEvent = listener.getEvents().get(0);
    assertTrue(firstEvent instanceof ConsoleEvent);
    assertThat(((ConsoleEvent) firstEvent).getLevel(), Matchers.is(Level.SEVERE));
    assertThat(((ConsoleEvent) firstEvent).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 10 with BuckEvent

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

the class WatchmanWatcherTest method whenWatchmanCellReportsFilesChangedThenPostEvent.

@Test
public void whenWatchmanCellReportsFilesChangedThenPostEvent() throws IOException, InterruptedException {
    ImmutableMap<String, Object> watchmanRootOutput = ImmutableMap.of("files", ImmutableList.of());
    ImmutableMap<String, Object> watchmanSecondaryOutput = ImmutableMap.of("files", ImmutableList.of(ImmutableMap.<String, Object>of("name", "foo/bar/baz")));
    WatchmanWatcher watcher = new WatchmanWatcher(new EventBus("watchman test"), new FakeWatchmanClient(0, ImmutableMap.of(FAKE_CLOCK_QUERY, watchmanRootOutput, FAKE_SECONDARY_QUERY.toList("c:0:0"), watchmanSecondaryOutput)), 10000, ImmutableMap.of(FAKE_ROOT, FAKE_QUERY, FAKE_SECONDARY_ROOT, FAKE_SECONDARY_QUERY), ImmutableMap.of(FAKE_ROOT, new WatchmanCursor("c:0:0"), FAKE_SECONDARY_ROOT, new WatchmanCursor("c:0:0")));
    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) {
        System.err.println(String.format("Event: %s", event));
        zeroFilesChangedSeen |= event.getEventName().equals("WatchmanZeroFileChanges");
    }
    assertFalse(zeroFilesChangedSeen);
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeWatchmanClient(com.facebook.buck.io.FakeWatchmanClient) WatchmanStatusEvent(com.facebook.buck.event.WatchmanStatusEvent) FakeClock(com.facebook.buck.timing.FakeClock) WatchmanCursor(com.facebook.buck.io.WatchmanCursor) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) Subscribe(com.google.common.eventbus.Subscribe) BuckEvent(com.facebook.buck.event.BuckEvent) EasyMock.anyObject(org.easymock.EasyMock.anyObject) 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