def test_life_cycle(self): kv_store = KeyValueClient('squirly.ca:9090') assert kv_store.put('my_value', 'test_data') is None assert kv_store.get('my_value').rstrip('\x00') == 'test_data' assert kv_store.put('my_value', 'another_test') is None assert kv_store.get('my_value').rstrip('\x00') == 'another_test' assert kv_store.delete('my_value') is None with pytest.raises(InvalidKeyError): kv_store.get('my_value') with pytest.raises(InvalidKeyError): kv_store.delete('my_value')
def test_get(self): kv_store = KeyValueClient('192.168.1.100:5665') socket = MockSocket(['\x00', 'expected_value' + '\x00'*1010]) with patch('kvclient.base.create_connection', socket): response = kv_store.get('test_key') assert socket.connection_info == ('192.168.1.100', 5665) assert socket.sent_value == '\x02' + 'test_key' + '\x00'*24 assert response == 'expected_value' + '\x00'*1010 assert socket.closed
def test_run_command_system_overload(self): kv_store = KeyValueClient('192.168.1.100:5665') socket = MockSocket(['\x03']) with patch('kvclient.base.create_connection', socket): with pytest.raises(SystemOverloadError): kv_store.get('test')
def test_run_command_out_of_space(self): kv_store = KeyValueClient('192.168.1.100:5665') socket = MockSocket(['\x02']) with patch('kvclient.base.create_connection', socket): with pytest.raises(OutOfSpaceError): kv_store.get('test')
def test_run_command_invalid_key(self): kv_store = KeyValueClient('192.168.1.100:5665') socket = MockSocket(['\x01']) with patch('kvclient.base.create_connection', socket): with pytest.raises(InvalidKeyError): kv_store.get('test')
def test_run_command_unknown_command(self): kv_store = KeyValueClient('192.168.1.100:5665') socket = MockSocket(['\x05']) with patch('kvclient.base.create_connection', socket): with pytest.raises(UnknownCommandError): kv_store.get('test')
def test_run_command_server_failure(self): kv_store = KeyValueClient('192.168.1.100:5665') socket = MockSocket(['\x04']) with patch('kvclient.base.create_connection', socket): with pytest.raises(ServerFailureError): kv_store.get('test')
from kvclient import KeyValueClient, InvalidKeyError SERVER = 'planetlab1.cs.unc.edu:5000' KEY = '11' VALUE = '1' client = KeyValueClient(SERVER) client.put(KEY, VALUE) print(client.get(KEY)) client.delete(KEY) try: print(client.get(KEY)) except InvalidKeyError, error: print(str(error))