/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * 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. */ package org.apache.hadoop.hdfs; import junit.framework.TestCase; import java.io.*; import java.util.Random; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; /** * This class tests if FSOutputSummer works correctly. */ public class TestFSOutputSummer extends TestCase { private static final long seed = 0xDEADBEEFL; private static final int BYTES_PER_CHECKSUM = 10; private static final int BLOCK_SIZE = 2*BYTES_PER_CHECKSUM; private static final int HALF_CHUNK_SIZE = BYTES_PER_CHECKSUM/2; private static final int FILE_SIZE = 2*BLOCK_SIZE-1; private static final short NUM_OF_DATANODES = 2; private byte[] expected = new byte[FILE_SIZE]; private byte[] actual = new byte[FILE_SIZE]; private FileSystem fileSys; /* create a file, write all data at once */ private void writeFile1(Path name) throws Exception { FSDataOutputStream stm = fileSys.create(name, true, fileSys.getConf().getInt("io.file.buffer.size", 4096), NUM_OF_DATANODES, BLOCK_SIZE); stm.write(expected); stm.close(); checkFile(name); cleanupFile(name); } /* create a file, write data chunk by chunk */ private void writeFile2(Path name) throws Exception { FSDataOutputStream stm = fileSys.create(name, true, fileSys.getConf().getInt("io.file.buffer.size", 4096), NUM_OF_DATANODES, BLOCK_SIZE); int i=0; for( ;i