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 ;
@@ -135,6 +138,20 @@ public class RemoteExecutionServiceTest {
135
138
private final Reporter reporter = new Reporter (new EventBus ());
136
139
private final StoredEventHandler eventHandler = new StoredEventHandler ();
137
140
141
+ private final ServerCapabilities removeExecutorCapabilities =
142
+ ServerCapabilities .newBuilder ()
143
+ .setLowApiVersion (ApiVersion .current .toSemVer ())
144
+ .setHighApiVersion (ApiVersion .current .toSemVer ())
145
+ .setExecutionCapabilities (ExecutionCapabilities .newBuilder ().setExecEnabled (true ).build ())
146
+ .build ();
147
+ private final ApiVersion oldApiVersion = new ApiVersion (SemVer .newBuilder ().setMajor (2 ).build ());
148
+ private final ServerCapabilities legacyRemoveExecutorCapabilities =
149
+ ServerCapabilities .newBuilder ()
150
+ .setLowApiVersion (oldApiVersion .toSemVer ())
151
+ .setHighApiVersion (oldApiVersion .toSemVer ())
152
+ .setExecutionCapabilities (ExecutionCapabilities .newBuilder ().setExecEnabled (true ).build ())
153
+ .build ();
154
+
138
155
RemoteOptions remoteOptions ;
139
156
private Path execRoot ;
140
157
private ArtifactRoot artifactRoot ;
@@ -174,6 +191,7 @@ public final void setUp() throws Exception {
174
191
175
192
cache = spy (new InMemoryRemoteCache (spy (new InMemoryCacheClient ()), remoteOptions , digestUtil ));
176
193
executor = mock (RemoteExecutionClient .class );
194
+ when (executor .getServerCapabilities ()).thenReturn (removeExecutorCapabilities );
177
195
178
196
RequestMetadata metadata =
179
197
TracingMetadataUtils .buildMetadata ("none" , "none" , "action-id" , null );
@@ -192,8 +210,25 @@ public void buildRemoteAction_withRegularFileAsOutput() throws Exception {
192
210
193
211
RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
194
212
195
- assertThat (remoteAction .getCommand ().getOutputFilesList ()).containsExactly (execPath .toString ());
213
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ();
214
+ assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
196
215
assertThat (remoteAction .getCommand ().getOutputPathsList ()).containsExactly (execPath .toString ());
216
+ }
217
+
218
+ @ Test
219
+ public void legacy_buildRemoteAction_withRegularFileAsOutput () throws Exception {
220
+ when (executor .getServerCapabilities ()).thenReturn (legacyRemoveExecutorCapabilities );
221
+ PathFragment execPath = execRoot .getRelative ("path/to/tree" ).asFragment ();
222
+ Spawn spawn =
223
+ new SpawnBuilder ("dummy" )
224
+ .withOutput (ActionsTestUtil .createArtifactWithExecPath (artifactRoot , execPath ))
225
+ .build ();
226
+ FakeSpawnExecutionContext context = newSpawnExecutionContext (spawn );
227
+ RemoteExecutionService service = newRemoteExecutionService ();
228
+
229
+ RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
230
+
231
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).containsExactly (execPath .toString ());
197
232
assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
198
233
}
199
234
@@ -210,6 +245,25 @@ public void buildRemoteAction_withTreeArtifactAsOutput() throws Exception {
210
245
211
246
RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
212
247
248
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ();
249
+ assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
250
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).containsExactly ("path/to/dir" );
251
+ }
252
+
253
+ @ Test
254
+ public void legacy_buildRemoteAction_withTreeArtifactAsOutput () throws Exception {
255
+ when (executor .getServerCapabilities ()).thenReturn (legacyRemoveExecutorCapabilities );
256
+ Spawn spawn =
257
+ new SpawnBuilder ("dummy" )
258
+ .withOutput (
259
+ ActionsTestUtil .createTreeArtifactWithGeneratingAction (
260
+ artifactRoot , PathFragment .create ("path/to/dir" )))
261
+ .build ();
262
+ FakeSpawnExecutionContext context = newSpawnExecutionContext (spawn );
263
+ RemoteExecutionService service = newRemoteExecutionService ();
264
+
265
+ RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
266
+
213
267
assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ();
214
268
assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).containsExactly ("path/to/dir" );
215
269
}
@@ -227,11 +281,29 @@ public void buildRemoteAction_withUnresolvedSymlinkAsOutput() throws Exception {
227
281
228
282
RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
229
283
230
- assertThat (remoteAction .getCommand ().getOutputFilesList ()).containsExactly ( "path/to/link" );
284
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ( );
231
285
assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
232
286
assertThat (remoteAction .getCommand ().getOutputPathsList ()).containsExactly ("path/to/link" );
233
287
}
234
288
289
+ @ Test
290
+ public void legacy_buildRemoteAction_withUnresolvedSymlinkAsOutput () throws Exception {
291
+ when (executor .getServerCapabilities ()).thenReturn (legacyRemoveExecutorCapabilities );
292
+ Spawn spawn =
293
+ new SpawnBuilder ("dummy" )
294
+ .withOutput (
295
+ ActionsTestUtil .createUnresolvedSymlinkArtifactWithExecPath (
296
+ artifactRoot , PathFragment .create ("path/to/link" )))
297
+ .build ();
298
+ FakeSpawnExecutionContext context = newSpawnExecutionContext (spawn );
299
+ RemoteExecutionService service = newRemoteExecutionService ();
300
+
301
+ RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
302
+
303
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).containsExactly ("path/to/link" );
304
+ assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
305
+ }
306
+
235
307
@ Test
236
308
public void buildRemoteAction_withActionInputFileAsOutput () throws Exception {
237
309
Spawn spawn =
@@ -243,6 +315,23 @@ public void buildRemoteAction_withActionInputFileAsOutput() throws Exception {
243
315
244
316
RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
245
317
318
+ assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ();
319
+ assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
320
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).containsExactly ("path/to/file" );
321
+ }
322
+
323
+ @ Test
324
+ public void legacy_buildRemoteAction_withActionInputFileAsOutput () throws Exception {
325
+ when (executor .getServerCapabilities ()).thenReturn (legacyRemoveExecutorCapabilities );
326
+ Spawn spawn =
327
+ new SpawnBuilder ("dummy" )
328
+ .withOutput (ActionInputHelper .fromPath (PathFragment .create ("path/to/file" )))
329
+ .build ();
330
+ FakeSpawnExecutionContext context = newSpawnExecutionContext (spawn );
331
+ RemoteExecutionService service = newRemoteExecutionService ();
332
+
333
+ RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
334
+
246
335
assertThat (remoteAction .getCommand ().getOutputFilesList ()).containsExactly ("path/to/file" );
247
336
assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
248
337
}
@@ -259,7 +348,8 @@ public void buildRemoteAction_withActionInputDirectoryAsOutput() throws Exceptio
259
348
RemoteAction remoteAction = service .buildRemoteAction (spawn , context );
260
349
261
350
assertThat (remoteAction .getCommand ().getOutputFilesList ()).isEmpty ();
262
- assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).containsExactly ("path/to/dir" );
351
+ assertThat (remoteAction .getCommand ().getOutputDirectoriesList ()).isEmpty ();
352
+ assertThat (remoteAction .getCommand ().getOutputPathsList ()).containsExactly ("path/to/dir" );
263
353
}
264
354
265
355
@ Test
0 commit comments