use of com.google.devtools.build.lib.testutil.TestThread in project bazel by bazelbuild.
the class ResourceManagerTest method testInterruptedAcquisitionClearsResources.
@Test
public void testInterruptedAcquisitionClearsResources() throws Exception {
assertFalse(rm.inUse());
// Acquire a small amount of resources so that future requests can block (the initial request
// always succeeds even if it's for too much).
TestThread smallThread = new TestThread() {
@Override
public void runTest() throws InterruptedException {
acquire(1, 0, 0, 0);
}
};
smallThread.start();
smallThread.joinAndAssertState(TestUtils.WAIT_TIMEOUT_MILLISECONDS);
TestThread thread1 = new TestThread() {
@Override
public void runTest() {
Thread.currentThread().interrupt();
try {
acquire(1999, 0, 0, 0);
fail("Didn't throw interrupted exception");
} catch (InterruptedException e) {
// Expected.
}
}
};
thread1.start();
thread1.joinAndAssertState(TestUtils.WAIT_TIMEOUT_MILLISECONDS);
// This should process the queue. If the request from above is still present, it will take all
// the available memory. But it shouldn't.
rm.setAvailableResources(ResourceSet.create(/*memoryMb=*/
2000.0, /*cpuUsage=*/
1.0, /*ioUsage=*/
1.0, /*testCount=*/
2));
TestThread thread2 = new TestThread() {
@Override
public void runTest() throws InterruptedException {
acquire(1999, 0, 0, 0);
release(1999, 0, 0, 0);
}
};
thread2.start();
thread2.joinAndAssertState(TestUtils.WAIT_TIMEOUT_MILLISECONDS);
}
use of com.google.devtools.build.lib.testutil.TestThread in project bazel by bazelbuild.
the class ResourceManagerTest method testHasResources.
@Test
public void testHasResources() throws Exception {
assertFalse(rm.inUse());
assertFalse(rm.threadHasResources());
acquire(1.0, 0.1, 0.1, 1);
assertTrue(rm.threadHasResources());
// We have resources in this thread - make sure other threads
// are not affected.
TestThread thread1 = new TestThread() {
@Override
public void runTest() throws Exception {
assertFalse(rm.threadHasResources());
acquire(1.0, 0, 0, 0);
assertTrue(rm.threadHasResources());
release(1.0, 0, 0, 0);
assertFalse(rm.threadHasResources());
acquire(0, 0.1, 0, 0);
assertTrue(rm.threadHasResources());
release(0, 0.1, 0, 0);
assertFalse(rm.threadHasResources());
acquire(0, 0, 0.1, 0);
assertTrue(rm.threadHasResources());
release(0, 0, 0.1, 0);
assertFalse(rm.threadHasResources());
acquire(0, 0, 0, 1);
assertTrue(rm.threadHasResources());
release(0, 0, 0, 1);
assertFalse(rm.threadHasResources());
}
};
thread1.start();
thread1.joinAndAssertState(10000);
release(1.0, 0.1, 0.1, 1);
assertFalse(rm.threadHasResources());
assertFalse(rm.inUse());
}
Aggregations