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)
Beispiel #2
0
        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}))
Beispiel #4
0
    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': 2
        }))
    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}))
Beispiel #6
0
        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)
Beispiel #8
0
 def __init__(self):
     self.buf = NoCloseStringIO()
     self.writes = 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)
 def __init__(self):
     self.buf = NoCloseStringIO()
     self.writes = 0
 def write(self, data):
     """Cancel the request, and then go on and write."""
     aq.cancel_download(request.ROOT, self.file_id)
     NoCloseStringIO.write(self, data)