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)));
}
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));
}
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));
}
}
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);
}
Aggregations