From f0e44b3a3fa20b0be5b1e1c2bae7b5a8b73f4828 Mon Sep 17 00:00:00 2001 From: Shashikant Banerjee Date: Mon, 27 May 2019 16:26:21 +0530 Subject: [PATCH] HDDS-1584. Fix TestFailureHandlingByClient tests. Contributed by Shashikant Banerjee (#845). --- .../rpc/TestFailureHandlingByClient.java | 67 ++++++++++--------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestFailureHandlingByClient.java b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestFailureHandlingByClient.java index 4bd4506b55..d95807689b 100644 --- a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestFailureHandlingByClient.java +++ b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/client/rpc/TestFailureHandlingByClient.java @@ -31,6 +31,7 @@ import org.apache.hadoop.ozone.client.ObjectStore; import org.apache.hadoop.ozone.client.OzoneClient; 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.OzoneOutputStream; 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.OmKeyLocationInfo; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import java.io.IOException; @@ -52,9 +52,7 @@ /** * Tests Close Container Exception handling by Ozone Client. - * XXX Disabled [HDDS-1323] */ -@Ignore public class TestFailureHandlingByClient { private MiniOzoneCluster cluster; @@ -214,12 +212,17 @@ public void testMultiBlockWritesWithIntermittentDnFailures() // get the name of a valid container Assert.assertTrue(key.getOutputStream() instanceof KeyOutputStream); - KeyOutputStream groupOutputStream = + KeyOutputStream keyOutputStream = (KeyOutputStream) key.getOutputStream(); - List locationInfoList = - groupOutputStream.getLocationInfoList(); - Assert.assertTrue(locationInfoList.size() == 6); - long containerId = locationInfoList.get(1).getContainerID(); + List streamEntryList = + keyOutputStream.getStreamEntries(); + + // 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 = cluster.getStorageContainerManager().getContainerManager() .getContainer(ContainerID.valueof(containerId)); @@ -243,8 +246,9 @@ public void testMultiBlockWritesWithIntermittentDnFailures() .setRefreshPipeline(true) .build(); OmKeyInfo keyInfo = cluster.getOzoneManager().lookupKey(keyArgs); - Assert.assertEquals(3 * data.getBytes().length, keyInfo.getDataSize()); - validateData(keyName, data.concat(data).concat(data).getBytes()); + Assert.assertEquals(4 * data.getBytes().length, keyInfo.getDataSize()); + validateData(keyName, + data.concat(data).concat(data).concat(data).getBytes()); shutdown(); } @@ -309,15 +313,15 @@ public void testContainerExclusionWithClosedContainerException() Assert.assertTrue(key.getOutputStream() instanceof KeyOutputStream); KeyOutputStream keyOutputStream = (KeyOutputStream) key.getOutputStream(); - List locationInfoList = - keyOutputStream.getLocationInfoList(); + List streamEntryList = + keyOutputStream.getStreamEntries(); // Assert that 1 block will be preallocated - Assert.assertEquals(1, locationInfoList.size()); + Assert.assertEquals(1, streamEntryList.size()); key.write(data.getBytes()); key.flush(); - long containerId = locationInfoList.get(0).getContainerID(); - BlockID blockId = locationInfoList.get(0).getBlockID(); + long containerId = streamEntryList.get(0).getBlockID().getContainerID(); + BlockID blockId = streamEntryList.get(0).getBlockID(); List containerIdList = new ArrayList<>(); containerIdList.add(containerId); @@ -368,15 +372,15 @@ public void testDatanodeExclusionWithMajorityCommit() throws Exception { Assert.assertTrue(key.getOutputStream() instanceof KeyOutputStream); KeyOutputStream keyOutputStream = (KeyOutputStream) key.getOutputStream(); - List locationInfoList = - keyOutputStream.getLocationInfoList(); + List streamEntryList = + keyOutputStream.getStreamEntries(); // Assert that 1 block will be preallocated - Assert.assertEquals(1, locationInfoList.size()); + Assert.assertEquals(1, streamEntryList.size()); key.write(data.getBytes()); key.flush(); - long containerId = locationInfoList.get(0).getContainerID(); - BlockID blockId = locationInfoList.get(0).getBlockID(); + long containerId = streamEntryList.get(0).getBlockID().getContainerID(); + BlockID blockId = streamEntryList.get(0).getBlockID(); ContainerInfo container = cluster.getStorageContainerManager().getContainerManager() .getContainer(ContainerID.valueof(containerId)); @@ -391,14 +395,16 @@ public void testDatanodeExclusionWithMajorityCommit() throws Exception { key.write(data.getBytes()); key.write(data.getBytes()); - // The close will just write to the buffer - key.close(); + key.flush(); + Assert.assertTrue(keyOutputStream.getExcludeList().getDatanodes() .contains(datanodes.get(0))); Assert.assertTrue( keyOutputStream.getExcludeList().getContainerIds().isEmpty()); Assert.assertTrue( keyOutputStream.getExcludeList().getPipelineIds().isEmpty()); + // The close will just write to the buffer + key.close(); OmKeyArgs keyArgs = new OmKeyArgs.Builder().setVolumeName(volumeName) .setBucketName(bucketName).setType(HddsProtos.ReplicationType.RATIS) @@ -430,15 +436,15 @@ public void testPipelineExclusionWithPipelineFailure() throws Exception { Assert.assertTrue(key.getOutputStream() instanceof KeyOutputStream); KeyOutputStream keyOutputStream = (KeyOutputStream) key.getOutputStream(); - List locationInfoList = - keyOutputStream.getLocationInfoList(); + List streamEntryList = + keyOutputStream.getStreamEntries(); // Assert that 1 block will be preallocated - Assert.assertEquals(1, locationInfoList.size()); + Assert.assertEquals(1, streamEntryList.size()); key.write(data.getBytes()); key.flush(); - long containerId = locationInfoList.get(0).getContainerID(); - BlockID blockId = locationInfoList.get(0).getBlockID(); + long containerId = streamEntryList.get(0).getBlockID().getContainerID(); + BlockID blockId = streamEntryList.get(0).getBlockID(); ContainerInfo container = cluster.getStorageContainerManager().getContainerManager() .getContainer(ContainerID.valueof(containerId)); @@ -447,21 +453,22 @@ public void testPipelineExclusionWithPipelineFailure() throws Exception { .getPipeline(container.getPipelineID()); List 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 cluster.shutdownHddsDatanode(datanodes.get(0)); cluster.shutdownHddsDatanode(datanodes.get(1)); key.write(data.getBytes()); key.write(data.getBytes()); - // The close will just write to the buffer - key.close(); + key.flush(); Assert.assertTrue(keyOutputStream.getExcludeList().getPipelineIds() .contains(pipeline.getId())); Assert.assertTrue( keyOutputStream.getExcludeList().getContainerIds().isEmpty()); Assert.assertTrue( keyOutputStream.getExcludeList().getDatanodes().isEmpty()); + // The close will just write to the buffer + key.close(); OmKeyArgs keyArgs = new OmKeyArgs.Builder().setVolumeName(volumeName) .setBucketName(bucketName).setType(HddsProtos.ReplicationType.RATIS)