예제 #1
0
 def _setup(self):
     inst = ZkSharedCache("zk", "path", "handler")
     inst._path = "/path"
     inst._zk = create_mock(["is_connected"])
     inst._kazoo = create_mock(["create", "set"])
     inst._incoming_entries = create_mock(["append"])
     return inst
예제 #2
0
 def _check_children_exception(self, excp, expected, init):
     inst = ZkSharedCache("zk", "path", "handler")
     inst._path = "/path"
     inst._kazoo = create_mock(["get_children"])
     inst._kazoo.get_children.side_effect = excp
     # Call
     ntools.assert_raises(expected, inst._list_entries)
예제 #3
0
 def test_no_cache(self, init):
     inst = ZkSharedCache("zk", "path", "handler")
     inst._path = "/path"
     inst._kazoo = create_mock(["get_children"])
     inst._kazoo.get_children.side_effect = NoNodeError
     # Call
     ntools.eq_(inst._list_entries(), set())
예제 #4
0
 def _check_exception(self, excp, expected, init):
     inst = ZkSharedCache("zk", "path", "handler")
     inst._path = "/path"
     inst._kazoo = create_mock(["get"])
     inst._kazoo.get.side_effect = excp
     # Call
     ntools.assert_raises(expected, inst._get, "name")
예제 #5
0
 def _setup(self, time_, entries):
     inst = ZkSharedCache("zk", "path", "handler")
     inst._zk = create_mock(["is_connected"])
     time_.return_value = 1000
     inst._entries = entries
     inst._kazoo = create_mock(["delete"])
     inst._path = "/path"
     return inst
예제 #6
0
 def test_sucesss(self, init):
     inst = ZkSharedCache("zk", "path", "handler")
     inst._path = "/path"
     inst._kazoo = create_mock(["get_children"])
     inst._kazoo.get_children.return_value = [
         "node0", "node1", "node2", "node3"
     ]
     # Call
     ntools.eq_(inst._list_entries(), {"node0", "node1", "node2", "node3"})
예제 #7
0
 def test_no_entry(self, init):
     inst = ZkSharedCache("zk", "path", "handler")
     inst._path = "/path"
     inst._kazoo = create_mock(["get"])
     inst._kazoo.get.side_effect = NoNodeError
     inst._entries = create_mock(["pop"])
     # Call
     ntools.assert_raises(ZkNoNodeError, inst._get, "name")
     # Tests
     inst._kazoo.get.assert_called_once_with("/path/name")
     inst._entries.pop.assert_called_once_with("name", None)
예제 #8
0
 def test_success(self, init, time_):
     inst = ZkSharedCache("zk", "path", "handler")
     inst._path = "/path"
     inst._kazoo = create_mock(["get"])
     inst._kazoo.get.return_value = ("data", "meta")
     inst._entries = create_mock(["setdefault"])
     # Call
     ntools.eq_(inst._get("name"), "data")
     # Tests
     inst._kazoo.get.assert_called_once_with("/path/name")
     inst._entries.setdefault.assert_called_once_with(
         "name", time_.return_value)