39
39
import build .bazel .remote .execution .v2 .Digest ;
40
40
import build .bazel .remote .execution .v2 .Directory ;
41
41
import build .bazel .remote .execution .v2 .DirectoryNode ;
42
+ import build .bazel .remote .execution .v2 .ExecutionCapabilities ;
42
43
import build .bazel .remote .execution .v2 .FileNode ;
43
44
import build .bazel .remote .execution .v2 .NodeProperties ;
44
45
import build .bazel .remote .execution .v2 .NodeProperty ;
47
48
import build .bazel .remote .execution .v2 .OutputSymlink ;
48
49
import build .bazel .remote .execution .v2 .Platform ;
49
50
import build .bazel .remote .execution .v2 .RequestMetadata ;
51
+ import build .bazel .remote .execution .v2 .ServerCapabilities ;
50
52
import build .bazel .remote .execution .v2 .SymlinkAbsolutePathStrategy ;
51
53
import build .bazel .remote .execution .v2 .SymlinkNode ;
52
54
import build .bazel .remote .execution .v2 .Tree ;
55
+ import build .bazel .semver .SemVer ;
53
56
import com .google .common .base .Throwables ;
54
57
import com .google .common .collect .ImmutableClassToInstanceMap ;
55
58
import com .google .common .collect .ImmutableList ;
@@ -138,6 +141,20 @@ public class RemoteExecutionServiceTest {
138
141
private final Reporter reporter = new Reporter (new EventBus ());
139
142
private final StoredEventHandler eventHandler = new StoredEventHandler ();
140
143
144
+ private final ServerCapabilities removeExecutorCapabilities =
145
+ ServerCapabilities .newBuilder ()
146
+ .setLowApiVersion (ApiVersion .current .toSemVer ())
147
+ .setHighApiVersion (ApiVersion .current .toSemVer ())
148
+ .setExecutionCapabilities (ExecutionCapabilities .newBuilder ().setExecEnabled (true ).build ())
149
+ .build ();
150
+ private final ApiVersion oldApiVersion = new ApiVersion (SemVer .newBuilder ().setMajor (2 ).build ());
151
+ private final ServerCapabilities legacyRemoveExecutorCapabilities =
152
+ ServerCapabilities .newBuilder ()
153
+ .setLowApiVersion (oldApiVersion .toSemVer ())
154
+ .setHighApiVersion (oldApiVersion .toSemVer ())
155
+ .setExecutionCapabilities (ExecutionCapabilities .newBuilder ().setExecEnabled (true ).build ())
156
+ .build ();
157
+
141
158
RemoteOptions remoteOptions ;
142
159
private Path execRoot ;
143
160
private ArtifactRoot artifactRoot ;
@@ -177,6 +194,7 @@ public final void setUp() throws Exception {
177
194
178
195
cache = spy (new InMemoryRemoteCache (spy (new InMemoryCacheClient ()), remoteOptions , digestUtil ));
179
196
executor = mock (RemoteExecutionClient .class );
197
+ when (executor .getServerCapabilities ()).thenReturn (removeExecutorCapabilities );
180
198
181
199
RequestMetadata metadata =
182
200
TracingMetadataUtils .buildMetadata ("none" , "none" , "action-id" , null );
@@ -195,9 +213,27 @@ public void buildRemoteAction_withRegularFileAsOutput() throws Exception {
195
213
196
214
RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
197
215
198
- assertThat (remoteAction .getCommand ().getOutputFilesList ()).containsExactly (execPath .toString ());
216
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ();
217
+ assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
199
218
assertThat (remoteAction .getCommand ().getOutputPathsList ()).containsExactly (execPath .toString ());
219
+ }
220
+
221
+ @ Test
222
+ public void legacy_buildRemoteAction_withRegularFileAsOutput () throws Exception {
223
+ when (executor .getServerCapabilities ()).thenReturn (legacyRemoveExecutorCapabilities );
224
+ PathFragment execPath = execRoot .getRelative ("path/to/tree" ).asFragment ();
225
+ Spawn spawn =
226
+ new SpawnBuilder ("dummy" )
227
+ .withOutput (ActionsTestUtil .createArtifactWithExecPath (artifactRoot , execPath ))
228
+ .build ();
229
+ FakeSpawnExecutionContext context = newSpawnExecutionContext (spawn );
230
+ RemoteExecutionService service = newRemoteExecutionService ();
231
+
232
+ RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
233
+
234
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).containsExactly (execPath .toString ());
200
235
assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
236
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).isEmpty ();
201
237
}
202
238
203
239
@ Test
@@ -213,8 +249,28 @@ public void buildRemoteAction_withTreeArtifactAsOutput() throws Exception {
213
249
214
250
RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
215
251
252
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ();
253
+ assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
254
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).containsExactly ("path/to/dir" );
255
+ }
256
+
257
+ @ Test
258
+ public void legacy_buildRemoteAction_withTreeArtifactAsOutput () throws Exception {
259
+ when (executor .getServerCapabilities ()).thenReturn (legacyRemoveExecutorCapabilities );
260
+ Spawn spawn =
261
+ new SpawnBuilder ("dummy" )
262
+ .withOutput (
263
+ ActionsTestUtil .createTreeArtifactWithGeneratingAction (
264
+ artifactRoot , PathFragment .create ("path/to/dir" )))
265
+ .build ();
266
+ FakeSpawnExecutionContext context = newSpawnExecutionContext (spawn );
267
+ RemoteExecutionService service = newRemoteExecutionService ();
268
+
269
+ RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
270
+
216
271
assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ();
217
272
assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).containsExactly ("path/to/dir" );
273
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).isEmpty ();
218
274
}
219
275
220
276
@ Test
@@ -230,11 +286,30 @@ public void buildRemoteAction_withUnresolvedSymlinkAsOutput() throws Exception {
230
286
231
287
RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
232
288
233
- assertThat (remoteAction .getCommand ().getOutputFilesList ()).containsExactly ( "path/to/link" );
289
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ( );
234
290
assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
235
291
assertThat (remoteAction .getCommand ().getOutputPathsList ()).containsExactly ("path/to/link" );
236
292
}
237
293
294
+ @ Test
295
+ public void legacy_buildRemoteAction_withUnresolvedSymlinkAsOutput () throws Exception {
296
+ when (executor .getServerCapabilities ()).thenReturn (legacyRemoveExecutorCapabilities );
297
+ Spawn spawn =
298
+ new SpawnBuilder ("dummy" )
299
+ .withOutput (
300
+ ActionsTestUtil .createUnresolvedSymlinkArtifactWithExecPath (
301
+ artifactRoot , PathFragment .create ("path/to/link" )))
302
+ .build ();
303
+ FakeSpawnExecutionContext context = newSpawnExecutionContext (spawn );
304
+ RemoteExecutionService service = newRemoteExecutionService ();
305
+
306
+ RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
307
+
308
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).containsExactly ("path/to/link" );
309
+ assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
310
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).isEmpty ();
311
+ }
312
+
238
313
@ Test
239
314
public void buildRemoteAction_withActionInputFileAsOutput () throws Exception {
240
315
Spawn spawn =
@@ -246,8 +321,26 @@ public void buildRemoteAction_withActionInputFileAsOutput() throws Exception {
246
321
247
322
RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
248
323
324
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ();
325
+ assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
326
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).containsExactly ("path/to/file" );
327
+ }
328
+
329
+ @ Test
330
+ public void legacy_buildRemoteAction_withActionInputFileAsOutput () throws Exception {
331
+ when (executor .getServerCapabilities ()).thenReturn (legacyRemoveExecutorCapabilities );
332
+ Spawn spawn =
333
+ new SpawnBuilder ("dummy" )
334
+ .withOutput (ActionInputHelper .fromPath (PathFragment .create ("path/to/file" )))
335
+ .build ();
336
+ FakeSpawnExecutionContext context = newSpawnExecutionContext (spawn );
337
+ RemoteExecutionService service = newRemoteExecutionService ();
338
+
339
+ RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
340
+
249
341
assertThat (remoteAction .getCommand ().getOutputFilesList ()).containsExactly ("path/to/file" );
250
342
assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
343
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).isEmpty ();
251
344
}
252
345
253
346
@ Test
@@ -262,7 +355,8 @@ public void buildRemoteAction_withActionInputDirectoryAsOutput() throws Exceptio
262
355
RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
263
356
264
357
assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ();
265
- assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).containsExactly ("path/to/dir" );
358
+ assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
359
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).containsExactly ("path/to/dir" );
266
360
}
267
361
268
362
@ Test
0 commit comments