|
39 | 39 | import com.google.devtools.build.lib.bazel.repository.downloader.Checksum;
|
40 | 40 | import com.google.devtools.build.lib.bazel.repository.downloader.Downloader;
|
41 | 41 | import com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException;
|
| 42 | +import com.google.devtools.build.lib.clock.BlazeClock; |
42 | 43 | import com.google.devtools.build.lib.events.ExtendedEventHandler;
|
43 | 44 | import com.google.devtools.build.lib.remote.ChannelConnectionWithServerCapabilitiesFactory;
|
44 | 45 | import com.google.devtools.build.lib.remote.ReferenceCountedChannel;
|
|
51 | 52 | import com.google.devtools.build.lib.remote.util.InMemoryCacheClient;
|
52 | 53 | import com.google.devtools.build.lib.remote.util.TestUtils;
|
53 | 54 | import com.google.devtools.build.lib.remote.util.TracingMetadataUtils;
|
| 55 | +import com.google.devtools.build.lib.testutil.ManualClock; |
54 | 56 | import com.google.devtools.build.lib.testutil.Scratch;
|
55 | 57 | import com.google.devtools.build.lib.vfs.DigestHashFunction;
|
56 | 58 | import com.google.devtools.build.lib.vfs.FileSystemUtils;
|
57 | 59 | import com.google.devtools.build.lib.vfs.Path;
|
58 | 60 | import com.google.devtools.build.lib.vfs.SyscallCache;
|
59 | 61 | import com.google.devtools.common.options.Options;
|
60 | 62 | import com.google.protobuf.ByteString;
|
| 63 | +import com.google.protobuf.util.Timestamps; |
61 | 64 | import io.grpc.CallCredentials;
|
62 | 65 | import io.grpc.ManagedChannel;
|
63 | 66 | import io.grpc.Server;
|
|
68 | 71 | import io.reactivex.rxjava3.core.Single;
|
69 | 72 | import java.io.IOException;
|
70 | 73 | import java.io.InputStream;
|
| 74 | +import java.net.URI; |
71 | 75 | import java.net.URL;
|
| 76 | +import java.time.Duration; |
72 | 77 | import java.util.List;
|
73 | 78 | import java.util.Map;
|
74 | 79 | import java.util.Optional;
|
|
85 | 90 | @RunWith(JUnit4.class)
|
86 | 91 | public class GrpcRemoteDownloaderTest {
|
87 | 92 |
|
| 93 | + private static final ManualClock clock = new ManualClock(); |
| 94 | + |
88 | 95 | private static final DigestUtil DIGEST_UTIL =
|
89 | 96 | new DigestUtil(SyscallCache.NO_CACHE, DigestHashFunction.SHA256);
|
90 | 97 |
|
@@ -112,6 +119,8 @@ public final void setUp() throws Exception {
|
112 | 119 | context = RemoteActionExecutionContext.create(metadata);
|
113 | 120 |
|
114 | 121 | retryService = MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(1));
|
| 122 | + |
| 123 | + BlazeClock.setClock(clock); |
115 | 124 | }
|
116 | 125 |
|
117 | 126 | @After
|
@@ -207,6 +216,8 @@ public void fetchBlob(
|
207 | 216 | .isEqualTo(
|
208 | 217 | FetchBlobRequest.newBuilder()
|
209 | 218 | .setDigestFunction(DIGEST_UTIL.getDigestFunction())
|
| 219 | + .setOldestContentAccepted( |
| 220 | + Timestamps.fromMillis(clock.advance(Duration.ofHours(1)))) |
210 | 221 | .addUris("http://example.com/content.txt")
|
211 | 222 | .build());
|
212 | 223 | responseObserver.onNext(
|
@@ -385,4 +396,27 @@ public void testFetchBlobRequest() throws Exception {
|
385 | 396 | .setValue("foo,bar"))
|
386 | 397 | .build());
|
387 | 398 | }
|
| 399 | + |
| 400 | + @Test |
| 401 | + public void testFetchBlobRequest_withoutChecksum() throws Exception { |
| 402 | + FetchBlobRequest request = |
| 403 | + GrpcRemoteDownloader.newFetchBlobRequest( |
| 404 | + "instance name", |
| 405 | + ImmutableList.of(new URI("http://example.com/").toURL()), |
| 406 | + Optional.empty(), |
| 407 | + "canonical ID", |
| 408 | + DIGEST_UTIL.getDigestFunction(), |
| 409 | + ImmutableMap.of()); |
| 410 | + |
| 411 | + assertThat(request) |
| 412 | + .isEqualTo( |
| 413 | + FetchBlobRequest.newBuilder() |
| 414 | + .setInstanceName("instance name") |
| 415 | + .setDigestFunction(DIGEST_UTIL.getDigestFunction()) |
| 416 | + .setOldestContentAccepted(Timestamps.fromMillis(clock.advance(Duration.ofHours(1)))) |
| 417 | + .addUris("http://example.com/") |
| 418 | + .addQualifiers( |
| 419 | + Qualifier.newBuilder().setName("bazel.canonical_id").setValue("canonical ID")) |
| 420 | + .build()); |
| 421 | + } |
388 | 422 | }
|
0 commit comments