def test_properties(self):
        c1 = ActorSystemConventionUpdate('addr', {'caps':1}, True)
        self.assertEqual(c1.remoteAdminAddress, 'addr')
        self.assertEqual(c1.remoteCapabilities, {'caps':1})
        self.assertEqual(c1.remoteAdded, True)

        c2 = ActorSystemConventionUpdate('addr', {'caps':1}, False)
        self.assertEqual(c2.remoteAdded, False)

        c3 = ActorSystemConventionUpdate('addr', {'caps':1})
        self.assertEqual(c3.remoteAdded, True)
Пример #2
0
def test_reg_dereg_rereg_with_delay_and_updates(lcs1, lcs2):

    # Setup both in the registered condition
    notifyAddr = test_reg_with_notifications(lcs1, lcs2)

    # Now add some elapsed time and check update messages

    lcs2_rereg = ConventionRegister(lcs2.myAddress,
                                    lcs2.capabilities,
                                    preRegister=False,
                                    firstTime=False)

    lcs2_exited_update = ActorSystemConventionUpdate(lcs2.myAddress,
                                                     lcs2.capabilities,
                                                     added=False)

    with patch('thespian.system.utilis.datetime') as p_datetime:
        p_datetime.now.return_value = (datetime.now() +
                                       CONVENTION_REREGISTRATION_PERIOD +
                                       timedelta(seconds=1))
        # Convention leader does not take action
        verify_io(lcs1.check_convention(), [])
        # But convention member should re-up their membership
        verify_io(lcs2.check_convention(), [
            (ConventionRegister,
             lambda r, a: r == lcs2_rereg and a == lcs1.myAddress),
            (LogAggregator, None),
        ])

    # Too long
    with patch('thespian.system.utilis.datetime') as p_datetime:
        p_datetime.now.return_value = (datetime.now() +
                                       (CONVENTION_REREGISTRATION_PERIOD *
                                        CONVENTION_REGISTRATION_MISS_MAX) +
                                       timedelta(seconds=1))
        # Convention leader does not take action
        verify_io(lcs1.check_convention(), [
            (LostRemote, None),
            (ActorSystemConventionUpdate, lambda r, a:
             (r == lcs2_exited_update and a == notifyAddr)),
            (HysteresisCancel, None),
        ])
        # But convention member should re-up their membership
        verify_io(lcs2.check_convention(), [
            (ConventionRegister,
             lambda r, a: r == lcs2_rereg and a == lcs1.myAddress),
            (LogAggregator, None),
        ])

    lcs2_to_1_convdereg = ConventionDeRegister(lcs2.myAddress,
                                               preRegistered=False)

    verify_io(lcs1.got_convention_deregister(lcs2_to_1_convdereg), [
        (LostRemote, None),
        (HysteresisCancel, None),
    ])

    test_reg_with_notifications(lcs1, lcs2)
Пример #3
0
def test_prereg_reg_with_notifications(solo_lcs1, solo_lcs2):
    lcs1, lcs2 = solo_lcs1, solo_lcs2

    notifyAddr = ActorAddress('notify')

    lcs1.add_notification_handler(notifyAddr)

    lcs1_prereg_2_convreg = ConventionRegister(
        lcs2.myAddress, {'Admin Port': lcs2.capabilities['Admin Port']},
        firstTime=False,
        preRegister=True)
    lcs1_to_2_convreg_first = ConventionRegister(lcs1.myAddress,
                                                 lcs1.capabilities,
                                                 firstTime=True,
                                                 preRegister=False)
    lcs2_to_1_convreg = ConventionRegister(lcs2.myAddress,
                                           lcs2.capabilities,
                                           firstTime=False,
                                           preRegister=False)
    lcs1_to_2_convreg = ConventionRegister(lcs1.myAddress,
                                           lcs1.capabilities,
                                           firstTime=False,
                                           preRegister=False)

    verify_io(lcs1.got_convention_register(lcs1_prereg_2_convreg), [
        (LostRemote, None),
        (HysteresisCancel, None),
        (ConventionRegister, lambda r, a:
         (r == lcs1_to_2_convreg_first and a == lcs2.myAddress)),
    ])

    # lcs2 gets the ConventionRegister generated above, and responds
    # with actual info of its own.  If the other side is indicating
    # firstTime, that means it has no previous knowledge; this side
    # should not also set firstTime or that will bounce back and forth
    # indefinitely.  Note that this side will perform a transport
    # reset (LostRemote and HysteresisCancel); the TCPTransport may
    # ignore the transport reset for TXOnly addresses.

    verify_io(lcs2.got_convention_register(lcs1_to_2_convreg_first), [
        (LostRemote, None),
        (HysteresisCancel, None),
        (ConventionRegister, lambda r, a:
         (r == lcs2_to_1_convreg and a == lcs1.myAddress)),
    ])

    # lcs1 gets full ConventionRegister from lcs2.  This should also
    # cause an update notification with the full specification.
    verify_io(lcs1.got_convention_register(lcs2_to_1_convreg), [
        (ConventionRegister, lambda r, a:
         (r == lcs1_to_2_convreg and a == lcs2.myAddress)),
        (ActorSystemConventionUpdate, lambda r, a:
         (r == ActorSystemConventionUpdate(lcs2.myAddress,
                                           lcs2.capabilities,
                                           added=True) and a == notifyAddr)),
    ])

    verify_normal_notification_updates(lcs1, lcs2)
Пример #4
0
def test_reg_with_notifications(lcs1, lcs2):
    notifyAddr = ActorAddress('notify')

    lcs1.add_notification_handler(notifyAddr)

    lcs2_to_1_convreg_first = lcs2._expected_setup_convreg
    lcs1_to_2_convreg_first = ConventionRegister(lcs1.myAddress,
                                                 lcs1.capabilities,
                                                 firstTime=False,
                                                 preRegister=False)
    lcs2_to_1_convreg = ConventionRegister(lcs2.myAddress,
                                           lcs2.capabilities,
                                           firstTime=False,
                                           preRegister=False)
    lcs1_to_2_convreg = ConventionRegister(lcs1.myAddress,
                                           lcs1.capabilities,
                                           firstTime=False,
                                           preRegister=False)

    verify_io(lcs1.got_convention_register(lcs2_to_1_convreg_first), [
        (LostRemote, None),
        (HysteresisCancel, None),
        (ConventionRegister, lambda r, a:
         (r == lcs1_to_2_convreg_first and a == lcs2.myAddress)),
        (ActorSystemConventionUpdate, lambda r, a:
         (r == ActorSystemConventionUpdate(lcs2.myAddress,
                                           lcs2.capabilities,
                                           added=True) and a == notifyAddr)),
    ])

    verify_io(lcs2.got_convention_register(lcs1_to_2_convreg_first), [])

    # Non-convention leader generates periodic registrations to the
    # leader (i.e. keepalive) and the leader responds accordingly.

    verify_io(lcs1.got_convention_register(lcs2_to_1_convreg), [
        (ConventionRegister, lambda r, a:
         (r == lcs1_to_2_convreg and a == lcs2.myAddress)),
    ])
    verify_io(lcs2.got_convention_register(lcs1_to_2_convreg), [])
    verify_io(lcs1.got_convention_register(lcs2_to_1_convreg), [
        (ConventionRegister, lambda r, a:
         (r == lcs1_to_2_convreg and a == lcs2.myAddress)),
    ])
    verify_io(lcs2.got_convention_register(lcs1_to_2_convreg), [])

    # Convention check shows all is in order and nothing needs to be done

    assert [] == lcs1.check_convention()
    assert [] == lcs2.check_convention()

    return notifyAddr  # used by callers
Пример #5
0
def test_reg_dereg_with_notifications(lcs1, lcs2):

    # Setup both in the registered condition
    notifyAddr = test_reg_with_notifications(lcs1, lcs2)

    lcs2_to_1_convdereg = ConventionDeRegister(lcs2.myAddress,
                                               preRegistered=False)

    verify_io(lcs1.got_convention_deregister(lcs2_to_1_convdereg), [
        (LostRemote, None),
        (ActorSystemConventionUpdate, lambda r, a:
         (r == ActorSystemConventionUpdate(lcs2.myAddress,
                                           lcs2.capabilities,
                                           added=False) and a == notifyAddr)),
        (HysteresisCancel, None),
    ])
Пример #6
0
def test_notification_management_with_registrations(lcs1, lcs2):

    # Setup both in the registered condition
    notifyAddr = test_reg_with_notifications(lcs1, lcs2)

    # Re-registration does nothing
    verify_io(lcs1.add_notification_handler(notifyAddr), [])

    # Registering a another handler is fine
    notifyAddr2 = ActorAddress('notify2')

    notify_of_lcs2 = ActorSystemConventionUpdate(lcs2.myAddress,
                                                 lcs2.capabilities,
                                                 added=True)

    verify_io(lcs1.add_notification_handler(notifyAddr2), [
        (ActorSystemConventionUpdate, lambda r, a:
         (r == notify_of_lcs2 and a == notifyAddr2)),
    ])

    # Re-registration still does nothing
    verify_io(lcs1.add_notification_handler(notifyAddr), [])

    # De-registration
    lcs1.remove_notification_handler(notifyAddr)

    # Re-registration now adds it back
    verify_io(lcs1.add_notification_handler(notifyAddr), [
        (ActorSystemConventionUpdate, lambda r, a:
         (r == notify_of_lcs2 and a == notifyAddr)),
    ])

    # Multiple de-registration is ok
    lcs1.remove_notification_handler(notifyAddr)
    lcs1.remove_notification_handler(notifyAddr)

    # Re-registration now adds it back again
    verify_io(lcs1.add_notification_handler(notifyAddr), [
        (ActorSystemConventionUpdate, lambda r, a:
         (r == notify_of_lcs2 and a == notifyAddr)),
    ])
 def test_equality(self):
     c1 = ActorSystemConventionUpdate('addr1', 'cap1', True)
     self.assertEqual(c1, ActorSystemConventionUpdate('addr1', 'cap1', True))
 def test_inheritance(self):
     self.assertTrue(isinstance(ActorSystemConventionUpdate(1, 2, True), ActorSystemConventionUpdate))
     self.assertTrue(isinstance(ActorSystemConventionUpdate('one', None, False), ActorSystemConventionUpdate))
     self.assertTrue(isinstance(ActorSystemConventionUpdate(1, 2, True), ActorSystemMessage))
     self.assertTrue(isinstance(ActorSystemConventionUpdate('one', None, False), ActorSystemMessage))
 def test_inequality(self):
     c1 = ActorSystemConventionUpdate('addr1', 'cap1', True)
     self.assertNotEqual(c1, ActorSystemConventionUpdate('addr1', 'cap1', False))
     self.assertNotEqual(c1, ActorSystemConventionUpdate('addr1', ['cap1'], True))
     self.assertNotEqual(c1, ActorSystemConventionUpdate(2, 'cap1', True))
Пример #10
0
def test_reg_with_multiple_notifications(lcs1, lcs2):

    notifyAddr1 = ActorAddress('notify1')
    lcs1.add_notification_handler(notifyAddr1)

    notifyAddr2 = ActorAddress('notify2')
    lcs1.add_notification_handler(notifyAddr2)

    notifyAddr3 = ActorAddress('notify3')
    lcs1.add_notification_handler(notifyAddr3)

    # KWQ: lcs2.add_notification_handler .. never gets called

    lcs2_to_1_convreg_first = lcs2._expected_setup_convreg
    lcs1_to_2_convreg_first = ConventionRegister(lcs1.myAddress,
                                                 lcs1.capabilities,
                                                 firstTime=False,
                                                 preRegister=False)
    lcs2_to_1_convreg = ConventionRegister(lcs2.myAddress,
                                           lcs2.capabilities,
                                           firstTime=False,
                                           preRegister=False)
    lcs1_to_2_convreg = ConventionRegister(lcs1.myAddress,
                                           lcs1.capabilities,
                                           firstTime=False,
                                           preRegister=False)
    notificationUp = ActorSystemConventionUpdate(lcs2.myAddress,
                                                 lcs2.capabilities,
                                                 added=True)

    verify_io(lcs1.got_convention_register(lcs2_to_1_convreg_first), [
        (LostRemote, None),
        (HysteresisCancel, None),
        (ConventionRegister, lambda r, a:
         (r == lcs1_to_2_convreg_first and a == lcs2.myAddress)),
        (ActorSystemConventionUpdate, lambda r, a:
         (r == notificationUp and a == notifyAddr1)),
        (ActorSystemConventionUpdate, lambda r, a:
         (r == notificationUp and a == notifyAddr2)),
        (ActorSystemConventionUpdate, lambda r, a:
         (r == notificationUp and a == notifyAddr3)),
    ])

    verify_io(lcs2.got_convention_register(lcs1_to_2_convreg_first), [])

    # Non-convention leader generates periodic registrations to the
    # leader (i.e. keepalive) and the leader responds accordingly.

    verify_io(lcs1.got_convention_register(lcs2_to_1_convreg), [
        (ConventionRegister, lambda r, a:
         (r == lcs1_to_2_convreg and a == lcs2.myAddress)),
    ])
    verify_io(lcs2.got_convention_register(lcs1_to_2_convreg), [])
    verify_io(lcs1.got_convention_register(lcs2_to_1_convreg), [
        (ConventionRegister, lambda r, a:
         (r == lcs1_to_2_convreg and a == lcs2.myAddress)),
    ])
    verify_io(lcs2.got_convention_register(lcs1_to_2_convreg), [])

    # De-registration

    lcs2_to_1_convdereg = ConventionDeRegister(lcs2.myAddress,
                                               preRegistered=False)
    notificationDown = ActorSystemConventionUpdate(lcs2.myAddress,
                                                   lcs2.capabilities,
                                                   added=False)

    verify_io(lcs1.got_convention_deregister(lcs2_to_1_convdereg), [
        (LostRemote, None),
        (ActorSystemConventionUpdate, lambda r, a:
         (r == notificationDown and a == notifyAddr1)),
        (ActorSystemConventionUpdate, lambda r, a:
         (r == notificationDown and a == notifyAddr2)),
        (ActorSystemConventionUpdate, lambda r, a:
         (r == notificationDown and a == notifyAddr3)),
        (HysteresisCancel, None),
    ])