コード例 #1
0
    def test_multiput_pool_size(self):
        """
        The pool size for multiputs can be configured at client initiation
        time. Multiput still works as expected.
        """
        client = self.create_client(multiput_pool_size=2)
        self.assertEqual(2, client._multiput_pool._size)

        bucket = client.bucket(self.bucket_name)
        k1 = self.randname()
        k2 = self.randname()
        o1 = RiakObject(client, bucket, k1)
        o2 = RiakObject(client, bucket, k2)

        if PY2:
            o1.encoded_data = k1
            o2.encoded_data = k2
        else:
            o1.data = k1
            o2.data = k2

        objs = [o1, o2]
        for robj in objs:
            robj.content_type = 'text/plain'

        results = client.multiput(objs, return_body=True)
        for obj in results:
            self.assertIsInstance(obj, RiakObject)
            self.assertTrue(obj.exists)
            self.assertEqual(obj.content_type, 'text/plain')
            if PY2:
                self.assertEqual(obj.key, obj.encoded_data)
            else:
                self.assertEqual(obj.key, obj.data)
        client.close()
コード例 #2
0
    def test_multiput_pool_options(self):
        sz = 4
        client = self.create_client(multiput_pool_size=sz)
        self.assertEqual(sz, client._multiput_pool._size)

        bucket = client.bucket(self.bucket_name)
        k1 = self.randname()
        k2 = self.randname()
        o1 = RiakObject(client, bucket, k1)
        o2 = RiakObject(client, bucket, k2)

        if PY2:
            o1.encoded_data = k1
            o2.encoded_data = k2
        else:
            o1.data = k1
            o2.data = k2

        objs = [o1, o2]
        for robj in objs:
            robj.content_type = 'text/plain'

        results = client.multiput(objs, return_body=False)
        for obj in results:
            if client.protocol == 'pbc':
                self.assertIsInstance(obj, RiakObject)
                self.assertFalse(obj.exists)
                self.assertEqual(obj.content_type, 'text/plain')
            else:
                self.assertIsNone(obj)
        client.close()
コード例 #3
0
    def test_multiput_errors(self):
        """
        Unrecoverable errors are captured along with the bucket/key
        and not propagated.
        """
        client = self.create_client(http_port=DUMMY_HTTP_PORT,
                                    pb_port=DUMMY_PB_PORT)
        bucket = client.bucket(self.bucket_name)
        k1 = self.randname()
        k2 = self.randname()
        o1 = RiakObject(client, bucket, k1)
        o2 = RiakObject(client, bucket, k2)

        if PY2:
            o1.encoded_data = k1
            o2.encoded_data = k2
        else:
            o1.data = k1
            o2.data = k2

        objs = [o1, o2]
        for robj in objs:
            robj.content_type = 'text/plain'

        results = client.multiput(objs, return_body=True)
        for failure in results:
            self.assertIsInstance(failure, tuple)
            self.assertIsInstance(failure[0], RiakObject)
            if PY2:
                self.assertIsInstance(failure[1], StandardError)  # noqa
            else:
                self.assertIsInstance(failure[1], Exception)
        client.close()
コード例 #4
0
    def test_multiput_pool_options(self):
        sz = 4
        client = self.create_client(multiput_pool_size=sz)
        self.assertEqual(sz, client._multiput_pool._size)

        bucket = client.bucket(self.bucket_name)
        k1 = self.randname()
        k2 = self.randname()
        o1 = RiakObject(client, bucket, k1)
        o2 = RiakObject(client, bucket, k2)

        if PY2:
            o1.encoded_data = k1
            o2.encoded_data = k2
        else:
            o1.data = k1
            o2.data = k2

        objs = [o1, o2]
        for robj in objs:
            robj.content_type = 'text/plain'

        results = client.multiput(objs, return_body=False)
        for obj in results:
            if client.protocol == 'pbc':
                self.assertIsInstance(obj, RiakObject)
                self.assertFalse(obj.exists)
                self.assertEqual(obj.content_type, 'text/plain')
            else:
                self.assertIsNone(obj)
        client.close()
コード例 #5
0
    def test_multiput_pool_size(self):
        """
        The pool size for multiputs can be configured at client initiation
        time. Multiput still works as expected.
        """
        client = self.create_client(multiput_pool_size=2)
        self.assertEqual(2, client._multiput_pool._size)

        bucket = client.bucket(self.bucket_name)
        k1 = self.randname()
        k2 = self.randname()
        o1 = RiakObject(client, bucket, k1)
        o2 = RiakObject(client, bucket, k2)

        if PY2:
            o1.encoded_data = k1
            o2.encoded_data = k2
        else:
            o1.data = k1
            o2.data = k2

        objs = [o1, o2]
        for robj in objs:
            robj.content_type = 'text/plain'

        results = client.multiput(objs, return_body=True)
        for obj in results:
            self.assertIsInstance(obj, RiakObject)
            self.assertTrue(obj.exists)
            self.assertEqual(obj.content_type, 'text/plain')
            if PY2:
                self.assertEqual(obj.key, obj.encoded_data)
            else:
                self.assertEqual(obj.key, obj.data)
        client.close()
コード例 #6
0
    def test_multiput_errors(self):
        """
        Unrecoverable errors are captured along with the bucket/key
        and not propagated.
        """
        client = self.create_client(http_port=DUMMY_HTTP_PORT,
                                    pb_port=DUMMY_PB_PORT)
        bucket = client.bucket(self.bucket_name)
        k1 = self.randname()
        k2 = self.randname()
        o1 = RiakObject(client, bucket, k1)
        o2 = RiakObject(client, bucket, k2)

        if PY2:
            o1.encoded_data = k1
            o2.encoded_data = k2
        else:
            o1.data = k1
            o2.data = k2

        objs = [o1, o2]
        for robj in objs:
            robj.content_type = 'text/plain'

        results = client.multiput(objs, return_body=True)
        for failure in results:
            self.assertIsInstance(failure, tuple)
            self.assertIsInstance(failure[0], RiakObject)
            if PY2:
                self.assertIsInstance(failure[1], StandardError)  # noqa
            else:
                self.assertIsInstance(failure[1], Exception)
        client.close()
コード例 #7
0
    def new(self, key=None, data=None, content_type='application/json',
            encoded_data=None):
        """A shortcut for manually instantiating a new
        :class:`~riak.riak_object.RiakObject` or a new
        :class:`~riak.datatypes.Datatype`, based on the presence and value
        of the :attr:`datatype <BucketType.datatype>` bucket property. When
        the bucket contains a :class:`~riak.datatypes.Datatype`, all
        arguments are ignored except ``key``, otherwise they are used to
        initialize the :class:`~riak.riak_object.RiakObject`.

        :param key: Name of the key. Leaving this to be None (default)
                    will make Riak generate the key on store.
        :type key: str
        :param data: The data to store in a
           :class:`~riak.riak_object.RiakObject`, see
           :attr:`RiakObject.data <riak.riak_object.RiakObject.data>`.
        :type data: object
        :param content_type: The media type of the data stored in the
           :class:`~riak.riak_object.RiakObject`, see
           :attr:`RiakObject.content_type
           <riak.riak_object.RiakObject.content_type>`.
        :type content_type: str
        :param encoded_data: The encoded data to store in a
           :class:`~riak.riak_object.RiakObject`, see
           :attr:`RiakObject.encoded_data
           <riak.riak_object.RiakObject.encoded_data>`.
        :type encoded_data: str
        :rtype: :class:`~riak.riak_object.RiakObject` or
                :class:`~riak.datatypes.Datatype`

        """
        if self.bucket_type.datatype:
            return TYPES[self.bucket_type.datatype](bucket=self, key=key)

        if PY2:
            try:
                if isinstance(data, string_types):
                    data = data.encode('ascii')
            except UnicodeError:
                raise TypeError('Unicode data values are not supported.')

        obj = RiakObject(self._client, self, key)
        obj.content_type = content_type
        if data is not None:
            obj.data = data
        if encoded_data is not None:
            obj.encoded_data = encoded_data
        return obj