Search in sources :

Example 1 with FakeListeningExecutorService

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());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BorrowablePath(com.facebook.buck.io.BorrowablePath) LazyPath(com.facebook.buck.io.LazyPath) Path(java.nio.file.Path) RuleKey(com.facebook.buck.rules.RuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) LazyPath(com.facebook.buck.io.LazyPath) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpService(com.facebook.buck.slb.HttpService) FakeListeningExecutorService(com.facebook.buck.util.concurrent.FakeListeningExecutorService) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) FakeListeningExecutorService(com.facebook.buck.util.concurrent.FakeListeningExecutorService)

Aggregations

BuckEventBus (com.facebook.buck.event.BuckEventBus)1 BorrowablePath (com.facebook.buck.io.BorrowablePath)1 LazyPath (com.facebook.buck.io.LazyPath)1 RuleKey (com.facebook.buck.rules.RuleKey)1 HttpService (com.facebook.buck.slb.HttpService)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1 FakeListeningExecutorService (com.facebook.buck.util.concurrent.FakeListeningExecutorService)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 Path (java.nio.file.Path)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1