Exemplo n.º 1
0
def run_test():
    
    endpoint = DummyEndpoint()
    init_map_val = {
        'a': 'hi',
        'b': 'hello'
        }
    map_var = LockedMapVariable(Waldo._host_uuid,False,{})

    init_list_val = [1,3,3,4,5]
    list_var = LockedListVariable(Waldo._host_uuid,False,[])

    ### load each container with elements
    load_event = endpoint._act_event_map.create_root_event()
    for map_index in init_map_val.keys():
        map_var.get_val(load_event).add_key(load_event,map_index,init_map_val[map_index])

    for list_index in range(0,len(init_list_val)):
        list_var.get_val(load_event).append_val(load_event,init_list_val[list_index])
        
    load_event.begin_first_phase_commit()
        
    
    ### Check that each can read initial value
    read_event_1 = endpoint._act_event_map.create_root_event()
    read_event_2 = endpoint._act_event_map.create_root_event()


    if not check_len(read_event_1,map_var,'map',len(init_map_val)):
        return False
    if not check_len(read_event_1,list_var,'list',len(init_list_val)):
        return False
    
    if not check_len(read_event_2,map_var,'map',len(init_map_val)):
        return False
    if not check_len(read_event_2,list_var,'list',len(init_list_val)):
        return False
    
    # try to commit both events
    read_event_1.begin_first_phase_commit()
    read_event_2.begin_first_phase_commit()

    # now try to read each value from list and map
    read_element_event = endpoint._act_event_map.create_root_event()
    for list_val_index in range(0,len(init_list_val)):
        list_val = list_var.get_val(read_element_event).get_val_on_key(read_element_event,list_val_index)
        if list_val != init_list_val[list_val_index]:
            print 'Incorrect internal val in list'
            return False

    for map_val_index in init_map_val.keys():
        map_val = map_var.get_val(read_element_event).get_val_on_key(read_element_event,map_val_index)
        if map_val != init_map_val[map_val_index]:
            print 'Incorrect internal val in map'
            return False

    read_element_event.begin_first_phase_commit()
        
    return True
Exemplo n.º 2
0
def run_test():
    
    endpoint = DummyEndpoint()
    init_map_val = {
        'a': 'hi',
        'b': 'hello'
        }
    map_var = LockedMapVariable(Waldo._host_uuid,False,{})

    init_list_val = [1,3,3,4,5]
    list_var = LockedListVariable(Waldo._host_uuid,False,[])

    ### load each container with elements
    load_event = endpoint._act_event_map.create_root_event()
    for map_index in init_map_val.keys():
        map_var.get_val(load_event).add_key(load_event,map_index,init_map_val[map_index])

    for list_index in range(0,len(init_list_val)):
        list_var.get_val(load_event).append_val(load_event,init_list_val[list_index])
        
    load_event.begin_first_phase_commit()
        

    ### create conflicting events: both try to write
    older_event,younger_event = endpoint.create_older_and_younger_root_events()

    should_commit = 57
    should_not_commit = should_commit + 1
    list_var.get_val(younger_event).append_val(younger_event,should_not_commit)
    list_var.get_val(older_event).append_val(older_event,should_commit)

    older_event.begin_first_phase_commit()

    read_event = endpoint._act_event_map.create_root_event()
    if list_var.get_val(read_event).get_len(read_event) != (len(init_list_val) + 1):
        print 'Error did not commit anything'
        return False

    if list_var.get_val(read_event).get_val_on_key(read_event,len(init_list_val)) != should_commit:
        print 'Error did not commit correct value'
        return False
    
    return True
Exemplo n.º 3
0
def run_test():
    
    endpoint = DummyEndpoint()
    init_map_val = {
        'a': 'hi',
        'b': 'hello'
        }
    map_var = LockedMapVariable(Waldo._host_uuid,False,{})

    ### load each container with elements
    load_event = endpoint._act_event_map.create_root_event()
    for map_index in init_map_val.keys():
        internal_map = map_var.get_val(load_event)        
        internal_map.add_key(load_event,map_index,init_map_val[map_index])

    load_event.begin_first_phase_commit()
        
    
    ### Check that each can read initial value
    # concurrent map changes:
    map_change_event_1 = endpoint._act_event_map.create_root_event()
    map_change_event_2 = endpoint._act_event_map.create_root_event()

    a_val = 'test it'
    b_val = 'test other'


    internal_map = map_var.get_val(map_change_event_1)
    internal_map.set_val_on_key(map_change_event_1,'a',a_val)
    map_var.get_val(map_change_event_1).get_val_on_key(map_change_event_1,'a')
    map_var.get_val(map_change_event_2).set_val_on_key(map_change_event_2,'b',b_val)
    
    # try to commit both events
    map_change_event_1.begin_first_phase_commit()
    map_change_event_2.begin_first_phase_commit()

    ### Check values
    map_read_event = endpoint._act_event_map.create_root_event()
    if a_val != map_var.get_val(map_read_event).get_val_on_key(map_read_event,'a'):
        print '\nDid not concurrently write a\n'
        return False
    if b_val != map_var.get_val(map_read_event).get_val_on_key(map_read_event,'b'):
        print '\nDid not concurrently write b\n'
        return False

    
    return True