|
@@ -20,9 +20,12 @@ package org.apache.hadoop.io.erasurecode.rawcoder;
|
|
|
import org.apache.hadoop.io.erasurecode.ECChunk;
|
|
|
import org.apache.hadoop.io.erasurecode.ErasureCoderOptions;
|
|
|
import org.apache.hadoop.io.erasurecode.TestCoderBase;
|
|
|
+import org.apache.hadoop.test.LambdaTestUtils;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
/**
|
|
|
* Raw coder test base with utilities.
|
|
|
*/
|
|
@@ -104,6 +107,28 @@ public abstract class TestRawCoderBase extends TestCoderBase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Test encode / decode after release(). It should raise IOException.
|
|
|
+ *
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ void testAfterRelease() throws Exception {
|
|
|
+ prepareCoders(true);
|
|
|
+ prepareBufferAllocator(true);
|
|
|
+
|
|
|
+ encoder.release();
|
|
|
+ final ECChunk[] data = prepareDataChunksForEncoding();
|
|
|
+ final ECChunk[] parity = prepareParityChunksForEncoding();
|
|
|
+ LambdaTestUtils.intercept(IOException.class, "closed",
|
|
|
+ () -> encoder.encode(data, parity));
|
|
|
+
|
|
|
+ decoder.release();
|
|
|
+ final ECChunk[] in = prepareInputChunksForDecoding(data, parity);
|
|
|
+ final ECChunk[] out = prepareOutputChunksForDecoding();
|
|
|
+ LambdaTestUtils.intercept(IOException.class, "closed",
|
|
|
+ () -> decoder.decode(in, getErasedIndexesForDecoding(), out));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testCodingWithErasingTooMany() {
|
|
|
try {
|
|
@@ -121,6 +146,16 @@ public abstract class TestRawCoderBase extends TestCoderBase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testIdempotentReleases() {
|
|
|
+ prepareCoders(true);
|
|
|
+
|
|
|
+ for (int i = 0; i < 3; i++) {
|
|
|
+ encoder.release();
|
|
|
+ decoder.release();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void performTestCoding(int chunkSize, boolean usingSlicedBuffer,
|
|
|
boolean useBadInput, boolean useBadOutput,
|
|
|
boolean allowChangeInputs) {
|
|
@@ -144,7 +179,11 @@ public abstract class TestRawCoderBase extends TestCoderBase {
|
|
|
ECChunk[] clonedDataChunks = cloneChunksWithData(dataChunks);
|
|
|
markChunks(dataChunks);
|
|
|
|
|
|
- encoder.encode(dataChunks, parityChunks);
|
|
|
+ try {
|
|
|
+ encoder.encode(dataChunks, parityChunks);
|
|
|
+ } catch (IOException e) {
|
|
|
+ Assert.fail("Should not get IOException: " + e.getMessage());
|
|
|
+ }
|
|
|
dumpChunks("Encoded parity chunks", parityChunks);
|
|
|
|
|
|
if (!allowChangeInputs) {
|
|
@@ -174,7 +213,12 @@ public abstract class TestRawCoderBase extends TestCoderBase {
|
|
|
}
|
|
|
|
|
|
dumpChunks("Decoding input chunks", inputChunks);
|
|
|
- decoder.decode(inputChunks, getErasedIndexesForDecoding(), recoveredChunks);
|
|
|
+ try {
|
|
|
+ decoder.decode(inputChunks, getErasedIndexesForDecoding(),
|
|
|
+ recoveredChunks);
|
|
|
+ } catch (IOException e) {
|
|
|
+ Assert.fail("Should not get IOException: " + e.getMessage());
|
|
|
+ }
|
|
|
dumpChunks("Decoded/recovered chunks", recoveredChunks);
|
|
|
|
|
|
if (!allowChangeInputs) {
|
|
@@ -268,7 +312,11 @@ public abstract class TestRawCoderBase extends TestCoderBase {
|
|
|
ECChunk[] dataChunks = prepareDataChunksForEncoding();
|
|
|
ECChunk[] parityChunks = prepareParityChunksForEncoding();
|
|
|
ECChunk[] clonedDataChunks = cloneChunksWithData(dataChunks);
|
|
|
- encoder.encode(dataChunks, parityChunks);
|
|
|
+ try {
|
|
|
+ encoder.encode(dataChunks, parityChunks);
|
|
|
+ } catch (IOException e) {
|
|
|
+ Assert.fail("Should not get IOException: " + e.getMessage());
|
|
|
+ }
|
|
|
verifyBufferPositionAtEnd(dataChunks);
|
|
|
|
|
|
// verify decode
|
|
@@ -277,7 +325,12 @@ public abstract class TestRawCoderBase extends TestCoderBase {
|
|
|
clonedDataChunks, parityChunks);
|
|
|
ensureOnlyLeastRequiredChunks(inputChunks);
|
|
|
ECChunk[] recoveredChunks = prepareOutputChunksForDecoding();
|
|
|
- decoder.decode(inputChunks, getErasedIndexesForDecoding(), recoveredChunks);
|
|
|
+ try {
|
|
|
+ decoder.decode(inputChunks, getErasedIndexesForDecoding(),
|
|
|
+ recoveredChunks);
|
|
|
+ } catch (IOException e) {
|
|
|
+ Assert.fail("Should not get IOException: " + e.getMessage());
|
|
|
+ }
|
|
|
verifyBufferPositionAtEnd(inputChunks);
|
|
|
}
|
|
|
|