use of com.facebook.buck.io.LazyPath 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());
}
use of com.facebook.buck.io.LazyPath in project buck by facebook.
the class TwoLevelArtifactCacheDecoratorTest method testMetadataIsNotShared.
@Test
public void testMetadataIsNotShared() throws InterruptedException, IOException {
try (InMemoryArtifactCache inMemoryArtifactCache = new InMemoryArtifactCache();
TwoLevelArtifactCacheDecorator twoLevelCache = new TwoLevelArtifactCacheDecorator(inMemoryArtifactCache, new ProjectFilesystem(tmp.getRoot()), BuckEventBusFactory.newInstance(), /* performTwoLevelStores */
true, /* minimumTwoLevelStoredArtifactSize */
0L, /* maximumTwoLevelStoredArtifactSize */
Optional.empty())) {
LazyPath dummyFile = LazyPath.ofInstance(tmp.newFile());
final String testMetadataKey = "testMetaKey";
twoLevelCache.store(ArtifactInfo.builder().addRuleKeys(dummyRuleKey).setMetadata(ImmutableMap.of(testMetadataKey, "value1")).build(), BorrowablePath.notBorrowablePath(dummyFile.get()));
twoLevelCache.store(ArtifactInfo.builder().addRuleKeys(dummyRuleKey2).setMetadata(ImmutableMap.of(testMetadataKey, "value2")).build(), BorrowablePath.notBorrowablePath(dummyFile.get()));
CacheResult fetch1 = twoLevelCache.fetch(dummyRuleKey, dummyFile);
CacheResult fetch2 = twoLevelCache.fetch(dummyRuleKey2, dummyFile);
// Content hashes should be the same
assertEquals(fetch1.getMetadata().get(TwoLevelArtifactCacheDecorator.METADATA_KEY), fetch2.getMetadata().get(TwoLevelArtifactCacheDecorator.METADATA_KEY));
// But the metadata shouldn't be shared
assertNotEquals(fetch1.getMetadata().get(testMetadataKey), fetch2.getMetadata().get(testMetadataKey));
}
}
use of com.facebook.buck.io.LazyPath in project buck by facebook.
the class TwoLevelArtifactCacheDecoratorTest method testCacheFetch.
@Test
public void testCacheFetch() throws InterruptedException, IOException {
try (InMemoryArtifactCache inMemoryArtifactCache = new InMemoryArtifactCache();
TwoLevelArtifactCacheDecorator twoLevelCache = new TwoLevelArtifactCacheDecorator(inMemoryArtifactCache, new ProjectFilesystem(tmp.getRoot()), BuckEventBusFactory.newInstance(), /* performTwoLevelStores */
true, /* minimumTwoLevelStoredArtifactSize */
0L, /* maximumTwoLevelStoredArtifactSize */
Optional.empty())) {
LazyPath dummyFile = LazyPath.ofInstance(tmp.newFile());
assertThat(twoLevelCache.fetch(dummyRuleKey, dummyFile).getType(), Matchers.equalTo(CacheResultType.MISS));
twoLevelCache.store(ArtifactInfo.builder().addRuleKeys(dummyRuleKey).build(), BorrowablePath.notBorrowablePath(dummyFile.get()));
assertThat(twoLevelCache.fetch(dummyRuleKey, dummyFile).getType(), Matchers.equalTo(CacheResultType.HIT));
twoLevelCache.store(ArtifactInfo.builder().addRuleKeys(dummyRuleKey2).build(), BorrowablePath.notBorrowablePath(dummyFile.get()));
assertThat(twoLevelCache.fetch(dummyRuleKey2, dummyFile).getType(), Matchers.equalTo(CacheResultType.HIT));
assertThat(inMemoryArtifactCache.getArtifactCount(), Matchers.equalTo(3));
}
}
use of com.facebook.buck.io.LazyPath in project buck by facebook.
the class TwoLevelArtifactCacheDecoratorTest method testStoreThresholds.
private void testStoreThresholds(int artifactSize, int expectedArtifactsInCache) throws InterruptedException, IOException {
try (InMemoryArtifactCache inMemoryArtifactCache = new InMemoryArtifactCache();
TwoLevelArtifactCacheDecorator twoLevelCache = new TwoLevelArtifactCacheDecorator(inMemoryArtifactCache, new ProjectFilesystem(tmp.getRoot()), BuckEventBusFactory.newInstance(), /* performTwoLevelStores */
true, /* minimumTwoLevelStoredArtifactSize */
5L, /* maximumTwoLevelStoredArtifactSize */
Optional.of(10L))) {
LazyPath lazyPath = LazyPath.ofInstance(tmp.newFile());
Files.write(lazyPath.get(), new byte[artifactSize]);
twoLevelCache.store(ArtifactInfo.builder().addRuleKeys(dummyRuleKey).build(), BorrowablePath.notBorrowablePath(lazyPath.get()));
assertThat(inMemoryArtifactCache.getArtifactCount(), Matchers.equalTo(expectedArtifactsInCache));
}
}
use of com.facebook.buck.io.LazyPath in project buck by facebook.
the class TwoLevelArtifactCacheDecoratorTest method testCanRead2LStoresIfStoresDisabled.
@Test
public void testCanRead2LStoresIfStoresDisabled() throws InterruptedException, IOException {
try (InMemoryArtifactCache inMemoryArtifactCache = new InMemoryArtifactCache();
TwoLevelArtifactCacheDecorator twoLevelCache = new TwoLevelArtifactCacheDecorator(inMemoryArtifactCache, new ProjectFilesystem(tmp.getRoot()), BuckEventBusFactory.newInstance(), /* performTwoLevelStores */
true, /* minimumTwoLevelStoredArtifactSize */
0L, /* maximumTwoLevelStoredArtifactSize */
Optional.empty());
TwoLevelArtifactCacheDecorator twoLevelCacheNoStore = new TwoLevelArtifactCacheDecorator(inMemoryArtifactCache, new ProjectFilesystem(tmp.getRoot()), BuckEventBusFactory.newInstance(), /* performTwoLevelStores */
false, /* minimumTwoLevelStoredArtifactSize */
0L, /* maximumTwoLevelStoredArtifactSize */
Optional.empty())) {
LazyPath dummyFile = LazyPath.ofInstance(tmp.newFile());
twoLevelCache.store(ArtifactInfo.builder().addRuleKeys(dummyRuleKey).build(), BorrowablePath.notBorrowablePath(dummyFile.get()));
assertThat(inMemoryArtifactCache.getArtifactCount(), Matchers.equalTo(2));
assertThat(twoLevelCacheNoStore.fetch(dummyRuleKey, dummyFile).getType(), Matchers.equalTo(CacheResultType.HIT));
}
}
Aggregations