Properly passing endpoint to dnode registration packet, added test just in case
This commit is contained in:
parent
a281bd2a9e
commit
3bd0e60169
@ -8,11 +8,12 @@ use a03::*;
|
||||
use std::net::{TcpStream, Shutdown};
|
||||
use std::io::Write;
|
||||
use std::net::TcpListener;
|
||||
use serde_json::from_str;
|
||||
|
||||
fn main() {
|
||||
let endpoint = parse_endpoint_from_cli(0);
|
||||
let listener = TcpListener::bind(endpoint).unwrap();
|
||||
register_with_meta_server();
|
||||
let listener = TcpListener::bind(&endpoint).unwrap();
|
||||
register_with_meta_server(&endpoint);
|
||||
|
||||
for stream in listener.incoming() {
|
||||
let mut stream = stream.unwrap();
|
||||
@ -29,7 +30,7 @@ fn main() {
|
||||
Ok(packet @ Packet { .. }) => match packet.p_type {
|
||||
// PacketType::GetFiles => shutdown(&mut stream),
|
||||
// PacketType::PutFile => put(&mut stream, &packet.json.unwrap(), &mut Vec::new()),
|
||||
PacketType::ShutdownDataNode => shutdown(&mut stream),
|
||||
PacketType::ShutdownDataNode => shutdown(&mut stream, &endpoint),
|
||||
_ => (),
|
||||
},
|
||||
Err(e) => println!("Error parsing json: {}", e.to_string()),
|
||||
@ -37,14 +38,19 @@ fn main() {
|
||||
}
|
||||
}
|
||||
|
||||
fn register_with_meta_server() {
|
||||
fn register_with_meta_server(endpoint: &String) {
|
||||
let mut stream = TcpStream::connect("localhost:6770").unwrap();
|
||||
let split: Vec<&str> = endpoint.split(":").collect();
|
||||
serde_json::to_writer(
|
||||
&mut stream,
|
||||
&Packet {
|
||||
p_type: PacketType::NodeRegistration,
|
||||
json: Some(serde_json::to_string(
|
||||
&NodeRegistration { register: true, ip: String::from("localhost"), port: 6771 }).unwrap()),
|
||||
&NodeRegistration {
|
||||
register: true,
|
||||
ip: String::from(split[0]),
|
||||
port: from_str(split[1]).unwrap() })
|
||||
.unwrap()),
|
||||
})
|
||||
.unwrap();
|
||||
println!("Registered myself");
|
||||
@ -58,14 +64,19 @@ fn register_with_meta_server() {
|
||||
// let files: PutFiles = serde_json::from_str(json).unwrap();
|
||||
//}
|
||||
|
||||
fn shutdown(stream: &mut TcpStream) {
|
||||
fn shutdown(stream: &mut TcpStream, endpoint: &String) {
|
||||
let mut stream = TcpStream::connect("localhost:6770").unwrap();
|
||||
let split: Vec<&str> = endpoint.split(":").collect();
|
||||
serde_json::to_writer(
|
||||
&mut stream,
|
||||
&Packet {
|
||||
p_type: PacketType::NodeRegistration,
|
||||
json: Some(serde_json::to_string(
|
||||
&NodeRegistration { register: false, ip: String::from("localhost"), port: 6771 }).unwrap()),
|
||||
&NodeRegistration {
|
||||
register: false,
|
||||
ip: String::from(split[0]),
|
||||
port: from_str(split[1]).unwrap() })
|
||||
.unwrap()),
|
||||
})
|
||||
.unwrap();
|
||||
println!("Unregistered myself");
|
||||
|
@ -397,6 +397,7 @@ cid TEXT NOT NULL DEFAULT \"0\")",
|
||||
add_file(&conn, &filename, 128);
|
||||
add_data_node(&conn, "127.0.0.1", 1337);
|
||||
add_data_node(&conn, "127.0.0.2", 1338);
|
||||
add_data_node(&conn, "127.0.0.2", 1339);
|
||||
let inode = get_file_info(&conn, &filename);
|
||||
let blocks = vec!(
|
||||
Block {
|
||||
@ -411,12 +412,18 @@ cid TEXT NOT NULL DEFAULT \"0\")",
|
||||
node_id: 2,
|
||||
chunk_id: String::from("c2"),
|
||||
},
|
||||
Block {
|
||||
file_id: inode.id,
|
||||
id: 0,
|
||||
node_id: 3,
|
||||
chunk_id: String::from("c3"),
|
||||
},
|
||||
);
|
||||
add_blocks_to_inode(&conn, &filename, &blocks);
|
||||
let (inode, blocks) = get_file_inode(&conn, &filename);
|
||||
assert_eq!(inode.name, "main_file");
|
||||
assert_eq!(inode.size, 128);
|
||||
assert_eq!(blocks.len(), 2);
|
||||
assert_eq!(blocks.len(), 3);
|
||||
assert_eq!(blocks[0].chunk_id, "c1");
|
||||
assert_eq!(blocks[0].data_node.id, 1);
|
||||
assert_eq!(blocks[0].data_node.ip, "127.0.0.1");
|
||||
@ -425,6 +432,10 @@ cid TEXT NOT NULL DEFAULT \"0\")",
|
||||
assert_eq!(blocks[1].data_node.id, 2);
|
||||
assert_eq!(blocks[1].data_node.ip, "127.0.0.2");
|
||||
assert_eq!(blocks[1].data_node.port, 1338);
|
||||
assert_eq!(blocks[2].chunk_id, "c3");
|
||||
assert_eq!(blocks[2].data_node.id, 3);
|
||||
assert_eq!(blocks[2].data_node.ip, "127.0.0.2");
|
||||
assert_eq!(blocks[2].data_node.port, 1339);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user