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_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 _verify_super(self, supercf='Super1', key='key1'): col = self.client.request( 'get', _make_read_params(key, supercf, 'sc1', avro_utils.i64(4), 'ONE'))['column'] avro_utils.assert_columns_match(col, { 'name': avro_utils.i64(4), 'value': 'value4', 'timestamp': 0 }) slice = [ result['super_column'] for result in self._big_slice(key, {'column_family': supercf}) ] assert slice == _SUPER_COLUMNS, _SUPER_COLUMNS
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_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_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 _verify_super(self, supercf='Super1', key='key1'): col = self.client.request('get', _make_read_params(key, supercf, 'sc1', avro_utils.i64(4), 'ONE'))['column'] avro_utils.assert_columns_match(col, {'name': avro_utils.i64(4), 'value': 'value4', 'timestamp': 0}) slice = [result['super_column'] for result in self._big_slice(key, {'column_family': supercf})] assert slice == _SUPER_COLUMNS, _SUPER_COLUMNS