示例#1
0
    def test_message_encode_decode(self):
        task = IbisTaskMessage(12345, 'foo', 12, 1000)

        encoded = task.encode()
        decoded = IbisTaskMessage.decode(encoded)
        encoded2 = decoded.encode()

        self.assertEqual(encoded, encoded2)

        attrs = ['semaphore_id', 'shmem_name', 'shmem_offset', 'shmem_size']
        for attr in attrs:
            self.assertEqual(getattr(task, attr), getattr(decoded, attr))
示例#2
0
    def test_message_encode_decode(self):
        task = IbisTaskMessage(12345, 'foo', 12, 1000)

        encoded = task.encode()
        decoded = IbisTaskMessage.decode(encoded)
        encoded2 = decoded.encode()

        self.assertEqual(encoded, encoded2)

        attrs = ['semaphore_id', 'shmem_name', 'shmem_offset', 'shmem_size']
        for attr in attrs:
            self.assertEqual(getattr(task, attr), getattr(decoded, attr))
示例#3
0
    def _make_update_task(self, uda_class, cols, prior_state=None):

        # Overall layout here:
        # - task name
        # - serialized agg class
        # - prior state flag 1/0
        # - (optional) serialized prior state
        # - serialized table fragment

        payload = BytesIO()
        msg_writer = wire.PackedMessageWriter(payload)
        msg_writer.string('agg-update')
        msg_writer.string(compat.pickle_dump(uda_class))

        if prior_state is not None:
            msg_writer.uint8(1)
            msg_writer.string(compat.pickle_dump(prior_state))
        else:
            msg_writer.uint8(0)

        writer = IbisTableWriter(cols)

        # Create memory map of the appropriate size
        path = 'task_%s' % guid()
        size = writer.total_size() + payload.tell()
        offset = 0
        mm = SharedMmap(path, size, create=True)
        self.paths_to_delete.append(path)

        mm.write(payload.getvalue())
        writer.write(mm)

        task = IbisTaskMessage(self.lock.semaphore_id, path, offset, size)

        return task, mm
示例#4
0
    def setUp(self):
        self.paths_to_delete = []

        # make size small so tracebacks get truncated
        path, size, offset = 'task_%s' % guid(), 36, 0
        self.paths_to_delete.append(path)

        self.lock = IPCLock(is_slave=0)
        self.task = IbisTaskMessage(self.lock.semaphore_id, path, offset, size)

        self.mm = SharedMmap(path, size, create=True)
        wire.PackedMessageWriter(self.mm).string('ping')
示例#5
0
    def _make_finalize_task(self, pickled):
        payload = BytesIO()
        msg_writer = wire.PackedMessageWriter(payload)
        msg_writer.string('agg-finalize')
        msg_writer.string(pickled)

        # Create memory map of the appropriate size
        path = 'task_%s' % guid()
        size = payload.tell()
        offset = 0
        mm = SharedMmap(path, size, create=True)
        self.paths_to_delete.append(path)

        mm.write(payload.getvalue())

        task = IbisTaskMessage(self.lock.semaphore_id, path, offset, size)

        return task, mm
示例#6
0
    def run(self):
        # TODO: task execution class should acquire OS semaphore, execute
        # task, then release the semaphore.

        encoded_task = self.sock.recv(1024)
        if not encoded_task:
            raise ValueError('Request was empty')

        try:
            task_msg = IbisTaskMessage.decode(encoded_task)
        except:
            self.sock.send(traceback.format_exc())
        else:
            # Acknowledge successful receipt
            self.sock.send('ok')
        finally:
            self.sock.close()

        self.execute(task_msg)