Skip to content

Commit 98882a0

Browse files
committed
close streams
1 parent 875e43e commit 98882a0

14 files changed

+74
-71
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testCreateStatistics() throws IOException {
9393

9494
fs.mkdirs(createDirectoryPath);
9595
fs.createNonRecursive(createFilePath, FsPermission
96-
.getDefault(), false, 1024, (short) 1, 1024, null);
96+
.getDefault(), false, 1024, (short) 1, 1024, null).close();
9797

9898
Map<String, Long> metricMap = fs.getInstrumentationMap();
9999
/*
@@ -119,7 +119,7 @@ public void testCreateStatistics() throws IOException {
119119
fs.mkdirs(path(getMethodName() + "Dir" + i));
120120
fs.createNonRecursive(path(getMethodName() + i),
121121
FsPermission.getDefault(), false, 1024, (short) 1,
122-
1024, null);
122+
1024, null).close();
123123
}
124124

125125
metricMap = fs.getInstrumentationMap();
@@ -162,7 +162,7 @@ public void testDeleteStatistics() throws IOException {
162162
files_deleted counters.
163163
*/
164164
fs.mkdirs(createDirectoryPath);
165-
fs.create(path(createDirectoryPath + getMethodName()));
165+
fs.create(path(createDirectoryPath + getMethodName())).close();
166166
fs.delete(createDirectoryPath, true);
167167

168168
Map<String, Long> metricMap = fs.getInstrumentationMap();
@@ -181,7 +181,7 @@ public void testDeleteStatistics() throws IOException {
181181
directories_deleted is called or not.
182182
*/
183183
fs.mkdirs(createDirectoryPath);
184-
fs.create(createFilePath);
184+
fs.create(createFilePath).close();
185185
fs.delete(createDirectoryPath, true);
186186
metricMap = fs.getInstrumentationMap();
187187

@@ -201,9 +201,9 @@ public void testOpenAppendRenameExists() throws IOException {
201201
Path createFilePath = path(getMethodName());
202202
Path destCreateFilePath = path(getMethodName() + "New");
203203

204-
fs.create(createFilePath);
205-
fs.open(createFilePath);
206-
fs.append(createFilePath);
204+
fs.create(createFilePath).close();
205+
fs.open(createFilePath).close();
206+
fs.append(createFilePath).close();
207207
assertTrue(fs.rename(createFilePath, destCreateFilePath));
208208

209209
Map<String, Long> metricMap = fs.getInstrumentationMap();
@@ -227,11 +227,11 @@ public void testOpenAppendRenameExists() throws IOException {
227227
//re-initialising Abfs to reset statistic values.
228228
fs.initialize(fs.getUri(), fs.getConf());
229229

230-
fs.create(destCreateFilePath);
230+
fs.create(destCreateFilePath).close();
231231

232232
for (int i = 0; i < NUMBER_OF_OPS; i++) {
233233
fs.open(destCreateFilePath);
234-
fs.append(destCreateFilePath);
234+
fs.append(destCreateFilePath).close();
235235
}
236236

237237
metricMap = fs.getInstrumentationMap();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void testAppendDirShouldFail() throws Exception {
4747
final AzureBlobFileSystem fs = getFileSystem();
4848
final Path filePath = path(TEST_FILE_PATH);
4949
fs.mkdirs(filePath);
50-
fs.append(filePath, 0);
50+
fs.append(filePath, 0).close();
5151
}
5252

5353
@Test
@@ -69,22 +69,22 @@ public void testAppendFileAfterDelete() throws Exception {
6969
ContractTestUtils.touch(fs, filePath);
7070
fs.delete(filePath, false);
7171

72-
fs.append(filePath);
72+
fs.append(filePath).close();
7373
}
7474

7575
@Test(expected = FileNotFoundException.class)
7676
public void testAppendDirectory() throws Exception {
7777
final AzureBlobFileSystem fs = getFileSystem();
7878
final Path folderPath = path(TEST_FOLDER_PATH);
7979
fs.mkdirs(folderPath);
80-
fs.append(folderPath);
80+
fs.append(folderPath).close();
8181
}
8282

8383
@Test
8484
public void testTracingForAppend() throws IOException {
8585
AzureBlobFileSystem fs = getFileSystem();
8686
Path testPath = path(TEST_FILE_PATH);
87-
fs.create(testPath);
87+
fs.create(testPath).close();
8888
fs.registerListener(new TracingHeaderValidator(
8989
fs.getAbfsStore().getAbfsConfiguration().getClientCorrelationId(),
9090
fs.getFileSystemId(), FSOperationType.APPEND, false, 0));

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void testSASTokenProviderEmptySASToken() throws Exception {
9999
this.getConfiguration().getRawConfiguration());
100100
intercept(SASTokenProviderException.class,
101101
() -> {
102-
testFs.create(new org.apache.hadoop.fs.Path("/testFile"));
102+
testFs.create(new org.apache.hadoop.fs.Path("/testFile")).close();
103103
});
104104
}
105105

@@ -114,7 +114,7 @@ public void testSASTokenProviderNullSASToken() throws Exception {
114114
testFs.initialize(fs.getUri(), this.getConfiguration().getRawConfiguration());
115115
intercept(SASTokenProviderException.class,
116116
()-> {
117-
testFs.create(new org.apache.hadoop.fs.Path("/testFile"));
117+
testFs.create(new org.apache.hadoop.fs.Path("/testFile")).close();
118118
});
119119
}
120120

@@ -297,7 +297,7 @@ private void executeOp(Path reqPath, AzureBlobFileSystem fs,
297297
fs.listStatus(reqPath);
298298
break;
299299
case CreatePath:
300-
fs.create(reqPath);
300+
fs.create(reqPath).close();
301301
break;
302302
case RenamePath:
303303
fs.rename(reqPath,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ public void testProperties() throws Exception {
398398
public void testSignatureMask() throws Exception {
399399
final AzureBlobFileSystem fs = getFileSystem();
400400
String src = String.format("/testABC/test%s.xt", UUID.randomUUID());
401-
fs.create(new Path(src));
401+
fs.create(new Path(src)).close();
402402
AbfsRestOperation abfsHttpRestOperation = fs.getAbfsClient()
403403
.renamePath(src, "/testABC" + "/abc.txt", null,
404404
getTestTracingContext(fs, false));

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -176,29 +176,30 @@ public void testReadWithFileNotFoundException() throws Exception {
176176
final Path testFilePath = path(methodName.getMethodName());
177177
testWriteOneByteToFile(testFilePath);
178178

179-
FSDataInputStream inputStream = fs.open(testFilePath, TEST_DEFAULT_BUFFER_SIZE);
180-
fs.delete(testFilePath, true);
181-
assertPathDoesNotExist(fs, "This path should not exist", testFilePath);
179+
try (FSDataInputStream inputStream = fs.open(testFilePath,
180+
TEST_DEFAULT_BUFFER_SIZE)) {
181+
fs.delete(testFilePath, true);
182+
assertPathDoesNotExist(fs, "This path should not exist", testFilePath);
182183

183-
intercept(FileNotFoundException.class,
184-
() -> inputStream.read(new byte[1]));
184+
intercept(FileNotFoundException.class, () -> inputStream.read(new byte[1]));
185+
}
185186
}
186187

187188
@Test
188189
public void testWriteWithFileNotFoundException() throws Exception {
189190
final AzureBlobFileSystem fs = getFileSystem();
190191
final Path testFilePath = path(methodName.getMethodName());
191192

192-
FSDataOutputStream stream = fs.create(testFilePath);
193-
assertPathExists(fs, "Path should exist", testFilePath);
194-
stream.write(TEST_BYTE);
193+
try (FSDataOutputStream stream = fs.create(testFilePath)) {
194+
assertPathExists(fs, "Path should exist", testFilePath);
195+
stream.write(TEST_BYTE);
195196

196-
fs.delete(testFilePath, true);
197-
assertPathDoesNotExist(fs, "This path should not exist", testFilePath);
197+
fs.delete(testFilePath, true);
198+
assertPathDoesNotExist(fs, "This path should not exist", testFilePath);
198199

199-
// trigger append call
200-
intercept(FileNotFoundException.class,
201-
() -> stream.close());
200+
// trigger append call
201+
intercept(FileNotFoundException.class, () -> stream.close());
202+
}
202203
}
203204

204205
@Test
@@ -209,14 +210,14 @@ public void testFlushWithFileNotFoundException() throws Exception {
209210
return;
210211
}
211212

212-
FSDataOutputStream stream = fs.create(testFilePath);
213-
assertPathExists(fs, "This path should exist", testFilePath);
213+
try (FSDataOutputStream stream = fs.create(testFilePath)) {
214+
assertPathExists(fs, "This path should exist", testFilePath);
214215

215-
fs.delete(testFilePath, true);
216-
assertPathDoesNotExist(fs, "This path should not exist", testFilePath);
216+
fs.delete(testFilePath, true);
217+
assertPathDoesNotExist(fs, "This path should not exist", testFilePath);
217218

218-
intercept(FileNotFoundException.class,
219-
() -> stream.close());
219+
intercept(FileNotFoundException.class, () -> stream.close());
220+
}
220221
}
221222

222223
private void testWriteOneByteToFile(Path testFilePath) throws Exception {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ public void testAbfsPathWithHost() throws IOException {
112112
Path pathwithouthost2 = new Path("/abfs/file2.txt");
113113

114114
// verify compatibility of this path format
115-
fs.create(pathWithHost1);
115+
fs.create(pathWithHost1).close();
116116
assertPathExists(fs, "This path should exist", pathwithouthost1);
117117

118-
fs.create(pathwithouthost2);
118+
fs.create(pathwithouthost2).close();
119119
assertPathExists(fs, "This path should exist", pathWithHost2);
120120

121121
// verify get
@@ -135,7 +135,7 @@ public void testLastModifiedTime() throws IOException {
135135
// Dividing and multiplying by 1000 to make last 3 digits 0.
136136
// It is observed that modification time is returned with last 3
137137
// digits 0 always.
138-
fs.create(testFilePath);
138+
fs.create(testFilePath).close();
139139
long createEndTime = System.currentTimeMillis();
140140
FileStatus fStat = fs.getFileStatus(testFilePath);
141141
long lastModifiedTime = fStat.getModificationTime();

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,13 @@ public void testTracingHeaderForAppendBlob() throws Exception {
316316

317317
byte[] buf = new byte[10];
318318
new Random().nextBytes(buf);
319-
FSDataOutputStream out = fs.create(new Path("/testFile"));
320-
((AbfsOutputStream) out.getWrappedStream()).registerListener(
321-
new TracingHeaderValidator(
322-
fs.getAbfsStore().getAbfsConfiguration().getClientCorrelationId(),
323-
fs.getFileSystemId(), FSOperationType.WRITE, false, 0,
324-
((AbfsOutputStream) out.getWrappedStream()).getStreamID()));
325-
out.write(buf);
326-
out.hsync();
319+
try (FSDataOutputStream out = fs.create(new Path("/testFile"))) {
320+
((AbfsOutputStream) out.getWrappedStream()).registerListener(new TracingHeaderValidator(
321+
fs.getAbfsStore().getAbfsConfiguration().getClientCorrelationId(), fs.getFileSystemId(), FSOperationType.WRITE, false, 0,
322+
((AbfsOutputStream) out.getWrappedStream()).getStreamID()));
323+
out.write(buf);
324+
out.hsync();
325+
}
327326
}
328327

329328
@Test
@@ -383,9 +382,10 @@ private byte[] getRandomBytesArray() {
383382

384383
private FSDataOutputStream getStreamAfterWrite(AzureBlobFileSystem fs, Path path, byte[] buffer, boolean enableFlush) throws IOException {
385384
fs.getAbfsStore().getAbfsConfiguration().setEnableFlush(enableFlush);
386-
FSDataOutputStream stream = fs.create(path);
387-
stream.write(buffer);
388-
return stream;
385+
try (FSDataOutputStream stream = fs.create(path)) {
386+
stream.write(buffer);
387+
return stream;
388+
}
389389
}
390390

391391
private void validate(InputStream stream, byte[] writeBuffer, boolean isEqual)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ DEFAULT_FS_AZURE_ENABLE_MKDIR_OVERWRITE && getIsNamespaceEnabled(
7979
getFileSystem()));
8080
final AzureBlobFileSystem fs = getFileSystem();
8181
Path path = path("testFilePath");
82-
fs.create(path);
82+
fs.create(path).close();
8383
assertTrue(fs.getFileStatus(path).isFile());
8484
intercept(FileAlreadyExistsException.class, () -> fs.mkdirs(path));
8585
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void testBlobDataReader() throws Exception {
158158
// TEST WRITE FILE
159159
try {
160160
abfsStore.openFileForWrite(existedFilePath, fs.getFsStatistics(), true,
161-
tracingContext);
161+
tracingContext).close();
162162
} catch (AbfsRestOperationException e) {
163163
assertEquals(AzureServiceErrorCode.AUTHORIZATION_PERMISSION_MISS_MATCH, e.getErrorCode());
164164
} finally {
@@ -171,7 +171,7 @@ private void prepareFiles(Path existedFilePath, Path existedFolderPath) throws I
171171
// create test files/folders to verify access control diff between
172172
// Blob data contributor and Blob data reader
173173
final AzureBlobFileSystem fs = this.getFileSystem();
174-
fs.create(existedFilePath);
174+
fs.create(existedFilePath).close();
175175
assertPathExists(fs, "This path should exist", existedFilePath);
176176
fs.mkdirs(existedFolderPath);
177177
assertPathExists(fs, "This path should exist", existedFolderPath);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public void testFilePermission() throws Exception {
8484
new FsPermission(FsAction.ALL, FsAction.NONE, FsAction.NONE));
8585
fs.removeDefaultAcl(path.getParent());
8686

87-
fs.create(path, permission, true, KILOBYTE, (short) 1, KILOBYTE - 1, null);
87+
fs.create(path, permission, true, KILOBYTE, (short) 1, KILOBYTE - 1,
88+
null).close();
8889
FileStatus status = fs.getFileStatus(path);
8990
Assert.assertEquals(permission.applyUMask(DEFAULT_UMASK_PERMISSION), status.getPermission());
9091
}

0 commit comments

Comments
 (0)