use of com.facebook.buck.event.BuckEventBus 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.BuckEventBus in project buck by facebook.
the class ArtifactCachesTest method testCreateHttpCacheOnly.
@Test
public void testCreateHttpCacheOnly() throws Exception {
ArtifactCacheBuckConfig cacheConfig = ArtifactCacheBuckConfigTest.createFromText("[cache]", "mode = http");
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance();
ArtifactCache artifactCache = new ArtifactCaches(cacheConfig, buckEventBus, projectFilesystem, Optional.empty(), MoreExecutors.newDirectExecutorService(), Optional.empty()).newInstance();
assertThat(stripDecorators(artifactCache), Matchers.instanceOf(HttpArtifactCache.class));
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class ArtifactCachesTest method testCreateReadOnlyDirCacheExperimentalCache.
@Test
public void testCreateReadOnlyDirCacheExperimentalCache() throws Exception {
assumeThat(Platform.detect(), Matchers.not(Matchers.equalTo(Platform.WINDOWS)));
ArtifactCacheBuckConfig cacheConfig = ArtifactCacheBuckConfigTest.createFromText("[cache]", "mode = dir, http", "_exp_propagation = true", "_exp_propagation_force_control_group = true");
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance();
ArtifactCache artifactCache = new ArtifactCaches(cacheConfig, buckEventBus, projectFilesystem, Optional.empty(), MoreExecutors.newDirectExecutorService(), Optional.empty()).newInstance();
ArtifactCache result = stripDecorators(artifactCache);
assertThat(result, Matchers.instanceOf(RemoteArtifactsInLocalCacheArtifactCache.class));
RemoteArtifactsInLocalCacheArtifactCache experimentalCache = (RemoteArtifactsInLocalCacheArtifactCache) result;
assertThat(experimentalCache.getLocalCaches(), Matchers.instanceOf(MultiArtifactCache.class));
assertThat(experimentalCache.getLocalCaches().getArtifactCaches().get(0), Matchers.instanceOf(CacheDecorator.class));
CacheDecorator decorator = (CacheDecorator) experimentalCache.getLocalCaches().getArtifactCaches().get(0);
assertThat(decorator.getDelegate(), Matchers.instanceOf(DirArtifactCache.class));
assertThat(experimentalCache.getRemoteCaches(), Matchers.instanceOf(MultiArtifactCache.class));
assertThat(experimentalCache.getRemoteCaches().getArtifactCaches().get(0), Matchers.instanceOf(HttpArtifactCache.class));
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class AuditInputCommandTest method setUp.
@Before
public void setUp() throws IOException, InterruptedException {
console = new TestConsole();
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
projectFilesystem.touch(Paths.get("src/com/facebook/AndroidLibraryTwo.java"));
projectFilesystem.touch(Paths.get("src/com/facebook/TestAndroidLibrary.java"));
projectFilesystem.touch(Paths.get("src/com/facebook/TestJavaLibrary.java"));
Cell cell = new TestCellBuilder().setFilesystem(projectFilesystem).build();
ArtifactCache artifactCache = new NoopArtifactCache();
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
auditInputCommand = new AuditInputCommand();
params = CommandRunnerParamsForTesting.createCommandRunnerParamsForTesting(console, cell, new FakeAndroidDirectoryResolver(), artifactCache, eventBus, FakeBuckConfig.builder().build(), Platform.detect(), ImmutableMap.copyOf(System.getenv()), new FakeJavaPackageFinder(), objectMapper, Optional.empty());
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class QueryCommandTest method setUp.
@Before
public void setUp() throws IOException, InterruptedException {
TestConsole console = new TestConsole();
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "query_command", tmp);
workspace.setUp();
ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath().toRealPath().normalize());
Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
AndroidDirectoryResolver androidDirectoryResolver = new FakeAndroidDirectoryResolver();
ArtifactCache artifactCache = new NoopArtifactCache();
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
queryCommand = new QueryCommand();
queryCommand.outputAttributes = Suppliers.ofInstance(ImmutableSet.<String>of());
params = CommandRunnerParamsForTesting.createCommandRunnerParamsForTesting(console, cell, androidDirectoryResolver, artifactCache, eventBus, FakeBuckConfig.builder().build(), Platform.detect(), ImmutableMap.copyOf(System.getenv()), new FakeJavaPackageFinder(), objectMapper, Optional.empty());
executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
}
Aggregations