Search in sources :

Example 1 with BuckEvent

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

the class HttpArtifactCacheTest method errorTextReplaced.

@Test
public void errorTextReplaced() throws InterruptedException {
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
    final String cacheName = "http cache";
    final RuleKey ruleKey = new RuleKey("00000000000000000000000000000000");
    final RuleKey otherRuleKey = new RuleKey("11111111111111111111111111111111");
    final String data = "data";
    final AtomicBoolean consoleEventReceived = new AtomicBoolean(false);
    argsBuilder.setCacheName(cacheName).setProjectFilesystem(filesystem).setBuckEventBus(new BuckEventBus(new IncrementingFakeClock(), new BuildId()) {

        @Override
        public void post(BuckEvent event) {
            if (event instanceof ConsoleEvent) {
                consoleEventReceived.set(true);
                ConsoleEvent consoleEvent = (ConsoleEvent) event;
                assertThat(consoleEvent.getMessage(), Matchers.containsString(cacheName));
                assertThat(consoleEvent.getMessage(), Matchers.containsString("incorrect key name"));
            }
        }
    }).setFetchClient(withMakeRequest((path, requestBuilder) -> {
        Request request = requestBuilder.url(SERVER + path).build();
        Response response = new Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(HttpURLConnection.HTTP_OK).body(createResponseBody(ImmutableSet.of(otherRuleKey), ImmutableMap.of(), ByteSource.wrap(data.getBytes(Charsets.UTF_8)), data)).build();
        return new OkHttpResponseWrapper(response);
    }));
    HttpArtifactCache cache = new HttpArtifactCache(argsBuilder.build());
    Path output = Paths.get("output/file");
    CacheResult result = cache.fetch(ruleKey, LazyPath.ofInstance(output));
    assertEquals(CacheResultType.ERROR, result.getType());
    assertEquals(Optional.empty(), filesystem.readFileIfItExists(output));
    assertTrue(consoleEventReceived.get());
    cache.close();
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuckEventBus(com.facebook.buck.event.BuckEventBus) HttpURLConnection(java.net.HttpURLConnection) DataInputStream(java.io.DataInputStream) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BuckEvent(com.facebook.buck.event.BuckEvent) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) Assert.assertThat(org.junit.Assert.assertThat) Lists(com.google.common.collect.Lists) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) BuildId(com.facebook.buck.model.BuildId) RuleKey(com.facebook.buck.rules.RuleKey) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Response(okhttp3.Response) ByteSource(com.google.common.io.ByteSource) HttpResponse(com.facebook.buck.slb.HttpResponse) Path(java.nio.file.Path) MediaType(okhttp3.MediaType) ResponseBody(okhttp3.ResponseBody) HttpService(com.facebook.buck.slb.HttpService) Before(org.junit.Before) Charsets(com.google.common.base.Charsets) Request(okhttp3.Request) Buffer(okio.Buffer) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Assert.assertTrue(org.junit.Assert.assertTrue) OkHttpResponseWrapper(com.facebook.buck.slb.OkHttpResponseWrapper) Matchers(org.hamcrest.Matchers) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) List(java.util.List) Paths(java.nio.file.Paths) LazyPath(com.facebook.buck.io.LazyPath) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Optional(java.util.Optional) Protocol(okhttp3.Protocol) Assert.assertEquals(org.junit.Assert.assertEquals) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Path(java.nio.file.Path) LazyPath(com.facebook.buck.io.LazyPath) RuleKey(com.facebook.buck.rules.RuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Request(okhttp3.Request) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) OkHttpResponseWrapper(com.facebook.buck.slb.OkHttpResponseWrapper) BuckEvent(com.facebook.buck.event.BuckEvent) Response(okhttp3.Response) HttpResponse(com.facebook.buck.slb.HttpResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BuildId(com.facebook.buck.model.BuildId) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) Test(org.junit.Test)

Example 2 with BuckEvent

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

the class BuckEventOrdererTest method testMergesTwoSetsOfSerialEvents.

@Test
public void testMergesTwoSetsOfSerialEvents() {
    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(fourth);
        orderer.add(first);
        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 3 with BuckEvent

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

the class BuckEventOrdererTest method testMergesSingleEventAtEndCorrectly.

@Test
public void testMergesSingleEventAtEndCorrectly() {
    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(first);
        orderer.add(third);
        orderer.add(second);
    }
    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 4 with BuckEvent

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

the class BuckEventOrdererTest method testMergesSingleSetOfSerialEvents.

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

Example 5 with BuckEvent

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

the class BuckEventOrdererTest method testReordersEventsWithinSkewWindow.

@Test
public void testReordersEventsWithinSkewWindow() {
    BuckEvent first = createUniqueEvent(0, TimeUnit.MILLISECONDS, THREAD_ONE);
    BuckEvent second = createUniqueEvent(5, TimeUnit.MILLISECONDS, THREAD_ONE);
    try (BuckEventOrderer<BuckEvent> orderer = new BuckEventOrderer<>(addToSerializedEventsFunction, MAX_SKEW, TimeUnit.MILLISECONDS)) {
        orderer.add(second);
        orderer.add(first);
    }
    assertThat(serializedEvents, Matchers.contains(first, second));
}
Also used : BuckEvent(com.facebook.buck.event.BuckEvent) AbstractBuckEvent(com.facebook.buck.event.AbstractBuckEvent) 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