示例#1
0
    def test_trackResourceInformation_validDynamicBoxes(self):
        "trackResourceInformation, retrieveTrackedResourceInformation - Associates communication & user aspects related to a resource. Associating dynamically created in/out boxes with a resource is the default"
        a = AdaptiveCommsComponent.AdaptiveCommsComponent()

        inboxes = [
            a.addInbox("dynamic"),
            a.addInbox("dynamic"),
            a.addInbox("dynamic")
        ]
        outboxes = [
            a.addOutbox("dynamic"),
            a.addOutbox("dynamic"),
            a.addOutbox("dynamic")
        ]
        arbitraryInformation = "qwertyuiopasdfghjklzxcvbnm"
        resource = "resource"
        a.trackResourceInformation(resource, inboxes, outboxes,
                                   arbitraryInformation)
        storedInboxes, storedOutboxes, storedInformation = a.retrieveTrackedResourceInformation(
            resource)
        self.assertEqual(inboxes, storedInboxes,
                         "We can retrieve the right set of inboxes")
        self.assertEqual(outboxes, storedOutboxes,
                         "We can retrieve the right set of outboxes")
        self.assertEqual(arbitraryInformation, storedInformation,
                         "We can retrieve the right arbitrary information")
示例#2
0
 def test_addOutbox_newName(self):
     "addOutbox - adding an outbox with a completely new name results in that outbox being created/added"
     a = AdaptiveCommsComponent.AdaptiveCommsComponent()
     name = a.addOutbox("name")
     self.assertEqual("name", name,
                      "Inbox was added with the name we requested")
     outboxNames = list(a.outboxes)
     self.assert_(name in outboxNames, "Outbox was added")
     self.assert_(len(a.outboxes[name]) == 0, "Outbox created was empty")
示例#3
0
 def test_trackResource_invalidInbox(self):
     "trackResource,retrieveTrackedResource - Tracking resources using an invalid inbox name should fail."
     import time
     a = AdaptiveCommsComponent.AdaptiveCommsComponent()
     resource = "resource"
     inboxResourceAssociatedWith = a.addInbox("name") + str(
         time.time())  # Ensure non-existant
     self.assertRaises(KeyError, a.trackResource, resource,
                       inboxResourceAssociatedWith)
示例#4
0
 def test_trackResource_validDynamicInbox(self):
     "trackResource,retrieveTrackedResource - Tracking resources using a custom dynamic inbox name should work."
     a = AdaptiveCommsComponent.AdaptiveCommsComponent()
     resource = "resource"
     inboxResourceAssociatedWith = a.addInbox("dynamic")
     a.trackResource(resource, inboxResourceAssociatedWith)
     storedResource = a.retrieveTrackedResource(inboxResourceAssociatedWith)
     self.assertEqual(resource, storedResource,
                      "The resource was correctly stored")
示例#5
0
 def test_trackResource_validDefaultInbox(self):
     "trackResource,retrieveTrackedResource - Adds to & retrieves from the mapping of inbox -> resource to a local store. This allows retrieval of the resource based on which inbox messages arrive on. Whilst designed for custom inboxes, it should work with the 'default' inboxes for a component"
     a = AdaptiveCommsComponent.AdaptiveCommsComponent()
     resource = "resource"
     inboxResourceAssociatedWith = "inbox"
     a.trackResource(resource, inboxResourceAssociatedWith)
     storedResource = a.retrieveTrackedResource(inboxResourceAssociatedWith)
     self.assertEqual(resource, storedResource,
                      "The resource was correctly stored")
示例#6
0
 def test_addOutbox_existingName(self):
     "addOutbox - adding an outbox with an existing name results in an outbox being created/added with a similar name - same name with a suffix"
     import re
     a = AdaptiveCommsComponent.AdaptiveCommsComponent()
     name = a.addOutbox("name")
     name = a.addOutbox(
         "name")  # Attempt to create second box with existing name
     self.assertNotEqual("name", name,
                         "Inbox was added with the name we requested")
     self.assert_(re.match("name", name),
                  "Inbox created has a simlar name (same start)")
示例#7
0
 def test_SmokeTest_NoArguments(self):
     "__init__ - Called with no arguments is expected, results in component superconstructor being called. performs no local initialisation"
     a = AdaptiveCommsComponent.AdaptiveCommsComponent()
     self.assert_(
         isinstance(a, AdaptiveCommsComponent.AdaptiveCommsComponent),
         "Right Type")
     self.assert_(isinstance(a, Component.component), "Right Base Type")
     self.assert_(
         0 == len(a.inboxes['control']) and 0 == len(a.inboxes['inbox'])
         and 2 == len(a.inboxes), "Correct Basic inboxes")
     self.assert_(
         0 == len(a.outboxes['signal']) and 0 == len(a.outboxes['outbox'])
         and 2 == len(a.outboxes), "Correct Basic outboxes")
示例#8
0
    def test_trackResourceInformation_invalidOutboxes(self):
        "trackResourceInformation, retrieveTrackedResourceInformation - Tracking invalid outboxes using a resource fails."
        import time
        a = AdaptiveCommsComponent.AdaptiveCommsComponent()

        inboxes = [a.addInbox("dynamic")
                   ]  # List of "guaranteed" valid  outboxes
        outboxes = [a.addOutbox("name") + str(time.time())
                    ]  # This list of inboxes is "guaranteed" not to exist
        arbitraryInformation = "qwertyuiopasdfghjklzxcvbnm"
        resource = "resource"
        self.assertRaises(KeyError, a.trackResourceInformation, resource,
                          inboxes, outboxes, arbitraryInformation)
示例#9
0
    def test_deleteInbox_validInbox(self):
        "deleteInbox - Deletes the named inbox"
        import random
        a = AdaptiveCommsComponent.AdaptiveCommsComponent()
        # Pick a random inbox to delete
        inboxNames = list(a.inboxes)
        inboxNames.sort()
        box = inboxNames[random.randint(0, len(inboxNames) - 1)]

        a.deleteInbox(box)
        newinboxNames = list(a.inboxes)
        newinboxNames.sort()
        self.assertNotEqual(inboxNames, newinboxNames, "Inboxes were changed")
        self.assert_(box not in newinboxNames, "Inbox " + box + "was deleted")
示例#10
0
 def test_InboxModification(self):
     "-Acceptance Test - Check Addition and Deletion of Inboxes"
     a = AdaptiveCommsComponent.AdaptiveCommsComponent()
     addedNames = []
     for i in [1, 2, 3, 4]:
         inboxNames = list(a.inboxes)
         name = a.addInbox("name")
         self.assert_(name not in inboxNames, "Inbox added had a new name")
         inboxNames = list(a.inboxes)
         self.assert_(name in inboxNames, "Inbox was added")
         addedNames.append(name)
         self.assert_(len(a.inboxes[name]) == 0, "Inbox created was empty")
     #
     for name in addedNames:
         a.deleteInbox(name)
         self.assert_(name not in a.inboxes, "Inbox was deleted")
     #
     self.assert_(
         0 == len(a.inboxes['control']) and 0 == len(a.inboxes['inbox'])
         and 2 == len(a.inboxes), "Only have default inboxes left")
示例#11
0
 def test_OutboxModification(self):
     "-Acceptance Test - Check Addition and Deletion of Outboxes"
     a = AdaptiveCommsComponent.AdaptiveCommsComponent()
     addedNames = []
     for i in [1, 2, 3, 4]:
         outboxNames = list(a.outboxes)
         name = a.addOutbox("name")
         self.assert_(name not in outboxNames,
                      "Outbox added had a new name")
         outboxNames = list(a.outboxes)
         self.assert_(name in outboxNames, "Outbox was added")
         addedNames.append(name)
         self.assert_(
             len(a.outboxes[name]) == 0, "Outbox created was empty")
     #
     for name in addedNames:
         a.deleteOutbox(name)
         self.assert_(name not in a.outboxes, "Outbox was deleted")
     #
     self.assert_(
         0 == len(a.outboxes['signal']) and 0 == len(a.outboxes['outbox'])
         and 2 == len(a.outboxes), "Only have one outbox left")
示例#12
0
 def test_SmokeTest_Arguments(self):
     "__init__ - Called with with arguments does not cause problems"
     AdaptiveCommsComponent.AdaptiveCommsComponent("hello", "world")
示例#13
0
 def test_deleteOutbox_invalidOutbox(self):
     "deleteOutbox - KeyError exception raised if you try to delete an outbox that does not exist - this includes the case of an already deleted Outbox"
     a = AdaptiveCommsComponent.AdaptiveCommsComponent()
     self.assertRaises(KeyError, a.deleteOutbox, "NonExistantInbox")