Пример #1
0
    def __test03_dht_collisions_resolutions(self):
        server = server1 = None
        try:
            home1 =  self._make_fake_hdd('node_1986', 1024, '/dev/loop0')
            home2 =  self._make_fake_hdd('node_1987', 1024, '/dev/loop1')

            server = TestServerThread(1986, home1)
            server.start()
            time.sleep(1)
            server1 = TestServerThread(1987, home2, neighbour='127.0.0.1:1986',  config={'DHT_CYCLE_TRY_COUNT':10, 'ALLOW_USED_SIZE_PERCENTS':70})
            server1.start()
            self.__wait_oper_status(server1, DS_NORMALWORK)

            print 'REMOVING 1987 NODE RANGE FROM DHT'
            rm_list = [(MAX_HASH/2+1, MAX_HASH, '127.0.0.1:1987')]
            params = {'append': [], 'remove': rm_list}
            packet_obj = FabnetPacketRequest(method='UpdateHashRangeTable', sender='127.0.0.1:1986', parameters=params)
            server.operator.call_network(packet_obj)

            self.__wait_oper_status(server, DS_NORMALWORK)
            self.__wait_oper_status(server1, DS_NORMALWORK)

            table_dump = server1.operator.dump_ranges_table()
            table = HashRangesTable()
            table.load(table_dump)
            self.assertEqual(table.count(), 2)
            hr = table.find(0)
            self.assertEqual(hr.start, 0)
            self.assertEqual(hr.end, MAX_HASH/2)
            hr = table.find(MAX_HASH)
            self.assertEqual(hr.start, MAX_HASH/2+1)
            self.assertEqual(hr.end, MAX_HASH)
        finally:
            if server:
                server.stop()
            if server1:
                server1.stop()
            self._destroy_fake_hdd('node_1986', '/dev/loop0')
            self._destroy_fake_hdd('node_1987', '/dev/loop1')
Пример #2
0
    def test01_dht_init(self):
        server = server1 = None
        try:
            home1 = '/tmp/node_1986_home'
            home2 = '/tmp/node_1987_home'
            if os.path.exists(home1):
                shutil.rmtree(home1)
            os.mkdir(home1)
            if os.path.exists(home2):
                shutil.rmtree(home2)
            os.mkdir(home2)

            server = TestServerThread(1986, home1, config={'MAX_USED_SIZE_PERCENTS': 99})
            server.start()
            time.sleep(1)
            server1 = TestServerThread(1987, home2, neighbour='127.0.0.1:1986', config={'MAX_USED_SIZE_PERCENTS': 99})
            server1.start()
            time.sleep(.2)
            self.__wait_oper_status(server1, DS_NORMALWORK)

            node86_stat = server.get_stat()
            node87_stat = server1.get_stat()

            self.assertEqual(long(node86_stat['DHTInfo']['range_start'], 16), 0L)
            self.assertEqual(long(node86_stat['DHTInfo']['range_end'], 16), MAX_HASH/2)
            self.assertEqual(long(node87_stat['DHTInfo']['range_start'], 16), MAX_HASH/2+1)
            self.assertEqual(long(node87_stat['DHTInfo']['range_end'], 16), MAX_HASH)

            table_dump = server.operator.dump_ranges_table()
            table = HashRangesTable()
            table.load(table_dump)
            self.assertEqual(table.count(), 2)
            hr = table.find(0)
            self.assertEqual(hr.start, 0)
            self.assertEqual(hr.end, MAX_HASH/2)
            hr = table.find(MAX_HASH)
            self.assertEqual(hr.start, MAX_HASH/2+1)
            self.assertEqual(hr.end, MAX_HASH)

            data_block = 'Hello, fabregas!'
            replica_block = 'This is replica data!'
            resp = server.put_data_block(data_block, MAX_HASH-100500) #should be appended into reservation range
            self.assertEqual(resp.ret_code, RC_OK, resp.ret_message)
            resp = server1.put_data_block(replica_block, 100, is_replica=True)
            self.assertEqual(resp.ret_code, RC_OK, resp.ret_message)

            time.sleep(2)

            data = server1.get_data_block(MAX_HASH-100500)
            self.assertEqual(data.data(), data_block)
            data = server.get_data_block(100, is_replica=True)
            self.assertEqual(data.data(), replica_block)

            data = server.get_data_block(MAX_HASH-100500)
            self.assertEqual(data, None)
            data = server1.get_data_block(100, is_replica=True)
            self.assertEqual(data, None)

            resp = server1.put_data_block('New data block', MAX_HASH-100500, user_id=3232)
            self.assertEqual(resp.ret_code, RC_PERMISSION_DENIED, resp.ret_message)
            data = server1.get_data_block(MAX_HASH-100500)
            self.assertEqual(data.data(), data_block)

            resp = server1.put_data_block('New data block', MAX_HASH-100, user_id=3232)
            self.assertEqual(resp.ret_code, RC_OK, resp.ret_message)
            data = server1.get_data_block(MAX_HASH-100, user_id=3232)
            self.assertEqual(data.data(), 'New data block')
            try:
                server1.get_data_block(MAX_HASH-100)
            except Exception, err:
                pass
            else: