4141import com .google .devtools .common .options .OptionsParsingException ;
4242import com .google .devtools .common .options .OptionsParsingResult ;
4343import java .io .IOException ;
44- import org .junit .Before ;
4544import org .junit .Rule ;
4645import org .junit .Test ;
4746import org .junit .runner .RunWith ;
@@ -58,14 +57,10 @@ public class WorkerModuleTest {
5857 @ Mock BuildRequest request ;
5958 @ Mock OptionsParsingResult startupOptionsProvider ;
6059
61- private FileSystem fs ;
60+ private final FileSystem fs =
61+ new InMemoryFileSystem (BlazeClock .instance (), DigestHashFunction .SHA256 );
6262 private StoredEventHandler storedEventHandler ;
6363
64- @ Before
65- public void setUp () {
66- fs = new InMemoryFileSystem (BlazeClock .instance (), DigestHashFunction .SHA256 );
67- }
68-
6964 @ Test
7065 public void buildStarting_createsPools ()
7166 throws AbruptExitException , IOException , InterruptedException {
@@ -75,7 +70,7 @@ public void buildStarting_createsPools()
7570 setupEnvironment ("/outputRoot" );
7671
7772 module .beforeCommand (env );
78- module .buildStarting (new BuildStartingEvent (env , request ));
73+ module .buildStarting (BuildStartingEvent . create (env , request ));
7974
8075 assertThat (storedEventHandler .getEvents ()).isEmpty ();
8176 assertThat (fs .getPath ("/outputRoot/outputBase/bazel-workers" ).exists ()).isFalse ();
@@ -96,7 +91,7 @@ public void buildStarting_noRestartOnSandboxChange() throws IOException, AbruptE
9691 setupEnvironment ("/outputRoot" );
9792
9893 module .beforeCommand (env );
99- module .buildStarting (new BuildStartingEvent (env , request ));
94+ module .buildStarting (BuildStartingEvent . create (env , request ));
10095 assertThat (storedEventHandler .getEvents ()).isEmpty ();
10196
10297 Path workerDir = fs .getPath ("/outputRoot/outputBase/bazel-workers" );
@@ -106,7 +101,7 @@ public void buildStarting_noRestartOnSandboxChange() throws IOException, AbruptE
106101 WorkerPool oldPool = module .workerPool ;
107102 options .workerSandboxing = !options .workerSandboxing ;
108103 module .beforeCommand (env );
109- module .buildStarting (new BuildStartingEvent (env , request ));
104+ module .buildStarting (BuildStartingEvent . create (env , request ));
110105 assertThat (storedEventHandler .getEvents ()).isEmpty ();
111106 assertThat (module .workerPool ).isSameInstanceAs (oldPool );
112107 assertThat (aLog .exists ()).isTrue ();
@@ -122,7 +117,7 @@ public void buildStarting_workersDestroyedOnRestart()
122117 setupEnvironment ("/outputRoot" );
123118
124119 module .beforeCommand (env );
125- module .buildStarting (new BuildStartingEvent (env , request ));
120+ module .buildStarting (BuildStartingEvent . create (env , request ));
126121 WorkerKey workerKey = TestUtils .createWorkerKey (JSON , fs , true );
127122 Worker worker = module .workerPool .borrowObject (workerKey );
128123 assertThat (worker .workerKey ).isEqualTo (workerKey );
@@ -138,7 +133,7 @@ public void buildStarting_workersDestroyedOnRestart()
138133 WorkerPool oldPool = module .workerPool ;
139134 options .highPriorityWorkers = ImmutableList .of ("Foobar" );
140135 module .beforeCommand (env );
141- module .buildStarting (new BuildStartingEvent (env , request ));
136+ module .buildStarting (BuildStartingEvent . create (env , request ));
142137 assertThat (storedEventHandler .getEvents ()).hasSize (1 );
143138 assertThat (storedEventHandler .getEvents ().get (0 ).getMessage ())
144139 .contains ("Worker pool configuration has changed" );
@@ -154,7 +149,7 @@ public void buildStarting_restartsOnOutputbaseChanges() throws IOException, Abru
154149 setupEnvironment ("/outputRoot" );
155150
156151 module .beforeCommand (env );
157- module .buildStarting (new BuildStartingEvent (env , request ));
152+ module .buildStarting (BuildStartingEvent . create (env , request ));
158153 assertThat (storedEventHandler .getEvents ()).isEmpty ();
159154
160155 // Log file from old root, doesn't get cleaned
@@ -166,7 +161,7 @@ public void buildStarting_restartsOnOutputbaseChanges() throws IOException, Abru
166161 WorkerPool oldPool = module .workerPool ;
167162 setupEnvironment ("/otherRootDir" );
168163 module .beforeCommand (env );
169- module .buildStarting (new BuildStartingEvent (env , request ));
164+ module .buildStarting (BuildStartingEvent . create (env , request ));
170165 assertThat (storedEventHandler .getEvents ()).hasSize (1 );
171166 assertThat (storedEventHandler .getEvents ().get (0 ).getMessage ())
172167 .contains ("Worker factory configuration has changed" );
@@ -190,7 +185,7 @@ public void buildStarting_clearsLogsOnFactoryCreation() throws IOException, Abru
190185 oldLog .createSymbolicLink (PathFragment .EMPTY_FRAGMENT );
191186
192187 module .beforeCommand (env );
193- module .buildStarting (new BuildStartingEvent (env , request ));
188+ module .buildStarting (BuildStartingEvent . create (env , request ));
194189
195190 assertThat (storedEventHandler .getEvents ()).isEmpty ();
196191 assertThat (fs .getPath ("/outputRoot/outputBase/bazel-workers" ).exists ()).isTrue ();
@@ -206,7 +201,7 @@ public void buildStarting_restartsOnHiPrioChanges() throws IOException, AbruptEx
206201
207202 module .beforeCommand (env );
208203 // Check that new pools/factories are made with default options
209- module .buildStarting (new BuildStartingEvent (env , request ));
204+ module .buildStarting (BuildStartingEvent . create (env , request ));
210205 assertThat (storedEventHandler .getEvents ()).isEmpty ();
211206
212207 // Logs are only cleared on factory reset, not on pool reset, so this file should survive
@@ -218,7 +213,7 @@ public void buildStarting_restartsOnHiPrioChanges() throws IOException, AbruptEx
218213 WorkerPool oldPool = module .workerPool ;
219214 options .highPriorityWorkers = ImmutableList .of ("foo" );
220215 module .beforeCommand (env );
221- module .buildStarting (new BuildStartingEvent (env , request ));
216+ module .buildStarting (BuildStartingEvent . create (env , request ));
222217 assertThat (storedEventHandler .getEvents ()).hasSize (1 );
223218 assertThat (storedEventHandler .getEvents ().get (0 ).getMessage ())
224219 .contains ("Worker pool configuration has changed" );
@@ -236,13 +231,13 @@ public void buildStarting_restartsOnNumMultiplexWorkersChanges()
236231
237232 module .beforeCommand (env );
238233 // Check that new pools/factories are made with default options
239- module .buildStarting (new BuildStartingEvent (env , request ));
234+ module .buildStarting (BuildStartingEvent . create (env , request ));
240235 assertThat (storedEventHandler .getEvents ()).isEmpty ();
241236
242237 WorkerPool oldPool = module .workerPool ;
243238 options .workerMaxMultiplexInstances = Lists .newArrayList (Maps .immutableEntry ("foo" , 42 ));
244239 module .beforeCommand (env );
245- module .buildStarting (new BuildStartingEvent (env , request ));
240+ module .buildStarting (BuildStartingEvent . create (env , request ));
246241 assertThat (storedEventHandler .getEvents ()).hasSize (1 );
247242 assertThat (storedEventHandler .getEvents ().get (0 ).getMessage ())
248243 .contains ("Worker pool configuration has changed" );
@@ -259,34 +254,32 @@ public void buildStarting_restartsOnNumWorkersChanges() throws IOException, Abru
259254
260255 module .beforeCommand (env );
261256 // Check that new pools/factories are made with default options
262- module .buildStarting (new BuildStartingEvent (env , request ));
257+ module .buildStarting (BuildStartingEvent . create (env , request ));
263258 assertThat (storedEventHandler .getEvents ()).isEmpty ();
264259
265260 WorkerPool oldPool = module .workerPool ;
266261 options .workerMaxInstances = Lists .newArrayList (Maps .immutableEntry ("bar" , 3 ));
267262 module .beforeCommand (env );
268- module .buildStarting (new BuildStartingEvent (env , request ));
263+ module .buildStarting (BuildStartingEvent . create (env , request ));
269264 assertThat (storedEventHandler .getEvents ()).hasSize (1 );
270265 assertThat (storedEventHandler .getEvents ().get (0 ).getMessage ())
271266 .contains ("Worker pool configuration has changed" );
272267 assertThat (module .workerPool ).isNotSameInstanceAs (oldPool );
273268 }
274269
275270 @ Test
276- public void buildStarting_survivesNoWorkerDir ()
277- throws IOException , AbruptExitException , InterruptedException {
271+ public void buildStarting_survivesNoWorkerDir () throws Exception {
278272 WorkerModule module = new WorkerModule ();
279273 WorkerOptions options = WorkerOptions .DEFAULTS ;
280274
281275 when (request .getOptions (WorkerOptions .class )).thenReturn (options );
282276 setupEnvironment ("/outputRoot" );
283277
284278 module .beforeCommand (env );
285- Path workerDir =
286- env .getOutputBase ().getRelative (env .getRuntime ().getProductName () + "-workers" );
279+ Path workerDir = fs .getPath ("/outputRoot/outputBase/bazel-workers" );
287280
288281 // Check that new pools/factories can be created without a worker dir.
289- module .buildStarting (new BuildStartingEvent (env , request ));
282+ module .buildStarting (BuildStartingEvent . create (env , request ));
290283
291284 // But once we try to get a worker, it should fail. This forces a situation where we can't
292285 // have a workerDir.
@@ -322,5 +315,6 @@ private void setupEnvironment(String rootDir) throws IOException, AbruptExitExce
322315 EventBus eventBus = new EventBus ();
323316 when (env .getEventBus ()).thenReturn (eventBus );
324317 when (env .getReporter ()).thenReturn (new Reporter (eventBus , storedEventHandler ));
318+ when (env .determineOutputFileSystem ()).thenReturn ("OutputFileSystem" );
325319 }
326320}
0 commit comments