use of com.facebook.buck.util.concurrent.FakeListeningExecutorService in project buck by facebook.
the class AbstractNetworkCacheTest method testStoreCall.
private void testStoreCall(int expectStoreCallCount, Optional<Long> maxArtifactSizeBytes, int... artifactBytes) throws InterruptedException, IOException, ExecutionException {
final AtomicInteger storeCallCount = new AtomicInteger(0);
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
ListeningExecutorService service = new FakeListeningExecutorService() {
@Override
public void execute(Runnable command) {
command.run();
}
};
AbstractNetworkCache cache = new AbstractNetworkCache(NetworkCacheArgs.builder().setCacheName("AbstractNetworkCacheTest").setRepository("some_repository").setScheduleType("some_schedule_type").setFetchClient(EasyMock.createMock(HttpService.class)).setStoreClient(EasyMock.createMock(HttpService.class)).setDoStore(true).setProjectFilesystem(filesystem).setBuckEventBus(EasyMock.createMock(BuckEventBus.class)).setHttpWriteExecutorService(service).setErrorTextTemplate("super error message").setMaxStoreSizeBytes(maxArtifactSizeBytes).setDistributedBuildModeEnabled(false).build()) {
@Override
protected CacheResult fetchImpl(RuleKey ruleKey, LazyPath output, HttpArtifactCacheEvent.Finished.Builder eventBuilder) throws IOException {
return null;
}
@Override
protected void storeImpl(ArtifactInfo info, Path file, HttpArtifactCacheEvent.Finished.Builder eventBuilder) throws IOException {
storeCallCount.incrementAndGet();
}
};
for (int bytes : artifactBytes) {
Path path = filesystem.getPathForRelativePath("topspin_" + this.getClass().getName());
filesystem.writeBytesToPath(new byte[bytes], path);
ListenableFuture<Void> future = cache.store(ArtifactInfo.builder().build(), BorrowablePath.notBorrowablePath(path));
future.get();
}
Assert.assertEquals(expectStoreCallCount, storeCallCount.get());
}
Aggregations