@@ -114,21 +114,42 @@ private ResourceHandle acquire(double ram, double cpu, int tests)
114
114
return acquire (ram , cpu , tests , ResourcePriority .LOCAL );
115
115
}
116
116
117
- private ResourceHandle acquire (double ram , double cpu , int tests , ImmutableMap < String , Float > extraResources , String mnemonic )
117
+ private ResourceHandle acquire (double ram , double cpu , int tests , String mnemonic )
118
118
throws InterruptedException , IOException {
119
119
120
120
return rm .acquireResources (
121
121
resourceOwner ,
122
- ResourceSet .createWithWorkerKey (ram , cpu , tests , extraResources , createWorkerKey (mnemonic )),
122
+ ResourceSet .createWithWorkerKey (ram , cpu , tests , createWorkerKey (mnemonic )),
123
+ ResourcePriority .LOCAL );
124
+ }
125
+
126
+ private ResourceHandle acquire (double ram , double cpu , ImmutableMap <String , Float > extraResources , int tests , ResourcePriority priority )
127
+ throws InterruptedException , IOException {
128
+ return rm .acquireResources (resourceOwner , ResourceSet .create (ram , cpu , extraResources , tests ), priority );
129
+ }
130
+
131
+ private ResourceHandle acquire (double ram , double cpu , ImmutableMap <String , Float > extraResources , int tests )
132
+ throws InterruptedException , IOException {
133
+ return acquire (ram , cpu , extraResources , tests , ResourcePriority .LOCAL );
134
+ }
135
+
136
+ private ResourceHandle acquire (double ram , double cpu , ImmutableMap <String , Float > extraResources , int tests , String mnemonic )
137
+ throws InterruptedException , IOException {
138
+
139
+ return rm .acquireResources (
140
+ resourceOwner ,
141
+ ResourceSet .createWithWorkerKey (ram , cpu , extraResources , tests , createWorkerKey (mnemonic )),
123
142
ResourcePriority .LOCAL );
124
143
}
125
144
126
145
private void release (double ram , double cpu , int tests ) throws IOException , InterruptedException {
127
- rm .releaseResources (resourceOwner , ResourceSet .create (ram , cpu , tests ), /* worker=*/ null );
146
+ rm .releaseResources (resourceOwner , ResourceSet .create (ram , cpu , tests ), /* worker= */ null );
128
147
}
129
148
130
- private void release (double ram , double cpu , int tests , ImmutableMap <String , Float > extraResources ) {
131
- rm .releaseResources (resourceOwner , ResourceSet .create (ram , cpu , extraResources , tests ));
149
+ private void release (double ram , double cpu , ImmutableMap <String , Float > extraResources , int tests )
150
+ throws InterruptedException , IOException {
151
+ rm .releaseResources (resourceOwner , ResourceSet .create (ram , cpu , extraResources , tests ),
152
+ /* worker= */ null );
132
153
}
133
154
134
155
private void validate (int count ) {
@@ -181,9 +202,9 @@ public void testOverBudgetRequests() throws Exception {
181
202
182
203
// Ditto, for extra resources (even if they don't exist in the available resource set):
183
204
ImmutableMap <String , Float > bigExtraResources = ImmutableMap .of ("gpu" , 10.0f , "fancyresource" , 10.0f , "nonexisting" , 10.0f );
184
- acquire (0 , 0 , 0 , bigExtraResources );
205
+ acquire (0 , 0 , bigExtraResources , 0 );
185
206
assertThat (rm .inUse ()).isTrue ();
186
- release (0 , 0 , 0 , bigExtraResources );
207
+ release (0 , 0 , bigExtraResources , 0 );
187
208
assertThat (rm .inUse ()).isFalse ();
188
209
}
189
210
@@ -271,20 +292,21 @@ public void testThatExtraResourcesCannotBeOverallocated() throws Exception {
271
292
assertThat (rm .inUse ()).isFalse ();
272
293
273
294
// Given a partially acquired extra resources:
274
- acquire (0 , 0 , 1 , ImmutableMap .of ("gpu" , 1.0f ));
295
+ acquire (0 , 0 , ImmutableMap .of ("gpu" , 1.0f ), 1 );
275
296
276
297
// When a request for extra resources is made that would overallocate,
277
298
// Then the request fails:
278
- TestThread thread1 = new TestThread (() -> assertThat ( acquireNonblocking ( 0 , 0 , 0 , ImmutableMap .of ("gpu" , 1.1f ))). isNull ( ));
299
+ TestThread thread1 = new TestThread (() -> acquire ( 0 , 0 , ImmutableMap .of ("gpu" , 1.1f ), 0 ));
279
300
thread1 .start ();
280
- thread1 .joinAndAssertState (10000 );
301
+ AssertionError e = assertThrows (AssertionError .class , () -> thread1 .joinAndAssertState (10000 ));
302
+ assertThat (e ).hasCauseThat ().hasMessageThat ().contains ("is still alive" );
281
303
}
282
304
283
305
@ Test
284
306
public void testHasResources () throws Exception {
285
307
assertThat (rm .inUse ()).isFalse ();
286
308
assertThat (rm .threadHasResources ()).isFalse ();
287
- acquire (1 , 0.1 , 1 , ImmutableMap .of ("gpu" , 1.0f ));
309
+ acquire (1 , 0.1 , ImmutableMap .of ("gpu" , 1.0f ), 1 );
288
310
assertThat (rm .threadHasResources ()).isTrue ();
289
311
290
312
// We have resources in this thread - make sure other threads
@@ -305,15 +327,15 @@ public void testHasResources() throws Exception {
305
327
assertThat (rm .threadHasResources ()).isTrue ();
306
328
release (0 , 0 , 1 );
307
329
assertThat (rm .threadHasResources ()).isFalse ();
308
- acquire (0 , 0 , 0 , ImmutableMap .of ("gpu" , 1.0f ));
330
+ acquire (0 , 0 , ImmutableMap .of ("gpu" , 1.0f ), 0 );
309
331
assertThat (rm .threadHasResources ()).isTrue ();
310
- release (0 , 0 , 0 , ImmutableMap .of ("gpu" , 1.0f ));
332
+ release (0 , 0 , ImmutableMap .of ("gpu" , 1.0f ), 0 );
311
333
assertThat (rm .threadHasResources ()).isFalse ();
312
334
});
313
335
thread1 .start ();
314
336
thread1 .joinAndAssertState (10000 );
315
337
316
- release (1 , 0.1 , 1 , ImmutableMap .of ("gpu" , 1.0f ));
338
+ release (1 , 0.1 , ImmutableMap .of ("gpu" , 1.0f ), 1 );
317
339
assertThat (rm .threadHasResources ()).isFalse ();
318
340
assertThat (rm .inUse ()).isFalse ();
319
341
}
0 commit comments