async def _test_state_transfer(self): config = bft_tester.TestConfig(n=4, f=1, c=0, num_clients=10, key_file_prefix=KEY_FILE_PREFIX, start_replica_cmd=start_replica_cmd) with bft_tester.BftTester(config) as tester: await tester.init() [tester.start_replica(i) for i in range(3)] self.protocol = skvbc.SimpleKVBCProtocol() # Write enough data to create a need for state transfer # Run num_clients concurrent requests a bunch of times for i in range(100): async with trio.open_nursery() as nursery: for client in tester.clients.values(): msg = self.protocol.write_req( [], [(tester.random_key(), tester.random_value())]) nursery.start_soon(client.sendSync, msg, False) await tester.assert_state_transfer_not_started_all_up_nodes(self) tester.start_replica(3) await tester.wait_for_state_transfer_to_start() await tester.wait_for_state_transfer_to_stop(0, 3) await self.assert_successful_put_get(tester) tester.stop_replica(2) await self.assert_successful_put_get(tester)
async def run_concurrent_ops(self, num_ops): max_concurrency = len(self.tester.clients) // 2 write_weight = .70 self.protocol = skvbc.SimpleKVBCProtocol() max_size = len(self.tester.keys) // 2 sent = 0 while sent < num_ops: clients = self.tester.random_clients(max_concurrency) async with trio.open_nursery() as nursery: for client in clients: if random.random() < write_weight: nursery.start_soon(self.send_write, client, max_size) else: nursery.start_soon(self.send_read, client, max_size) sent += len(clients)
async def _test_get_block_data(self): config = bft_tester.TestConfig(n=4, f=1, c=0, num_clients=10, key_file_prefix=KEY_FILE_PREFIX, start_replica_cmd=start_replica_cmd) with bft_tester.BftTester(config) as tester: await tester.init() [tester.start_replica(i) for i in range(3)] self.protocol = skvbc.SimpleKVBCProtocol() p = self.protocol client = tester.random_client() last_block = p.parse_reply(await client.read(p.get_last_block_req())) # Perform an unconditional KV put. # Ensure keys aren't identical kv = [(tester.keys[0], tester.random_value()), (tester.keys[1], tester.random_value())] reply = await client.write(p.write_req([], kv)) reply = p.parse_reply(reply) self.assertTrue(reply.success) self.assertEqual(last_block + 1, reply.last_block_id) last_block = reply.last_block_id # Get the kvpairs in the last written block data = await client.read(p.get_block_data_req(last_block)) kv2 = p.parse_reply(data) self.assertDictEqual(kv2, dict(kv)) # Write another block with the same keys but (probabilistically) # different data kv3 = [(tester.keys[0], tester.random_value()), (tester.keys[1], tester.random_value())] reply = await client.write(p.write_req([], kv3)) reply = p.parse_reply(reply) self.assertTrue(reply.success) self.assertEqual(last_block + 1, reply.last_block_id) # Get the kvpairs in the previously written block data = await client.read(p.get_block_data_req(last_block)) kv2 = p.parse_reply(data) self.assertDictEqual(kv2, dict(kv))
def setUp(self): self.protocol = skvbc.SimpleKVBCProtocol()