use of org.apache.flink.core.testutils.CheckedThread in project flink by apache.
the class DefaultLeaderElectionServiceTest method testServiceShutDownWithSynchronizedDriver.
/**
* Tests that we can shut down the DefaultLeaderElectionService if the used LeaderElectionDriver
* holds an internal lock. See FLINK-20008 for more details.
*/
@Test
public void testServiceShutDownWithSynchronizedDriver() throws Exception {
final TestingLeaderElectionDriver.TestingLeaderElectionDriverFactory testingLeaderElectionDriverFactory = new TestingLeaderElectionDriver.TestingLeaderElectionDriverFactory();
final DefaultLeaderElectionService leaderElectionService = new DefaultLeaderElectionService(testingLeaderElectionDriverFactory);
final TestingContender testingContender = new TestingContender(TEST_URL, leaderElectionService);
leaderElectionService.start(testingContender);
final TestingLeaderElectionDriver currentLeaderDriver = Preconditions.checkNotNull(testingLeaderElectionDriverFactory.getCurrentLeaderDriver());
final CheckedThread isLeaderThread = new CheckedThread() {
@Override
public void go() {
currentLeaderDriver.isLeader();
}
};
isLeaderThread.start();
leaderElectionService.stop();
isLeaderThread.sync();
}
use of org.apache.flink.core.testutils.CheckedThread in project flink by apache.
the class DefaultJobLeaderServiceTest method handlesConcurrentJobAdditionsAndLeaderChanges.
/**
* Tests that we can concurrently modify the JobLeaderService and complete the leader retrieval
* operation. See FLINK-16373.
*/
@Test
public void handlesConcurrentJobAdditionsAndLeaderChanges() throws Exception {
final JobLeaderService jobLeaderService = new DefaultJobLeaderService(new LocalUnresolvedTaskManagerLocation(), RetryingRegistrationConfiguration.defaultConfiguration());
final TestingJobLeaderListener jobLeaderListener = new TestingJobLeaderListener();
final int numberOperations = 20;
final BlockingQueue<SettableLeaderRetrievalService> instantiatedLeaderRetrievalServices = new ArrayBlockingQueue<>(numberOperations);
final HighAvailabilityServices haServices = new TestingHighAvailabilityServicesBuilder().setJobMasterLeaderRetrieverFunction(leaderForJobId -> {
final SettableLeaderRetrievalService leaderRetrievalService = new SettableLeaderRetrievalService();
instantiatedLeaderRetrievalServices.offer(leaderRetrievalService);
return leaderRetrievalService;
}).build();
jobLeaderService.start("foobar", rpcServiceResource.getTestingRpcService(), haServices, jobLeaderListener);
final CheckedThread addJobAction = new CheckedThread() {
@Override
public void go() throws Exception {
for (int i = 0; i < numberOperations; i++) {
final JobID jobId = JobID.generate();
jobLeaderService.addJob(jobId, "foobar");
Thread.yield();
jobLeaderService.removeJob(jobId);
}
}
};
addJobAction.start();
for (int i = 0; i < numberOperations; i++) {
final SettableLeaderRetrievalService leaderRetrievalService = instantiatedLeaderRetrievalServices.take();
leaderRetrievalService.notifyListener("foobar", UUID.randomUUID());
}
addJobAction.sync();
}
use of org.apache.flink.core.testutils.CheckedThread in project flink by apache.
the class BlobServerPutTest method testServerContentAddressableGetStorageLocationConcurrent.
private void testServerContentAddressableGetStorageLocationConcurrent(@Nullable final JobID jobId) throws Exception {
final Configuration config = new Configuration();
try (BlobServer server = new BlobServer(config, temporaryFolder.newFolder(), new VoidBlobStore())) {
server.start();
BlobKey key1 = new TransientBlobKey();
BlobKey key2 = new PermanentBlobKey();
CheckedThread[] threads = new CheckedThread[] { new ContentAddressableGetStorageLocation(server, jobId, key1), new ContentAddressableGetStorageLocation(server, jobId, key1), new ContentAddressableGetStorageLocation(server, jobId, key1), new ContentAddressableGetStorageLocation(server, jobId, key2), new ContentAddressableGetStorageLocation(server, jobId, key2), new ContentAddressableGetStorageLocation(server, jobId, key2) };
checkedThreadSimpleTest(threads);
}
}
use of org.apache.flink.core.testutils.CheckedThread in project flink by apache.
the class NetworkBufferPoolTest method testRequestMemorySegmentsInterruptable2.
/**
* Tests {@link NetworkBufferPool#requestUnpooledMemorySegments(int)}, verifying it may be
* aborted and remains in a defined state even if the waiting is interrupted.
*/
@Test
public void testRequestMemorySegmentsInterruptable2() throws Exception {
final int numBuffers = 10;
NetworkBufferPool globalPool = new NetworkBufferPool(numBuffers, 128);
MemorySegment segment = globalPool.requestPooledMemorySegment();
assertNotNull(segment);
final OneShotLatch isRunning = new OneShotLatch();
CheckedThread asyncRequest = new CheckedThread() {
@Override
public void go() throws IOException {
isRunning.trigger();
globalPool.requestUnpooledMemorySegments(10);
}
};
asyncRequest.start();
// We want the destroy call inside the blocking part of the
// globalPool.requestMemorySegments()
// call above. We cannot guarantee this though but make it highly probable:
isRunning.await();
Thread.sleep(10);
asyncRequest.interrupt();
globalPool.recyclePooledMemorySegment(segment);
try {
asyncRequest.sync();
} catch (IOException e) {
assertThat(e, hasProperty("cause", instanceOf(InterruptedException.class)));
// test indirectly for NetworkBufferPool#numTotalRequiredBuffers being correct:
// -> creating a new buffer pool should not fail
globalPool.createBufferPool(10, 10);
} finally {
globalPool.destroy();
}
}
use of org.apache.flink.core.testutils.CheckedThread in project flink by apache.
the class NetworkBufferPoolTest method testRequestMemorySegmentsTimeout.
/**
* Tests {@link NetworkBufferPool#requestUnpooledMemorySegments(int)} and verifies it will end
* exceptionally when failing to acquire all the segments in the specific timeout.
*/
@Test
public void testRequestMemorySegmentsTimeout() throws Exception {
final int numBuffers = 10;
final int numberOfSegmentsToRequest = 2;
final Duration requestSegmentsTimeout = Duration.ofMillis(50L);
NetworkBufferPool globalPool = new NetworkBufferPool(numBuffers, 128, requestSegmentsTimeout);
BufferPool localBufferPool = globalPool.createBufferPool(1, numBuffers);
for (int i = 0; i < numBuffers; ++i) {
localBufferPool.requestBuffer();
}
assertEquals(0, globalPool.getNumberOfAvailableMemorySegments());
CheckedThread asyncRequest = new CheckedThread() {
@Override
public void go() throws Exception {
globalPool.requestUnpooledMemorySegments(numberOfSegmentsToRequest);
}
};
asyncRequest.start();
try {
Exception ex = assertThrows(IOException.class, asyncRequest::sync);
assertTrue(ex.getMessage().contains("Timeout"));
} finally {
globalPool.destroy();
}
}
Aggregations