Skip to content

Commit

Permalink
Load environment config from JSON file. Might delete later.
Browse files Browse the repository at this point in the history
  • Loading branch information
awygle committed Mar 16, 2023
1 parent 048042e commit a677b59
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 56 deletions.
79 changes: 79 additions & 0 deletions fog/ledger/server/tests/data/normal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"router_address": "127.0.0.1:21095",
"router_admin_address": "127.0.0.1:16761",
"shards": [
{
"address": "127.0.0.1:24242",
"block_range": {
"start_block": 1,
"end_block": 4
},
"stores": [
{
"address": "127.0.0.1:20488",
"block_range": null,
"omap_capacity": 1000
},
{
"address": "127.0.0.1:21157",
"block_range": null,
"omap_capacity": 1000
},
{
"address": "127.0.0.1:18213",
"block_range": null,
"omap_capacity": 1000
}
]
},
{
"address": "127.0.0.1:19430",
"block_range": {
"start_block": 4,
"end_block": 7
},
"stores": [
{
"address": "127.0.0.1:16542",
"block_range": null,
"omap_capacity": 1000
},
{
"address": "127.0.0.1:21010",
"block_range": null,
"omap_capacity": 1000
},
{
"address": "127.0.0.1:22270",
"block_range": null,
"omap_capacity": 1000
}
]
},
{
"address": "127.0.0.1:23515",
"block_range": {
"start_block": 7,
"end_block": 10
},
"stores": [
{
"address": "127.0.0.1:17984",
"block_range": null,
"omap_capacity": 1000
},
{
"address": "127.0.0.1:22947",
"block_range": null,
"omap_capacity": 1000
},
{
"address": "127.0.0.1:15143",
"block_range": null,
"omap_capacity": 1000
}
]
}
],
"omap_capacity": 1000
}
79 changes: 79 additions & 0 deletions fog/ledger/server/tests/data/overlap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"router_address": "127.0.0.1:19336",
"router_admin_address": "127.0.0.1:21616",
"shards": [
{
"address": "127.0.0.1:22977",
"block_range": {
"start_block": 1,
"end_block": 4
},
"stores": [
{
"address": "127.0.0.1:21902",
"block_range": null,
"omap_capacity": 1000
},
{
"address": "127.0.0.1:19791",
"block_range": null,
"omap_capacity": 1000
},
{
"address": "127.0.0.1:17895",
"block_range": null,
"omap_capacity": 1000
}
]
},
{
"address": "127.0.0.1:21165",
"block_range": {
"start_block": 2,
"end_block": 5
},
"stores": [
{
"address": "127.0.0.1:20836",
"block_range": null,
"omap_capacity": 1000
},
{
"address": "127.0.0.1:20965",
"block_range": null,
"omap_capacity": 1000
},
{
"address": "127.0.0.1:18061",
"block_range": null,
"omap_capacity": 1000
}
]
},
{
"address": "127.0.0.1:17297",
"block_range": {
"start_block": 3,
"end_block": 6
},
"stores": [
{
"address": "127.0.0.1:22423",
"block_range": null,
"omap_capacity": 1000
},
{
"address": "127.0.0.1:22547",
"block_range": null,
"omap_capacity": 1000
},
{
"address": "127.0.0.1:23316",
"block_range": null,
"omap_capacity": 1000
}
]
}
],
"omap_capacity": 1000
}
65 changes: 9 additions & 56 deletions fog/ledger/server/tests/router_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use rand::thread_rng;
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
net::{IpAddr, Ipv4Addr, SocketAddr},
net::SocketAddr,
path::{Path, PathBuf},
str::FromStr,
sync::Arc,
Expand Down Expand Up @@ -360,43 +360,17 @@ struct StoreConfig {

type BlockConfig = Vec<HashMap<PublicAddress, Vec<KeyImage>>>;

fn free_sockaddr() -> SocketAddr {
let port = portpicker::pick_unused_port().unwrap();
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), port)
}

#[tokio::test(flavor = "multi_thread")]
async fn smoke_test() {
let logger = logger::create_test_logger("smoke_test".to_string());
log::info!(logger, "test");
// Three shards, three stores each, correct config, each stores three blocks,
// each has three users with three keys each
let mut rng = RngType::from_seed([0u8; 32]);
let mut shards_config = vec![];
for i in 0..3 {
let mut stores_config = vec![];
for _ in 0..3 {
let store = StoreConfig {
address: free_sockaddr(),
block_range: None,
omap_capacity: 1000,
};
stores_config.push(store);
}
let shard = ShardConfig {
address: free_sockaddr(),
block_range: BlockRange::new((i * 3) + 1, ((i + 1) * 3) + 1),
stores: stores_config,
};
shards_config.push(shard);
}
let config = TestEnvironmentConfig {
router_address: free_sockaddr(),
router_admin_address: free_sockaddr(),
shards: shards_config,
omap_capacity: 1000,
};
let env_config_str = include_str!("data/normal.json");
let config: TestEnvironmentConfig =
serde_json::from_str(env_config_str).expect("Couldn't load config");

let mut rng = RngType::from_seed([0u8; 32]);
let mut blocks_config = vec![];
let mut key_index = 0;
for _ in 1..10 {
Expand Down Expand Up @@ -472,32 +446,11 @@ async fn overlapping_stores() {
// Three shards, three stores each, correct config, each stores three blocks,
// each has three users with three keys each - but the blocks overlap (so
// total of 5 blocks)
let mut rng = RngType::from_seed([0u8; 32]);
let mut shards_config = vec![];
for i in 0..3 {
let mut stores_config = vec![];
for _ in 0..3 {
let store = StoreConfig {
address: free_sockaddr(),
block_range: None,
omap_capacity: 1000,
};
stores_config.push(store);
}
let shard = ShardConfig {
address: free_sockaddr(),
block_range: BlockRange::new(i + 1, i + 4),
stores: stores_config,
};
shards_config.push(shard);
}
let config = TestEnvironmentConfig {
router_address: free_sockaddr(),
router_admin_address: free_sockaddr(),
shards: shards_config,
omap_capacity: 1000,
};
let env_config_str = include_str!("data/overlap.json");
let config: TestEnvironmentConfig =
serde_json::from_str(env_config_str).expect("Couldn't load config");

let mut rng = RngType::from_seed([0u8; 32]);
let mut blocks_config = vec![];
let mut key_index = 0;
for _ in 1..5 {
Expand Down

0 comments on commit a677b59

Please sign in to comment.