示例#1
0
 def end_protocol_error(self):
     s1 = ClientStorage(address=self.address)
     c1 = Connection(s1)
     r1 = c1.get_root()
     s1.s = FakeSocket('\0\0\0\0?')
     r1._p_note_change()
     raises(ProtocolError, c1.commit)
示例#2
0
 def check_write_conflict(self):
     s1 = ClientStorage(address=self.address)
     c1 = Connection(s1)
     r1 = c1.get_root()
     s1.s = FakeSocket('\0\0\0\0', STATUS_INVALID)
     r1._p_note_change()
     raises(WriteConflictError, c1.commit)
示例#3
0
def interactive_client(file, address, cache_size, readonly, repair,
                       startup, storage_class=None):
    if file:
        storage = get_storage(file, storage_class=storage_class,
                readonly=readonly, repair=repair)
        description = file
    else:
        socket_address = SocketAddress.new(address)
        wait_for_server(address=socket_address)
        storage = ClientStorage(address=socket_address)
        description = socket_address
    connection = Connection(storage, cache_size=cache_size)
    console_module = ModuleType('__console__')
    sys.modules['__console__'] = console_module
    namespace = {'connection': connection,
                 'root': connection.get_root(),
                 'get': connection.get,
                 'sys': sys,
                 'os': os,
                 'int8_to_str': int8_to_str,
                 'str_to_int8': str_to_int8,
                 'pp': pprint}
    vars(console_module).update(namespace)
    configure_readline(
        vars(console_module), os.path.expanduser("~/.durushistory"))
    console = InteractiveConsole(vars(console_module))
    if startup:
        console.runsource('execfile("%s")' % os.path.expanduser(startup))
    help = ('    connection -> the Connection\n'
            '    root       -> the root instance')
    console.interact('Durus %s\n%s' % (description, help))
示例#4
0
def pack_storage_main():
    parser = OptionParser()
    parser.set_description("Packs a Durus storage.")
    parser.add_option(
        '--file',
        dest="file",
        default=None,
        help="If this is not given, the storage is through a Durus server.")
    parser.add_option('--port',
                      dest="port",
                      default=DEFAULT_PORT,
                      type="int",
                      help="Port the server is on. (default=%s)" %
                      DEFAULT_PORT)
    parser.add_option('--host',
                      dest="host",
                      default=DEFAULT_HOST,
                      help="Host of the server. (default=%s)" % DEFAULT_HOST)
    (options, args) = parser.parse_args()
    if options.file is None:
        wait_for_server(options.host, options.port)
        storage = ClientStorage(host=options.host, port=options.port)
    else:
        storage = FileStorage(options.file)
    connection = Connection(storage)
    connection.pack()
示例#5
0
 def check_oid_reuse(self):
     # Requires ShelfStorage oid reuse pack semantics
     s1 = ClientStorage(address=self.address)
     s1.oid_pool_size = 1
     c1 = Connection(s1)
     r1 = c1.get_root()
     s2 = ClientStorage(address=self.address)
     s2.oid_pool_size = 1
     c2 = Connection(s2)
     r2 = c2.get_root()
     r1['a'] = PersistentDict()
     r1['b'] = PersistentDict()
     c1.commit()
     c2.abort()
     a_oid = r1['a']._p_oid
     assert 'a' in r1 and 'b' in r1 and len(r1['b']) == 0
     assert 'a' in r2 and 'b' in r2 and len(r2['b']) == 0
     del r2['a'] # remove only reference to a
     c2.commit()
     c2.pack() # force relinquished oid back into availability
     sleep(0.5) # Give time for pack to complete
     c2.abort()
     assert c2.get(a_oid) is None
     c1.abort()
     assert c1.get(a_oid)._p_is_ghost()
     r2['b']['new'] = Persistent()
     r2['b']['new'].bogus = 1
     c2.commit()
     assert c2.get(a_oid) is r2['b']['new']
     c1.abort()
     assert c1.get(a_oid).__class__ == PersistentDict
     r1['b']['new'].bogus
     assert c1.get(a_oid).__class__ == Persistent
     s1.close()
示例#6
0
def main():
    parser = OptionParser()
    parser.set_description('Stress test a Durus Server')
    parser.add_option('--port',
                      dest='port',
                      default=DEFAULT_PORT,
                      type='int',
                      help='Port to listen on. (default=%s)' % DEFAULT_PORT)
    parser.add_option('--host',
                      dest='host',
                      default=DEFAULT_HOST,
                      help='Host to listen on. (default=%s)' % DEFAULT_HOST)
    parser.add_option('--cache_size',
                      dest="cache_size",
                      default=4000,
                      type="int",
                      help="Size of client cache (default=4000)")
    parser.add_option('--max-loops',
                      dest='loops',
                      default=None,
                      type='int',
                      help='Maximum number of loops before exiting.')

    (options, args) = parser.parse_args()
    from durus.logger import logger
    logger.setLevel(5)
    storage = ClientStorage(host=options.host, port=options.port)
    connection = Connection(storage, cache_size=options.cache_size)
    try:
        if 'obj' not in connection.get_root():
            init_db(connection)
            verify_db(connection, all=True)
            connection.commit()
    except ConflictError:
        connection.abort()
    n = options.loops
    while n is None or n > 0:
        if n is not None:
            n -= 1
        try:
            if hasattr(sys, 'gettotalrefcount'):
                sys.stdout.write('refs = %s\n' % sys.gettotalrefcount())
            if randbool():
                connection.abort()
            verify_db(connection)
            mutate_db(connection)
            connection.commit()
            maybe_sleep()
        except ConflictError:
            sys.stdout.write('conflict\n')
            connection.abort()
            maybe_sleep()
示例#7
0
 def __init__(self, host, port):
     self._connection = Connection(ClientStorage(host=host, port=port))
示例#8
0
 def check_client_storage(self):
     b = ClientStorage(address=self.address)
     c = ClientStorage(address=self.address)
     oid = b.new_oid()
     assert oid == int8_to_str(0), repr(oid)
     oid = b.new_oid()
     assert oid == int8_to_str(1), repr(oid)
     oid = b.new_oid()
     assert oid == int8_to_str(2), repr(oid)
     raises(KeyError, b.load, int8_to_str(0))
     record = pack_record(int8_to_str(0), as_bytes('ok'), as_bytes(''))
     b.begin()
     b.store(int8_to_str(0), record)
     assert b.end() is None
     b.load(int8_to_str(0))
     assert b.sync() == []
     b.begin()
     b.store(
         int8_to_str(1),
         pack_record(int8_to_str(1), as_bytes('no'), as_bytes('')))
     b.end()
     assert len(list(b.gen_oid_record())) == 1
     records = b.bulk_load([int8_to_str(0), int8_to_str(1)])
     assert len(list(records)) == 2
     records = b.bulk_load([int8_to_str(0), int8_to_str(1), int8_to_str(2)])
     raises(DurusKeyError, list, records)
     b.pack()
     assert len(list(b.gen_oid_record())) == 1
     raises(ReadConflictError, c.load, int8_to_str(0))
     raises(ReadConflictError, c.load, int8_to_str(0))
     assert set(c.sync()) == set([int8_to_str(0), int8_to_str(1)])
     assert record == c.load(int8_to_str(0))
     b.close()
     c.close()
示例#9
0
 def close(self):
     s1 = ClientStorage(address=self.address)
     s1.close()
示例#10
0
 def load_protocol_error(self):
     s1 = ClientStorage(address=self.address)
     c1 = Connection(s1)
     s1.s = FakeSocket('?')
     raises(ProtocolError, s1.load, int8_to_str(0))
示例#11
0
 def pack_protocol_error(self):
     s1 = ClientStorage(address=self.address)
     s1.s = FakeSocket('?')
     raises(ProtocolError, s1.pack)
示例#12
0
 def _get_storage(self):
     return ClientStorage(port=self.port)