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