def _check(node_data, signal_d, hash_value, data):
            """Check the upload was ok."""
            mdid, node_id = node_data

            # download it
            buf = NoCloseStringIO()
            self.patch(self.main.fs, 'get_partial_for_writing',
                       lambda s, n: buf)
            yield self.aq.download(request.ROOT, node_id, hash_value, mdid)
            yield self.wait_for_nirvana()
            self.assertEqual(buf.getvalue(), data)

            # it's ok, we're happy
            signal_d.callback(None)
        def _check(node_data, signal_d, hash_value, data):
            """Check the upload was ok."""
            mdid, node_id = node_data

            # download it
            buf = NoCloseStringIO()
            self.patch(self.main.fs, 'get_partial_for_writing',
                       lambda s, n: buf)
            yield self.aq.download(request.ROOT, node_id, hash_value, mdid)
            yield self.wait_for_nirvana()
            self.assertEqual(buf.getvalue(), data)

            # it's ok, we're happy
            signal_d.callback(None)
    def test_upload(self):
        """Test we can upload stuff."""
        buf = NoCloseStringIO()
        self.patch(self.main.fs, 'get_partial_for_writing', lambda s, n: buf)

        hash_value, _, data, d = self._mk_file_w_content()
        mdid, node_id = yield d
        yield self.aq.download(request.ROOT, node_id, hash_value, mdid)
        yield self.wait_for_nirvana()
        self.assertEqual(buf.getvalue(), data)

        self.assertEvent(('AQ_UPLOAD_FINISHED', {'share_id': request.ROOT,
                                                 'node_id': node_id,
                                                 'hash': hash_value,
                                                 'new_generation': 2L}))
    def test_upload(self):
        """Test we can upload stuff."""
        buf = NoCloseStringIO()
        self.patch(self.main.fs, 'get_partial_for_writing', lambda s, n: buf)

        hash_value, _, data, d = self._mk_file_w_content()
        mdid, node_id = yield d
        yield self.aq.download(request.ROOT, node_id, hash_value, mdid)
        yield self.wait_for_nirvana()
        self.assertEqual(buf.getvalue(), data)

        self.assertEvent(('AQ_UPLOAD_FINISHED', {
            'share_id': request.ROOT,
            'node_id': node_id,
            'hash': hash_value,
            'new_generation': 2L
        }))
Exemplo n.º 5
0
    def test_download(self):
        """Download."""
        hash_value, _, _, d = self._mk_file_w_content('hola.txt')
        mdid, node_id = yield d
        buf = NoCloseStringIO()
        self.patch(self.main.fs, 'get_partial_for_writing', lambda s, n: buf)

        self.aq.download('', node_id, hash_value, mdid)
        waiter = self.wait_for('SYS_QUEUE_DONE')
        self.eq.push('SYS_NET_DISCONNECTED')
        self.eq.push('SYS_CONNECTION_LOST')
        self.eq.push('SYS_NET_CONNECTED')
        yield waiter
        yield self.wait_for_nirvana(1)
        self.assertEvent(('AQ_DOWNLOAD_COMMIT', {
            'share_id': '',
            'node_id': node_id,
            'server_hash': hash_value
        }))
        class Foo(object):
            """A proxy for NoCloseStringIO.

            Disconnects the network after the second write.
            """
            def __init__(self):
                self.buf = NoCloseStringIO()
                self.writes = 0

            def write(self, data):
                """Write data to the buffer."""
                rv = self.buf.write(data)
                self.writes += 1
                if self.writes == 2:
                    outer_self.main.event_q.push('SYS_NET_DISCONNECTED')
                    outer_self.main.event_q.push('SYS_NET_CONNECTED')
                return rv

            def __getattr__(self, attr):
                return getattr(self.buf, attr)
        class Foo(object):
            """A proxy for NoCloseStringIO.

            Disconnects the network after the second write.
            """
            def __init__(self):
                self.buf = NoCloseStringIO()
                self.writes = 0

            def write(self, data):
                """Write data to the buffer."""
                rv = self.buf.write(data)
                self.writes += 1
                if self.writes == 2:
                    outer_self.main.event_q.push('SYS_NET_DISCONNECTED')
                    outer_self.main.event_q.push('SYS_NET_CONNECTED')
                return rv

            def __getattr__(self, attr):
                return getattr(self.buf, attr)
 def write(self, data):
     """Cancel the request, and then go on and write."""
     outer_self.aq.cancel_download(request.ROOT, self.file_id)
     NoCloseStringIO.write(self, data)
 def __init__(self):
     self.buf = NoCloseStringIO()
     self.writes = 0
Exemplo n.º 10
0
 def write(self, data):
     """Cancel the request, and then go on and write."""
     outer_self.aq.cancel_download(request.ROOT, self.file_id)
     NoCloseStringIO.write(self, data)
Exemplo n.º 11
0
 def __init__(self):
     self.buf = NoCloseStringIO()
     self.writes = 0