1313// limitations under the License.
1414package com .google .devtools .build .lib .remote ;
1515
16+ import static com .google .common .truth .Truth .assertThat ;
1617import static com .google .devtools .build .lib .testutil .TestUtils .tmpDirFile ;
1718
1819import com .google .common .collect .ImmutableList ;
1920import com .google .devtools .build .lib .authandtls .credentialhelper .CredentialModule ;
2021import com .google .devtools .build .lib .buildtool .util .BuildIntegrationTestCase ;
22+ import com .google .devtools .build .lib .remote .util .IntegrationTestUtils ;
23+ import com .google .devtools .build .lib .remote .util .IntegrationTestUtils .WorkerInstance ;
2124import com .google .devtools .build .lib .runtime .BlazeModule ;
2225import com .google .devtools .build .lib .runtime .BlazeRuntime ;
2326import com .google .devtools .build .lib .runtime .BlockWaitingModule ;
3235
3336@ RunWith (JUnit4 .class )
3437public class DiskCacheIntegrationTest extends BuildIntegrationTestCase {
38+ private WorkerInstance worker ;
39+
40+ private void startWorker () throws Exception {
41+ if (worker == null ) {
42+ worker = IntegrationTestUtils .startWorker ();
43+ }
44+ }
45+
46+ private void enableRemoteExec (String ... additionalOptions ) {
47+ assertThat (worker ).isNotNull ();
48+ addOptions ("--remote_executor=grpc://localhost:" + worker .getPort ());
49+ addOptions (additionalOptions );
50+ }
51+
52+ private void enableRemoteCache (String ... additionalOptions ) {
53+ assertThat (worker ).isNotNull ();
54+ addOptions ("--remote_cache=grpc://localhost:" + worker .getPort ());
55+ addOptions (additionalOptions );
56+ }
3557
3658 private static PathFragment getDiskCacheDir () {
3759 PathFragment testTmpDir = PathFragment .create (tmpDirFile ().getAbsolutePath ());
@@ -48,6 +70,10 @@ protected void setupOptions() throws Exception {
4870 @ After
4971 public void tearDown () throws IOException {
5072 getWorkspace ().getFileSystem ().getPath (getDiskCacheDir ()).deleteTree ();
73+
74+ if (worker != null ) {
75+ worker .stop ();
76+ }
5177 }
5278
5379 @ Override
@@ -93,7 +119,7 @@ public void hitDiskCache() throws Exception {
93119 events .assertContainsInfo ("2 disk cache hit" );
94120 }
95121
96- private void blobsReferencedInAAreMissingCasIgnoresAc (String ... additionalOptions )
122+ private void doBlobsReferencedInAcAreMissingFromCasIgnoresAc (String ... additionalOptions )
97123 throws Exception {
98124 // Arrange: Prepare the workspace and populate disk cache
99125 write (
@@ -126,13 +152,72 @@ private void blobsReferencedInAAreMissingCasIgnoresAc(String... additionalOption
126152 }
127153
128154 @ Test
129- public void blobsReferencedInAcAreMissingCas_ignoresAc () throws Exception {
130- blobsReferencedInAAreMissingCasIgnoresAc ();
155+ public void blobsReferencedInAcAreMissingFromCas_ignoresAc () throws Exception {
156+ doBlobsReferencedInAcAreMissingFromCasIgnoresAc ();
157+ }
158+
159+ @ Test
160+ public void bwob_blobsReferencedInAcAreMissingFromCas_ignoresAc () throws Exception {
161+ doBlobsReferencedInAcAreMissingFromCasIgnoresAc ("--remote_download_minimal" );
131162 }
132163
133164 @ Test
134- public void bwob_blobsReferencedInAcAreMissingCas_ignoresAc () throws Exception {
135- blobsReferencedInAAreMissingCasIgnoresAc ("--remote_download_minimal" );
165+ public void bwobAndRemoteExec_blobsReferencedInAcAreMissingFromCas_ignoresAc () throws Exception {
166+ startWorker ();
167+ enableRemoteExec ("--remote_download_minimal" );
168+ doBlobsReferencedInAcAreMissingFromCasIgnoresAc ();
169+ }
170+
171+ @ Test
172+ public void bwobAndRemoteCache_blobsReferencedInAcAreMissingFromCas_ignoresAc () throws Exception {
173+ startWorker ();
174+ enableRemoteCache ("--remote_download_minimal" );
175+ doBlobsReferencedInAcAreMissingFromCasIgnoresAc ();
176+ }
177+
178+ private void doRemoteExecWithDiskCache (String ... additionalOptions ) throws Exception {
179+ // Arrange: Prepare the workspace and populate disk cache
180+ startWorker ();
181+ enableRemoteExec (additionalOptions );
182+ write (
183+ "BUILD" ,
184+ "genrule(" ,
185+ " name = 'foo'," ,
186+ " srcs = ['foo.in']," ,
187+ " outs = ['foo.out']," ,
188+ " cmd = 'cat $(SRCS) > $@'," ,
189+ ")" ,
190+ "genrule(" ,
191+ " name = 'foobar'," ,
192+ " srcs = [':foo.out', 'bar.in']," ,
193+ " outs = ['foobar.out']," ,
194+ " cmd = 'cat $(SRCS) > $@'," ,
195+ ")" );
196+ write ("foo.in" , "foo" );
197+ write ("bar.in" , "bar" );
198+ buildTarget ("//:foobar" );
199+ cleanAndRestartServer ();
200+
201+ // Act: Do a clean build
202+ enableRemoteExec ("--remote_download_minimal" );
203+ buildTarget ("//:foobar" );
204+ }
205+
206+ @ Test
207+ public void remoteExecWithDiskCache_hitDiskCache () throws Exception {
208+ doRemoteExecWithDiskCache ();
209+
210+ // Assert: Should hit the disk cache
211+ events .assertContainsInfo ("2 disk cache hit" );
212+ }
213+
214+ @ Test
215+ public void bwob_remoteExecWithDiskCache_hitRemoteCache () throws Exception {
216+ doRemoteExecWithDiskCache ("--remote_download_minimal" );
217+
218+ // Assert: Should hit the remote cache because blobs referenced by the AC are missing from disk
219+ // cache due to BwoB.
220+ events .assertContainsInfo ("2 remote cache hit" );
136221 }
137222
138223 private void cleanAndRestartServer () throws Exception {
0 commit comments