|
42 | 42 | import com.google.devtools.build.lib.bazel.repository.downloader.Checksum; |
43 | 43 | import com.google.devtools.build.lib.bazel.repository.downloader.Downloader; |
44 | 44 | import com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException; |
| 45 | +import com.google.devtools.build.lib.clock.BlazeClock; |
45 | 46 | import com.google.devtools.build.lib.events.ExtendedEventHandler; |
46 | 47 | import com.google.devtools.build.lib.remote.ChannelConnectionWithServerCapabilitiesFactory; |
47 | 48 | import com.google.devtools.build.lib.remote.ReferenceCountedChannel; |
|
54 | 55 | import com.google.devtools.build.lib.remote.util.InMemoryCacheClient; |
55 | 56 | import com.google.devtools.build.lib.remote.util.TestUtils; |
56 | 57 | import com.google.devtools.build.lib.remote.util.TracingMetadataUtils; |
| 58 | +import com.google.devtools.build.lib.testutil.ManualClock; |
57 | 59 | import com.google.devtools.build.lib.testutil.Scratch; |
58 | 60 | import com.google.devtools.build.lib.vfs.DigestHashFunction; |
59 | 61 | import com.google.devtools.build.lib.vfs.FileSystemUtils; |
60 | 62 | import com.google.devtools.build.lib.vfs.Path; |
61 | 63 | import com.google.devtools.build.lib.vfs.SyscallCache; |
62 | 64 | import com.google.devtools.common.options.Options; |
63 | 65 | import com.google.protobuf.ByteString; |
| 66 | +import com.google.protobuf.util.Timestamps; |
64 | 67 | import io.grpc.CallCredentials; |
65 | 68 | import io.grpc.ManagedChannel; |
66 | 69 | import io.grpc.Server; |
|
73 | 76 | import java.io.InputStream; |
74 | 77 | import java.net.URI; |
75 | 78 | import java.net.URL; |
| 79 | +import java.time.Duration; |
76 | 80 | import java.util.HashMap; |
77 | 81 | import java.util.List; |
78 | 82 | import java.util.Map; |
|
90 | 94 | @RunWith(JUnit4.class) |
91 | 95 | public class GrpcRemoteDownloaderTest { |
92 | 96 |
|
| 97 | + private static final ManualClock clock = new ManualClock(); |
| 98 | + |
93 | 99 | private static final DigestUtil DIGEST_UTIL = |
94 | 100 | new DigestUtil(SyscallCache.NO_CACHE, DigestHashFunction.SHA256); |
95 | 101 |
|
@@ -117,6 +123,8 @@ public final void setUp() throws Exception { |
117 | 123 | context = RemoteActionExecutionContext.create(metadata); |
118 | 124 |
|
119 | 125 | retryService = MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(1)); |
| 126 | + |
| 127 | + BlazeClock.setClock(clock); |
120 | 128 | } |
121 | 129 |
|
122 | 130 | @After |
@@ -212,6 +220,8 @@ public void fetchBlob( |
212 | 220 | .isEqualTo( |
213 | 221 | FetchBlobRequest.newBuilder() |
214 | 222 | .setDigestFunction(DIGEST_UTIL.getDigestFunction()) |
| 223 | + .setOldestContentAccepted( |
| 224 | + Timestamps.fromMillis(clock.advance(Duration.ofHours(1)))) |
215 | 225 | .addUris("http://example.com/content.txt") |
216 | 226 | .build()); |
217 | 227 | responseObserver.onNext( |
@@ -474,4 +484,29 @@ public void testFetchBlobRequest_withoutCredentialsPropagation() throws Exceptio |
474 | 484 | Qualifier.newBuilder().setName("bazel.canonical_id").setValue("canonical ID")) |
475 | 485 | .build()); |
476 | 486 | } |
| 487 | + |
| 488 | + @Test |
| 489 | + public void testFetchBlobRequest_withoutChecksum() throws Exception { |
| 490 | + FetchBlobRequest request = |
| 491 | + GrpcRemoteDownloader.newFetchBlobRequest( |
| 492 | + "instance name", |
| 493 | + false, |
| 494 | + ImmutableList.of(new URI("http://example.com/").toURL()), |
| 495 | + Optional.<Checksum>empty(), |
| 496 | + "canonical ID", |
| 497 | + DIGEST_UTIL.getDigestFunction(), |
| 498 | + ImmutableMap.of(), |
| 499 | + StaticCredentials.EMPTY); |
| 500 | + |
| 501 | + assertThat(request) |
| 502 | + .isEqualTo( |
| 503 | + FetchBlobRequest.newBuilder() |
| 504 | + .setInstanceName("instance name") |
| 505 | + .setDigestFunction(DIGEST_UTIL.getDigestFunction()) |
| 506 | + .setOldestContentAccepted(Timestamps.fromMillis(clock.advance(Duration.ofHours(1)))) |
| 507 | + .addUris("http://example.com/") |
| 508 | + .addQualifiers( |
| 509 | + Qualifier.newBuilder().setName("bazel.canonical_id").setValue("canonical ID")) |
| 510 | + .build()); |
| 511 | + } |
477 | 512 | } |
0 commit comments