BIND 10 trac1427, updated. 34de4dab534c2ccc735f6c815aa0459553aa1153 [1427] The drop_application method

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Nov 28 12:03:37 UTC 2011


The branch, trac1427 has been updated
       via  34de4dab534c2ccc735f6c815aa0459553aa1153 (commit)
      from  7f573f432cfca90d2f9409829f14b3645083b9af (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 34de4dab534c2ccc735f6c815aa0459553aa1153
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Mon Nov 28 13:02:40 2011 +0100

    [1427] The drop_application method

-----------------------------------------------------------------------

Summary of changes:
 src/lib/python/isc/bind10/socket_cache.py          |   13 ++++++++++-
 .../python/isc/bind10/tests/socket_cache_test.py   |   23 ++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/python/isc/bind10/socket_cache.py b/src/lib/python/isc/bind10/socket_cache.py
index 689cefb..83fdcb6 100644
--- a/src/lib/python/isc/bind10/socket_cache.py
+++ b/src/lib/python/isc/bind10/socket_cache.py
@@ -263,4 +263,15 @@ class Cache:
         If the application is invalid (no get_socket was successful with this
         value of application), it raises ValueError.
         """
-        pass
+        try:
+            # Get a copy. Who knows how iteration works through sets if we
+            # delete from it during the time, so we'll just have our own copy
+            # to iterate
+            to_drop = set(self._active_apps[application])
+        except KeyError:
+            raise ValueError("Application " + str(application) +
+                             " doesn't hold any sockets")
+        for token in to_drop:
+            self.drop_socket(token)
+        # We don't call del now. The last drop_socket should have
+        # removed the application key as well.
diff --git a/src/lib/python/isc/bind10/tests/socket_cache_test.py b/src/lib/python/isc/bind10/tests/socket_cache_test.py
index 93f99dd..bf8b85f 100644
--- a/src/lib/python/isc/bind10/tests/socket_cache_test.py
+++ b/src/lib/python/isc/bind10/tests/socket_cache_test.py
@@ -280,6 +280,29 @@ class SocketCacheTest(Test):
         # Trying to get it again fails
         self.assertRaises(ValueError, self.__cache.get_socket, token, app)
 
+    def test_drop_application(self):
+        """
+        Test that a drop_application calls drop_socket on all the sockets
+        held by the application.
+        """
+        sockets = set()
+        def drop_socket(token):
+            sockets.add(token)
+        # Mock the drop_socket so we know it is called
+        self.__cache.drop_socket = drop_socket
+        self.assertRaises(ValueError, self.__cache.drop_application,
+                          "bad token")
+        self.assertEqual(set(), sockets)
+        # Put the tokens into active_apps. Nothing else should be touched
+        # by this call, so leave it alone.
+        self.__cache._active_apps = {
+            1: set(['t1', 't2']),
+            2: set(['t3'])
+        }
+        self.__cache.drop_application(1)
+        self.assertEqual({2: set(['t3'])}, self.__cache._active_apps)
+        self.assertEqual(set(['t1', 't2']), sockets)
+
 if __name__ == '__main__':
     isc.log.init("bind10")
     isc.log.resetUnitTestRootLogger()




More information about the bind10-changes mailing list