def test_nested_sequence_serialization(self): '''Test serialization of a nested sequence''' expected = ''.join( chr(i) for i in itertools.chain( (5, 0, 0, 0), # Sequence (3, 0, 0, 0), # 3 steps (2, 0, 0, 0), # Delete (3, 0, 0, 0), bytes_('key'), (5, 0, 0, 0), # Sequence (2, 0, 0, 0), # 2 steps (2, 0, 0, 0), # Delete (3, 0, 0, 0), bytes_('key'), (1, 0, 0, 0), # Set (3, 0, 0, 0), bytes_('key'), (5, 0, 0, 0), bytes_('value'), (5, 0, 0, 0), # Sequence (0, 0, 0, 0), # 0 steps )) received = ''.join( sequence.Sequence([ sequence.Delete('key'), sequence.Sequence( [sequence.Delete('key'), sequence.Set('key', 'value')]), sequence.Sequence([]) ]).serialize()) self.assertEquals(expected, received)
def test_step(self): '''Test step checks''' self._run_test( protocol.STEP, (sequence.Set('key', 'value'), True), (sequence.Delete('key'), True), (sequence.Sequence([]), True), (sequence.Sequence([sequence.Set('key', 'value')]), True), (sequence.Sequence( [sequence.Set('key', 'value'), sequence.Delete('key')]), True), (sequence.Sequence([ sequence.Set('key', 'value'), sequence.Sequence( [sequence.Set('key', 'value'), sequence.Delete('key')]) ]), True), (object(), False), (None, False), (sequence.Sequence( [sequence.Delete('key'), object()]), False))
def test_set_step_serialization(self): '''Test serialization of 'set' steps''' expected = ''.join( chr(i) for i in itertools.chain( (1, 0, 0, 0), (3, 0, 0, 0), bytes_('key'), (5, 0, 0, 0), bytes_('value'), )) received = ''.join(sequence.Set('key', 'value').serialize()) self.assertEquals(expected, received)
def test_sequence_serialization(self): '''Test serialization of a sequence''' expected = ''.join( chr(i) for i in itertools.chain( (5, 0, 0, 0), (2, 0, 0, 0), (1, 0, 0, 0), (3, 0, 0, 0), bytes_('key'), (5, 0, 0, 0), bytes_('value'), (2, 0, 0, 0), (3, 0, 0, 0), bytes_('key'), )) received = ''.join( sequence.Sequence([ sequence.Set('key', 'value'), sequence.Delete('key'), ]).serialize()) self.assertEquals(expected, received)
def convert_set(step): return sequence.Set(step._key, step._value)
def test_scenario(self): '''Run a full-fledged scenario against the test server''' client = self._create_client() self.assertFalse(client.exists('key')) self.assertRaises(compat.ArakoonNotFound, client.get, 'key') self.assertRaises(compat.ArakoonNotFound, client.delete, 'key') client.set('key', 'value') self.assertTrue(client.exists('key')) self.assertEquals(client.get('key'), 'value') client.delete('key') self.assertFalse(client.exists('key')) for i in xrange(100): client.set('key_%d' % i, 'value') matches = client.prefix('key_') self.assertEquals(len(matches), 100) matches = client.prefix('key_1', 5) self.assertEquals(len(matches), 5) for match in matches: self.assertEquals(client.get(match), 'value') matches = client.range('key_10', True, 'key_15', False) self.assertEquals(len(matches), 5) self.assertEquals(set(matches), set('key_%d' % i for i in xrange(10, 15))) matches = client.range_entries('key_20', True, 'key_29', True, 20) self.assertEquals(len(matches), 10) for key, value in matches: self.assert_(key.startswith('key_2')) self.assertEquals(value, 'value') values = client.multiGet(['key_%d' % i for i in xrange(50)]) self.assertEquals(len(values), 50) self.assert_(all(value == 'value' for value in values)) self.assert_(client.expectProgressPossible()) self.assertEquals(client.testAndSet('taskey', None, 'value0'), None) self.assertEquals(client.testAndSet('taskey', 'value0', 'value1'), 'value0') self.assertEquals(client.testAndSet('taskey', 'value0', 'value2'), 'value1') self.assertEquals(client.testAndSet('taskey', 'value1', None), 'value1') self.assertFalse(client.exists('taskey')) sequence_ = compat.Sequence() sequence_.addSet('skey', 'value0') sequence_.addDelete('skey') sequence_.addSet('skey', 'value1') sequence2 = compat.Sequence() sequence2.addDelete('skey') sequence2.addSet('skey', 'value2') sequence2.addAssert('skey', 'value2') sequence2.addAssert('skey2', None) sequence_.addUpdate(sequence2) client.sequence(sequence_) client.sequence(sequence_, sync=False) client.sequence(sequence_, sync=True) self.assertEquals(client.get('skey'), 'value2') sequence_ = compat.Sequence() sequence_.addDelete('skey') sequence_.addDelete('skey2') self.assertRaises(compat.ArakoonNotFound, client.sequence, sequence_) # This is a bit out-of-place, but it's the only occasion where # sequence-with-a-list can be tested easily client._client.sequence([sequence.Set('skey', 'svalue3')]) self.assertEquals(client.get('skey'), 'svalue3')
def test_step(self): '''Test encoding and decoding of Step values''' self.assertRaises(NotImplementedError, self._run_test, protocol.STEP, sequence.Set('key', 'value'))