-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a0f172
commit 3de9781
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# -*- coding: utf-8 -*- | ||
from unittest import TestCase | ||
|
||
from yarn_api_client import constants | ||
|
||
|
||
class ConstantsTestCase(TestCase): | ||
def test_stats_len(self): | ||
self.assertEqual(8, len(constants.YarnApplicationState)) | ||
self.assertEqual(6, len(constants.ApplicationState)) | ||
self.assertEqual(4, len(constants.FinalApplicationStatus)) | ||
self.assertEqual(14, len(constants.JobStateInternal)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# -*- coding: utf-8 -*- | ||
from tempfile import NamedTemporaryFile | ||
|
||
from mock import patch | ||
from unittest import TestCase | ||
|
||
from yarn_api_client import hadoop_conf | ||
|
||
empty_config = '<configuration></configuration>' | ||
|
||
yarn_site_xml = """\ | ||
<configuration> | ||
<property> | ||
<name>yarn.resourcemanager.webapp.address</name> | ||
<value>localhost:8022</value> | ||
</property> | ||
</configuration> | ||
""" | ||
|
||
|
||
class HadoopConfTestCase(TestCase): | ||
def test_parse(self): | ||
with NamedTemporaryFile() as f: | ||
f.write(yarn_site_xml) | ||
f.flush() | ||
|
||
key = 'yarn.resourcemanager.webapp.address' | ||
value = hadoop_conf.parse(f.name, key) | ||
self.assertEqual('localhost:8022', value) | ||
|
||
with NamedTemporaryFile() as f: | ||
f.write(empty_config) | ||
f.flush() | ||
|
||
key = 'yarn.resourcemanager.webapp.address' | ||
value = hadoop_conf.parse(f.name, key) | ||
self.assertEqual(None, value) | ||
|
||
def test_get_resource_host_port(self): | ||
with patch('yarn_api_client.hadoop_conf.parse') as parse_mock: | ||
parse_mock.return_value = 'example.com:8022' | ||
|
||
host_port = hadoop_conf.get_resource_manager_host_port() | ||
|
||
self.assertEqual(('example.com', '8022'), host_port) | ||
parse_mock.assert_called_with('/etc/hadoop/conf/yarn-site.xml', | ||
'yarn.resourcemanager.webapp.address') | ||
|
||
parse_mock.reset_mock() | ||
parse_mock.return_value = None | ||
|
||
host_port = hadoop_conf.get_resource_manager_host_port() | ||
self.assertIsNone(host_port) | ||
|
||
def test_get_jobhistory_host_port(self): | ||
with patch('yarn_api_client.hadoop_conf.parse') as parse_mock: | ||
parse_mock.return_value = 'example.com:8022' | ||
|
||
host_port = hadoop_conf.get_jobhistory_host_port() | ||
|
||
self.assertEqual(('example.com', '8022'), host_port) | ||
parse_mock.assert_called_with('/etc/hadoop/conf/mapred-site.xml', | ||
'mapreduce.jobhistory.webapp.address') | ||
|
||
parse_mock.reset_mock() | ||
parse_mock.return_value = None | ||
|
||
host_port = hadoop_conf.get_jobhistory_host_port() | ||
self.assertIsNone(host_port) | ||
|
||
def test_get_webproxy_host_port(self): | ||
with patch('yarn_api_client.hadoop_conf.parse') as parse_mock: | ||
parse_mock.return_value = 'example.com:8022' | ||
|
||
host_port = hadoop_conf.get_webproxy_host_port() | ||
|
||
self.assertEqual(('example.com', '8022'), host_port) | ||
parse_mock.assert_called_with('/etc/hadoop/conf/yarn-site.xml', | ||
'yarn.web-proxy.address') | ||
|
||
parse_mock.reset_mock() | ||
parse_mock.return_value = None | ||
|
||
host_port = hadoop_conf.get_webproxy_host_port() | ||
self.assertIsNone(host_port) |