def test_status(self): with HTTMock(local_mock): query = MyriaQuery(COMPLETED_QUERY_ID, connection=self.connection) self.assertEqual(query.status, STATE_SUCCESS) query = MyriaQuery(RUNNING_QUERY_ID, connection=self.connection) self.assertEqual(query.status, STATE_RUNNING)
def test_connection(self): with HTTMock(local_mock): query = MyriaQuery(QUERY_ID, connection=self.connection) self.assertEqual(query.connection, self.connection) query = MyriaQuery(QUERY_ID) self.assertEqual(query.connection, MyriaRelation.DefaultConnection)
def test_dict(self): with HTTMock(local_mock): query = MyriaQuery(COMPLETED_QUERY_ID, connection=self.connection) self.assertEqual(query.to_dict(), TUPLES) query = MyriaQuery(RUNNING_QUERY_ID, connection=self.connection, timeout=1) self.assertRaises(requests.Timeout, query.to_dict)
def test_dict(self): with HTTMock(local_mock): query = MyriaQuery(COMPLETED_QUERY_ID, connection=self.connection) self.assertEqual(query.to_dict(), TUPLES) for i in xrange(1, len(TUPLES) + 1): self.assertEqual(query.to_dict(limit=i), TUPLES[:i]) query = MyriaQuery(RUNNING_QUERY_ID, connection=self.connection, timeout=1) self.assertRaises(requests.Timeout, query.to_dict)
def test_timeout(self): timeout = 999 with HTTMock(local_mock): query = MyriaQuery(QUERY_ID, connection=self.connection, timeout=timeout) self.assertEqual(query.timeout, timeout)
def test_parallel_import(self): with HTTMock(local_mock): schema = MyriaSchema({'columnNames': ['column'], 'columnTypes': ['INT_TYPE']}) relation = MyriaRelation(FULL_NAME, schema=schema, connection=self.connection) work = [('http://input-uri-0', 0), ('http://input-uri-1', 1)] query = MyriaQuery.parallel_import(relation, work) self.assertEquals(query.status, 'Unittest-Success')
def test_wait_for_completion(self): with HTTMock(local_mock): query = MyriaQuery(COMPLETED_QUERY_ID, connection=self.connection, wait_for_completion=True, timeout=1) self.assertEqual(query.status, STATE_SUCCESS) self.assertRaises(requests.Timeout, MyriaQuery, RUNNING_QUERY_ID, connection=self.connection, wait_for_completion=True, timeout=1) query = MyriaQuery(RUNNING_QUERY_ID, connection=self.connection, wait_for_completion=False, timeout=1) self.assertRaises(requests.Timeout, query.wait_for_completion)
def execute(self, relation=None): """ Execute a query :param relation: The name of a relation in which the result is stored :return: A MyriaQuery instance that represents the executing query """ from myria.query import MyriaQuery if not self.result: json = self._store(relation or _unique_name(self.query)).to_json() self.result = MyriaQuery.submit_plan(json, self.connection) return self.result
def test_parallel_import(self): with HTTMock(local_mock): schema = MyriaSchema({ 'columnNames': ['column'], 'columnTypes': ['INT_TYPE'] }) relation = MyriaRelation(FULL_NAME, schema=schema, connection=self.connection) work = [('http://input-uri-0', 0), ('http://input-uri-1', 1)] query = MyriaQuery.parallel_import(relation, work) self.assertEquals(query.status, 'Unittest-Success')
def test_name(self): with HTTMock(local_mock): query = MyriaQuery(COMPLETED_QUERY_ID, connection=self.connection) self.assertEqual(query.name, FULL_NAME) self.assertEqual(query.qualified_name, QUALIFIED_NAME) self.assertEqual(query.components, NAME_COMPONENTS)
def test_submit_program(self): with HTTMock(local_mock): program = 'COMPLETE_IMMEDIATELY = empty(i:int);\n' \ 'store(COMPLETE_IMMEDIATELY, COMPLETE_IMMEDIATELY);' query = MyriaQuery.submit(program, connection=self.connection) self.assertEquals(query.status, STATE_SUCCESS)
def test_submit_plan(self): with HTTMock(local_mock): plan = 'This is a Myria JSON plan' query = MyriaQuery.submit_plan(plan, connection=self.connection) self.assertEquals(query.status, 'Unittest-Success')
def sink(self): """ Execute the query but ignore its results """ from myria.query import MyriaQuery return MyriaQuery.submit_plan(self._sink().to_json(), self.connection)
def test_id(self): with HTTMock(local_mock): query = MyriaQuery(QUERY_ID, connection=self.connection) self.assertEqual(query.query_id, QUERY_ID)