-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestdb.py
More file actions
69 lines (56 loc) · 1.67 KB
/
testdb.py
File metadata and controls
69 lines (56 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
###############################################################################
#
# Filename: test.py
# Author: Christian Rodriguez and Jose R. Ortiz
#
# Description:
# Script to test the MySQL support library for the DFS project.
#
#
# This is how to import a local library
from mds_db import *
# Create an object of type mds_db
db = mds_db("dfs.db")
# Connect to the database
print "Connecting to database"
db.Connect()
# Testing how to add a new node to the metadata server.
# Note that I used a node name, the address and the port.
# Address and port are necessary for connection.
print "Testing node addition"
id1 = db.AddDataNode("136.145.54.10", 80)
id2 = db.AddDataNode("136.145.54.11", 80)
print
print "Testing if node was inserted"
print "A tupple with node name and connection info must appear"
print db.CheckNode(id1)
print
print "Testing all Available data nodes"
for address, port in db.GetDataNodes():
print address, port
print
print "Inserting two files to DB"
db.InsertFile("/hola/cheo.txt", 20)
db.InsertFile("/opt/blah.txt", 30)
print
print "Choteando one of the steps of the assignment :) ..."
print "Files in the database"
for file, size in db.GetFiles():
print file, size
print
print "Adding blocks to the file, duplicate message if not the first time running"
print "this script"
try:
db.AddBlockToInode("/hola/cheo.txt", [(id1, "1"), (id2, "1")])
except:
print "Won't duplicate"
print
print "Testing retreiving Inode info"
fsize, chunks_info = db.GetFileInode("/hola/cheo.txt")
print "File Size is:", fsize
print "and can be constructed from: "
for address, port, chunk in chunks_info:
print address, port, chunk
print
print "Closing connection"
db.Close()