Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/apollo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,5 @@ apollo_test(NAME osexample_demo_tests SUITE test_osexample_demo)
if(ENABLE_RESTART_RECOVERY_TESTS)
apollo_test(NAME skvbc_restart_recovery_tests SUITE test_skvbc_restart_recovery NIGHTLY)
endif()

apollo_test(NAME skvbc_fullnode_tests SUITE test_skvbc_fullnode)
3 changes: 1 addition & 2 deletions tests/apollo/clientservice/request_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"""Client and server classes corresponding to protobuf-defined services."""
import grpc

import request_pb2 as request__pb2

import clientservice.request_pb2 as request__pb2

class RequestServiceStub(object):
"""Service error handling
Expand Down
146 changes: 146 additions & 0 deletions tests/apollo/test_skvbc_fullnode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Concord
#
# Copyright (c) 2019 VMware, Inc. All Rights Reserved.
#
# This product is licensed to you under the Apache 2.0 license (the "License").
# You may not use this product except in compliance with the Apache 2.0 License.
#
# This product may include a number of subcomponents with separate copyright
# notices and license terms. Your use of these subcomponents is subject to the
# terms and conditions of the subcomponent's license, as noted in the LICENSE
# file.
import os.path
import random
import unittest
from os import environ

from google.protobuf import duration_pb2 as duration_proto

import trio

import os.path
import sys
sys.path.append(os.path.abspath("../../build/tests/apollo/util/"))
import skvbc_messages

from util.test_base import ApolloTest
from util import skvbc as kvbc
from util.pyclient import bft_grpc_client as client
from util.bft import with_trio, with_bft_network, KEY_FILE_PREFIX

def start_replica_cmd(builddir, replica_id):
"""
Return a command that starts an skvbc replica when passed to
subprocess.Popen.

Note each arguments is an element in a list.
"""
statusTimerMilli = "500"
viewChangeTimeoutMilli = "10000"
path = os.path.join(builddir, "tests", "simpleKVBC", "TesterReplica", "skvbc_replica")

if os.environ.get('BLOCKCHAIN_VERSION', default="1").lower() == "4" :
blockchain_version = "4"
else :
blockchain_version = "1"

return [path,
"-k", KEY_FILE_PREFIX,
"-i", str(replica_id),
"-s", statusTimerMilli,
"-V",blockchain_version,
"-v", viewChangeTimeoutMilli,
"-e", str(True)
]

class SkvbcFullNodeTest(ApolloTest):

@with_trio
@with_bft_network(start_replica_cmd=start_replica_cmd, num_fn=1, selected_configs=lambda n, f, c: n == 6)
async def test_read_write_request(self, bft_network):

print(f"Running test_read_write_request")
bft_network.start_all_replicas()
bft_network.start_all_fns()

await trio.sleep(5)

bft_client = client.GrpcClient()
skvbc = kvbc.SimpleKVBCProtocol(bft_network)

key = skvbc.random_key()
value = skvbc.random_value()

print(f"Random Value {value}")
kv_pair = [(key, value)]

msg = skvbc.write_req([], kv_pair, 0)
res = bft_client.sendRequest(msg)
#print(f"Write Response Raw {res} ")

write_res = skvbc.parse_reply(res)
#print(f"Write Response Parsed {write_res.success} {write_res.last_block_id}")

msg_read = skvbc.read_req([key])
read_res = bft_client.sendRequest(msg_read, duration_proto.Duration(seconds =5), True)
#print(f"Read Response Raw {read_res} ")

value_read_dict = skvbc.parse_reply(read_res)
value_read = value_read_dict[key]

print(f"Random Value Read {value_read}")

self.assertEqual(value, value_read, "A BFT Client failed to read a " \
"key-value pair from a SimpleKVBC cluster matching the " \
"key-value pair it wrote immediately prior to the read.")

@with_trio
@with_bft_network(start_replica_cmd=start_replica_cmd, num_fn=1, selected_configs=lambda n, f, c: n == 6)
async def test_read_write_restart_fn(self, bft_network):

print(f"Running test_read_write_restart_fn")
bft_network.start_all_replicas()
bft_network.start_all_fns()

await trio.sleep(5)

bft_client = client.GrpcClient()
skvbc = kvbc.SimpleKVBCProtocol(bft_network)

key = skvbc.random_key()
value = skvbc.random_value()

print(f"Random Value Before Restart {value}")
kv_pair = [(key, value)]

msg = skvbc.write_req([], kv_pair, 0)
res = bft_client.sendRequest(msg)
#print(f"Write Response Raw {res} ")

#write_res = skvbc.parse_reply(res)
#print(f"Write Response Parsed {write_res.success} {write_res.last_block_id}")

bft_network.stop_fn()

bft_network.start_all_fns()
await trio.sleep(5)
bft_client = client.GrpcClient()

msg_read = skvbc.read_req([key])
read_res = bft_client.sendRequest(msg_read, duration_proto.Duration(seconds =5), True)
#print(f"Read Response Raw {read_res} ")

value_read_dict = skvbc.parse_reply(read_res)
value_read = value_read_dict[key]

print(f"Random Value Read After Restart{value_read}")

self.assertEqual(value, value_read, "A BFT Client failed to read a " \
"key-value pair from a SimpleKVBC cluster matching the " \
"key-value pair it wrote immediately prior to the read.")

skvbc.parse_reply(res)

print("Response received")


26 changes: 17 additions & 9 deletions tests/apollo/test_skvbc_reconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ async def test_single_signature_scheme_to_no_single_signature_scheme(self, bft_n
key_file_prefix=KEY_FILE_PREFIX,
start_replica_cmd=lambda builddir, replica_id: start_replica_cmd(builddir, replica_id) +
["--key-exchange-on-start", "True"],
stop_replica_cmd=None, num_ro_replicas=0)
stop_replica_cmd=None, num_ro_replicas=0, num_fn=0)
await bft_network.change_configuration(conf, generate_tls=False)

bft_network.restart_clients(restart_replicas=True)
Expand Down Expand Up @@ -1550,7 +1550,8 @@ async def test_remove_nodes(self, bft_network):
key_file_prefix=KEY_FILE_PREFIX,
start_replica_cmd=start_replica_cmd_with_key_exchange,
stop_replica_cmd=None,
num_ro_replicas=0)
num_ro_replicas=0,
num_fn=0)
await bft_network.change_configuration(conf)
await op.add_remove_with_wedge(test_config, bft=False)
await self.validate_epoch_number(bft_network, 1, bft_network.all_replicas())
Expand Down Expand Up @@ -1598,7 +1599,8 @@ async def test_remove_nodes_with_f_failures(self, bft_network):
key_file_prefix=KEY_FILE_PREFIX,
start_replica_cmd=start_replica_cmd_with_key_exchange,
stop_replica_cmd=None,
num_ro_replicas=0)
num_ro_replicas=0,
num_fn=0)
await bft_network.change_configuration(conf)
await op.add_remove_with_wedge(test_config, bft=True, restart=True)
await self.validate_epoch_number(bft_network, 1, bft_network.all_replicas())
Expand Down Expand Up @@ -1641,7 +1643,8 @@ async def test_remove_nodes_with_unwedge(self, bft_network):
key_file_prefix=KEY_FILE_PREFIX,
start_replica_cmd=start_replica_cmd_with_key_exchange,
stop_replica_cmd=None,
num_ro_replicas=0)
num_ro_replicas=0,
num_fn=0)
await bft_network.change_configuration(conf)
await op.add_remove_with_wedge(test_config, bft=False, restart=False)
await self.validate_stop_on_wedge_point(bft_network, skvbc, fullWedge=True)
Expand Down Expand Up @@ -1691,7 +1694,8 @@ async def test_add_nodes(self, bft_network):
key_file_prefix=KEY_FILE_PREFIX,
start_replica_cmd=start_replica_cmd,
stop_replica_cmd=None,
num_ro_replicas=0)
num_ro_replicas=0,
num_fn=0)
await bft_network.change_configuration(conf, generate_tls=True)
bft_network.restart_clients()
await self.validate_epoch_number(bft_network, 1, bft_network.all_replicas())
Expand Down Expand Up @@ -1730,7 +1734,8 @@ async def test_key_exchange_after_add_nodes_with_failure(self, bft_network):
key_file_prefix=KEY_FILE_PREFIX,
start_replica_cmd=start_replica_cmd_with_key_exchange,
stop_replica_cmd=None,
num_ro_replicas=0)
num_ro_replicas=0,
num_fn=0)
await bft_network.change_configuration(conf, generate_tls=True)
bft_network.restart_clients(restart_replicas=False)
bft_network.start_replicas(replicas=bft_network.all_replicas(without=late_replica_set))
Expand Down Expand Up @@ -1816,7 +1821,8 @@ async def test_add_nodes_with_failures(self, bft_network):
key_file_prefix=KEY_FILE_PREFIX,
start_replica_cmd=start_replica_cmd_with_key_exchange,
stop_replica_cmd=None,
num_ro_replicas=0)
num_ro_replicas=0,
num_fn=0)
await bft_network.change_configuration(conf, generate_tls=True)
bft_network.restart_clients(generate_tx_signing_keys=True, restart_replicas=False)

Expand Down Expand Up @@ -1928,7 +1934,8 @@ async def test_reconfiguration_with_ror(self, bft_network):
key_file_prefix=KEY_FILE_PREFIX,
start_replica_cmd=start_replica_cmd_with_object_store_and_ke,
stop_replica_cmd=None,
num_ro_replicas=1)
num_ro_replicas=1,
num_fn=0)
await bft_network.change_configuration(conf)
ro_replica_id = bft_network.config.n
await bft_network.check_initial_key_exchange(stop_replicas=False)
Expand Down Expand Up @@ -1965,7 +1972,8 @@ async def test_reconfiguration_with_ror(self, bft_network):
key_file_prefix=KEY_FILE_PREFIX,
start_replica_cmd=start_replica_cmd_with_object_store_and_ke,
stop_replica_cmd=None,
num_ro_replicas=1)
num_ro_replicas=1,
num_fn=0)
await bft_network.change_configuration(conf)
ro_replica_id = bft_network.config.n
await bft_network.check_initial_key_exchange(stop_replicas=False)
Expand Down
Loading