Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #24931 compare with known size of 'usedResourceHandles' instead of theoretical maximum 'maxConnectionPoolSize' #24932

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void basicConnectionPoolMultiThreadedTest() throws Exception {
null, null, null, false);

// Keep track of resources and number of tasks executed
final Set<ResourceHandle> usedResouceHandles = Collections.synchronizedSet(new HashSet<>());
final Set<ResourceHandle> usedResourceHandles = Collections.synchronizedSet(new HashSet<>());
AtomicInteger numberOfThreadsFinished = new AtomicInteger();

// Make sure there are no resources in the pool before we start processing tasks
Expand All @@ -284,7 +284,7 @@ void basicConnectionPoolMultiThreadedTest() throws Exception {

// Keep track of unique resources, we want to validate if resources are being reused
// which is the basic usage of the pool.
boolean isNewlyAdded = usedResouceHandles.add(resource);
boolean isNewlyAdded = usedResourceHandles.add(resource);
if (isNewlyAdded) {
// Adding should only be ok for the first 'maxConnectionPoolSize' number of tasks that start
LOG.log(Level.FINE, "Adding resource: {0}", resource);
Expand All @@ -309,22 +309,23 @@ void basicConnectionPoolMultiThreadedTest() throws Exception {
}
runTheTasks(tasks);

// Pool should be filled to maximum pool size. Resources can be idle for "idle-timeout-in-seconds" (which is 789
// seconds) before they can be removed from the pool.
assertResourcesSize(maxConnectionPoolSize);
// Pool should be filled up to the maximum pool size. Resources can be idle for "idle-timeout-in-seconds" (which is 789
// seconds) before they can be removed from the pool. We cannot check against "maxConnectionPoolSize" value, on some
// systems the pool is never used to the maximum and we do not want to increase the taskCount to avoid long during unit tests.
assertResourcesSize(usedResourceHandles.size());

cleanupConnectionPool();

// Just another proof that all 1000 threads finished.
// Just another proof that all threads finished.
assertEquals(taskCount, numberOfThreadsFinished.get());

// No new resources are being used, check the remaining ones for the state.
for (ResourceHandle resource : usedResouceHandles) {
for (ResourceHandle resource : usedResourceHandles) {
assertResourceIsNotBusy(resource);
}

// Validate there are no more resources created, than the maximum pool size, because they should be reused
assertTrue(usedResouceHandles.size() <= maxConnectionPoolSize, "failed, size=" + usedResouceHandles.size());
assertTrue(usedResourceHandles.size() <= maxConnectionPoolSize, "failed, size=" + usedResourceHandles.size());
}

/**
Expand Down