Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ediskandarov committed Jun 7, 2014
1 parent 8a0f172 commit 3de9781
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/test_constants.py
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))
85 changes: 85 additions & 0 deletions tests/test_hadoop_conf.py
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)

0 comments on commit 3de9781

Please sign in to comment.