]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/test/test_provisioning.py
7e1f9a2f5771a03b35bfaf53b93983fbcb45f030
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / test / test_provisioning.py
1
2 from twisted.trial import unittest
3 from allmydata import provisioning
4 ReliabilityModel = None
5 try:
6     from allmydata.reliability import ReliabilityModel
7 except ImportError:
8     pass # might not be importable, since it needs NumPy
9
10 from nevow import inevow
11 from zope.interface import implements
12
13 class MyRequest:
14     implements(inevow.IRequest)
15     pass
16
17 class Provisioning(unittest.TestCase):
18     def getarg(self, name, astype=int):
19         if name in self.fields:
20             return astype(self.fields[name])
21         return None
22
23     def test_load(self):
24         pt = provisioning.ProvisioningTool()
25         self.fields = {}
26         #r = MyRequest()
27         #r.fields = self.fields
28         #ctx = RequestContext()
29         #unfilled = pt.renderSynchronously(ctx)
30         lots_of_stan = pt.do_forms(self.getarg)
31
32         self.fields = {'filled': True,
33                        "num_users": 50e3,
34                        "files_per_user": 1000,
35                        "space_per_user": 1e9,
36                        "sharing_ratio": 1.0,
37                        "encoding_parameters": "3-of-10-5",
38                        "num_servers": 30,
39                        "ownership_mode": "A",
40                        "download_rate": 100,
41                        "upload_rate": 10,
42                        "delete_rate": 10,
43                        "lease_timer": 7,
44                        }
45         #filled = pt.renderSynchronously(ctx)
46         more_stan = pt.do_forms(self.getarg)
47
48         # trigger the wraparound configuration
49         self.fields["num_servers"] = 5
50         #filled = pt.renderSynchronously(ctx)
51         more_stan = pt.do_forms(self.getarg)
52
53         # and other ownership modes
54         self.fields["ownership_mode"] = "B"
55         more_stan = pt.do_forms(self.getarg)
56         self.fields["ownership_mode"] = "E"
57         more_stan = pt.do_forms(self.getarg)
58
59     def test_provisioning_math(self):
60         self.failUnlessEqual(provisioning.binomial(10, 0), 1)
61         self.failUnlessEqual(provisioning.binomial(10, 1), 10)
62         self.failUnlessEqual(provisioning.binomial(10, 2), 45)
63         self.failUnlessEqual(provisioning.binomial(10, 9), 10)
64         self.failUnlessEqual(provisioning.binomial(10, 10), 1)
65
66 DAY=24*60*60
67 MONTH=31*DAY
68 YEAR=365*DAY
69
70 class Reliability(unittest.TestCase):
71     def test_basic(self):
72         if ReliabilityModel is None:
73             raise unittest.SkipTest("reliability model requires NumPy")
74
75         # test that numpy math works the way I think it does
76         import numpy
77         decay = numpy.matrix([[1,0,0],
78                              [.1,.9,0],
79                              [.01,.09,.9],
80                              ])
81         start = numpy.array([0,0,1])
82         g2 = (start * decay).A[0]
83         self.failUnlessEqual(repr(g2), repr(numpy.array([.01,.09,.9])))
84         g3 = (g2 * decay).A[0]
85         self.failUnlessEqual(repr(g3), repr(numpy.array([.028,.162,.81])))
86
87         # and the dot product
88         recoverable = numpy.array([0,1,1])
89         P_recoverable_g2 = numpy.dot(g2, recoverable)
90         self.failUnlessAlmostEqual(P_recoverable_g2, .9 + .09)
91         P_recoverable_g3 = numpy.dot(g3, recoverable)
92         self.failUnlessAlmostEqual(P_recoverable_g3, .81 + .162)
93
94         r = ReliabilityModel.run(delta=100000,
95                                  report_period=3*MONTH,
96                                  report_span=5*YEAR)
97         self.failUnlessEqual(len(r.samples), 20)
98
99         last_row = r.samples[-1]
100         #print last_row
101         (when, unmaintained_shareprobs, maintained_shareprobs,
102          P_repaired_last_check_period,
103          cumulative_number_of_repairs,
104          cumulative_number_of_new_shares,
105          P_dead_unmaintained, P_dead_maintained) = last_row
106         self.failUnless(isinstance(P_repaired_last_check_period, float))
107         self.failUnless(isinstance(P_dead_unmaintained, float))
108         self.failUnless(isinstance(P_dead_maintained, float))
109         self.failUnlessAlmostEqual(P_dead_unmaintained, 0.033591004555395272)
110         self.failUnlessAlmostEqual(P_dead_maintained, 3.2983995819177542e-08)
111