def test_cache_update(self): c = Cache() c["path"] = 2 c.apply_changes([[], {123: "test"}]) self.assertEqual("test", c[123]) with self.assertRaises(KeyError): c["path"]
def __init__(self, process, _=None): super(PvaServerComms, self).__init__(process) self.name = "PvaServerComms" self.set_logger_name(self.name) self._lock = RLock() self._current_id = 1 self._root_id = 0 self._blocklist = {} self._cache = Cache() self._server = None self._endpoints = {} self._cb = None self._rpcs = {} self._puts = {} self._dead_rpcs = [] # Create the V4 PVA server object self.create_pva_server() # Add a thread for executing the V4 PVA server self.add_spawn_function(self.start_pva_server) # Set up the subscription for everything (root down) request = Subscribe(None, self.q, [], True) request.set_id(self._root_id) self.process.q.put(request)
def __init__(self, name, sync_factory): self.set_logger_name(name) self.name = name self.sync_factory = sync_factory self.q = self.create_queue() self._blocks = OrderedDict() # block_name -> Block self._controllers = OrderedDict() # block_name -> Controller self._block_state_cache = Cache() self._recv_spawned = None self._other_spawned = [] # lookup of all Subscribe requests, ordered to guarantee subscription # notification ordering # {Request.generate_key(): Subscribe} self._subscriptions = OrderedDict() self.comms = [] self._client_comms = OrderedDict() # client comms -> list of blocks self._handle_functions = { Post: self._forward_block_request, Put: self._forward_block_request, Get: self._handle_get, Subscribe: self._handle_subscribe, Unsubscribe: self._handle_unsubscribe, BlockChanges: self._handle_block_changes, BlockRespond: self._handle_block_respond, BlockAdd: self._handle_block_add, BlockList: self._handle_block_list, AddSpawned: self._add_spawned, } self.create_process_block()
def __init__(self, name, sync_factory): self.set_logger_name(name) self.name = name self.sync_factory = sync_factory self.q = self.create_queue() self._blocks = OrderedDict() # block name -> block self._block_state_cache = Cache() self._recv_spawned = None self._other_spawned = [] self._subscriptions = [] self.comms = [] self._client_comms = OrderedDict() # client comms -> list of blocks self._handle_functions = { Post: self._forward_block_request, Put: self._forward_block_request, Get: self._handle_get, Subscribe: self._handle_subscribe, Unsubscribe: self._handle_unsubscribe, BlockChanges: self._handle_block_changes, BlockRespond: self._handle_block_respond, BlockAdd: self._handle_block_add, BlockList: self._handle_block_list, } self.create_process_block()
def test_walk_path(self): c = Cache() c[1] = {2: {3: "end"}} walked = c.walk_path([1, 2, 3]) self.assertEqual(walked, "end")
def test_non_string_path_errors(self): c = Cache() self.assertRaises(AssertionError, c.apply_changes, [[1], 3])
def test_deletion(self): c = Cache() c["path"] = 2 c.apply_changes([["path"]]) self.assertEqual(list(c), [])
def test_change(self): c = Cache() c[1] = 3 c.apply_changes([["path"], 4]) self.assertEqual(c["path"], 4)
def test_addition(self): c = Cache() c.apply_changes([["thing"], {1: 2}]) self.assertEqual(c["thing"][1], 2)
def test_update_root_errors(self): c = Cache() self.assertRaises(AssertionError, c.delta_update, [[], 3])
def test_change(self): c = Cache() c[1] = 3 c.delta_update([[1], 4]) self.assertEqual(c[1], 4)
def test_deletion(self): c = Cache() c[1] = 2 c.delta_update([[1]]) self.assertEqual(list(c), [])
def test_addition(self): c = Cache() c.delta_update([["thing"], {1: 2}]) self.assertEqual(c["thing"][1], 2)