def test_target_path_exists_rename_fails_hadoopcli(self, remove): testpath = self._test_file() try: if self.fs.exists(testpath): self.fs.remove(testpath, skip_trash=True) except BaseException: if self.fs.exists(self._test_dir()): self.fs.remove(self._test_dir(), skip_trash=True) with hdfs.HdfsAtomicWritePipe(testpath) as fobj: fobj.write(b'test1') fobj = hdfs.HdfsAtomicWritePipe(testpath) self.assertRaises(hdfs.HDFSCliError, fobj.close)
def test_target_path_exists_rename_fails_snakebite(self, remove, rename): rename.side_effect = hdfs.get_autoconfig_client(threading.local()).rename testpath = self._test_file() try: if self.fs.exists(testpath): self.fs.remove(testpath, skip_trash=True) except: if self.fs.exists(self._test_dir()): self.fs.remove(self._test_dir(), skip_trash=True) with hdfs.HdfsAtomicWritePipe(testpath) as fobj: fobj.write(b'test1') fobj = hdfs.HdfsAtomicWritePipe(testpath) self.assertRaises(HdfsAtomicWriteError, fobj.close)
def test_target_path_exists_rename_fails_snakebite(self, remove, rename): rename.side_effect = hdfs.get_autoconfig_client( threading.local()).rename with hdfs.HdfsAtomicWritePipe(self.path) as fobj: fobj.write(b'test1') fobj = hdfs.HdfsAtomicWriteDirPipe(self.path) self.assertRaises(HdfsAtomicWriteError, fobj.close)
def test_target_path_exists(self): testpath = self._test_file() try: if self.fs.exists(testpath): self.fs.remove(testpath, skip_trash=True) except BaseException: if self.fs.exists(self._test_dir()): self.fs.remove(self._test_dir(), skip_trash=True) with hdfs.HdfsAtomicWritePipe(testpath) as fobj: fobj.write(b'test1') with hdfs.HdfsAtomicWritePipe(testpath) as fobj: fobj.write(b'test2') with HdfsReadPipe(testpath) as read_pipe: contents = read_pipe.read() self.assertEqual(b'test2', contents)
def test_atomicity(self): testpath = self._test_dir() if self.fs.exists(testpath): self.fs.remove(testpath, skip_trash=True) pipe = hdfs.HdfsAtomicWritePipe(testpath) self.assertFalse(self.fs.exists(testpath)) pipe.close() self.assertTrue(self.fs.exists(testpath))
def test_target_path_exists(self): with hdfs.HdfsAtomicWriteDirPipe(self.path) as fobj: fobj.write(b'test1') with hdfs.HdfsAtomicWritePipe(self.path) as fobj: fobj.write(b'test2') with HdfsReadPipe(self.path) as read_pipe: contents = read_pipe.read() self.assertEqual(b'test2', contents)
def test_with_close(self): testpath = self._test_file() try: if self.fs.exists(testpath): self.fs.remove(testpath, skip_trash=True) except BaseException: if self.fs.exists(self._test_dir()): self.fs.remove(self._test_dir(), skip_trash=True) with hdfs.HdfsAtomicWritePipe(testpath) as fobj: fobj.write(b'hej') self.assertTrue(self.fs.exists(testpath))
def test_target_path_exists_rename_fails_hadoopcli(self, remove): with hdfs.HdfsAtomicWritePipe(self.path) as fobj: fobj.write(b'test1') fobj = hdfs.HdfsAtomicWriteDirPipe(self.path) self.assertRaises(hdfs.HDFSCliError, fobj.close)
def foo(): with hdfs.HdfsAtomicWritePipe(self.path) as fobj: fobj.write(b'hej') raise TestException('Test triggered exception')
def test_with_close(self): with hdfs.HdfsAtomicWritePipe(self.path) as fobj: fobj.write(b'hej') self.assertTrue(self.fs.exists(self.path))