Search in sources :

Example 91 with EventBus

use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.

the class LexerTest method createLexer.

/**
   * Create a lexer which takes input from the specified string. Resets the
   * error handler beforehand.
   */
private Lexer createLexer(String input) {
    PathFragment somePath = new PathFragment("/some/path.txt");
    ParserInputSource inputSource = ParserInputSource.create(input, somePath);
    Reporter reporter = new Reporter(new EventBus());
    reporter.addHandler(new EventHandler() {

        @Override
        public void handle(Event event) {
            if (EventKind.ERRORS.contains(event.getKind())) {
                lastErrorLocation = event.getLocation();
                lastError = lastErrorLocation.getPath() + ":" + event.getLocation().getStartLineAndColumn().getLine() + ": " + event.getMessage();
            }
        }
    });
    return new Lexer(inputSource, reporter);
}
Also used : Reporter(com.google.devtools.build.lib.events.Reporter) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) EventHandler(com.google.devtools.build.lib.events.EventHandler) Event(com.google.devtools.build.lib.events.Event) EventBus(com.google.common.eventbus.EventBus)

Example 92 with EventBus

use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.

the class DarwinSandboxedStrategy method exec.

@Override
public void exec(Spawn spawn, ActionExecutionContext actionExecutionContext, AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException {
    Executor executor = actionExecutionContext.getExecutor();
    // Certain actions can't run remotely or in a sandbox - pass them on to the standalone strategy.
    if (!spawn.isRemotable() || spawn.hasNoSandbox()) {
        SandboxHelpers.fallbackToNonSandboxedExecution(spawn, actionExecutionContext, executor);
        return;
    }
    EventBus eventBus = actionExecutionContext.getExecutor().getEventBus();
    ActionExecutionMetadata owner = spawn.getResourceOwner();
    eventBus.post(ActionStatusMessage.schedulingStrategy(owner));
    try (ResourceHandle handle = ResourceManager.instance().acquireResources(owner, spawn.getLocalResources())) {
        SandboxHelpers.postActionStatusMessage(eventBus, spawn);
        actuallyExec(spawn, actionExecutionContext, writeOutputFiles);
    }
}
Also used : ActionExecutionMetadata(com.google.devtools.build.lib.actions.ActionExecutionMetadata) Executor(com.google.devtools.build.lib.actions.Executor) ResourceHandle(com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle) EventBus(com.google.common.eventbus.EventBus)

Example 93 with EventBus

use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.

the class LinuxSandboxedStrategy method exec.

@Override
public void exec(Spawn spawn, ActionExecutionContext actionExecutionContext, AtomicReference<Class<? extends SpawnActionContext>> writeOutputFiles) throws ExecException, InterruptedException {
    Executor executor = actionExecutionContext.getExecutor();
    // Certain actions can't run remotely or in a sandbox - pass them on to the standalone strategy.
    if (!spawn.isRemotable() || spawn.hasNoSandbox()) {
        SandboxHelpers.fallbackToNonSandboxedExecution(spawn, actionExecutionContext, executor);
        return;
    }
    EventBus eventBus = actionExecutionContext.getExecutor().getEventBus();
    ActionExecutionMetadata owner = spawn.getResourceOwner();
    eventBus.post(ActionStatusMessage.schedulingStrategy(owner));
    try (ResourceHandle handle = ResourceManager.instance().acquireResources(owner, spawn.getLocalResources())) {
        SandboxHelpers.postActionStatusMessage(eventBus, spawn);
        actuallyExec(spawn, actionExecutionContext, writeOutputFiles);
    }
}
Also used : ActionExecutionMetadata(com.google.devtools.build.lib.actions.ActionExecutionMetadata) Executor(com.google.devtools.build.lib.actions.Executor) ResourceHandle(com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle) EventBus(com.google.common.eventbus.EventBus)

Example 94 with EventBus

use of com.google.common.eventbus.EventBus in project buck by facebook.

the class WatchmanWatcherIntegrationTest method setUp.

@Before
public void setUp() throws InterruptedException, IOException {
    // Create an empty watchman config file.
    Files.write(tmp.getRoot().resolve(".watchmanconfig"), new byte[0]);
    watchman = Watchman.build(ImmutableSet.of(tmp.getRoot()), ImmutableMap.copyOf(System.getenv()), new Console(Verbosity.ALL, System.out, System.err, Ansi.withoutTty()), new DefaultClock(), Optional.empty());
    assumeTrue(watchman.getWatchmanClient().isPresent());
    eventBus = new EventBus();
    watchmanEventCollector = new WatchmanEventCollector();
    eventBus.register(watchmanEventCollector);
}
Also used : DefaultClock(com.facebook.buck.timing.DefaultClock) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) Before(org.junit.Before)

Example 95 with EventBus

use of com.google.common.eventbus.EventBus in project buck by facebook.

the class WatchmanWatcherTest method whenWatchmanProducesAWarningThenWarningAddedToCache.

@Test
public void whenWatchmanProducesAWarningThenWarningAddedToCache() throws IOException, InterruptedException {
    String message = "I'm a warning!";
    ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of(), "warning", message);
    EventBus eventBus = new EventBus("watchman test");
    WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
    Set<WatchmanDiagnostic> diagnostics = new HashSet<>();
    BuckEventBus buckEventBus = BuckEventBusFactory.newInstance(new FakeClock(0));
    buckEventBus.register(new WatchmanDiagnosticEventListener(buckEventBus, diagnostics));
    watcher.postEvents(buckEventBus, WatchmanWatcher.FreshInstanceAction.NONE);
    assertThat(diagnostics, hasItem(WatchmanDiagnostic.of(WatchmanDiagnostic.Level.WARNING, message)));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeClock(com.facebook.buck.timing.FakeClock) WatchmanDiagnostic(com.facebook.buck.io.WatchmanDiagnostic) EasyMock.anyObject(org.easymock.EasyMock.anyObject) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) WatchmanDiagnosticEventListener(com.facebook.buck.io.WatchmanDiagnosticEventListener) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

EventBus (com.google.common.eventbus.EventBus)163 Test (org.junit.Test)73 Before (org.junit.Before)24 BuckEventBus (com.facebook.buck.event.BuckEventBus)21 HashMap (java.util.HashMap)20 FakeClock (com.facebook.buck.timing.FakeClock)19 Subscribe (com.google.common.eventbus.Subscribe)19 ArrayList (java.util.ArrayList)19 EasyMock.anyObject (org.easymock.EasyMock.anyObject)18 Reporter (com.google.devtools.build.lib.events.Reporter)15 List (java.util.List)14 WatchEvent (java.nio.file.WatchEvent)12 Test (org.junit.jupiter.api.Test)11 RefreshEndpointEvent (org.apache.servicecomb.http.client.event.RefreshEndpointEvent)10 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)8 Expectations (mockit.Expectations)8 Microservice (org.apache.servicecomb.registry.api.registry.Microservice)8 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)8 Test (org.testng.annotations.Test)8 Path (com.google.devtools.build.lib.vfs.Path)7