Esempio n. 1
0
def get_usernames():
    users = underlyingDatabaseRead.readUsers()
    usernames = []
    for user in users:
        usernames.append(user.username)

    return usernames
Esempio n. 2
0
def test_changes_in dbs(NUM_SERVERS=NUM_SERVERS):
    dbNames = ['RAFT_DB_' + str(i) for i in range(0,NUM_SERVERS)]
    for dbName in dbNames:
        mongoengine.register_connection(alias='core', name=dbName)
        users = databaseRead.readUsers(dbName=dbName)
        print("Database Name : ", dbName)
        print("Num of Users : ", len(users))
        print('----------Users------------')
        databaseRead.print_users(users)
        mongoengine.disconnect(alias='core')
Esempio n. 3
0
def getUsers(request):
    if request.method == 'POST':
        dbName = json.loads(request.POST['dbName'])
        # print('dbName : ', dbName)
        users_json = databaseRead.readUsers(dbName=dbName).to_json()
        users = json.dumps(users_json)
        # print('type of users : ', type(users))
        return JsonResponse({
            "status": True,
            "users": users,
        })
Esempio n. 4
0
    from discs.manageDatabases import deleteDatabase
    import random

    NUM_FAKE_USERS = 1
    NUM_FAKE_POSTS = 1

    dbName = 'CRDT-DisCS_test'
    for _ in range(NUM_FAKE_USERS):
        user = get_fake_user()
        add_user(name=user.name,
                 username=user.username,
                 nationality=user.nationality,
                 age=user.age,
                 dbName=dbName)

    users = readUsers(dbName=dbName)
    print_users(users)

    post_ids = []
    for _ in range(NUM_FAKE_POSTS):
        post = get_fake_post()
        author_index = random.randint(0, len(users) - 1)
        post.author = users[0].username
        post_id = add_post(author=post.author,
                           creation_time=post.creation_time,
                           content=post.content,
                           dbName=dbName)
        post_ids.append(post_id)

    myPostID = post_ids[0]
Esempio n. 5
0
import sys
sys.path.append('../scarf')

from discs.services.underlying import databaseRead
from discs.manageDatabases import deleteDatabase

import mongoengine
from num_running_servers import NUM_SERVERS

dbNames = ['RAFT_DB_' + str(i) for i in range(0,3)]

def test_changes_in dbs(NUM_SERVERS=NUM_SERVERS):
    dbNames = ['RAFT_DB_' + str(i) for i in range(0,NUM_SERVERS)]
    for dbName in dbNames:
        mongoengine.register_connection(alias='core', name=dbName)
        users = databaseRead.readUsers(dbName=dbName)
        print("Database Name : ", dbName)
        print("Num of Users : ", len(users))
        print('----------Users------------')
        databaseRead.print_users(users)
        mongoengine.disconnect(alias='core')


if __name__ == "__main__":
    for dbName in dbNames:
        users = databaseRead.readUsers(dbName=dbName)
        print("Database Name : ", dbName)
        print("Num of Users : ", len(users))
        # databaseRead.print_users(users)
        deleteDatabase(dbName)
Esempio n. 6
0
    from client import put, get
    
    mongoengine.register_connection(alias='core', name=dbName)
    start = time.perf_counter()
    
    addr = "http://127.0.0.1:500" + str(random.randint(0, 2))
    print("Current Address : ", addr)
    key = 'my_msg'
    value = msg
    put(addr, key, value)
    addr = "http://127.0.0.1:500" + str(random.randint(0, 2))
    print("Recieving Address from Server Address : ", addr)
    recv_msg = get(addr, key)
    # print('Recieved message : ',recv_msg)

    print("Num of Users : ", len(readUsers()))

    parsable_message = recv_msg['payload']['value']
    parseMessage(parsable_message, dbName=None)
    users = readUsers()
    print("Num of Users : ", len(users))
    print("----------------Users----------------- ")
    print_users(users)
    
    finish = time.perf_counter()
    print(f'\n\n\nFinished in {round(finish-start, 3)} seconds')

    mongoengine.disconnect(alias='core')

    deleteDatabase(dbName=dbName)