def test_insert_unicode(self): "send some unicode to the server" self.client.request('set_keyspace', {'keyspace': 'Keyspace1'}) params = dict() params['key'] = 'key1' params['column_parent'] = {'column_family': 'Standard1'} params['column'] = dict() params['column']['name'] = struct.pack('bbbbbbbbbb', 36, -62, -94, -30, -126, -84, -16, -92, -83, -94) params['column']['value'] = struct.pack('bbbbbbbbbb', 36, -62, -94, -30, -126, -84, -16, -92, -83, -94) params['column']['timestamp'] = timestamp() params['column']['ttl'] = None params['consistency_level'] = 'ONE' self.client.request('insert', params) read_params = dict() read_params['key'] = params['key'] read_params['column_path'] = dict() read_params['column_path']['column_family'] = 'Standard1' read_params['column_path']['column'] = params['column']['name'] read_params['consistency_level'] = 'ONE' cosc = self.client.request('get', read_params) avro_utils.assert_cosc(cosc) avro_utils.assert_columns_match(cosc['column'], params['column'])
def test_remove_simple(self): "removing a simple column" self.client.request('set_keyspace', {'keyspace': 'Keyspace1'}) params = dict() params['key'] = 'key1' params['column_parent'] = {'column_family': 'Standard1'} params['column'] = new_column(1) params['consistency_level'] = 'ONE' self.client.request('insert', params) read_params = dict() read_params['key'] = params['key'] read_params['column_path'] = dict() read_params['column_path']['column_family'] = 'Standard1' read_params['column_path']['column'] = params['column']['name'] read_params['consistency_level'] = 'ONE' cosc = self.client.request('get', read_params) avro_utils.assert_cosc(cosc) remove_params = read_params remove_params['timestamp'] = timestamp() self.client.request('remove', remove_params) avro_utils.assert_raises(AvroRemoteException, self.client.request, 'get', read_params)
def test_slice_super(self): "tests simple insert and get_slice" self._set_keyspace('Keyspace1') self._insert_super() p = {'slice_range': {'start': '', 'finish': '', 'reversed': False, 'count': 10}} parent = {'column_family': 'Super1', 'super_column': 'sc1'} cosc = self.client.request('get_slice', {'key': 'key1', 'column_parent': parent, 'predicate': p, 'consistency_level': 'ONE'}) avro_utils.assert_cosc(cosc[0])
def test_get_slice_simple(self): "performing a slice of simple columns" self.client.request('set_keyspace', {'keyspace': 'Keyspace1'}) columns = list() mutations = list() for i in range(6): columns.append(new_column(i)) for column in columns: mutation = {'column_or_supercolumn': {'column': column}} mutations.append(mutation) mutation_params = dict() map_entry = {'key': 'key1', 'mutations': {'Standard1': mutations}} mutation_params['mutation_map'] = [map_entry] mutation_params['consistency_level'] = 'ONE' self.client.request('batch_mutate', mutation_params) # Slicing on list of column names slice_params = dict() slice_params['key'] = 'key1' slice_params['column_parent'] = {'column_family': 'Standard1'} slice_params['predicate'] = {'column_names': list()} slice_params['predicate']['column_names'].append(columns[0]['name']) slice_params['predicate']['column_names'].append(columns[4]['name']) slice_params['consistency_level'] = 'ONE' coscs = self.client.request('get_slice', slice_params) for cosc in coscs: avro_utils.assert_cosc(cosc) avro_utils.assert_columns_match(coscs[0]['column'], columns[0]) avro_utils.assert_columns_match(coscs[1]['column'], columns[4]) # Slicing on a range of column names slice_range = dict() slice_range['start'] = columns[2]['name'] slice_range['finish'] = columns[5]['name'] slice_range['reversed'] = False slice_range['count'] = 1000 slice_params['predicate'] = {'slice_range': slice_range} coscs = self.client.request('get_slice', slice_params) for cosc in coscs: avro_utils.assert_cosc(cosc) assert len(coscs) == 4, "expected 4 results, got %d" % len(coscs) avro_utils.assert_columns_match(coscs[0]['column'], columns[2]) avro_utils.assert_columns_match(coscs[3]['column'], columns[5])
def test_batch_mutate(self): "batching addition/removal mutations" self.client.request('set_keyspace', {'keyspace': 'Keyspace1'}) mutations = list() # New column mutations for i in range(3): cosc = {'column': new_column(i)} mutation = {'column_or_supercolumn': cosc} mutations.append(mutation) map_entry = {'key': 'key1', 'mutations': {'Standard1': mutations}} params = dict() params['mutation_map'] = [map_entry] params['consistency_level'] = 'ONE' self.client.request('batch_mutate', params) # Verify that new columns were added for i in range(3): column = new_column(i) cosc = self.__get('key1', 'Standard1', None, column['name']) avro_utils.assert_cosc(cosc) avro_utils.assert_columns_match(cosc['column'], column) # Add one more column; remove one column extra_column = new_column(3) remove_column = new_column(0) mutations = [{'column_or_supercolumn': {'column': extra_column}}] deletion = dict() deletion['timestamp'] = timestamp() deletion['predicate'] = {'column_names': [remove_column['name']]} mutations.append({'deletion': deletion}) map_entry = {'key': 'key1', 'mutations': {'Standard1': mutations}} params = dict() params['mutation_map'] = [map_entry] params['consistency_level'] = 'ONE' self.client.request('batch_mutate', params) # Ensure successful column removal avro_utils.assert_raises(AvroRemoteException, self.__get, 'key1', 'Standard1', None, remove_column['name']) # Ensure successful column addition cosc = self.__get('key1', 'Standard1', None, extra_column['name']) avro_utils.assert_cosc(cosc) avro_utils.assert_columns_match(cosc['column'], extra_column)
def test_batch_mutate(self): "batching addition/removal mutations" self.client.request('set_keyspace', {'keyspace': 'Keyspace1'}) mutations = list() # New column mutations for i in range(3): cosc = {'column': new_column(i)} mutation = {'column_or_supercolumn': cosc} mutations.append(mutation) map_entry = {'key': 'key1', 'mutations': {'Standard1': mutations}} params = dict() params['mutation_map'] = [map_entry] params['consistency_level'] = 'ONE' self.client.request('batch_mutate', params) # Verify that new columns were added for i in range(3): column = new_column(i) cosc = self.__get('key1', 'Standard1', None, column['name']) avro_utils.assert_cosc(cosc) avro_utils.assert_columns_match(cosc['column'], column) # Add one more column; remove one column extra_column = new_column(3); remove_column = new_column(0) mutations = [{'column_or_supercolumn': {'column': extra_column}}] deletion = dict() deletion['timestamp'] = timestamp() deletion['predicate'] = {'column_names': [remove_column['name']]} mutations.append({'deletion': deletion}) map_entry = {'key': 'key1', 'mutations': {'Standard1': mutations}} params = dict() params['mutation_map'] = [map_entry] params['consistency_level'] = 'ONE' self.client.request('batch_mutate', params) # Ensure successful column removal avro_utils.assert_raises(AvroRemoteException, self.__get, 'key1', 'Standard1', None, remove_column['name']) # Ensure successful column addition cosc = self.__get('key1', 'Standard1', None, extra_column['name']) avro_utils.assert_cosc(cosc) avro_utils.assert_columns_match(cosc['column'], extra_column)
def test_get_slice_simple(self): "performing a slice of simple columns" self.client.request('set_keyspace', {'keyspace': 'Keyspace1'}) columns = list(); mutations = list() for i in range(6): columns.append(new_column(i)) for column in columns: mutation = {'column_or_supercolumn': {'column': column}} mutations.append(mutation) mutation_params = dict() map_entry = {'key': 'key1', 'mutations': {'Standard1': mutations}} mutation_params['mutation_map'] = [map_entry] mutation_params['consistency_level'] = 'ONE' self.client.request('batch_mutate', mutation_params) # Slicing on list of column names slice_params= dict() slice_params['key'] = 'key1' slice_params['column_parent'] = {'column_family': 'Standard1'} slice_params['predicate'] = {'column_names': list()} slice_params['predicate']['column_names'].append(columns[0]['name']) slice_params['predicate']['column_names'].append(columns[4]['name']) slice_params['consistency_level'] = 'ONE' coscs = self.client.request('get_slice', slice_params) for cosc in coscs: avro_utils.assert_cosc(cosc) avro_utils.assert_columns_match(coscs[0]['column'], columns[0]) avro_utils.assert_columns_match(coscs[1]['column'], columns[4]) # Slicing on a range of column names slice_range = dict() slice_range['start'] = columns[2]['name'] slice_range['finish'] = columns[5]['name'] slice_range['reversed'] = False slice_range['count'] = 1000 slice_params['predicate'] = {'slice_range': slice_range} coscs = self.client.request('get_slice', slice_params) for cosc in coscs: avro_utils.assert_cosc(cosc) assert len(coscs) == 4, "expected 4 results, got %d" % len(coscs) avro_utils.assert_columns_match(coscs[0]['column'], columns[2]) avro_utils.assert_columns_match(coscs[3]['column'], columns[5])
def test_insert_simple(self): # Also tests get "setting and getting a simple column" self.client.request('set_keyspace', {'keyspace': 'Keyspace1'}) params = dict() params['key'] = 'key1' params['column_parent'] = {'column_family': 'Standard1'} params['column'] = new_column(1) params['consistency_level'] = 'ONE' self.client.request('insert', params) read_params = dict() read_params['key'] = params['key'] read_params['column_path'] = dict() read_params['column_path']['column_family'] = 'Standard1' read_params['column_path']['column'] = params['column']['name'] read_params['consistency_level'] = 'ONE' cosc = self.client.request('get', read_params) avro_utils.assert_cosc(cosc) avro_utils.assert_columns_match(cosc['column'], params['column'])
def test_insert_unicode(self): "send some unicode to the server" self.client.request('set_keyspace', {'keyspace': 'Keyspace1'}) params = dict(); params['key'] = 'key1' params['column_parent'] = {'column_family': 'Standard1'} params['column'] = dict() params['column']['name'] = struct.pack('bbbbbbbbbb',36,-62,-94,-30,-126,-84,-16,-92,-83,-94) params['column']['value'] = struct.pack('bbbbbbbbbb',36,-62,-94,-30,-126,-84,-16,-92,-83,-94) params['column']['timestamp'] = timestamp() params['column']['ttl'] = None params['consistency_level'] = 'ONE' self.client.request('insert', params) read_params = dict(); read_params['key'] = params['key'] read_params['column_path'] = dict() read_params['column_path']['column_family'] = 'Standard1' read_params['column_path']['column'] = params['column']['name'] read_params['consistency_level'] = 'ONE' cosc = self.client.request('get', read_params) avro_utils.assert_cosc(cosc) avro_utils.assert_columns_match(cosc['column'], params['column'])