add json_snapshot to snapshot_suites so that the json_snapshot is being tested.

This commit is contained in:
Clayton Calabrese
2022-07-28 11:02:55 -05:00
parent 1892a29891
commit 46445273ad
9 changed files with 76 additions and 4 deletions
@@ -106,5 +106,58 @@ struct buffered_snapshot_suite {
}
};
using snapshot_suites = boost::mpl::list<variant_snapshot_suite, buffered_snapshot_suite>;
struct json_snapshot_suite {
using writer_t = ostream_json_snapshot_writer;
using reader_t = istream_json_snapshot_reader;
using write_storage_t = std::ostringstream;
using snapshot_t = std::string;
using read_storage_t = std::istringstream;
struct writer : public writer_t {
writer( const std::shared_ptr<write_storage_t>& storage )
:writer_t(*storage)
,storage(storage)
{
}
std::shared_ptr<write_storage_t> storage;
};
struct reader : public reader_t {
explicit reader(const std::shared_ptr<read_storage_t>& storage)
:reader_t(*storage)
,storage(storage)
{}
std::shared_ptr<read_storage_t> storage;
};
static auto get_writer() {
return std::make_shared<writer>(std::make_shared<write_storage_t>());
}
static auto finalize(const std::shared_ptr<writer>& w) {
w->finalize();
return w->storage->str();
}
static auto get_reader( const snapshot_t& buffer) {
return std::make_shared<reader>(std::make_shared<read_storage_t>(buffer));
}
static snapshot_t load_from_file(const std::string& filename) {
snapshot_input_file<snapshot::json_snapshot> file(filename);
return file.read_as_string();
}
static void write_to_file( const std::string& basename, const snapshot_t& snapshot ) {
snapshot_output_file<snapshot::json_snapshot> file(basename);
file.write<snapshot_t>(snapshot);
}
};
using snapshot_suites = boost::mpl::list<variant_snapshot_suite, buffered_snapshot_suite, json_snapshot_suite>;
+16 -3
View File
@@ -19,10 +19,12 @@ namespace eosio {
// tags for snapshot type
struct json {};
struct binary {};
struct json_snapshot{};
} // ns eosio::testing::snapshot
static inline constexpr snapshot::json json_tag;
static inline constexpr snapshot::binary binary_tag;
static inline constexpr snapshot::json_snapshot json_snapshot_tag;
namespace snapshot {
template <typename T>
@@ -30,6 +32,9 @@ namespace eosio {
template <typename T>
static inline constexpr bool is_binary_v =std::is_same_v<std::decay_t<T>, snapshot::binary>;
template <typename T>
static inline constexpr bool is_json_snapshot_v =std::is_same_v<std::decay_t<T>, snapshot::json_snapshot>;
} // ns eosio::testing::snapshot
template <typename TypeTag>
@@ -38,8 +43,10 @@ namespace eosio {
static inline constexpr auto file_suffix() {
if constexpr (snapshot::is_json_v<TypeTag>)
return ".json.gz";
else
else if constexpr (snapshot::is_binary_v<TypeTag>)
return ".bin.gz";
else
return ".bin.json.gz";
}
std::string file_name;
@@ -67,8 +74,10 @@ namespace eosio {
auto read() const {
if constexpr (snapshot::is_json_v<TypeTag>) {
return fc::json::from_string(read_as_string());
} else if constexpr (snapshot::is_binary_v<TypeTag>) {
return fc::json::from_string(read_as_string());
} else {
static_assert(snapshot::is_binary_v<TypeTag>, "unsupported type");
static_assert(snapshot::is_json_snapshot_v<TypeTag>, "unsupported type");
return fc::json::from_string(read_as_string());
}
}
@@ -85,8 +94,12 @@ namespace eosio {
if constexpr (snapshot::is_json_v<TypeTag>) {
out_string = fc::json::to_string(snapshot, fc::time_point::maximum());
} else if constexpr (snapshot::is_binary_v<TypeTag>) {
std::ostringstream out_stream;
out_stream.write(snapshot.data(), snapshot.size());
out_string = out_stream.str();
} else {
static_assert(snapshot::is_binary_v<TypeTag>, "unsupported type");
static_assert(snapshot::is_json_snapshot_v<TypeTag>, "unsupported type");
std::ostringstream out_stream;
out_stream.write(snapshot.data(), snapshot.size());
out_string = out_stream.str();
+6
View File
@@ -1,14 +1,20 @@
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/blocks.log ${CMAKE_CURRENT_BINARY_DIR}/blocks.log COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v2.bin.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v2.bin.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v2.json.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v2.json.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v2.bin.json.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v2.bin.json.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/prod_sched/blocks.log ${CMAKE_CURRENT_BINARY_DIR}/prod_sched/blocks.log COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v2_prod_sched.bin.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v2_prod_sched.bin.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v2_prod_sched.json.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v2_prod_sched.json.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v2_prod_sched.bin.json.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v2_prod_sched.bin.json.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v3.bin.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v3.bin.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v3.json.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v3.json.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v3.bin.json.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v3.bin.json.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v4.bin.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v4.bin.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v4.json.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v4.json.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v4.bin.json.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v4.bin.json.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v5.bin.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v5.bin.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v5.json.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v5.json.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v5.bin.json.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v5.bin.json.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v6.bin.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v6.bin.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v6.json.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v6.json.gz COPYONLY )
configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/snap_v6.bin.json.gz ${CMAKE_CURRENT_BINARY_DIR}/snap_v6.bin.json.gz COPYONLY )
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.