def test_symmetric_difference(self): a = set(["wagwaan", "hot", "skull"]) b = set(["wagwaan", "flute", "don"]) c = hot_redis.Set(a) d = a.symmetric_difference(b) self.assertEquals(d, c.symmetric_difference(b)) self.assertEquals(d, c.symmetric_difference(hot_redis.Set(b))) self.assertEquals(d, a.symmetric_difference(hot_redis.Set(b)))
def test_disjoint(self): a = set(["wagwaan", "hot", "skull"]) b = hot_redis.Set(a) c = hot_redis.Set(["wagwaan", "flute", "don"]) d = set(["nba", "hang", "time"]) e = hot_redis.Set(d) self.assertFalse(b.isdisjoint(a)) self.assertFalse(b.isdisjoint(c)) self.assertTrue(b.isdisjoint(d)) self.assertTrue(b.isdisjoint(e))
def test_difference(self): a = set(["wagwaan", "hot", "skull"]) b = set(["wagwaan", "flute", "don"]) c = set(["wagwaan", "worldstar", "hiphop"]) d = hot_redis.Set(a) e = a.difference(b, c) self.assertEquals(a.difference(b), d.difference(b)) self.assertEquals(e, d.difference(b, c)) self.assertEquals(e, d.difference(hot_redis.Set(b), c)) self.assertEquals(e, d.difference(b, hot_redis.Set(c))) self.assertEquals(e, d.difference(hot_redis.Set(b), hot_redis.Set(c)))
def test_intersection(self): a = set(["wagwaan", "hot", "skull"]) b = set(["wagwaan", "flute", "don"]) c = set(["wagwaan", "worldstar", "hiphop"]) d = hot_redis.Set(a) e = a.intersection(b, c) self.assertEqual(a.intersection(b), d.intersection(b)) self.assertEqual(e, d.intersection(b, c)) self.assertEqual(e, d.intersection(hot_redis.Set(b), c)) self.assertEqual(e, d.intersection(b, hot_redis.Set(c))) self.assertEqual(e, d.intersection(hot_redis.Set(b), hot_redis.Set(c)))
def test_symmetric_difference_update(self): a = set(["wagwaan", "hot", "skull"]) b = set(["wagwaan", "flute", "don"]) c = a.copy() c.difference_update(b) d = hot_redis.Set(a) d.difference_update(b) self.assertEquals(d, c) d = hot_redis.Set(a) d.difference_update(hot_redis.Set(b)) self.assertEquals(d, c)
def check_input_fault(key, client_id, value1, value2, data_type): result_dict = dict() # Checking for valid key if key is None or len(key) == 0: result_dict['status'] = status_codes['missing_key_or_state'] return result_dict # Checking for valid client ID if client_id is None or len(client_id) == 0: result_dict['status'] = status_codes['client_id_not_found'] return result_dict # Checking for valid value1 if (value1 is None or len(value1) == 0) and value1 != "default": result_dict['status'] = status_codes['value_not_found'] return result_dict # Checking for valid value2 if (value2 is None or len(value2) == 0) and value2 != "default": result_dict['status'] = status_codes['value_not_found'] return result_dict data_types = hot_redis.Dict(key=DATA_TYPES, client=connection) all_clients = hot_redis.Set(key=ALL_CLIENTS, client=connection) client_list = hot_redis.Set(key=get_client_list_key(key), client=connection) # Checking if client ID is valid if client_id not in all_clients: result_dict['status'] = status_codes['client_id_not_found'] return result_dict # Checking if key is present if key not in data_types.keys(): result_dict['status'] = status_codes['missing_key_or_state'] return result_dict # Checking if the key is the right type if data_types[key] != data_type: result_dict['status'] = status_codes['data_type_mismatch'] return result_dict # Checking if client is in the GCounter's client list if get_client_key(key=key, client_id=client_id) not in client_list: result_dict['status'] = status_codes['client_id_not_in_crdt'] return result_dict return False
def new_g_counter(): key = request.args.get('key') client_id = request.args.get('client_id') result_dict = dict() # Getting all clients and data types of all CRDTs all_clients = hot_redis.Set(key=ALL_CLIENTS, client=connection) data_types = hot_redis.Dict(key=DATA_TYPES, client=connection) # Checking if the client ID is valid if client_id not in all_clients: print 'Missing Client ID' result_dict['status'] = status_codes['client_id_not_found'] return jsonify(result_dict) # Checking if an empty or null key has been given, and generating key if key is None or len(key) is 0: key = generate_random_crdt_key() while key in data_types.keys(): key = generate_random_crdt_key() print 'Generated new random CRDT key' # Checking if the key has already been taken elif key in data_types.keys() and data_types[key] != G_COUNTER: result_dict['status'] = status_codes['data_type_mismatch'] return jsonify(result_dict) # All conditions met for key and client ID new_g_counter = GCounter(key=key) new_g_counter.add_client(client_id) result_dict['status'] = status_codes['success'] result_dict['key'] = key result_dict['data_type'] = data_types[key] result_dict['client_id'] = client_id return jsonify(result_dict)
def __init__(self, var, val): if type(val) == dict: # print('dict') instance = hot_redis.Dict(val, key=var) elif type(val) == list: # print('list') instance = hot_redis.List(val, key=var) elif type(val) == set: # print('set') instance = hot_redis.Set(val, key=var) elif type(val) == str: # print('str') instance = hot_redis.String(val, key=var) elif type(val) == int: # print('int') instance = hot_redis.Int(val, key=var) elif type(val) == None: # Not handled # print('None Not handled') return None elif callable(val): # print('function') return None else: # print("else, None:", type(val)) return None # instance = hot_redis(instance) # print("debug: ", var, val) self.instance = instance
def test_add(self): a = set(["wagwaan", "hot", "skull"]) b = hot_redis.Set(a) i = "popcaan" a.add(i) b.add(i) self.assertEquals(b, a)
def __init__(self, key): # Setting the key of the LWWERegister Instance self.key = key # Getting/Setting the client list and type of the LWWERegister instance self.client_list = hot_redis.Set(key=get_client_list_key(key), client=connection) hot_redis.Dict(key=DATA_TYPES, client=connection)[key] = LWW_REGISTER
def check_input_fault(key, client_id, timestamp, data_type): result_dict = dict() # Checking for valid key if key is None or len(key) == 0: result_dict['status'] = status_codes['missing_key_or_state'] return result_dict # Checking for valid client ID if client_id is None or len(client_id) == 0: result_dict['status'] = status_codes['client_id_not_found'] return result_dict # Checking validity of timestamp if timestamp != -1.0: try: timestamp = float(timestamp) except ValueError: result_dict['status'] = status_codes['timestamp_not_valid'] return result_dict data_types = hot_redis.Dict(key=DATA_TYPES, client=connection) all_clients = hot_redis.Set(key=ALL_CLIENTS, client=connection) client_list = hot_redis.Set(key=get_client_list_key(key), client=connection) # Checking if client ID is valid if client_id not in all_clients: result_dict['status'] = status_codes['client_id_not_found'] return result_dict # Checking if key is present if key not in data_types.keys(): result_dict['status'] = status_codes['missing_key_or_state'] return result_dict # Checking if the key is the right type if data_types[key] != data_type: result_dict['status'] = status_codes['data_type_mismatch'] return result_dict # Checking if client is in the GCounter's client list if get_client_key(key=key, client_id=client_id) not in client_list: result_dict['status'] = status_codes['client_id_not_in_crdt'] return result_dict return False
def test_update(self): a = set(["wagwaan", "hot", "skull"]) b = set(["nba", "hang", "time"]) c = set(["rap", "dot", "mom"]) d = hot_redis.Set(a) a.update(b, c) d.update(b, c) self.assertEquals(d, a)
def __init__(self, key): # Setting the key of the GSet Instance self.key = key # Getting/Setting the client list and type of the GSet instance self.client_list = hot_redis.Set(key=get_client_list_key(key), client=connection) hot_redis.Dict(key=DATA_TYPES, client=connection)[key] = G_SET
def test_remove(self): a = hot_redis.Set(["wagwaan", "hot", "skull"]) i = len(a) b = "wagwaan" a.remove(b) self.assertEquals(len(a), i - 1) self.assertNotIn(b, a) self.assertRaises(KeyError, lambda: a.remove("popcaan"))
def test_cmp(self): a = set(["wagwaan", "hot", "skull"]) b = set(["nba", "hang", "time"]) c = hot_redis.Set(a) d = hot_redis.Set(b) self.assertEquals(a > b, c > d) self.assertEquals(a < b, c < d) self.assertEquals(a > b, c > b) self.assertEquals(a < b, c < b) self.assertEquals(a >= b, c >= d) self.assertEquals(a <= b, c <= d) self.assertEquals(a >= b, c >= b) self.assertEquals(a <= b, c <= b) self.assertEquals(a.issubset(b), c.issubset(d)) self.assertEquals(a.issuperset(b), c.issuperset(d)) self.assertEquals(a.issubset(b), c.issubset(b)) self.assertEquals(a.issuperset(b), c.issuperset(b))
def test_discard(self): a = hot_redis.Set(["wagwaan", "hot", "skull"]) i = len(a) b = "wagwaan" a.discard(b) self.assertEquals(len(a), i - 1) self.assertNotIn(b, a) self.assertEquals(a.discard("popcaan"), None)
def __init__(self, key): # Setting the key of the PN Counter Instance self.key = key self.add_set = GSet(get_add_set_key(key)) self.delete_set = GSet(get_delete_set_key(key)) # Getting/Setting the client list and type of the GCounter instance self.client_list = hot_redis.Set(key=get_client_list_key(key), client=connection) hot_redis.Dict(key=DATA_TYPES, client=connection)[key] = TWO_P_SET
def __init__(self, key): # Setting the key of the PN Counter Instance self.key = key self.pcounter = GCounter(get_pcounter_key(key)) self.ncounter = GCounter(get_ncounter_key(key)) # Getting/Setting the client list and type of the GCounter instance self.client_list = hot_redis.Set(key=get_client_list_key(key), client=connection) hot_redis.Dict(key=DATA_TYPES, client=connection)[key] = PN_COUNTER
def __init__(self, key): # Setting the key of the TwoPTwoPGraph Instance self.key = key self.nodes = TwoPSet(get_nodes_set_key(key)) self.edges = TwoPSet(get_edges_set_key(key)) # Getting/Setting the client list and type of the TwoPTwoPGraph instance self.client_list = hot_redis.Set(key=get_client_list_key(key), client=connection) hot_redis.Dict(key=DATA_TYPES, client=connection)[key] = TWO_P_TWO_P_GRAPH
def test_intersection_update(self): a = set(["wagwaan", "hot", "skull"]) b = set(["wagwaan", "flute", "don"]) c = set(["wagwaan", "worldstar", "hiphop"]) d = a.copy() d.intersection_update(b) e = hot_redis.Set(a) e.intersection_update(b) self.assertEquals(e, d) d = a.copy() d.intersection_update(b, c) e = hot_redis.Set(a) e.intersection_update(b, c) self.assertEquals(e, d) e = hot_redis.Set(a) e.intersection_update(hot_redis.Set(b), c) self.assertEquals(e, d) e = hot_redis.Set(a) e.intersection_update(b, hot_redis.Set(c)) self.assertEquals(e, d) e = hot_redis.Set(a) e.intersection_update(hot_redis.Set(b), hot_redis.Set(c)) self.assertEquals(e, d)
def create_new_client(): client_id = request.args.get('client_id') result_dict = dict() # Getting all client IDs already assigned all_clients = hot_redis.Set(key=ALL_CLIENTS, client=connection) # Checking if the client id in request is None or an empty string if client_id is None or len(client_id) is 0: client_id = generate_random_client_key() while client_id in all_clients: client_id = generate_random_client_key() # If client ID in request is valid checking if the client ID is already present else: if client_id in all_clients: result_dict['status'] = status_codes['existing_client_id'] return jsonify(result_dict) # Adding the client ID to the all clients set all_clients.add(client_id) result_dict['status'] = status_codes['success'] result_dict['client_id'] = client_id return jsonify(result_dict)
def __init__(self, key): self.key = key self.client_list = hot_redis.Set(key=get_client_list_key(key), client=connection) hot_redis.Dict(key=DATA_TYPES, client=connection)[key] = PN_SET self.pnset = hot_redis.Set(key=get_pnset_key, client=connection)
def test_contains(self): a = hot_redis.Set(["wagwaan", "hot", "skull"]) self.assertIn("wagwaan", a) self.assertNotIn("popcaan", a)
def test_len(self): a = set(["wagwaan", "hot", "skull"]) b = hot_redis.Set(a) self.assertEquals(len(a), len(b))
def test_clear(self): a = hot_redis.Set(["wagwaan", "hot", "skull"]) a.clear() self.assertEquals(len(a), 0)
def test_pop(self): a = hot_redis.Set(["wagwaan", "hot", "skull"]) i = len(a) b = a.pop() self.assertEquals(len(a), i - 1) self.assertNotIn(b, a)
def test_value(self): a = set(["wagwaan", "hot", "skull"]) self.assertEquals(hot_redis.Set(a), a)
def test_empty(self): self.assertEquals(hot_redis.Set(), set())