def test_dataReceivedAfterRecovery():
    h="""
    Egy szerver ujraeledese utan ra kell tolteni a kihagyott adatokat
    Egy szenzornak megadunk ket szervert.
    A main szerver leallasa utan a szenzor a backup szervernek kuldi az adatokat.
    A main szerver feleledese utan meg kell kapnia a kimaradt adatokat.
    """

    print(h)

    mainServer = StorageServer(alive=True, id=1)
    backupServer = StorageServer(alive=True, id=2)
    mainServer.add_neighbour_server(backupServer)
    backupServer.add_neighbour_server(mainServer)

    s_id = 10
    sensor = Sensor(id=s_id, servers=[mainServer, backupServer])

    data_1 = Data("data_1 to mainServer")
    sensor.send_data(data=data_1)
    assert(data_1 in mainServer.data[s_id])
    assert(backupServer.data == {})

    #mainServer leallitasa
    mainServer.change_alive_state(False)
    data_2 = Data("data_2 during main down")
    sensor.send_data(data=data_2)
    assert(data_2 not in mainServer.data[s_id])
    assert(data_2 in backupServer.dead_servers_data[1][s_id])

    #main feleled
    mainServer.change_alive_state(True)
    assert(data_2 in mainServer.data[s_id])
Ejemplo n.º 2
0
def test_complexMessaging():
    h="""
    Masolatok keszitesenek ellenorzese
    Sok szerver es szenzor letrehozasa, sok adat elkuldese, majd ezek megletenek ellenorzese
    """

    print(h)

    random.seed(42)

    def create_network(num_servers, num_sensors):
        """
        num_servers darab szerverbol allo halozat letrehozasa, melyekhez kapcsolodo
        szenzorok szamat a num_sensors lista adja meg
        :param num_servers: szerverek szama
        :param num_sensors: szenzorok szama szerverenkent (lista vagy egy szam)
        :return: szerverek listaja, szenorok listainak listaja szerverenkent
        """
        if type(num_sensors) is int:
            num_sensors = [num_sensors] * num_servers
        # create servers
        servers = [StorageServer(alive=True, id=1001+i) for i in range(num_servers)]
        # create sensors
        sensors = []
        for i in range(num_servers):
            ss = []
            for j in range(num_sensors[i]):
                sensor = Sensor(9001+100*i+j, [servers[i]])
                servers[i].add_sensor(sensor)
                ss.append(sensor)
            sensors.append(ss)
        # szerverek kozotti teljes halozat letrehozasa
        for i in range(num_servers):
            for j in range(num_servers):
                servers[i].add_neighbour_server(servers[(i+j+1) % num_servers])
        return servers, sensors

    servers, sensors = create_network(5, 2)

    for sensor_list in sensors:
        for sensor in sensor_list:
            sensor.send_data(Data(randint(0,255)))
            sensor.send_data(Data(randint(1000, 1255)))

    for server in servers:
        print('Server', server.id)
        print('Own data:', server.data)
        print('Replicas', server.other_data)
        print('Temporal data:', server.dead_servers_data)
        print()

    for server in servers:
        assert (len(server.data) == 2 and len(server.other_data) == 2 and len(server.dead_servers_data) == 0)
        for od in server.other_data:
            assert (len(server.other_data[od]) == 2)
            for d in server.other_data[od].items():
                assert (len(d) == 2)
def test_MultipleServersDown():
    h = """
    A fo szerver mellett, mar mukodes kozben megjelenik egy masik szerver.
    A fo szerver ezutan meghal, ekkor a masiknak kell atvennie a helyet.
    A fo szerver feleledese utan meg kell kapnia az adatokat az uj szervertol.
    Ezutan az uj szerver all le, ekkor a fonek kell begyujtenie a keletkezett adatokat.
    """

    print(h)

    mainServer = StorageServer(alive=True, id=1001)

    s_id = 9001
    s2_id = 9002
    sensor = Sensor(id=s_id, servers=[])
    mainServer.add_sensor(sensor)

    data_1 = Data("data_1")
    sensor.send_data(data=data_1)
    assert (data_1 in mainServer.data[s_id])

    newServer = StorageServer(alive=True, id=1002)

    newServer.add_neighbour_server(mainServer)
    mainServer.add_neighbour_server(newServer)

    # mainServer leallitasa
    mainServer.change_alive_state(False)
    data_2 = Data("data_2 during main down")
    sensor.send_data(data=data_2)
    assert (data_2 not in mainServer.data[s_id])
    assert (data_2 in newServer.dead_servers_data[1001][s_id])

    # main feleled
    mainServer.change_alive_state(True)
    assert (data_2 in mainServer.data[s_id])

    # uj szerver is kap szenzort
    sensor2 = Sensor(s2_id, servers=[])
    newServer.add_sensor(sensor2)
    data_3 = Data('data for new server')
    sensor2.send_data(data_3)
    assert (data_3 in newServer.data[s2_id])
    assert (data_3 in mainServer.other_data[1002][s2_id])

    # uj szerver is leall
    newServer.change_alive_state(False)
    data_4 = Data('data during new sever dead')
    sensor2.send_data(data_4)
    assert (data_4 not in newServer.data[s2_id])
    assert (data_4 in mainServer.dead_servers_data[1002][s2_id])

    # uj szerver feleled
    newServer.change_alive_state(True)
    assert (data_4 in newServer.data[s2_id])
def test_MultipleServersDown():
    h = """
    A fo es az egyik backup szerver is inaktivva valik.
    A fo szerver feleledese utan igy is meg kell kapnia a kiesett adatokat.
    """

    print(h)

    mainServer = StorageServer(alive=True, id=1001)
    backupServer1 = StorageServer(alive=True, id=1002)
    backupServer2 = StorageServer(alive=True, id=1003)

    mainServer.add_neighbour_server(backupServer1)
    backupServer1.add_neighbour_server(mainServer)

    mainServer.add_neighbour_server(backupServer2)
    backupServer2.add_neighbour_server(mainServer)

    backupServer1.add_neighbour_server(backupServer2)
    backupServer2.add_neighbour_server(backupServer1)

    s_id = 9001
    sensor = Sensor(id=s_id, servers=[])
    mainServer.add_sensor(sensor)

    data_1 = Data("data_1")
    sensor.send_data(data=data_1)
    assert (data_1 in mainServer.data[s_id])
    assert (backupServer1.data == {})

    #mainServer leallitasa
    mainServer.change_alive_state(False)
    data_2 = Data("data_2 during main down")
    sensor.send_data(data=data_2)
    print('BS1 dead:', backupServer1.dead_servers_data)
    print('BS2 other:', backupServer2.other_data)
    assert (data_2 not in mainServer.data[s_id])
    assert (data_2 in backupServer1.dead_servers_data[1001][s_id])
    assert (data_2 in backupServer2.other_data[1001][s_id])

    # backup1 szerver leall
    backupServer1.change_alive_state(False)
    data_3 = Data('data_3 two servers down')
    sensor.send_data(data_3)

    assert (data_3 not in mainServer.data[s_id])
    assert (data_3 not in backupServer1.dead_servers_data[1001][s_id])
    assert (data_3 in backupServer2.dead_servers_data[1001][s_id])

    #main  es backup feleled
    mainServer.change_alive_state(True)
    backupServer1.change_alive_state(True)
    assert (data_2 in mainServer.data[s_id])
    assert (data_3 in mainServer.data[s_id])
Ejemplo n.º 5
0
def test_serverDown():
    h="""
    Szerver leallas ellenorzese.
    Egy szenzornak megadunk ket szervert.
    Ha a main szerver leall, akkor a szenzor a backup szervernek kuldi az adatot.
    """

    print(h)

    mainServer = StorageServer(alive=True, id=1)
    backupServer = StorageServer(alive=True, id=2)

    s_id = 10
    sensor = Sensor(id=s_id, servers=[mainServer, backupServer])

    #adat kuldese a fo szervernek
    data_1 = Data("data_1 to mainServer")
    sensor.send_data(data=data_1)
    assert(data_1 in mainServer.data[s_id])
    assert(backupServer.data == {})

    #mainServer leallitasa
    data_2 = Data("data_2 to backupServer")
    mainServer.alive = False
    sensor.send_data(data=data_2)
    assert(data_2 not in mainServer.data[s_id])
    assert(data_2 in backupServer.dead_servers_data[1][s_id])

    #mainServer feleled
    data_3 = Data("data_3 to mainServer")
    mainServer.alive = True
    sensor.send_data(data=data_3)
    assert(data_3 in mainServer.data[s_id])
    assert(data_3 not in backupServer.dead_servers_data[1][s_id])

    #ha egyik szerver sem kapja meg akkor kivetelt dob
    mainServer.alive = False
    backupServer.alive = False
    data_4 = Data("data_cannot_be_sent")
    ok = False
    try:
        sensor.send_data(data_4)
    except:
        ok = True
    assert(ok)

    print("Test ok")
Ejemplo n.º 6
0
def test_dataDuplication():
    h="""
    Egy szerveren nem szabad ketszer ugyanazt az adatot tarolni.
    Egy adatot ketszer kuldunk el a szervernek.
    Elvart viselkedes: csak egyszer jelenjen meg a szerveren
    """

    print(h)

    server = StorageServerService(alive=True)
    s_id = 10
    sensor = SensorService(id=s_id, servers=[server])
    data_ = Data('test data')

    sensor.send_data(data=data_)
    sensor.send_data(data=data_)

    assert(server.data[s_id].count(data_) == 1)
Ejemplo n.º 7
0
def test_replicas():
    h = """
    Masolatok keszitesenek ellenorzese
    Letrehozunk 4 db szervert, az egyikhez hozzaadunk 1 szenzort.
    A szenzor altal alkuldott adatnak a sajat szervere mellett ket masik szerveren kell megjelennie
    """

    print(h)

    server1 = StorageServer(alive=True, id=1001)
    server2 = StorageServer(alive=True, id=1002)
    server3 = StorageServer(alive=True, id=1003)
    server4 = StorageServer(alive=True, id=1004)
    sensor1 = Sensor(9001, servers=[])

    # most nincs full mesh, csak server1 van mindenkivel osszekotve
    server1.add_neighbour_server(server2)
    server2.add_neighbour_server(server1)
    server1.add_neighbour_server(server3)
    server3.add_neighbour_server(server1)
    server1.add_neighbour_server(server4)
    server4.add_neighbour_server(server1)

    server1.add_sensor(sensor1)
    #sensor1.redefine_servers([server1, server2, server3, server4])

    assert (len(sensor1.servers) == 4 and sensor1.servers[0] == server1)

    data = Data('simple_test_data')
    sensor1.send_data(data)

    print('Server1 data:', server1.data)
    assert (len(server1.data) == 1)

    print('Server2 replicas:', server2.other_data)
    assert (server2.other_data[1001][9001][0].data[1] == 'simple_test_data')

    print('Server3 replicas:', server3.other_data)
    assert (server3.other_data[1001][9001][0].data[1] == 'simple_test_data')

    print('Server4 replicas:', server4.other_data)
    assert (server4.other_data == {} or NUM_REPLICAS != 2)

    print('Test ok')
Ejemplo n.º 8
0
def test_dataSending():
    h="""
    Adatkuldes ellenorzese.
    Letrehozunk egy szervert es hozzaadunk egy szenzort.
    A szenzor elkuld egy adatot; ellenorizzuk, hogy a szerverre megerkezett-e.
    """

    print(h)

    server1 = StorageServer(alive=True, id=1001)
    sensor1 = Sensor(9001, servers=[])

    server1.add_sensor(sensor1)
    sensor1.redefine_servers([server1])

    data = Data('simple_test_data')
    #server1.receive_data('testdata', sensor1.id)
    sensor1.send_data(data)
    print('Server1 data:', server1.data)
    assert(len(server1.data) == 1)

    print('Test ok')
Ejemplo n.º 9
0
def test_loadTest():
    h="""
    Egy szerverhez csatlakozik 20 szenzor.
    A szenzorok folyamatosan kuldik az adatokat.
    Minden adatnak meg kell erkezni.
    """

    print(h)

    server = StorageServer(alive=True, id=1)
    sensor_number = 20
    sensors = [Sensor(id=100+i, servers=[server]) for i in range(sensor_number)]

    data_num = 100
    for n in range(data_num):
        for sensor in sensors:
            sensor.send_data(Data("data_from_sensor" + str(sensor.id) + "_data" + str(n)))

    for m in range(data_num):
        for sensor in sensors:
            # itt csak a datak ertekevel hasonlitjuk ossze, az idoket nem nezzuk
            assert("data_from_sensor" + str(sensor.id) + "_data" + str(m) in [d.data[1] for d in server.data[sensor.id]])

    print("Test ok")