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

QPID-7615 Number of selectors can be equal to connection thread pool size #34

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -543,9 +543,9 @@ private void validateConnectionThreadPoolSettings(QueueManagingVirtualHost<?> vi
{
throw new IllegalConfigurationException(String.format("Number of Selectors %d on VirtualHost %s must be greater than zero.", virtualHost.getNumberOfSelectors(), getName()));
}
if (virtualHost.getConnectionThreadPoolSize() <= virtualHost.getNumberOfSelectors())
if (virtualHost.getConnectionThreadPoolSize() < virtualHost.getNumberOfSelectors())
{
throw new IllegalConfigurationException(String.format("Number of Selectors %d on VirtualHost %s must be less than the connection pool size %d.", virtualHost.getNumberOfSelectors(), getName(), virtualHost.getConnectionThreadPoolSize()));
throw new IllegalConfigurationException(String.format("Number of Selectors %d on VirtualHost %s must be less than or equal to the connection pool size %d.", virtualHost.getNumberOfSelectors(), getName(), virtualHost.getConnectionThreadPoolSize()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,31 +509,47 @@ public void testExistingConnectionBlocking()
}

@Test
public void testCreateValidation()
public void testSelectorNumberMustBePositiveOnCreate()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to suggest splitting positive and negative tests into separate methods

{
createVirtualHost(getTestName(), Collections.singletonMap(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, "1"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It make sense to verify that attribute "numberOfSelectors" is indeed set to the specified value, for example

Map<String, Object> attributes = Collections.singletonMap(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, "1"); final QueueManagingVirtualHost<?> vh = createVirtualHost(getTestName(), attributes); assertEquals(1, vh.getNumberOfSelectors());

try
{
createVirtualHost(getTestName(), Collections.singletonMap(QueueManagingVirtualHost.NUMBER_OF_SELECTORS,
"-1"));
fail("Exception not thrown for negative number of selectors");
createVirtualHost(getTestName(), Collections.singletonMap(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, "0"));
fail("Exception not thrown for non-positive number of selectors");
}
catch (IllegalConfigurationException e)
{
// pass
}
}

@Test
public void testConnectionThreadPoolSizeMustBePositiveOnCreate()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, split method into positive and negative tests

{
final Map<String, Object> vhAttributes = new HashMap<>();
vhAttributes.put(QueueManagingVirtualHost.CONNECTION_THREAD_POOL_SIZE, 1);
vhAttributes.put(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, 1);
createVirtualHost(getTestName(), vhAttributes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test can be strengthen with asserts verifying that specified values are indeed set on the corresponding attributes

try
{
createVirtualHost(getTestName(), Collections.singletonMap(QueueManagingVirtualHost.CONNECTION_THREAD_POOL_SIZE, "-1"));
fail("Exception not thrown for negative connection thread pool size");
createVirtualHost(getTestName(), Collections.singletonMap(QueueManagingVirtualHost.CONNECTION_THREAD_POOL_SIZE, "0"));
fail("Exception not thrown for non-positive connection thread pool size");
}
catch (IllegalConfigurationException e)
{
// pass
}
}

@Test
public void testSelectorNumberMustBeLessOrEqualToThePoolSizeOnCreate()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to suggest splitting positive and negative tests into separate methods

{
createVirtualHost(getTestName(), Collections.singletonMap(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, QueueManagingVirtualHost.DEFAULT_VIRTUALHOST_CONNECTION_THREAD_POOL_SIZE - 1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test can be strengthen with asserts verifying that specified values are indeed set on the corresponding attributes

createVirtualHost(getTestName(), Collections.singletonMap(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, QueueManagingVirtualHost.DEFAULT_VIRTUALHOST_CONNECTION_THREAD_POOL_SIZE));
try
{
createVirtualHost(getTestName(), Collections.<String, Object>singletonMap(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, QueueManagingVirtualHost.DEFAULT_VIRTUALHOST_CONNECTION_THREAD_POOL_SIZE));
fail("Exception not thrown for number of selectors equal to connection thread pool size");
createVirtualHost(getTestName(), Collections.singletonMap(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, QueueManagingVirtualHost.DEFAULT_VIRTUALHOST_CONNECTION_THREAD_POOL_SIZE + 1));
fail("Exception not thrown for number of selectors greater than connection thread pool size");
}
catch (IllegalConfigurationException e)
{
Expand All @@ -542,32 +558,50 @@ public void testCreateValidation()
}

@Test
public void testChangeValidation()
public void testSelectorNumberMustBePositiveOnChange()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to suggest splitting positive and negative tests into separate methods

{
QueueManagingVirtualHost<?> virtualHost = createVirtualHost(getTestName());
final QueueManagingVirtualHost<?> virtualHost = createVirtualHost(getTestName());
virtualHost.setAttributes(Collections.singletonMap(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, "1"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test can be strengthen with asserts verifying that specified values are indeed set on the corresponding attributes

try
{
virtualHost.setAttributes(Collections.<String, Object>singletonMap(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, "-1"));
fail("Exception not thrown for negative number of selectors");
virtualHost.setAttributes(Collections.singletonMap(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, "0"));
fail("Exception not thrown for non-positive number of selectors");
}
catch (IllegalConfigurationException e)
{
// pass
}
}

@Test
public void testConnectionThreadPoolSizeMustBePositiveOnChange()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to suggest splitting positive and negative tests into separate methods

{
final QueueManagingVirtualHost<?> virtualHost = createVirtualHost(getTestName());
final Map<String, Object> vhAttributes = new HashMap<>();
vhAttributes.put(QueueManagingVirtualHost.CONNECTION_THREAD_POOL_SIZE, 1);
vhAttributes.put(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, 1);
virtualHost.setAttributes(vhAttributes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test can be strengthen with asserts verifying that specified values are indeed set on the corresponding attributes

try
{
virtualHost.setAttributes(Collections.singletonMap(QueueManagingVirtualHost.CONNECTION_THREAD_POOL_SIZE,
"-1"));
fail("Exception not thrown for negative connection thread pool size");
virtualHost.setAttributes(Collections.singletonMap(QueueManagingVirtualHost.CONNECTION_THREAD_POOL_SIZE, "0"));
fail("Exception not thrown for non-positive connection thread pool size");
}
catch (IllegalConfigurationException e)
{
// pass
}
}

@Test
public void testSelectorNumberMustBeLessOrEqualToThePoolSizeOnChange()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to suggest splitting positive and negative tests into separate methods

{
final QueueManagingVirtualHost<?> virtualHost = createVirtualHost(getTestName());
virtualHost.setAttributes(Collections.singletonMap(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, QueueManagingVirtualHost.DEFAULT_VIRTUALHOST_CONNECTION_THREAD_POOL_SIZE - 1));
virtualHost.setAttributes(Collections.singletonMap(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, QueueManagingVirtualHost.DEFAULT_VIRTUALHOST_CONNECTION_THREAD_POOL_SIZE));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test can be strengthen with asserts verifying that specified values are indeed set on the corresponding attributes

try
{
virtualHost.setAttributes(Collections.singletonMap(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, QueueManagingVirtualHost.DEFAULT_VIRTUALHOST_CONNECTION_THREAD_POOL_SIZE));
fail("Exception not thrown for number of selectors equal to connection thread pool size");
virtualHost.setAttributes(Collections.singletonMap(QueueManagingVirtualHost.NUMBER_OF_SELECTORS, QueueManagingVirtualHost.DEFAULT_VIRTUALHOST_CONNECTION_THREAD_POOL_SIZE + 1));
fail("Exception not thrown for number of selectors greater than connection thread pool size");
}
catch (IllegalConfigurationException e)
{
Expand Down