def test_insert_both(self): ''' Testa sincronização de dados inseridos em ambos. ''' from helpers import new_elastic_item, new_cassandra_item for i in xrange(10): uid = uuid.uuid4() new_cassandra_item(self.cass, uid) uid = uuid.uuid4() new_elastic_item(self.elas, uid) time.sleep(5) START_TIME = datetime.fromtimestamp(0) NEW_TIME = datetime.now() SYNC_INTERVAL = 2 itens = self.cass.select_all(START_TIME, NEW_TIME) self.assertEqual(len(itens), 10) itens = self.elas.select_all(START_TIME, NEW_TIME) self.assertEqual(itens['total'], 10) for i in xrange(3): NEW_TIME = datetime.now() sync(START_TIME, NEW_TIME, SYNC_INTERVAL, self.cass, self.elas) START_TIME = NEW_TIME time.sleep(SYNC_INTERVAL) itens = self.cass.select_all(datetime.fromtimestamp(0), datetime.now()) self.assertEqual(len(itens), 20) itens = self.elas.select_all(datetime.fromtimestamp(0), datetime.now()) self.assertEqual(itens['total'], 20)
def test_insert(self): ''' Testa a inserção de um item aleatório. ''' from helpers import new_cassandra_item uid = uuid.uuid4() new_cassandra_item(self.cass, uid) response = self.cass.select(uid) self.assertTrue('body' in response)
def test_select_all(self): ''' Testa inserir e recuperar vários itens. ''' from helpers import new_cassandra_item for i in xrange(500): new_cassandra_item(self.cass, uuid.uuid4()) time.sleep(1) start = datetime.now() for i in xrange(500): new_cassandra_item(self.cass, uuid.uuid4()) end = datetime.now() time.sleep(1) for i in xrange(500): new_cassandra_item(self.cass, uuid.uuid4()) time.sleep(5) response = self.cass.select_all(0, datetime.now()) self.assertEqual(len(response), 1500) response = self.cass.select_all(start, end) self.assertEqual(len(response), 500)
def test_insert_cass_to_elas(self): ''' Testa sincronização de dados de inserções no Cassandra para o Elastic Search. ''' from helpers import new_cassandra_item for i in xrange(10): uid = uuid.uuid4() new_cassandra_item(self.cass, uid) response = self.cass.select(uid) self.assertTrue('body' in response) START_TIME = datetime.fromtimestamp(0) NEW_TIME = datetime.now() itens = self.elas.select_all(START_TIME, NEW_TIME) self.assertEqual(itens['total'], 0) sync(START_TIME, NEW_TIME, self.cass, self.elas) itens = self.elas.select_all(START_TIME, NEW_TIME) self.assertEqual(itens['total'], 10)
def test_update(self): ''' Testa update de um item. ''' from helpers import new_cassandra_item uid = uuid.uuid4() item = new_cassandra_item(self.cass, uid) item = self.cass.select(uid) name = 'updated1 \o/' item['name'] = name self.cass.update(data=item) item = self.cass.select(uid=uid) self.assertEqual(item['name'], name)