13
13
// limitations under the License.
14
14
package com .google .devtools .build .lib .remote ;
15
15
16
+ import static com .google .common .truth .Truth .assertThat ;
16
17
import static com .google .devtools .build .lib .testutil .TestUtils .tmpDirFile ;
17
18
18
19
import com .google .common .collect .ImmutableList ;
19
20
import com .google .devtools .build .lib .authandtls .credentialhelper .CredentialModule ;
20
21
import 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 ;
21
24
import com .google .devtools .build .lib .runtime .BlazeModule ;
22
25
import com .google .devtools .build .lib .runtime .BlazeRuntime ;
23
26
import com .google .devtools .build .lib .runtime .BlockWaitingModule ;
32
35
33
36
@ RunWith (JUnit4 .class )
34
37
public 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
+ }
35
57
36
58
private static PathFragment getDiskCacheDir () {
37
59
PathFragment testTmpDir = PathFragment .create (tmpDirFile ().getAbsolutePath ());
@@ -48,6 +70,10 @@ protected void setupOptions() throws Exception {
48
70
@ After
49
71
public void tearDown () throws IOException {
50
72
getWorkspace ().getFileSystem ().getPath (getDiskCacheDir ()).deleteTree ();
73
+
74
+ if (worker != null ) {
75
+ worker .stop ();
76
+ }
51
77
}
52
78
53
79
@ Override
@@ -93,7 +119,7 @@ public void hitDiskCache() throws Exception {
93
119
events .assertContainsInfo ("2 disk cache hit" );
94
120
}
95
121
96
- private void blobsReferencedInAAreMissingCasIgnoresAc (String ... additionalOptions )
122
+ private void doBlobsReferencedInAcAreMissingFromCasIgnoresAc (String ... additionalOptions )
97
123
throws Exception {
98
124
// Arrange: Prepare the workspace and populate disk cache
99
125
write (
@@ -126,13 +152,72 @@ private void blobsReferencedInAAreMissingCasIgnoresAc(String... additionalOption
126
152
}
127
153
128
154
@ 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" );
131
162
}
132
163
133
164
@ 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" );
136
221
}
137
222
138
223
private void cleanAndRestartServer () throws Exception {
0 commit comments