def setup(self, host, port, data_dir, rlcount, checkpoint=True):
     self.host = host
     self.port = port
     self.ddir = data_dir
     self.store = KStore()
     self.pingcache = {}
     self.socket = self.rawserver.create_udpsocket(self.port, self.host)
     self.udp = krpc.hostbroker(self, (self.host, self.port), self.socket, self.rawserver.add_task, self.max_ul_rate, self.config, rlcount)
     self._load()
     self.rawserver.start_listening_udp(self.socket, self.udp)
     self.last = time()
     KeyExpirer(self.store, self.rawserver.add_task)
     self.refreshTable(force=1)
     if checkpoint:
         self.rawserver.add_task(30, self.findCloseNodes, lambda a: a, True)
         self.rawserver.add_task(60, self.checkpoint, 1)
Beispiel #2
0
 def setUp(self):
     self.k = KStore()
Beispiel #3
0
class BasicTests(unittest.TestCase):
    def setUp(self):
        self.k = KStore()

    def testNoKeys(self):
        self.assertEqual(self.k.keys(), [])

    def testKey(self):
        self.k['foo'] = 'bar'
        self.assertEqual(self.k.keys(), ['foo'])

    def testKeys(self):
        self.k['foo'] = 'bar'
        self.k['wing'] = 'wang'
        l = self.k.keys()
        l.sort()
        self.assertEqual(l, ['foo', 'wing'])

    def testInsert(self):
        self.k['foo'] = 'bar'
        self.assertEqual(self.k['foo'], ['bar'])

    def testInsertTwo(self):
        self.k['foo'] = 'bar'
        self.k['foo'] = 'bing'
        l = self.k['foo']
        l.sort()
        self.assertEqual(l, ['bar', 'bing'])

    def testExpire(self):
        self.k['foo'] = 'bar'
        self.k.expire(bttime() - 1)
        l = self.k['foo']
        l.sort()
        self.assertEqual(l, ['bar'])
        self.k['foo'] = 'bing'
        t = bttime()
        self.k.expire(bttime() - 1)
        l = self.k['foo']
        l.sort()
        self.assertEqual(l, ['bar', 'bing'])
        self.k['foo'] = 'ding'
        self.k['foo'] = 'dang'
        l = self.k['foo']
        l.sort()
        self.assertEqual(l, ['bar', 'bing', 'dang', 'ding'])
        self.k.expire(t)
        l = self.k['foo']
        l.sort()
        self.assertEqual(l, ['dang', 'ding'])

    def testDup(self):
        self.k['foo'] = 'bar'
        self.k['foo'] = 'bar'
        self.assertEqual(self.k['foo'], ['bar'])

    def testSample(self):
        for i in xrange(2):
            self.k['foo'] = i
        l = self.k.sample('foo', 5)
        l.sort()
        self.assertEqual(l, [0, 1])

        for i in xrange(10):
            for i in xrange(10):
                self.k['bar'] = i
            l = self.k.sample('bar', 5)
            self.assertEqual(len(l), 5)
            for i in xrange(len(l)):
                self.assert_(l[i] not in l[i + 1:])
Beispiel #4
0
 def setUp(self):
     self.k = KStore()
Beispiel #5
0
class BasicTests(unittest.TestCase):
    def setUp(self):
        self.k = KStore()
        
    def testNoKeys(self):
        self.assertEqual(self.k.keys(), [])

    def testKey(self):
        self.k['foo'] = 'bar'
        self.assertEqual(self.k.keys(), ['foo'])

    def testKeys(self):
        self.k['foo'] = 'bar'
        self.k['wing'] = 'wang'
        l = self.k.keys()
        l.sort()
        self.assertEqual(l, ['foo', 'wing'])
        
    def testInsert(self):
        self.k['foo'] = 'bar'
        self.assertEqual(self.k['foo'], ['bar'])

    def testInsertTwo(self):
        self.k['foo'] = 'bar'
        self.k['foo'] = 'bing'
        l = self.k['foo']
        l.sort()
        self.assertEqual(l, ['bar', 'bing'])
        
    def testExpire(self):
        self.k['foo'] = 'bar'
        self.k.expire(bttime() - 1)
        l = self.k['foo']
        l.sort()
        self.assertEqual(l, ['bar'])
        self.k['foo'] = 'bing'
        t = bttime()
        self.k.expire(bttime() - 1)
        l = self.k['foo']
        l.sort()
        self.assertEqual(l, ['bar', 'bing'])        
        self.k['foo'] = 'ding'
        self.k['foo'] = 'dang'
        l = self.k['foo']
        l.sort()
        self.assertEqual(l, ['bar', 'bing', 'dang', 'ding'])
        self.k.expire(t)
        l = self.k['foo']
        l.sort()
        self.assertEqual(l, ['dang', 'ding'])
        
    def testDup(self):
        self.k['foo'] = 'bar'
        self.k['foo'] = 'bar'
        self.assertEqual(self.k['foo'], ['bar'])

    def testSample(self):
        for i in xrange(2):
            self.k['foo'] = i
        l = self.k.sample('foo', 5)
        l.sort()
        self.assertEqual(l, [0, 1])

        for i in xrange(10):
            for i in xrange(10):
                self.k['bar'] = i
            l = self.k.sample('bar', 5)
            self.assertEqual(len(l), 5)
            for i in xrange(len(l)):
                self.assert_(l[i] not in l[i+1:])