|
16 | 16 | * limitations under the License. |
17 | 17 | */ |
18 | 18 |
|
19 | | -package org.apache.hadoop.hdfs; |
| 19 | +package org.apache.hadoop.io.erasurecode; |
20 | 20 |
|
21 | 21 | import org.apache.hadoop.conf.Configuration; |
22 | | -import org.apache.hadoop.hdfs.protocol.ErasureCodingPolicy; |
23 | | -import org.apache.hadoop.io.erasurecode.CodecUtil; |
24 | | -import org.apache.hadoop.io.erasurecode.ErasureCoderOptions; |
25 | 22 | import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureDecoder; |
26 | 23 | import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureEncoder; |
27 | 24 | import org.junit.Test; |
|
32 | 29 |
|
33 | 30 | public class TestErasureCodingEncodeAndDecode { |
34 | 31 |
|
35 | | - private static int CHUNCK = 1024; |
36 | | - private final ErasureCodingPolicy ecPolicy = StripedFileTestUtil.getDefaultECPolicy(); |
37 | | - private final int dataBlocks = ecPolicy.getNumDataUnits(); |
38 | | - private final int parityBlocks = ecPolicy.getNumParityUnits(); |
39 | | - private final int totalBlocks = ecPolicy.getNumDataUnits() + ecPolicy.getNumParityUnits(); |
40 | | - private final Configuration conf = new HdfsConfiguration(); |
| 32 | + private final static int CHUNCK = 1024; |
| 33 | + private final static int DATAB_LOCKS = 6; |
| 34 | + private final static int PARITY_BLOCKS = 3; |
| 35 | + private final static int TOTAL_BLOCKS = DATAB_LOCKS + PARITY_BLOCKS; |
41 | 36 |
|
42 | 37 | @Test |
43 | 38 | public void testEncodeAndDecode() throws Exception { |
44 | | - int totalBytes = CHUNCK * dataBlocks; |
| 39 | + Configuration conf = new Configuration(); |
| 40 | + int totalBytes = CHUNCK * DATAB_LOCKS; |
45 | 41 | Random random = new Random(); |
46 | 42 | byte[] tmpBytes = new byte[totalBytes]; |
47 | 43 | random.nextBytes(tmpBytes); |
48 | | - byte[][] data = new byte[dataBlocks][CHUNCK]; |
49 | | - for (int i = 0; i < dataBlocks; i++) { |
| 44 | + byte[][] data = new byte[DATAB_LOCKS][CHUNCK]; |
| 45 | + for (int i = 0; i < DATAB_LOCKS; i++) { |
50 | 46 | System.arraycopy(tmpBytes, i * CHUNCK, data[i], 0, CHUNCK); |
51 | 47 | } |
52 | | - ErasureCoderOptions coderOptions = new ErasureCoderOptions(dataBlocks, parityBlocks); |
| 48 | + ErasureCoderOptions coderOptions = new ErasureCoderOptions(DATAB_LOCKS, PARITY_BLOCKS); |
53 | 49 |
|
54 | 50 | // 1 Encode |
55 | 51 | RawErasureEncoder encoder = |
56 | | - CodecUtil.createRawEncoder(conf, ecPolicy.getCodecName(), coderOptions); |
57 | | - byte[][] parity = new byte[parityBlocks][CHUNCK]; |
| 52 | + CodecUtil.createRawEncoder(conf, ErasureCodeConstants.RS_CODEC_NAME, coderOptions); |
| 53 | + byte[][] parity = new byte[PARITY_BLOCKS][CHUNCK]; |
58 | 54 | encoder.encode(data, parity); |
59 | 55 |
|
60 | 56 | // 2 Compose the complete data |
61 | | - byte[][] all = new byte[dataBlocks + parityBlocks][CHUNCK]; |
62 | | - for (int i = 0; i < dataBlocks; i++) { |
| 57 | + byte[][] all = new byte[DATAB_LOCKS + PARITY_BLOCKS][CHUNCK]; |
| 58 | + for (int i = 0; i < DATAB_LOCKS; i++) { |
63 | 59 | System.arraycopy(data[i], 0, all[i], 0, CHUNCK); |
64 | 60 | } |
65 | | - for (int i = 0; i < parityBlocks; i++) { |
66 | | - System.arraycopy(parity[i], 0, all[i + dataBlocks], 0, CHUNCK); |
| 61 | + for (int i = 0; i < PARITY_BLOCKS; i++) { |
| 62 | + System.arraycopy(parity[i], 0, all[i + DATAB_LOCKS], 0, CHUNCK); |
67 | 63 | } |
68 | 64 |
|
69 | 65 | // 3 Decode |
70 | | - RawErasureDecoder rawDecoder = CodecUtil.createRawDecoder(conf, |
71 | | - ecPolicy.getCodecName(), coderOptions); |
72 | | - byte[][] backup = new byte[parityBlocks][CHUNCK]; |
73 | | - for (int i = 0; i < totalBlocks; i++) { |
74 | | - for (int j = 0; j < totalBlocks; j++) { |
75 | | - for (int k = 0; k < totalBlocks; k++) { |
| 66 | + RawErasureDecoder rawDecoder = |
| 67 | + CodecUtil.createRawDecoder(conf, ErasureCodeConstants.RS_CODEC_NAME, coderOptions); |
| 68 | + byte[][] backup = new byte[PARITY_BLOCKS][CHUNCK]; |
| 69 | + for (int i = 0; i < TOTAL_BLOCKS; i++) { |
| 70 | + for (int j = 0; j < TOTAL_BLOCKS; j++) { |
| 71 | + for (int k = 0; k < TOTAL_BLOCKS; k++) { |
76 | 72 | int[] erasedIndexes; |
77 | 73 | if (i == j && j == k) { |
78 | 74 | erasedIndexes = new int[]{i}; |
|
0 commit comments