Skip to content

Commit 757cc1f

Browse files
committed
move TestErasureCodingEncodeAndDecode to hadoop-common
1 parent af86d38 commit 757cc1f

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed
Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616
* limitations under the License.
1717
*/
1818

19-
package org.apache.hadoop.hdfs;
19+
package org.apache.hadoop.io.erasurecode;
2020

2121
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;
2522
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureDecoder;
2623
import org.apache.hadoop.io.erasurecode.rawcoder.RawErasureEncoder;
2724
import org.junit.Test;
@@ -32,47 +29,46 @@
3229

3330
public class TestErasureCodingEncodeAndDecode {
3431

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;
4136

4237
@Test
4338
public void testEncodeAndDecode() throws Exception {
44-
int totalBytes = CHUNCK * dataBlocks;
39+
Configuration conf = new Configuration();
40+
int totalBytes = CHUNCK * DATAB_LOCKS;
4541
Random random = new Random();
4642
byte[] tmpBytes = new byte[totalBytes];
4743
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++) {
5046
System.arraycopy(tmpBytes, i * CHUNCK, data[i], 0, CHUNCK);
5147
}
52-
ErasureCoderOptions coderOptions = new ErasureCoderOptions(dataBlocks, parityBlocks);
48+
ErasureCoderOptions coderOptions = new ErasureCoderOptions(DATAB_LOCKS, PARITY_BLOCKS);
5349

5450
// 1 Encode
5551
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];
5854
encoder.encode(data, parity);
5955

6056
// 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++) {
6359
System.arraycopy(data[i], 0, all[i], 0, CHUNCK);
6460
}
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);
6763
}
6864

6965
// 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++) {
7672
int[] erasedIndexes;
7773
if (i == j && j == k) {
7874
erasedIndexes = new int[]{i};

0 commit comments

Comments
 (0)