def test_client():
        c = RiakClient()
        c.set_client_id('testing-client')

        # Do some cleanup from a previous run.
        c.delete('testing', 'bar')
        c.delete('testing', 'foo')
        c.delete('testing', 'lala')
        c.delete('testing', 'baz')
        c.delete('testing', 'diff')
        c.delete('testing.pickles', 'here')
        c.delete('testing.pickles', 'there')
        diesel.sleep(3) # race condition for deleting PickleBucket keys?

        assert not c.get('testing', 'foo')
        assert c.put('testing', 'foo', '1', return_body=True)
        assert c.get('testing', 'foo')

        # Create a conflict for the 'bar' key in 'testing'.
        assert not c.set_bucket_props('testing', {'allow_mult':True})
        b1 = c.put('testing', 'bar', 'hi', return_body=True)
        b2 = c.put('testing', 'bar', 'bye', return_body=True)
        assert len(c.get('testing', 'bar')['content']) > 1

        def resolve_longest(t1, v1, t2, v2):
            if len(v1) > len(v2):
                return v1
            return v2

        # Test that the conflict is resolved, this time using the Bucket
        # interface.
        b = Bucket('testing', c, resolver=resolve_longest)
        resolved = b.get('bar')
        assert resolved == 'bye', resolved
        b.put('bar', resolved)
        assert len(c.get('testing', 'bar')['content']) == 1

        # put/get/delete with a Bucket
        assert b.put('lala', 'g'*1024)
        assert b.get('lala') == 'g'*1024
        b.delete('lala')
        assert not b.get('lala')

        # Multiple changes to a key using a Bucket should be a-ok.
        assert b.put('baz', 'zzzz')
        assert b.put('baz', 'ffff')
        assert b.put('baz', 'tttt')
        assert len(c.get('testing', 'baz')['content']) == 1
        assert b.get('baz') == 'tttt'

        # Custom Bucket.
        class PickleBucket(Bucket): # lol
            def loads(self, raw_value):
                return cPickle.loads(raw_value)

            def dumps(self, rich_value):
                return cPickle.dumps(rich_value)

            def resolve(self, t1, v1, t2, v2):
                # Returns the value with the smallest different between points.
                d1 = abs(v1.x - v1.y)
                d2 = abs(v2.x - v2.y)
                if d1 < d2:
                    return v1
                return v2

        assert not c.set_bucket_props('testing.pickles', {'allow_mult':True})
        p = PickleBucket('testing.pickles', c)
        assert p.put('here', Point(4,2))
        out = p.get('here')
        assert (4,2) == (out.x, out.y)
        assert isinstance(out, Point)

        # Resolve Point conflicts.
        p1 = PickleBucket('testing.pickles', c).for_client('c 1')
        p1.put('there', Point(4,12), safe=False)
        p2 = PickleBucket('testing.pickles', c).for_client('c 2')
        p2.put('there', Point(3,7), safe=False)
        p3 = PickleBucket('testing.pickles', c).for_client('c 3')
        p3.put('there', Point(90,99), safe=False)
        p4 = PickleBucket('testing.pickles', c).for_client('c 4')
        p4.put('there', Point(4,10), safe=False)
        p5 = PickleBucket('testing.pickles', c).for_client('c 5')
        p5.put('there', Point(1,9), safe=False)
        assert len(c.get('testing.pickles', 'there')['content']) == 5
        there = p5.get('there')
        assert (3,7) == (there.x, there.y), (there.x, there.y)
        assert isinstance(there, Point)

        # resolve on put
        p5.put('there', Point(1,9)) # should resolve b/c safe=True
        assert len(c.get('testing.pickles', 'there')['content']) == 1

        # Doing stuff with different client ids but the same vector clock.
        c.set_client_id('diff 1')
        assert b.put('diff', '---')
        c.set_client_id('diff 2')
        assert b.put('diff', '+++')
        assert b.get('diff') == '+++'

        # Provoking an error
        try:
            # Tell Riak to require 10000 nodes to write this before success.
            c.put('testing', 'error!', 'oh noes!', w=10000)
        except RiakErrorResp, e:
            assert e.errcode == 1, e.errcode
            assert e.errmsg == '{n_val_violation,3}', e.errmsg
            assert repr(e) == "RiakErrorResp: {n_val_violation,3}", repr(e)
        except Exception, e:
            assert 0, "UNEXPECTED EXCEPTION: %r" % e
        else:
            assert 0, "DID NOT RAISE"
        diesel.quickstop()
dataset/ETHPy150Open dieseldev/diesel/diesel/protocols/riak.py/test_client/original