'Make sure the right chunks get updated when we read a sparse file.'

def _testUpdateSparseImageChunks(self):

    filename = 'bigfile.txt'
    path = os.path.join(self.temp_dir, filename)
    chunksize = aff4_standard.AFF4SparseImage.chunksize
    contents = ('bigdata!' * chunksize)
    start_point = int((2.5 * chunksize))
    read_len = int((2.5 * chunksize))
    client_path = self.ClientPathToAFF4Path(path)
    with open(path, 'wb') as f:
        f.seek(start_point)
        f.write(contents)
    self.ListDirectoryOnClient(self.temp_dir)
    data = self.grr_fuse.Read(client_path, length=read_len, offset=start_point)
    self.assertEqual(data, contents[start_point:(start_point + read_len)], "Fuse    contents    don't    match.")
    fd = aff4.FACTORY.Open(client_path, mode='rw', token=self.token)
    self.assertIsInstance(fd, aff4_standard.AFF4SparseImage)
    missing_chunks = self.grr_fuse.GetMissingChunks(fd, length=(10 * chunksize), offset=0)
    self.assertEqual(missing_chunks, [0, 1, 5, 6, 7, 8, 9])
    fuse_contents = self.grr_fuse.Read(client_path, length=(8 * chunksize), offset=0)
    expected_contents = (('\x00' * start_point) + contents)[:(8 * chunksize)]
    self.assertEqual(fuse_contents, expected_contents, "Fuse    contents    don't    match.")
    expected_contents = (('Y' * start_point) + contents)[:(8 * chunksize)]
    with open(path, 'wb+') as f:
        f.seek(0)
        f.write(expected_contents)
    self.grr_fuse.max_age_before_refresh = datetime.timedelta(seconds=0)
    fuse_contents = self.grr_fuse.Read(client_path, length=len(contents), offset=0)
    self.assertEqual(fuse_contents, expected_contents, "Fuse    contents    don't    match.")
    self.grr_fuse.max_age_before_refresh = datetime.timedelta(seconds=30)
    missing_chunks = self.grr_fuse.GetMissingChunks(fd, length=(8 * chunksize), offset=0)
    self.assertEqual(missing_chunks, [])
