def testRange(self): self.store.close() t = HStore(self.store.path, 1, 0, 8) for i in range(200): t.set('/test/test%d.jpg' % i, 'value%d' % i) s = t.get('@') n = sum(int(l.split(' ')[2]) for l in s.split('\n') if l) t.close() self.assertEqual(n, 110)
def testScan(self): self.testHash() self.store.close() os.unlink(self.store.path + '/.0.index') t = HStore(self.store.path, self.store.height) t.check() try: s = t.get('@') n = sum(int(l.split(' ')[2]) for l in s.split('\n') if l) self.assertEqual(n, 200) s = t.get('@0') n = sum(1 for l in s.split('\n') if l) if n == 16: n = sum(int(l.split(' ')[2]) for l in s.split('\n') if l) self.assertEqual(n, 10) finally: t.close()
def setUp(self): self.store = HStore("/tmp/tmpdb2", self.height) self.store.clear()
def main(): from optparse import OptionParser parser = OptionParser() parser.add_option("-l", "--listen", dest="host", default="0.0.0.0", help="the ip interface to bind") parser.add_option("-p", "--port", default=7902, type=int, help="which port to listen") # parser.add_option("-d", "--daemon", action="store_true", # help="run in daemon", default=False) parser.add_option("-H", "--home", default="beansdb", help="the database path") parser.add_option("-c", "--count", default=16, type=int, help="number of db file, power of 16") parser.add_option("-s", "--start", default=0, type=int, help="start index of db file") parser.add_option("-e", "--end", default=-1, type=int, help="last end of db file, -1 means no limit") parser.add_option("-n", "--limit", default=100, type=int, help="diffs limit to do db scan") parser.add_option("-t", "--threads", type=int, default=20, help="number of IO threads") (options, args) = parser.parse_args() store = (HStore(options.home, int(math.log(options.count, 16)), options.start, options.end)) #store.check(options.limit, nonblocking=True) api.spawn(tpool.execute, store.check, options.limit) # check in thread pool api.spawn(tpool.execute, flush, store) print "server listening on %s:%s" % (options.host, options.port) server = api.tcp_listener((options.host, options.port)) util.set_reuse_addr(server) while True: try: new_sock, address = server.accept() except KeyboardInterrupt: break api.spawn(handler, store, new_sock, new_sock.makefile('r'), new_sock.makefile('w')) global quit quit = True print 'close listener ...' server.close() print 'stop checker thread ...' store.stop_check() print 'stop worker threads ...' tpool.killall() print 'close store...' store.close()