Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
dcae3c26
authored
May 04, 2020
by
olly
Committed by
Oliver Woodman
May 05, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
CronetDataSource: Use standard InterruptedIOException
PiperOrigin-RevId: 309710359
parent
5819b47f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
23 deletions
extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java
extensions/cronet/src/test/java/com/google/android/exoplayer2/ext/cronet/CronetDataSourceTest.java
extensions/cronet/src/main/java/com/google/android/exoplayer2/ext/cronet/CronetDataSource.java
View file @
dcae3c26
...
...
@@ -32,6 +32,7 @@ import com.google.android.exoplayer2.util.ConditionVariable;
import
com.google.android.exoplayer2.util.Log
;
import
com.google.android.exoplayer2.util.Predicate
;
import
java.io.IOException
;
import
java.io.InterruptedIOException
;
import
java.net.SocketTimeoutException
;
import
java.net.UnknownHostException
;
import
java.nio.ByteBuffer
;
...
...
@@ -83,14 +84,6 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
}
/** Thrown on catching an InterruptedException. */
public
static
final
class
InterruptedIOException
extends
IOException
{
public
InterruptedIOException
(
InterruptedException
e
)
{
super
(
e
);
}
}
static
{
ExoPlayerLibraryInfo
.
registerModule
(
"goog.exo.cronet"
);
}
...
...
@@ -440,7 +433,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
}
}
catch
(
InterruptedException
e
)
{
Thread
.
currentThread
().
interrupt
();
throw
new
OpenException
(
new
InterruptedIOException
(
e
),
dataSpec
,
Status
.
INVALID
);
throw
new
OpenException
(
new
InterruptedIOException
(),
dataSpec
,
Status
.
INVALID
);
}
// Check for a valid response code.
...
...
@@ -705,7 +698,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
if
(
dataSpec
.
httpBody
!=
null
&&
!
requestHeaders
.
containsKey
(
CONTENT_TYPE
))
{
throw
new
IOException
(
"HTTP request with non-empty body must set Content-Type"
);
}
// Set the Range header.
if
(
dataSpec
.
position
!=
0
||
dataSpec
.
length
!=
C
.
LENGTH_UNSET
)
{
StringBuilder
rangeValue
=
new
StringBuilder
();
...
...
@@ -769,7 +762,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
}
Thread
.
currentThread
().
interrupt
();
throw
new
HttpDataSourceException
(
new
InterruptedIOException
(
e
),
new
InterruptedIOException
(),
castNonNull
(
currentDataSpec
),
HttpDataSourceException
.
TYPE_READ
);
}
catch
(
SocketTimeoutException
e
)
{
...
...
extensions/cronet/src/test/java/com/google/android/exoplayer2/ext/cronet/CronetDataSourceTest.java
View file @
dcae3c26
...
...
@@ -40,6 +40,7 @@ import com.google.android.exoplayer2.upstream.TransferListener;
import
com.google.android.exoplayer2.util.Clock
;
import
com.google.android.exoplayer2.util.Util
;
import
java.io.IOException
;
import
java.io.InterruptedIOException
;
import
java.net.SocketTimeoutException
;
import
java.net.UnknownHostException
;
import
java.nio.ByteBuffer
;
...
...
@@ -284,7 +285,7 @@ public final class CronetDataSourceTest {
fail
(
"HttpDataSource.HttpDataSourceException expected"
);
}
catch
(
HttpDataSourceException
e
)
{
// Check for connection not automatically closed.
assertThat
(
e
.
getCause
()
instanceof
UnknownHostException
).
isFalse
(
);
assertThat
(
e
).
hasCauseThat
().
isNotInstanceOf
(
UnknownHostException
.
class
);
verify
(
mockUrlRequest
,
never
()).
cancel
();
verify
(
mockTransferListener
,
never
())
.
onTransferStart
(
dataSourceUnderTest
,
testDataSpec
,
/* isNetwork= */
true
);
...
...
@@ -322,7 +323,7 @@ public final class CronetDataSourceTest {
fail
(
"HttpDataSource.HttpDataSourceException expected"
);
}
catch
(
HttpDataSourceException
e
)
{
// Check for connection not automatically closed.
assertThat
(
e
.
getCause
()
instanceof
UnknownHostException
).
isTrue
(
);
assertThat
(
e
).
hasCauseThat
().
isInstanceOf
(
UnknownHostException
.
class
);
verify
(
mockUrlRequest
,
never
()).
cancel
();
verify
(
mockTransferListener
,
never
())
.
onTransferStart
(
dataSourceUnderTest
,
testDataSpec
,
/* isNetwork= */
true
);
...
...
@@ -338,7 +339,7 @@ public final class CronetDataSourceTest {
dataSourceUnderTest
.
open
(
testDataSpec
);
fail
(
"HttpDataSource.HttpDataSourceException expected"
);
}
catch
(
HttpDataSourceException
e
)
{
assertThat
(
e
instanceof
HttpDataSource
.
InvalidResponseCodeException
).
isTrue
(
);
assertThat
(
e
).
isInstanceOf
(
HttpDataSource
.
InvalidResponseCodeException
.
class
);
// Check for connection not automatically closed.
verify
(
mockUrlRequest
,
never
()).
cancel
();
verify
(
mockTransferListener
,
never
())
...
...
@@ -361,7 +362,7 @@ public final class CronetDataSourceTest {
dataSourceUnderTest
.
open
(
testDataSpec
);
fail
(
"HttpDataSource.HttpDataSourceException expected"
);
}
catch
(
HttpDataSourceException
e
)
{
assertThat
(
e
instanceof
HttpDataSource
.
InvalidContentTypeException
).
isTrue
(
);
assertThat
(
e
).
isInstanceOf
(
HttpDataSource
.
InvalidContentTypeException
.
class
);
// Check for connection not automatically closed.
verify
(
mockUrlRequest
,
never
()).
cancel
();
assertThat
(
testedContentTypes
).
hasSize
(
1
);
...
...
@@ -892,8 +893,8 @@ public final class CronetDataSourceTest {
fail
();
}
catch
(
HttpDataSourceException
e
)
{
// Expected.
assertThat
(
e
instanceof
CronetDataSource
.
OpenException
).
isTrue
(
);
assertThat
(
e
.
getCause
()
instanceof
SocketTimeoutException
).
isTrue
(
);
assertThat
(
e
).
isInstanceOf
(
CronetDataSource
.
OpenException
.
class
);
assertThat
(
e
).
hasCauseThat
().
isInstanceOf
(
SocketTimeoutException
.
class
);
assertThat
(((
CronetDataSource
.
OpenException
)
e
).
cronetConnectionStatus
)
.
isEqualTo
(
TEST_CONNECTION_STATUS
);
timedOutLatch
.
countDown
();
...
...
@@ -932,8 +933,8 @@ public final class CronetDataSourceTest {
fail
();
}
catch
(
HttpDataSourceException
e
)
{
// Expected.
assertThat
(
e
instanceof
CronetDataSource
.
OpenException
).
isTrue
(
);
assertThat
(
e
.
getCause
()
instanceof
CronetDataSource
.
InterruptedIOException
).
isTrue
(
);
assertThat
(
e
).
isInstanceOf
(
CronetDataSource
.
OpenException
.
class
);
assertThat
(
e
).
hasCauseThat
().
isInstanceOf
(
InterruptedIOException
.
class
);
assertThat
(((
CronetDataSource
.
OpenException
)
e
).
cronetConnectionStatus
)
.
isEqualTo
(
TEST_INVALID_CONNECTION_STATUS
);
timedOutLatch
.
countDown
();
...
...
@@ -1005,8 +1006,8 @@ public final class CronetDataSourceTest {
fail
();
}
catch
(
HttpDataSourceException
e
)
{
// Expected.
assertThat
(
e
instanceof
CronetDataSource
.
OpenException
).
isTrue
(
);
assertThat
(
e
.
getCause
()
instanceof
SocketTimeoutException
).
isTrue
(
);
assertThat
(
e
).
isInstanceOf
(
CronetDataSource
.
OpenException
.
class
);
assertThat
(
e
).
hasCauseThat
().
isInstanceOf
(
SocketTimeoutException
.
class
);
openExceptions
.
getAndIncrement
();
timedOutLatch
.
countDown
();
}
...
...
@@ -1231,7 +1232,7 @@ public final class CronetDataSourceTest {
fail
();
}
catch
(
HttpDataSourceException
e
)
{
// Expected.
assertThat
(
e
.
getCause
()
instanceof
CronetDataSource
.
InterruptedIOException
).
isTrue
(
);
assertThat
(
e
).
hasCauseThat
().
isInstanceOf
(
InterruptedIOException
.
class
);
timedOutLatch
.
countDown
();
}
}
...
...
@@ -1262,7 +1263,7 @@ public final class CronetDataSourceTest {
fail
();
}
catch
(
HttpDataSourceException
e
)
{
// Expected.
assertThat
(
e
.
getCause
()
instanceof
CronetDataSource
.
InterruptedIOException
).
isTrue
(
);
assertThat
(
e
).
hasCauseThat
().
isInstanceOf
(
InterruptedIOException
.
class
);
timedOutLatch
.
countDown
();
}
}
...
...
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