# Path: pydoop/hdfs/common.py
# BUFSIZE = 16384
# 
# Path: pydoop/test_utils.py
# UNI_CHR = _get_special_chr()
# 
# def make_random_data(size=_RANDOM_DATA_SIZE, printable=True):
#     randint = random.randint
#     start, stop = (32, 126) if printable else (0, 255)
#     return bytes(bytearray([randint(start, stop) for _ in range(size)]))
# 
# class FSTree(object):
#     """
#   >>> t = FSTree('root')
#   >>> d1 = t.add('d1')
#   >>> f1 = t.add('f1', 0)
#   >>> d2 = d1.add('d2')
#   >>> f2 = d2.add('f2', 0)
#   >>> for x in t.walk(): print x.name, x.kind
#   ...
#   root 1
#   d1 1
#   d2 1
#   f2 0
#   f1 0
#   """
# 
#     def __init__(self, name, kind=1):
#         assert kind in (0, 1)  # (file, dir)
#         self.name = name
#         self.kind = kind
#         if self.kind:
#             self.children = []
# 
#     def add(self, name, kind=1):
#         t = FSTree(name, kind)
#         self.children.append(t)
#         return t
# 
#     def walk(self):
#         yield self
#         if self.kind:
#             for c in self.children:
#                 for t in c.walk():
#                     yield t


import unittest
import tempfile
import os
import stat
import pydoop.hdfs as hdfs
from pydoop.utils.py3compat import czip
from threading import Thread
from pydoop.hdfs.common import BUFSIZE
from pydoop.test_utils import UNI_CHR, make_random_data, FSTree
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# END_COPYRIGHT

from __future__ import division




class TestHDFS(unittest.TestCase):

    def setUp(self):
        wd = tempfile.mkdtemp(suffix='_%s' % UNI_CHR)
        wd_bn = os.path.basename(wd)
        self.local_wd = "file:%s" % wd
        fs = hdfs.hdfs("default", 0)
        fs.create_directory(wd_bn)
        self.hdfs_wd = fs.get_path_info(wd_bn)["name"]
        fs.close()
        basenames = ["test_path_%d" % i for i in range(2)]
        self.local_paths = ["%s/%s" % (self.local_wd, bn) for bn in basenames]
        self.hdfs_paths = ["%s/%s" % (self.hdfs_wd, bn) for bn in basenames]
        self.data = make_random_data(

# Path: pydoop/hdfs/common.py
# BUFSIZE = 16384
# 
# Path: pydoop/test_utils.py
# UNI_CHR = _get_special_chr()
# 
# def make_random_data(size=_RANDOM_DATA_SIZE, printable=True):
#     randint = random.randint
#     start, stop = (32, 126) if printable else (0, 255)
#     return bytes(bytearray([randint(start, stop) for _ in range(size)]))
# 
# class FSTree(object):
#     """
#   >>> t = FSTree('root')
#   >>> d1 = t.add('d1')
#   >>> f1 = t.add('f1', 0)
#   >>> d2 = d1.add('d2')
#   >>> f2 = d2.add('f2', 0)
#   >>> for x in t.walk(): print x.name, x.kind
#   ...
#   root 1
#   d1 1
#   d2 1
#   f2 0
#   f1 0
#   """
# 
#     def __init__(self, name, kind=1):
#         assert kind in (0, 1)  # (file, dir)
#         self.name = name
#         self.kind = kind
#         if self.kind:
#             self.children = []
# 
#     def add(self, name, kind=1):
#         t = FSTree(name, kind)
#         self.children.append(t)
#         return t
# 
#     def walk(self):
#         yield self
#         if self.kind:
#             for c in self.children:
#                 for t in c.walk():
#                     yield t


# Path: test/hdfs/test_hdfs.py
import unittest
import tempfile
import os
import stat
import pydoop.hdfs as hdfs
from pydoop.utils.py3compat import czip
from threading import Thread
from pydoop.hdfs.common import BUFSIZE
from pydoop.test_utils import UNI_CHR, make_random_data, FSTree

#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# END_COPYRIGHT

from __future__ import division




class TestHDFS(unittest.TestCase):

    def setUp(self):
        wd = tempfile.mkdtemp(suffix='_%s' % UNI_CHR)
        wd_bn = os.path.basename(wd)
        self.local_wd = "file:%s" % wd
        fs = hdfs.hdfs("default", 0)
        fs.create_directory(wd_bn)
        self.hdfs_wd = fs.get_path_info(wd_bn)["name"]
        fs.close()
        basenames = ["test_path_%d" % i for i in range(2)]
        self.local_paths = ["%s/%s" % (self.local_wd, bn) for bn in basenames]
        self.hdfs_paths = ["%s/%s" % (self.hdfs_wd, bn) for bn in basenames]
        self.data = make_random_data(

            4 * BUFSIZE + BUFSIZE // 2, printable=False