HDDS-1584. Fix TestFailureHandlingByClient tests. Contributed by Shashikant Banerjee (#845).

This commit is contained in:
Shashikant Banerjee 2019-05-27 16:26:21 +05:30
parent a3745c59a3
commit f0e44b3a3f

View File

@ -31,6 +31,7 @@
import org.apache.hadoop.ozone.client.ObjectStore; import org.apache.hadoop.ozone.client.ObjectStore;
import org.apache.hadoop.ozone.client.OzoneClient; import org.apache.hadoop.ozone.client.OzoneClient;
import org.apache.hadoop.ozone.client.OzoneClientFactory; import org.apache.hadoop.ozone.client.OzoneClientFactory;
import org.apache.hadoop.ozone.client.io.BlockOutputStreamEntry;
import org.apache.hadoop.ozone.client.io.KeyOutputStream; import org.apache.hadoop.ozone.client.io.KeyOutputStream;
import org.apache.hadoop.ozone.client.io.OzoneOutputStream; import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
import org.apache.hadoop.ozone.container.ContainerTestHelper; import org.apache.hadoop.ozone.container.ContainerTestHelper;
@ -38,7 +39,6 @@
import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo; import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
@ -52,9 +52,7 @@
/** /**
* Tests Close Container Exception handling by Ozone Client. * Tests Close Container Exception handling by Ozone Client.
* XXX Disabled [HDDS-1323]
*/ */
@Ignore
public class TestFailureHandlingByClient { public class TestFailureHandlingByClient {
private MiniOzoneCluster cluster; private MiniOzoneCluster cluster;
@ -214,12 +212,17 @@ public void testMultiBlockWritesWithIntermittentDnFailures()
// get the name of a valid container // get the name of a valid container
Assert.assertTrue(key.getOutputStream() instanceof KeyOutputStream); Assert.assertTrue(key.getOutputStream() instanceof KeyOutputStream);
KeyOutputStream groupOutputStream = KeyOutputStream keyOutputStream =
(KeyOutputStream) key.getOutputStream(); (KeyOutputStream) key.getOutputStream();
List<OmKeyLocationInfo> locationInfoList = List<BlockOutputStreamEntry> streamEntryList =
groupOutputStream.getLocationInfoList(); keyOutputStream.getStreamEntries();
Assert.assertTrue(locationInfoList.size() == 6);
long containerId = locationInfoList.get(1).getContainerID(); // Assert that 6 block will be preallocated
Assert.assertEquals(6, streamEntryList.size());
key.write(data.getBytes());
key.flush();
long containerId = streamEntryList.get(0).getBlockID().getContainerID();
BlockID blockId = streamEntryList.get(0).getBlockID();
ContainerInfo container = ContainerInfo container =
cluster.getStorageContainerManager().getContainerManager() cluster.getStorageContainerManager().getContainerManager()
.getContainer(ContainerID.valueof(containerId)); .getContainer(ContainerID.valueof(containerId));
@ -243,8 +246,9 @@ public void testMultiBlockWritesWithIntermittentDnFailures()
.setRefreshPipeline(true) .setRefreshPipeline(true)
.build(); .build();
OmKeyInfo keyInfo = cluster.getOzoneManager().lookupKey(keyArgs); OmKeyInfo keyInfo = cluster.getOzoneManager().lookupKey(keyArgs);
Assert.assertEquals(3 * data.getBytes().length, keyInfo.getDataSize()); Assert.assertEquals(4 * data.getBytes().length, keyInfo.getDataSize());
validateData(keyName, data.concat(data).concat(data).getBytes()); validateData(keyName,
data.concat(data).concat(data).concat(data).getBytes());
shutdown(); shutdown();
} }
@ -309,15 +313,15 @@ public void testContainerExclusionWithClosedContainerException()
Assert.assertTrue(key.getOutputStream() instanceof KeyOutputStream); Assert.assertTrue(key.getOutputStream() instanceof KeyOutputStream);
KeyOutputStream keyOutputStream = KeyOutputStream keyOutputStream =
(KeyOutputStream) key.getOutputStream(); (KeyOutputStream) key.getOutputStream();
List<OmKeyLocationInfo> locationInfoList = List<BlockOutputStreamEntry> streamEntryList =
keyOutputStream.getLocationInfoList(); keyOutputStream.getStreamEntries();
// Assert that 1 block will be preallocated // Assert that 1 block will be preallocated
Assert.assertEquals(1, locationInfoList.size()); Assert.assertEquals(1, streamEntryList.size());
key.write(data.getBytes()); key.write(data.getBytes());
key.flush(); key.flush();
long containerId = locationInfoList.get(0).getContainerID(); long containerId = streamEntryList.get(0).getBlockID().getContainerID();
BlockID blockId = locationInfoList.get(0).getBlockID(); BlockID blockId = streamEntryList.get(0).getBlockID();
List<Long> containerIdList = new ArrayList<>(); List<Long> containerIdList = new ArrayList<>();
containerIdList.add(containerId); containerIdList.add(containerId);
@ -368,15 +372,15 @@ public void testDatanodeExclusionWithMajorityCommit() throws Exception {
Assert.assertTrue(key.getOutputStream() instanceof KeyOutputStream); Assert.assertTrue(key.getOutputStream() instanceof KeyOutputStream);
KeyOutputStream keyOutputStream = KeyOutputStream keyOutputStream =
(KeyOutputStream) key.getOutputStream(); (KeyOutputStream) key.getOutputStream();
List<OmKeyLocationInfo> locationInfoList = List<BlockOutputStreamEntry> streamEntryList =
keyOutputStream.getLocationInfoList(); keyOutputStream.getStreamEntries();
// Assert that 1 block will be preallocated // Assert that 1 block will be preallocated
Assert.assertEquals(1, locationInfoList.size()); Assert.assertEquals(1, streamEntryList.size());
key.write(data.getBytes()); key.write(data.getBytes());
key.flush(); key.flush();
long containerId = locationInfoList.get(0).getContainerID(); long containerId = streamEntryList.get(0).getBlockID().getContainerID();
BlockID blockId = locationInfoList.get(0).getBlockID(); BlockID blockId = streamEntryList.get(0).getBlockID();
ContainerInfo container = ContainerInfo container =
cluster.getStorageContainerManager().getContainerManager() cluster.getStorageContainerManager().getContainerManager()
.getContainer(ContainerID.valueof(containerId)); .getContainer(ContainerID.valueof(containerId));
@ -391,14 +395,16 @@ public void testDatanodeExclusionWithMajorityCommit() throws Exception {
key.write(data.getBytes()); key.write(data.getBytes());
key.write(data.getBytes()); key.write(data.getBytes());
// The close will just write to the buffer key.flush();
key.close();
Assert.assertTrue(keyOutputStream.getExcludeList().getDatanodes() Assert.assertTrue(keyOutputStream.getExcludeList().getDatanodes()
.contains(datanodes.get(0))); .contains(datanodes.get(0)));
Assert.assertTrue( Assert.assertTrue(
keyOutputStream.getExcludeList().getContainerIds().isEmpty()); keyOutputStream.getExcludeList().getContainerIds().isEmpty());
Assert.assertTrue( Assert.assertTrue(
keyOutputStream.getExcludeList().getPipelineIds().isEmpty()); keyOutputStream.getExcludeList().getPipelineIds().isEmpty());
// The close will just write to the buffer
key.close();
OmKeyArgs keyArgs = new OmKeyArgs.Builder().setVolumeName(volumeName) OmKeyArgs keyArgs = new OmKeyArgs.Builder().setVolumeName(volumeName)
.setBucketName(bucketName).setType(HddsProtos.ReplicationType.RATIS) .setBucketName(bucketName).setType(HddsProtos.ReplicationType.RATIS)
@ -430,15 +436,15 @@ public void testPipelineExclusionWithPipelineFailure() throws Exception {
Assert.assertTrue(key.getOutputStream() instanceof KeyOutputStream); Assert.assertTrue(key.getOutputStream() instanceof KeyOutputStream);
KeyOutputStream keyOutputStream = KeyOutputStream keyOutputStream =
(KeyOutputStream) key.getOutputStream(); (KeyOutputStream) key.getOutputStream();
List<OmKeyLocationInfo> locationInfoList = List<BlockOutputStreamEntry> streamEntryList =
keyOutputStream.getLocationInfoList(); keyOutputStream.getStreamEntries();
// Assert that 1 block will be preallocated // Assert that 1 block will be preallocated
Assert.assertEquals(1, locationInfoList.size()); Assert.assertEquals(1, streamEntryList.size());
key.write(data.getBytes()); key.write(data.getBytes());
key.flush(); key.flush();
long containerId = locationInfoList.get(0).getContainerID(); long containerId = streamEntryList.get(0).getBlockID().getContainerID();
BlockID blockId = locationInfoList.get(0).getBlockID(); BlockID blockId = streamEntryList.get(0).getBlockID();
ContainerInfo container = ContainerInfo container =
cluster.getStorageContainerManager().getContainerManager() cluster.getStorageContainerManager().getContainerManager()
.getContainer(ContainerID.valueof(containerId)); .getContainer(ContainerID.valueof(containerId));
@ -447,21 +453,22 @@ public void testPipelineExclusionWithPipelineFailure() throws Exception {
.getPipeline(container.getPipelineID()); .getPipeline(container.getPipelineID());
List<DatanodeDetails> datanodes = pipeline.getNodes(); List<DatanodeDetails> datanodes = pipeline.getNodes();
// Two nodes, next write will hit AlraedyClosedException , the pipeline // Two nodes, next write will hit AlreadyClosedException , the pipeline
// will be added in the exclude list // will be added in the exclude list
cluster.shutdownHddsDatanode(datanodes.get(0)); cluster.shutdownHddsDatanode(datanodes.get(0));
cluster.shutdownHddsDatanode(datanodes.get(1)); cluster.shutdownHddsDatanode(datanodes.get(1));
key.write(data.getBytes()); key.write(data.getBytes());
key.write(data.getBytes()); key.write(data.getBytes());
// The close will just write to the buffer key.flush();
key.close();
Assert.assertTrue(keyOutputStream.getExcludeList().getPipelineIds() Assert.assertTrue(keyOutputStream.getExcludeList().getPipelineIds()
.contains(pipeline.getId())); .contains(pipeline.getId()));
Assert.assertTrue( Assert.assertTrue(
keyOutputStream.getExcludeList().getContainerIds().isEmpty()); keyOutputStream.getExcludeList().getContainerIds().isEmpty());
Assert.assertTrue( Assert.assertTrue(
keyOutputStream.getExcludeList().getDatanodes().isEmpty()); keyOutputStream.getExcludeList().getDatanodes().isEmpty());
// The close will just write to the buffer
key.close();
OmKeyArgs keyArgs = new OmKeyArgs.Builder().setVolumeName(volumeName) OmKeyArgs keyArgs = new OmKeyArgs.Builder().setVolumeName(volumeName)
.setBucketName(bucketName).setType(HddsProtos.ReplicationType.RATIS) .setBucketName(bucketName).setType(HddsProtos.ReplicationType.RATIS)