You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ch...@apache.org on 2015/11/10 15:37:34 UTC
qpid-dispatch git commit: Add policy self test
Repository: qpid-dispatch
Updated Branches:
refs/heads/crolke-DISPATCH-188-1 93b5450f2 -> c9c6b2002
Add policy self test
Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/c9c6b200
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/c9c6b200
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/c9c6b200
Branch: refs/heads/crolke-DISPATCH-188-1
Commit: c9c6b200218def062eccbbad5b7cb062ff52fee1
Parents: 93b5450
Author: Chuck Rolke <cr...@redhat.com>
Authored: Tue Nov 10 09:37:27 2015 -0500
Committer: Chuck Rolke <cr...@redhat.com>
Committed: Tue Nov 10 09:37:27 2015 -0500
----------------------------------------------------------------------
src/policy.c | 4 +-
tests/CMakeLists.txt | 5 ++-
tests/system_tests_policy.py | 79 +++++++++++++++++++++++++++++++++++++++
3 files changed, 85 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/c9c6b200/src/policy.c
----------------------------------------------------------------------
diff --git a/src/policy.c b/src/policy.c
index a08bff8..7b4e98e 100644
--- a/src/policy.c
+++ b/src/policy.c
@@ -117,6 +117,7 @@ qd_error_t qd_router_configure_policy(qd_policy_t *policy, qd_entity_t *entity)
policy->max_connections = qd_entity_opt_long(entity, "maximumConnections", 0); QD_ERROR_RET();
if (policy->max_connections < 0)
return qd_error(QD_ERROR_CONFIG, "maximumConnections must be >= 0");
+ qd_log(policy->log_source, QD_LOG_INFO, "Configured maximumConnections: %d", policy->max_connections);
return QD_ERROR_NONE;
}
@@ -136,7 +137,6 @@ bool qd_policy_socket_accept(void *context, const char *hostname)
if (policy->max_connections == 0) {
// Policy not in force; connection counted and allowed
n_connections += 1;
- qd_log(policy->log_source, POLICY_LOG_LEVEL, "Connection '%s' allowed. N= %d", hostname, n_connections); // HACK EXTRA
} else {
// Policy in force
if (n_connections < policy->max_connections) {
@@ -158,8 +158,8 @@ void qd_policy_socket_close(void *context, const char *hostname)
qd_policy_t *policy = (qd_policy_t *)context;
n_connections -= 1;
+ assert (n_connections >= 0);
if (policy->max_connections > 0) {
- assert (n_connections >= 0);
qd_log(policy->log_source, POLICY_LOG_LEVEL, "Connection '%s' closed, N=%d", hostname, n_connections);
}
qd_log(policy->log_source, POLICY_LOG_LEVEL, "Connection '%s' closed, N=%d", hostname, n_connections); // HACK EXTRA
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/c9c6b200/tests/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index c02c4fa..d2d5e29 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -61,6 +61,7 @@ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/system_tests_qdmanage.py DESTINATION ${CMA
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/system_tests_qdstat.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/system_tests_two_routers.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/system_tests_link_routes.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
+file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/system_tests_policy.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/run_system_tests.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/system_test.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
@@ -86,6 +87,7 @@ add_test(system_tests_qdmanage ${TEST_WRAP} -s ${CMAKE_CURRENT_BINARY_DIR}/sy
add_test(system_tests_qdstat ${TEST_WRAP} -s ${CMAKE_CURRENT_BINARY_DIR}/system_tests_qdstat.py -v)
add_test(system_tests_two_routers ${TEST_WRAP} -s ${CMAKE_CURRENT_BINARY_DIR}/system_tests_two_routers.py -v)
add_test(system_tests_link_routes ${TEST_WRAP} -s ${CMAKE_CURRENT_BINARY_DIR}/system_tests_link_routes.py -v)
+add_test(system_tests_policy ${TEST_WRAP} -s ${CMAKE_CURRENT_BINARY_DIR}/system_tests_policy.py -v)
add_test(system_tests_sasl_plain ${TEST_WRAP} -s ${CMAKE_CURRENT_BINARY_DIR}/system_tests_sasl_plain.py -v)
add_test(management_tests ${TEST_WRAP} -m unittest -v management)
@@ -107,7 +109,8 @@ set(SYSTEM_TEST_FILES
${CMAKE_CURRENT_BINARY_DIR}/system_tests_qdstat.py
${CMAKE_CURRENT_BINARY_DIR}/system_tests_qdmanage.py
${CMAKE_CURRENT_BINARY_DIR}/system_tests_link_routes.py
- ${CMAKE_CURRENT_BINARY_DIR}/system_tests_sasl_plain.py)
+ ${CMAKE_CURRENT_BINARY_DIR}/system_tests_sasl_plain.py
+ ${CMAKE_CURRENT_BINARY_DIR}/system_tests_policy.py)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-2/A-ssl.conf.in ${CMAKE_CURRENT_BINARY_DIR}/config-2/A-ssl.conf)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-2/B-ssl.conf.in ${CMAKE_CURRENT_BINARY_DIR}/config-2/B-ssl.conf)
http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/c9c6b200/tests/system_tests_policy.py
----------------------------------------------------------------------
diff --git a/tests/system_tests_policy.py b/tests/system_tests_policy.py
new file mode 100644
index 0000000..280e534
--- /dev/null
+++ b/tests/system_tests_policy.py
@@ -0,0 +1,79 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+import sys
+import unittest
+from time import sleep
+from system_test import TestCase, Qdrouterd, main_module
+
+from proton import Message
+from proton import ConnectionException
+from proton.reactor import AtMostOnce
+from proton.utils import BlockingConnection, LinkDetached
+
+from qpid_dispatch.management.client import Node
+from system_test import TIMEOUT
+
+class AbsoluteConnectionCountLimit(TestCase):
+ """
+ Verify that connections beyond the absolute limit are denied
+ """
+ @classmethod
+ def setUpClass(cls):
+ """Start the router"""
+ super(AbsoluteConnectionCountLimit, cls).setUpClass()
+ config = Qdrouterd.Config([
+ ('container', {'workerThreads': 4, 'containerName': 'Qpid.Dispatch.Router.Policy'}),
+ ('router', {'mode': 'standalone', 'routerId': 'QDR.Policy'}),
+ ('listener', {'port': cls.tester.get_port()}),
+ ('policy', {'maximumConnections': 2})
+ ])
+
+ cls.router = cls.tester.qdrouterd('conn-limit-router', config, wait=True)
+
+ def address(self):
+ return self.router.addresses[0]
+
+ def test_aaa_verify_maximum_connections(self):
+ addr = self.address()
+
+ # two connections should be ok
+ denied = False
+ try:
+ bc1 = BlockingConnection(addr)
+ bc2 = BlockingConnection(addr)
+ except ConnectionException:
+ denied = True
+
+ self.assertFalse(denied) # connections that should open did not open
+
+ # third connection should be denied
+ denied = False
+ try:
+ bc3 = BlockingConnection(addr)
+ except ConnectionException:
+ denied = True
+
+ self.assertTrue(denied) # connection that should not open did open
+
+ bc1.close()
+ bc2.close()
+
+if __name__ == '__main__':
+ unittest.main(main_module())
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org