-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestdb.py
81 lines (56 loc) · 1.66 KB
/
testdb.py
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
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-
# Víctor A. Hernández & José R. Ortiz
# CCOM 4017 – Operating Systems
# Assignment 4: test.py (comes with 7 other files)
# Script to test the SQL support library for the DFS project
from mds_db import *
# mds_db()
db = mds_db("dfs.db")
# Connect()
print "Connecting to database"
db.Connect()
print
# AddDataNode()
print "Testing node addition (two numbers must appear)"
print db.AddDataNode("136.145.54.10", 80)
print db.AddDataNode("136.145.54.11", 70)
print
# CheckNode()
print "Testing if node was inserted (a number must appear)"
print db.CheckNode("136.145.54.11", 70)
print
# GetDataNodes()
print "Testing all available data nodes (two lines must appear)"
for address, port in db.GetDataNodes():
print address, port
print
# InsertFile()
print "Inserting two files to DB (two 1's must appear)"
print db.InsertFile("/hola/cheo.txt", 20)
print db.InsertFile("/opt/blah.txt", 30)
print
# GetFiles()
print "Files in the database (two lines must appear)"
for file, size in db.GetFiles():
print file, size
print
# AddBlockToInode()
print "Adding blocks to database (duplicate message if not the first time running this script)"
try:
db.AddBlockToInode("/hola/cheo.txt", [("136.145.54.11", 80, "1"), ("136.145.54.11", 70, "2")])
except:
print "Won't duplicate"
print
# GetFileInode()
print "Testing retrieving inode info (from `/hola/cheo.txt`)"
fsize, chunks_info = db.GetFileInode("/hola/cheo.txt")
print "\t- File size is:", fsize
print "\t- File can be constructed from:"
i = 1
for address, port, chunk in chunks_info:
print "\t\t%s. %s %s %s" % (i, address, port, chunk)
i += 1
print
# Close()
print "Closing connection..."
db.Close()