示例#1
0
 def test_invalid_namenode_list(self):
     """Make sure robust to invalid namenode list."""
     MockHdfsConnector.set_n_failovers(-1)
     with self.assertRaises(HdfsConnectError) as e:
         getattr(HAHdfsClient(MockHdfsConnector, []), 'ls')('random')
     self.assertTrue('Unable to connect' in str(e.exception))
     with self.assertRaises(HdfsConnectError) as e:
         getattr(HAHdfsClient(MockHdfsConnector, [None]), 'ls')('random')
     self.assertTrue('Unable to connect' in str(e.exception))
示例#2
0
 def test_unhandled_exception(self):
     """Exercise the unhandled exception execution path."""
     MockHdfsConnector.set_n_failovers(-1)
     with self.assertRaises(HdfsMockError) as e:
         getattr(HAHdfsClient(MockHdfsConnector, [HC.WARP_TURTLE_NN1]),
                 'ls')('random')
     self.assertTrue('random HDFS exception' in str(e.exception))
示例#3
0
    def _try_failover_combos(self, func, *args, **kwargs):
        """Common tests for each of the known HDFS operators, with varying failover counts."""
        MockHdfsConnector.set_n_failovers(1)
        suj = HAHdfsClient(MockHdfsConnector, self.NAMENODES)
        self.assertTrue(getattr(suj, func)(*args, **kwargs))

        MockHdfsConnector.set_n_failovers(
            namenode_failover.MAX_FAILOVER_ATTEMPTS)
        suj = HAHdfsClient(MockHdfsConnector, self.NAMENODES)
        self.assertTrue(getattr(suj, func)(*args, **kwargs))

        MockHdfsConnector.set_n_failovers(
            namenode_failover.MAX_FAILOVER_ATTEMPTS + 1)
        suj = HAHdfsClient(MockHdfsConnector, self.NAMENODES)
        with self.assertRaises(MaxFailoversExceeded) as e:
            getattr(suj, func)(*args, **kwargs)
        self.assertEqual(len(e.exception.failed_exceptions),
                         namenode_failover.MAX_FAILOVER_ATTEMPTS + 1)
        self.assertEqual(e.exception.max_failover_attempts,
                         namenode_failover.MAX_FAILOVER_ATTEMPTS)
        self.assertEqual(e.exception.__name__, func)
        self.assertTrue('Failover attempts exceeded' in str(e.exception))
示例#4
0
    def test_client_pickles_correctly(self):
        """
        Does HAHdfsClient pickle properly?

        Check that all attributes are equal, with the exception of the HDFS object, which is fine
        as long as the types are the same.
        """
        client = HAHdfsClient(MockHdfsConnector, self.NAMENODES)
        client_unpickled = pickle.loads(pickle.dumps(client))
        self.assertEqual(client._connector_cls,
                         client_unpickled._connector_cls)
        self.assertEqual(client._list_of_namenodes,
                         client_unpickled._list_of_namenodes)
        self.assertEqual(client._index_of_nn, client_unpickled._index_of_nn)
        self.assertEqual(type(client._hdfs), type(client_unpickled._hdfs))