Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
e11b7aff
Commit
e11b7aff
authored
May 31, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure that file is released back to pool when seek fails
Closes gh-9370
parent
a9fc18bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
7 deletions
+53
-7
RandomAccessDataFile.java
...pringframework/boot/loader/data/RandomAccessDataFile.java
+7
-7
RandomAccessDataFileTests.java
...framework/boot/loader/data/RandomAccessDataFileTests.java
+46
-0
No files found.
spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/data/RandomAccessDataFile.java
View file @
e11b7aff
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -170,11 +170,11 @@ public class RandomAccessDataFile implements RandomAccessData {
return
-
1
;
}
RandomAccessFile
file
=
this
.
file
;
if
(
file
==
null
)
{
file
=
RandomAccessDataFile
.
this
.
filePool
.
acquire
();
file
.
seek
(
RandomAccessDataFile
.
this
.
offset
+
this
.
position
);
}
try
{
if
(
file
==
null
)
{
file
=
RandomAccessDataFile
.
this
.
filePool
.
acquire
();
file
.
seek
(
RandomAccessDataFile
.
this
.
offset
+
this
.
position
);
}
if
(
b
==
null
)
{
int
rtn
=
file
.
read
();
moveOn
(
rtn
==
-
1
?
0
:
1
);
...
...
@@ -185,7 +185,7 @@ public class RandomAccessDataFile implements RandomAccessData {
}
}
finally
{
if
(
this
.
file
==
null
)
{
if
(
this
.
file
==
null
&&
file
!=
null
)
{
RandomAccessDataFile
.
this
.
filePool
.
release
(
file
);
}
}
...
...
@@ -229,7 +229,7 @@ public class RandomAccessDataFile implements RandomAccessData {
* Manage a pool that can be used to perform concurrent reads on the underlying
* {@link RandomAccessFile}.
*/
private
class
FilePool
{
class
FilePool
{
private
final
int
size
;
...
...
spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/data/RandomAccessDataFileTests.java
View file @
e11b7aff
...
...
@@ -18,7 +18,9 @@ package org.springframework.boot.loader.data;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.RandomAccessFile
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
...
...
@@ -35,10 +37,20 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.junit.rules.ExpectedException
;
import
org.junit.rules.TemporaryFolder
;
import
org.mockito.internal.util.MockUtil
;
import
org.mockito.invocation.InvocationOnMock
;
import
org.mockito.stubbing.Answer
;
import
org.springframework.boot.loader.data.RandomAccessData.ResourceAccess
;
import
org.springframework.boot.loader.data.RandomAccessDataFile.FilePool
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
BDDMockito
.
willAnswer
;
import
static
org
.
mockito
.
BDDMockito
.
willThrow
;
import
static
org
.
mockito
.
Matchers
.
anyLong
;
import
static
org
.
mockito
.
Mockito
.
spy
;
/**
* Tests for {@link RandomAccessDataFile}.
...
...
@@ -309,4 +321,38 @@ public class RandomAccessDataFileTests {
assertThat
(
queue
.
size
()).
isEqualTo
(
0
);
}
@Test
public
void
seekFailuresDoNotPreventSubsequentReads
()
throws
Exception
{
FilePool
filePool
=
(
FilePool
)
ReflectionTestUtils
.
getField
(
this
.
file
,
"filePool"
);
FilePool
spiedPool
=
spy
(
filePool
);
ReflectionTestUtils
.
setField
(
this
.
file
,
"filePool"
,
spiedPool
);
willAnswer
(
new
Answer
<
RandomAccessFile
>()
{
@Override
public
RandomAccessFile
answer
(
InvocationOnMock
invocation
)
throws
Throwable
{
RandomAccessFile
originalFile
=
(
RandomAccessFile
)
invocation
.
callRealMethod
();
if
(
new
MockUtil
().
isSpy
(
originalFile
))
{
return
originalFile
;
}
RandomAccessFile
spiedFile
=
spy
(
originalFile
);
willThrow
(
new
IOException
(
"Seek failed"
)).
given
(
spiedFile
)
.
seek
(
anyLong
());
return
spiedFile
;
}
}).
given
(
spiedPool
).
acquire
();
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
try
{
this
.
file
.
getInputStream
(
ResourceAccess
.
PER_READ
).
read
();
fail
(
"Read should fail due to exception from seek"
);
}
catch
(
IOException
ex
)
{
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment