Пример #1
0
def test_overwrite_max_full():
    conf = SyncManagerConfig()
    manager = SyncManager(conf)
    dist = TestDistributedManager()
    db = TestDatabaseManager()
    manager.set_managers(dist, db)
    # manager.set_logger(print)

    db.update_entry(
        DatabaseEntry({
            "imsi": '1',
            'max_known_sqn': "1",
            "vectors": '[{"sqn":"1"}]'
        }))
    db.update_entry(
        DatabaseEntry({
            "imsi": '2',
            'max_known_sqn': "1",
            "vectors": '[{"sqn":"1"}]'
        }))
    db.update_entry(
        DatabaseEntry({
            "imsi": '3',
            'max_known_sqn': "1",
            "vectors": '[{"sqn":"1"}]'
        }))

    dist.update_entry(
        DatabaseEntry({
            "imsi": '1',
            'max_known_sqn': "2",
            "vectors": '[{"sqn":"2"}]'
        }))
    dist.update_entry(
        DatabaseEntry({
            "imsi": '2',
            'max_known_sqn': "2",
            "vectors": '[{"sqn":"2"}]'
        }))
    dist.update_entry(
        DatabaseEntry({
            "imsi": '3',
            'max_known_sqn': "2",
            "vectors": '[{"sqn":"2"}]'
        }))

    assert db.get_all_keys() == {"1", "2", "3"}
    assert dist.get_all_keys() == {"1", "2", "3"}

    for imsi in db.get_all_keys():
        assert _check_entry(db.get_entry(imsi), imsi, "1", [{'sqn': '1'}])
        assert _check_entry(dist.get_entry(imsi), imsi, "2", [{'sqn': '2'}])

    manager.report_all()
    manager.sync_reported()

    for imsi in db.get_all_keys():
        assert _check_entry(db.get_entry(imsi), imsi, "2", [{'sqn': '2'}])
        assert _check_entry(dist.get_entry(imsi), imsi, "2", [{'sqn': '2'}])
Пример #2
0
def test_simple_sync():
    conf = SyncManagerConfig()
    manager = SyncManager(conf)
    dist = TestDistributedManager()
    db = TestDatabaseManager()
    manager.set_managers(dist, db)
    # manager.set_logger(print)

    db.update_entry(
        DatabaseEntry({
            "imsi": '2',
            'max_known_sqn': "1",
            "vectors": "[]"
        }))
    dist.update_entry(
        DatabaseEntry({
            "imsi": '1',
            'max_known_sqn': "1",
            "vectors": "[]"
        }))

    assert db.get_all_keys() == {"2"}
    assert dist.get_all_keys() == {"1"}

    manager.report_all()  # sets all keys to reported
    manager.sync_reported()  # does the actual syncing

    assert db.get_all_keys() == {"1", "2"}
    assert dist.get_all_keys() == {"1", "2"}

    db.update_entry(
        DatabaseEntry({
            "imsi": '3',
            'max_known_sqn': "1",
            "vectors": "[]"
        }))
    db.update_entry(
        DatabaseEntry({
            "imsi": '4',
            'max_known_sqn': "1",
            "vectors": "[]"
        }))
    db.update_entry(
        DatabaseEntry({
            "imsi": '5',
            'max_known_sqn': "1",
            "vectors": "[]"
        }))

    assert db.get_all_keys() == {"1", "2", "3", "4", "5"}
    assert dist.get_all_keys() == {"1", "2"}

    manager.report_update("4")
    manager.sync_reported()

    assert db.get_all_keys() == {"1", "2", "3", "4", "5"}
    assert dist.get_all_keys() == {"1", "2", "4"}

    manager.report_all()
    manager.sync_reported()

    assert db.get_all_keys() == {"1", "2", "3", "4", "5"}
    assert dist.get_all_keys() == {"1", "2", "3", "4", "5"}