Skip to content

Commit 6b28cf2

Browse files
author
Mehakmeet Singh
committed
Logging, closing, modifying
1 parent 72f7181 commit 6b28cf2

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsOutputStream.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
import com.google.common.annotations.VisibleForTesting;
3737
import com.google.common.base.Preconditions;
3838

39-
import org.apache.hadoop.fs.FileSystem.Statistics;
4039
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException;
4140
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AzureBlobFileSystemException;
4241
import org.apache.hadoop.io.ElasticByteBufferPool;
42+
import org.apache.hadoop.fs.FileSystem.Statistics;
4343
import org.apache.hadoop.fs.FSExceptionMessages;
4444
import org.apache.hadoop.fs.StreamCapabilities;
4545
import org.apache.hadoop.fs.Syncable;
@@ -51,7 +51,6 @@
5151
*/
5252
public class AbfsOutputStream extends OutputStream implements Syncable, StreamCapabilities {
5353
private final AbfsClient client;
54-
private final Statistics statistics;
5554
private final String path;
5655
private long position;
5756
private boolean closed;
@@ -82,6 +81,8 @@ public class AbfsOutputStream extends OutputStream implements Syncable, StreamCa
8281
private final ElasticByteBufferPool byteBufferPool
8382
= new ElasticByteBufferPool();
8483

84+
private final Statistics statistics;
85+
8586
public AbfsOutputStream(
8687
final AbfsClient client,
8788
final Statistics statistics,

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/AbstractAbfsTestWithTimeout.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,15 @@ protected boolean validateContent(AzureBlobFileSystem fs, Path path,
110110

111111
while (valueOfContentAtPos != -1 && pos < lenOfOriginalByteArray) {
112112
if (originalByteArray[pos] != valueOfContentAtPos) {
113+
assertEquals("Mismatch in content validation at position {}", pos,
114+
originalByteArray[pos], valueOfContentAtPos);
113115
return false;
114116
}
115117
valueOfContentAtPos = (byte) in.read();
116118
pos++;
117119
}
118120
if (valueOfContentAtPos != -1) {
121+
assertEquals("Expected end of file", -1, valueOfContentAtPos);
119122
return false;
120123
}
121124
return true;

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAbfsStreamStatistics.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
package org.apache.hadoop.fs.azurebfs;
2020

21-
import org.junit.Assert;
2221
import org.junit.Test;
2322

23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
2426
import org.apache.hadoop.fs.FSDataOutputStream;
2527
import org.apache.hadoop.fs.FSDataInputStream;
2628
import org.apache.hadoop.fs.FileSystem;
@@ -35,6 +37,9 @@ public class ITestAbfsStreamStatistics extends AbstractAbfsIntegrationTest {
3537
public ITestAbfsStreamStatistics() throws Exception {
3638
}
3739

40+
private static final Logger LOG =
41+
LoggerFactory.getLogger(ITestAbfsStreamStatistics.class);
42+
3843
private static int LARGE_NUMBER_OF_OPS = 1000000;
3944

4045
/***
@@ -71,20 +76,29 @@ public void testAbfsStreamOps() throws Exception {
7176
//Test for a single write operation
7277
assertReadWriteOps("write", 1, statistics.getWriteOps());
7378

79+
//Flushing output stream to see content to read
80+
outForOneOperation.hflush();
7481
inForOneOperation = fs.open(smallOperationsFile);
75-
inForOneOperation.read(testReadWriteOps.getBytes(), 0,
82+
statistics.reset();
83+
int result = inForOneOperation.read(testReadWriteOps.getBytes(), 0,
7684
testReadWriteOps.getBytes().length);
7785

78-
//Test for a single read operation
79-
assertReadWriteOps("read", 1, statistics.getReadOps());
86+
LOG.info("Result of Read operation : {}", result);
87+
/*
88+
Testing if 2 read_ops value is coming after reading full content from a
89+
file (3 if anything to read from Buffer too).
90+
Reason: read() call gives read_ops=1,
91+
reading from AbfsClient(http GET) gives read_ops=2.
92+
*/
93+
assertReadWriteOps("read", 2, statistics.getReadOps());
8094

8195
} finally {
82-
IOUtils.cleanupWithLogger(null, inForOneOperation,
96+
IOUtils.cleanupWithLogger(LOG, inForOneOperation,
8397
outForOneOperation);
8498
}
8599

86100
//Validating if content is being written in the smallOperationsFile
87-
Assert.assertEquals("Mismatch in content validation", true,
101+
assertTrue("Mismatch in content validation",
88102
validateContent(fs, smallOperationsFile,
89103
testReadWriteOps.getBytes()));
90104

@@ -101,6 +115,8 @@ public void testAbfsStreamOps() throws Exception {
101115
//Creating the String for content Validation
102116
largeOperationsValidationString.append(testReadWriteOps);
103117
}
118+
LOG.info("Number of bytes of Large data written: {}",
119+
largeOperationsValidationString.toString().getBytes().length);
104120

105121
//Test for 1000000 write operations
106122
assertReadWriteOps("write", largeValue, statistics.getWriteOps());
@@ -116,12 +132,11 @@ public void testAbfsStreamOps() throws Exception {
116132
assertReadWriteOps("read", largeValue, statistics.getReadOps());
117133

118134
} finally {
119-
IOUtils.cleanupWithLogger(null, inForLargeOperations,
135+
IOUtils.cleanupWithLogger(LOG, inForLargeOperations,
120136
outForLargeOperations);
121137
}
122-
123138
//Validating if content is being written in largeOperationsFile
124-
Assert.assertTrue("Mismatch in content validation",
139+
assertTrue("Mismatch in content validation",
125140
validateContent(fs, largeOperationsFile,
126141
largeOperationsValidationString.toString().getBytes()));
127142

@@ -137,8 +152,7 @@ public void testAbfsStreamOps() throws Exception {
137152

138153
private void assertReadWriteOps(String operation, long expectedValue,
139154
long actualValue) {
140-
Assert
141-
.assertEquals("Mismatch in " + operation + " operations", expectedValue,
142-
actualValue);
155+
assertEquals("Mismatch in " + operation + " operations", expectedValue,
156+
actualValue);
143157
}
144158
}

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/ITestAzureBlobFileSystemOauth.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.io.InputStream;
2323
import java.util.Map;
2424

25-
import org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys;
2625
import org.junit.Assume;
2726
import org.junit.Test;
2827

@@ -31,6 +30,7 @@
3130
import org.apache.hadoop.fs.FSDataOutputStream;
3231
import org.apache.hadoop.fs.FileStatus;
3332
import org.apache.hadoop.fs.Path;
33+
import org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys;
3434
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException;
3535
import org.apache.hadoop.fs.azurebfs.contracts.services.AzureServiceErrorCode;
3636
import org.apache.hadoop.fs.azurebfs.services.AuthType;
@@ -146,6 +146,8 @@ public void testBlobDataReader() throws Exception {
146146
abfsStore.openFileForWrite(EXISTED_FILE_PATH, fs.getFsStatistics(), true);
147147
} catch (AbfsRestOperationException e) {
148148
assertEquals(AzureServiceErrorCode.AUTHORIZATION_PERMISSION_MISS_MATCH, e.getErrorCode());
149+
} finally {
150+
abfsStore.close();
149151
}
150152

151153
}

0 commit comments

Comments
 (0)