def test_late_start(self): self.q = Queue.Queue() def cb(key, value): self.q.put({"key": key, "value": value}) def started_cb(started): self.q.put(started) self.storage = storage.Storage() self.storage.set("test", "1", 1, None) self.storage.set("test", "2", 2, None) self.storage.set("test", "3", 3, None) assert "test1" in self.storage.localstore assert "test2" in self.storage.localstore assert "test3" in self.storage.localstore yield threads.defer_to_thread(self.storage.start, CalvinCB(started_cb)) yield threads.defer_to_thread(time.sleep, 2) value = self.q.get(timeout=0.2) assert value assert "test1" not in self.storage.localstore assert "test2" not in self.storage.localstore assert "test3" not in self.storage.localstore yield threads.defer_to_thread(self.storage.get, "test", "3", CalvinCB(func=cb)) value = self.q.get(timeout=0.2) assert value["value"] == 3 yield threads.defer_to_thread(self.storage.stop)
def __init__(self, uri, control_uri, attributes=None): super(Node, self).__init__() self.uri = uri self.control_uri = control_uri self.attributes = attributes self.id = calvinuuid.uuid("NODE") _log.debug("Calvin init 1") self.monitor = Event_Monitor() _log.debug("Calvin init 2") self.am = actormanager.ActorManager(self) _log.debug("Calvin init 3") self.control = calvincontrol.get_calvincontrol() _log.debug("Calvin init 4") self.sched = scheduler.Scheduler(self, self.am, self.monitor) _log.debug("Calvin init 5") self.control.start(node=self, uri=control_uri) self.async_msg_ids = {} _log.debug("Calvin init 6") self.storage = storage.Storage() self.storage.start() _log.debug("Calvin init 7") self.network = CalvinNetwork(self) _log.debug("Calvin init 8") self.proto = CalvinProto(self, self.network) self.pm = PortManager(self, self.proto) _log.debug("Calvin init 9") self.app_manager = appmanager.AppManager(self) _log.debug("Calvin init 10") # The initialization that requires the main loop operating is deferred to start function async.DelayedCall(0, self.start) _log.debug("Calvin init 11")
def __init__(self, uri, control_uri, attributes=None): super(Node, self).__init__() self.uri = uri self.control_uri = control_uri try: self.attributes = AttributeResolver(attributes) except: _log.exception("Attributes not correct, uses empty attribute!") self.attributes = AttributeResolver(None) self.id = calvinuuid.uuid("NODE") self.monitor = Event_Monitor() self.am = actormanager.ActorManager(self) self.control = calvincontrol.get_calvincontrol() _scheduler = scheduler.DebugScheduler if _log.getEffectiveLevel() <= logging.DEBUG else scheduler.Scheduler self.sched = _scheduler(self, self.am, self.monitor) self.control.start(node=self, uri=control_uri) self.async_msg_ids = {} self._calvinsys = CalvinSys(self) # Default will multicast and listen on all interfaces # TODO: be able to specify the interfaces # @TODO: Store capabilities self.storage = storage.Storage(self) self.network = CalvinNetwork(self) self.proto = CalvinProto(self, self.network) self.pm = PortManager(self, self.proto) self.app_manager = appmanager.AppManager(self) # The initialization that requires the main loop operating is deferred to start function async.DelayedCall(0, self.start)
def __init__(self, control_uri): super(StorageNode, self).__init__() self.id = calvinuuid.uuid("NODE") self.control_uri = control_uri self.control = calvincontrol.get_calvincontrol() _scheduler = scheduler.DebugScheduler if _log.getEffectiveLevel( ) <= logging.DEBUG else scheduler.Scheduler self.sched = _scheduler(self, FakeAM(), FakeMonitor()) self.control.start(node=self, uri=control_uri) self.storage = storage.Storage(self) async .DelayedCall(0, self.start)
def setup(self): _conf.set('global', 'storage_type', 'local') self.node = calvin.tests.TestNode(["127.0.0.1:5000"]) self.node.attributes = AttributeResolver( {"indexed_public": { "cpuTotal": "1" }}) self.storage = storage.Storage(self.node) self.cpu = CpuMonitor(self.node.id, self.storage) self.done = False self.storage.add_node(self.node) yield threads.defer_to_thread(time.sleep, .01)
def create_node(global_storage): node = calvin.tests.TestNode([""]) node._set_uris = __set_uris #node = MagicMock() #node.id = str(uuid.uuid4()) #node.name = node.id node.storage = storage.Storage(node, override_storage=global_storage) #node = calvin.tests.TestNode("127.0.0.1:5000") # Delay this until started, when we have a port and so on. #node.storage.add_node(node) return node
def prep_node(stype, n): n.storage = storage.Storage(n) if stype == "proxy": try: n.network = DummyNetwork(n) n.proto = DummyProto(n) except: traceback.print_exc() if stype != "notstarted": cb, d = create_callback(timeout=10, test_part=stype + " start") n.storage.start(cb=cb) return d
def test_late_start(self): self.q = Queue.Queue() self.q2 = Queue.Queue() def cb(key, value): self.q2.put({"key": key, "value": value}) def started_cb(started): self.q.put(started) cb, d = create_callback() self.storage = storage.Storage(DummyNode()) self.storage.start('', cb) self.storage2 = storage.Storage(DummyNode()) self.storage.set("test", "1", 1, None) self.storage.set("test", "2", 2, None) self.storage.set("test", "3", 3, None) assert "test1" in self.storage.localstore assert "test2" in self.storage.localstore assert "test3" in self.storage.localstore cb2, d = create_callback() self.storage2.start('', cb2) value = yield d # print value[0][0] assert value[0][0] yield wait_for(self.storage.localstore.keys, condition=lambda x: not x()) assert not self.storage.localstore.keys() cb, d = create_callback() self.storage.get("test", "3", cb) a, kw = yield d assert a[0] == "3" and a[1] == 3 self.storage.stop() self.storage2.stop()
def __init__(self, uri, control_uri, attributes=None): super(Node, self).__init__() self.uri = uri self.control_uri = control_uri self.external_uri = attributes.pop('external_uri', self.uri) \ if attributes else self.uri self.external_control_uri = attributes.pop('external_control_uri', self.control_uri) \ if attributes else self.control_uri try: self.attributes = AttributeResolver(attributes) except: _log.exception("Attributes not correct, uses empty attribute!") self.attributes = AttributeResolver(None) self.node_name = self.attributes.get_node_name_as_str() # Obtain node id, when using security also handle runtime certificate self.id = certificate.obtain_cert_node_info(self.node_name)['id'] self.authentication = authentication.Authentication(self) self.authorization = authorization.Authorization(self) try: self.domain = _conf.get("security", "security_domain_name") # cert_name is the node's certificate filename (without file extension) self.cert_name = certificate.get_own_cert_name(self.node_name) except: self.domain = None self.cert_name = None self.metering = metering.set_metering(metering.Metering(self)) self.monitor = Event_Monitor() self.am = actormanager.ActorManager(self) self.control = calvincontrol.get_calvincontrol() _scheduler = scheduler.DebugScheduler if _log.getEffectiveLevel() <= logging.DEBUG else scheduler.Scheduler self.sched = _scheduler(self, self.am, self.monitor) self.async_msg_ids = {} self._calvinsys = CalvinSys(self) # Default will multicast and listen on all interfaces # TODO: be able to specify the interfaces # @TODO: Store capabilities self.storage = storage.Storage(self) self.network = CalvinNetwork(self) self.proto = CalvinProto(self, self.network) self.pm = PortManager(self, self.proto) self.app_manager = appmanager.AppManager(self) # The initialization that requires the main loop operating is deferred to start function async.DelayedCall(0, self.start)
def __init__(self, uri, control_uri, attributes=None): super(Node, self).__init__() self.uri = uri self.control_uri = control_uri self.attributes = attributes self.id = calvinuuid.uuid("NODE") self.monitor = Event_Monitor() self.am = actormanager.ActorManager(self) self.control = calvincontrol.get_calvincontrol() _scheduler = scheduler.DebugScheduler if _log.getEffectiveLevel() <= logging.DEBUG else scheduler.Scheduler self.sched = _scheduler(self, self.am, self.monitor) self.control.start(node=self, uri=control_uri) self.async_msg_ids = {} self.storage = storage.Storage() self.storage.start() self.network = CalvinNetwork(self) self.proto = CalvinProto(self, self.network) self.pm = PortManager(self, self.proto) self.app_manager = appmanager.AppManager(self) # The initialization that requires the main loop operating is deferred to start function # FIXME: Don't use delayed call in calvin-tiny async.DelayedCall(0, self.start)
def __init__(self, uris, control_uri, attributes=None): super(Node, self).__init__() self.quitting = False # Warn if its not a uri if not isinstance(uris, list): _log.error("Calvin uris must be a list %s" % uris) raise TypeError("Calvin uris must be a list!") # Uris self.uris = uris if attributes: ext_uris = attributes.pop('external_uri', None) if ext_uris is not None: self.uris += ext_uris # Control uri self.control_uri = control_uri self.external_control_uri = attributes.pop('external_control_uri', self.control_uri) \ if attributes else self.control_uri try: self.attributes = AttributeResolver(attributes) except: _log.exception("Attributes not correct, uses empty attribute!") self.attributes = AttributeResolver(None) self.node_name = self.attributes.get_node_name_as_str() # Obtain node id, when using security also handle runtime certificate try: security_dir = _conf.get("security", "security_dir") self.runtime_credentials = RuntimeCredentials(self.node_name, node=self, security_dir=security_dir) self.id = self.runtime_credentials.get_node_id() except Exception as err: _log.debug("No runtime credentials, err={}".format(err)) self.runtime_credentials = None self.id = calvinuuid.uuid("Node") self.certificate_authority = certificate_authority.CertificateAuthority(self) self.authentication = authentication.Authentication(self) self.authorization = authorization.Authorization(self) self.metering = metering.set_metering(metering.Metering(self)) self.monitor = Event_Monitor() self.am = actormanager.ActorManager(self) self.rm = replicationmanager.ReplicationManager(self) self.control = calvincontrol.get_calvincontrol() _scheduler = scheduler.DebugScheduler if _log.getEffectiveLevel() <= logging.DEBUG else scheduler.Scheduler self.sched = _scheduler(self, self.am, self.monitor) self.async_msg_ids = {} self._calvinsys = CalvinSys(self) calvinsys = get_calvinsys() calvinsys.init(self) calvinlib = get_calvinlib() calvinlib.init(self) # Default will multicast and listen on all interfaces # TODO: be able to specify the interfaces # @TODO: Store capabilities self.storage = storage.Storage(self) self.network = CalvinNetwork(self) self.proto = CalvinProto(self, self.network) self.pm = PortManager(self, self.proto) self.app_manager = appmanager.AppManager(self) # The initialization that requires the main loop operating is deferred to start function async.DelayedCall(0, self.start)
def setup_class(self): self.storage = storage.Storage()
def setup_class(self): self.storage = storage.Storage() yield threads.defer_to_thread(self.storage.start) yield threads.defer_to_thread(time.sleep, 2)
def setup_class(self): self.storage = storage.Storage(DummyNode()) self.storage.start() yield threads.defer_to_thread(time.sleep, .01)