Пример #1
0
 def testEqualityFailsIfDifferentGeneratingAddress(self):
     genAddr = ActorAddress(id(self))
     genAddr2 = ActorAddress('hi')
     self.assertNotEqual(genAddr, genAddr2)
     addr1 = ActorLocalAddress(genAddr, 0, None)
     addr2 = ActorLocalAddress(genAddr2, 0, None)
     self.assertNotEqual(addr1, addr2)
Пример #2
0
 def testEqualityFailsIfDifferentGeneratingAddress(self):
     genAddr = ActorAddress(id(self))
     genAddr2 = ActorAddress('hi')
     assert genAddr != genAddr2
     addr1 = ActorLocalAddress(genAddr, 0, None)
     addr2 = ActorLocalAddress(genAddr2, 0, None)
     assert addr1 != addr2
Пример #3
0
def startAdmin(adminClass, addrOfStarter, endpointPrep, transportClass,
               adminAddr, capabilities, logDefs):
    # Unix Daemonization; skipped if not available
    import os, sys
    if hasattr(os, 'setsid'):
        os.setsid()
    try:
        import resource
        resource.setrlimit(resource.RLIMIT_CORE, (0, 0))  # No core dumps
    except Exception:
        pass
    if hasattr(os, 'fork'):
        if os.fork(): sys.exit(0)

    # Slight trickiness here.  There may *already* be an admin bound
    # to this start address.  However, the external process attempting
    # to start is going to wait for the EndpointConnected message
    # before continuing, so ensure that message is *not* sent until
    # the local admin Transport has had time to bind and listen to the
    # local address, but also ensure that the message is *always* sent
    # even if the local admin could not start (caller will use
    # _verifyAdminRunning to ensure things are OK.
    transport = transportClass(endpointPrep)
    try:
        admin = adminClass(transport, adminAddr, capabilities, logDefs)
    except Exception:
        transport.scheduleTransmit(
            None, TransmitIntent(addrOfStarter, EndpointConnected(0)))
        raise
    # Send of EndpointConnected is deferred until the logger is setup.  See MultiProcReplicator.h_LoggerConnected below.

    admin.addrOfStarter = addrOfStarter
    setProcName(adminClass.__name__, admin.transport.myAddress)

    # Generate the "placeholder" loggerAddr directly instead of going
    # through the AddressManager because the logger is not managed as
    # a normal child.
    loggerAddr = ActorAddress(ActorLocalAddress(transport.myAddress, -1, None))
    admin.asLogger = None
    logAggregator = capabilities.get('Convention Address.IPv4', None)
    if logAggregator:
        try:
            logAggregator = transportClass.getAddressFromString(logAggregator)
        except Exception as ex:
            thesplog(
                'Unable to adapt log aggregator address "%s" to a transport address: %s',
                logAggregator,
                ex,
                level=logging.WARNING)
    admin.asLogProc = startASLogger(
        loggerAddr, logDefs, transport, capabilities,
        logAggregator if logAggregator != admin.transport.myAddress else None)
    #closeUnusedFiles(transport)
    admin.run()
Пример #4
0
def _startLogger(transportClass, transport, admin, capabilities, logDefs,
                 concurrency_context):
    # Generate the "placeholder" loggerAddr directly instead of going
    # through the AddressManager because the logger is not managed as
    # a normal child.
    loggerAddr = ActorAddress(ActorLocalAddress(transport.myAddress, -1, None))
    admin.asLogger = None
    logAggregator = capabilities.get('Convention Address.IPv4', None)
    if logAggregator:
        try:
            logAggregator = transportClass.getAddressFromString(logAggregator)
        except Exception as ex:
            thesplog(
                'Unable to adapt log aggregator address "%s" to a transport address: %s',
                logAggregator,
                ex,
                level=logging.WARNING)
    admin.asLogProc = startASLogger(
        loggerAddr, logDefs, transport, capabilities,
        logAggregator if logAggregator != admin.transport.myAddress else None,
        concurrency_context)
Пример #5
0
 def testGetValidLocalAddress(self):
     am = ActorAddressManager(None, "I am me")
     addr = ActorAddress(ActorLocalAddress('I am me', 12, am))
     assert isinstance(addr.addressDetails, ActorLocalAddress)
Пример #6
0
 def testInstanceID(self):
     assert 5 == ActorLocalAddress(ActorAddress(id(self)), 5,
                                   None).addressInstanceNum
Пример #7
0
 def testStringForm(self):
     assert '' != str(ActorLocalAddress(ActorAddress(id(self)), 0, None))
Пример #8
0
 def testEqualityFailsIfDifferentInstanceNums(self):
     genAddr = ActorAddress(id(self))
     addr1 = ActorLocalAddress(genAddr, 0, None)
     addr2 = ActorLocalAddress(genAddr, 1, None)
     assert addr1 != addr2
Пример #9
0
 def testEquality(self):
     genAddr = ActorAddress(id(self))
     addr1 = ActorLocalAddress(genAddr, 0, None)
     addr2 = ActorLocalAddress(genAddr, 0, None)
     assert addr1 == addr2
Пример #10
0
 def testNonHashable(self):
     genAddr = ActorAddress(id(self))
     lclAddr1 = ActorLocalAddress(genAddr, 0, None)
     lclAddr2 = ActorLocalAddress(genAddr, 1, None)
     raises(TypeError, hash, lclAddr1)
     raises(TypeError, hash, lclAddr2)
Пример #11
0
 def testCreate(self):
     genAddr = ActorAddress(id(self))
     addr = ActorLocalAddress(genAddr, 0, None)
     # No exception thrown
     assert True
Пример #12
0
 def testGetValidLocalAddress(self):
     addr = ActorAddress(ActorLocalAddress(self.myAddress, 12, self.am))
     self.assertIsInstance(addr.addressDetails, ActorLocalAddress)
Пример #13
0
 def testInstanceID(self):
     self.assertEqual(
         5,
         ActorLocalAddress(ActorAddress(id(self)), 5,
                           None).addressInstanceNum)
Пример #14
0
 def testStringForm(self):
     self.assertNotEqual(
         '', str(ActorLocalAddress(ActorAddress(id(self)), 0, None)))
Пример #15
0
 def testEquality(self):
     genAddr = ActorAddress(id(self))
     addr1 = ActorLocalAddress(genAddr, 0, None)
     addr2 = ActorLocalAddress(genAddr, 0, None)
     self.assertEqual(addr1, addr2)
Пример #16
0
 def testUniqueHash(self):
     genAddr = ActorAddress(id(self))
     addrs = [ActorLocalAddress(genAddr, N, None) for N in range(32)]
     hashes = set([hash(A) for A in addrs])
     self.assertEqual(len(addrs), len(hashes))