Esempio n. 1
0
    def test_fs_notification(self):
        watcher = FSWatcher(self.station.store.object_root)

        _id = self.station.write("foobarbaz")
        ret = watcher.read()
        self.assertEqual(_id, path2id(ret))

        _id = self.station.write("foobarbaz1")
        ret = watcher.read()
        self.assertEqual(_id, path2id(ret))

        _id = self.station.write("foobarbaz2")
        self.station.write("foobarbaz2")
        ret = watcher.read()
        self.assertEqual(_id, path2id(ret))

        watcher.kill()
    def test_notifies_peer(self):
        read_sockets = []
        write_sockets = []

        def tick():
            return select.select(read_sockets, write_sockets, [], 1)

        addr = os.path.join(self.dir, "listener")
        listener = TestListener(addr)
        client = TestClient(addr)
        peer = listener.accept(PeerSocket)
        watcher = fs_watcher.FSWatcher(self.stations[0].store.object_root)

        read_sockets.append(client)
        read_sockets.append(watcher)
        self.stations[0].write("trolololol")
        (sread, _, _) = tick()

        self.assertIn(watcher, sread)
        obj_name = path2id(watcher.read())
        client.notify_new_object(self.stations[0], obj_name)
        client.send()

        peer.recv()
        data = peer.packet_queue.pop()
        gizmo = self.stations[1].gizmo_factory.hydrate(data, peer)
        assert gizmo is not None, "gizmo_factory returned None"
        gizmo.process()
        peer.send()

        client.recv()
        data = client.packet_queue.pop()
        gizmo = self.stations[0].gizmo_factory.hydrate(data, peer)
        assert gizmo is not None, "gizmo_factory returned None"
        self.assertEqual(gizmo.verb, "FETCHOBJECT")
        self.assertEqual(gizmo.payload, obj_name)
        gizmo.process()

        watcher.kill()
    def test_notifies_peer(self):
        read_sockets = []
        write_sockets = []
        def tick():
            return select.select(read_sockets, write_sockets, [], 1)

        addr = os.path.join(self.dir, "listener")
        listener = TestListener(addr)
        client = TestClient(addr)
        peer = listener.accept(PeerSocket)
        watcher = fs_watcher.FSWatcher(self.stations[0].store.object_root)

        read_sockets.append(client)
        read_sockets.append(watcher)
        self.stations[0].write("trolololol")
        (sread, _, _) = tick()

        self.assertIn(watcher, sread)
        obj_name = path2id(watcher.read())
        client.notify_new_object(self.stations[0], obj_name)
        client.send()

        peer.recv()
        data = peer.packet_queue.pop()
        gizmo = self.stations[1].gizmo_factory.hydrate(data, peer)
        assert gizmo is not None, "gizmo_factory returned None"
        gizmo.process()
        peer.send()

        client.recv()
        data = client.packet_queue.pop()
        gizmo = self.stations[0].gizmo_factory.hydrate(data, peer)
        assert gizmo is not None, "gizmo_factory returned None"
        self.assertEqual(gizmo.verb, "FETCHOBJECT")
        self.assertEqual(gizmo.payload, obj_name)
        gizmo.process()

        watcher.kill()
Esempio n. 4
0
 def notify_new_object(self, station, path):
     # TODO FSWatcher should probably be responsible for catching these to
     # keep signal:noise sane
     obj = path2id(path)
     notification = Notification("NEWOBJECT", station=station, stream=self, payload=obj)
     self.enqueue(notification)
Esempio n. 5
0
 def test_path2id(self):
     self.assertEqual(utils.path2id("/long/tail/name/as/asdfasdfasdf"), "asasdfasdfasdf")
Esempio n. 6
0
 def test_path2id(self):
     self.assertEqual(utils.path2id("/long/tail/name/as/asdfasdfasdf"),
                      "asasdfasdfasdf")