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
1de7ec2c
authored
Dec 10, 2019
by
olly
Committed by
Oliver Woodman
Dec 10, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Fix bug removing entries from CacheFileMetadataIndex
Issue: #6621 PiperOrigin-RevId: 284743414
parent
914a8df0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
1 deletions
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheFileMetadataIndex.java
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheFileMetadataIndexTest.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheFileMetadataIndex.java
View file @
1de7ec2c
...
@@ -43,7 +43,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
...
@@ -43,7 +43,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private
static
final
int
COLUMN_INDEX_LENGTH
=
1
;
private
static
final
int
COLUMN_INDEX_LENGTH
=
1
;
private
static
final
int
COLUMN_INDEX_LAST_TOUCH_TIMESTAMP
=
2
;
private
static
final
int
COLUMN_INDEX_LAST_TOUCH_TIMESTAMP
=
2
;
private
static
final
String
WHERE_NAME_EQUALS
=
COLUMN_
INDEX_
NAME
+
" = ?"
;
private
static
final
String
WHERE_NAME_EQUALS
=
COLUMN_NAME
+
" = ?"
;
private
static
final
String
[]
COLUMNS
=
private
static
final
String
[]
COLUMNS
=
new
String
[]
{
new
String
[]
{
...
...
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheFileMetadataIndexTest.java
0 → 100644
View file @
1de7ec2c
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
google
.
android
.
exoplayer2
.
upstream
.
cache
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.android.exoplayer2.database.DatabaseIOException
;
import
com.google.android.exoplayer2.testutil.TestUtil
;
import
java.util.HashSet
;
import
java.util.Map
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
/** Tests {@link CacheFileMetadataIndex}. */
@RunWith
(
AndroidJUnit4
.
class
)
public
class
CacheFileMetadataIndexTest
{
@Test
public
void
initiallyEmpty
()
throws
DatabaseIOException
{
CacheFileMetadataIndex
index
=
newInitializedIndex
();
assertThat
(
index
.
getAll
()).
isEmpty
();
}
@Test
public
void
insert
()
throws
DatabaseIOException
{
CacheFileMetadataIndex
index
=
newInitializedIndex
();
index
.
set
(
"name1"
,
/* length= */
123
,
/* lastTouchTimestamp= */
456
);
index
.
set
(
"name2"
,
/* length= */
789
,
/* lastTouchTimestamp= */
123
);
Map
<
String
,
CacheFileMetadata
>
all
=
index
.
getAll
();
assertThat
(
all
.
size
()).
isEqualTo
(
2
);
CacheFileMetadata
metadata
=
all
.
get
(
"name1"
);
assertThat
(
metadata
).
isNotNull
();
assertThat
(
metadata
.
length
).
isEqualTo
(
123
);
assertThat
(
metadata
.
lastTouchTimestamp
).
isEqualTo
(
456
);
metadata
=
all
.
get
(
"name2"
);
assertThat
(
metadata
).
isNotNull
();
assertThat
(
metadata
.
length
).
isEqualTo
(
789
);
assertThat
(
metadata
.
lastTouchTimestamp
).
isEqualTo
(
123
);
metadata
=
all
.
get
(
"name3"
);
assertThat
(
metadata
).
isNull
();
}
@Test
public
void
insertAndRemove
()
throws
DatabaseIOException
{
CacheFileMetadataIndex
index
=
newInitializedIndex
();
index
.
set
(
"name1"
,
/* length= */
123
,
/* lastTouchTimestamp= */
456
);
index
.
set
(
"name2"
,
/* length= */
789
,
/* lastTouchTimestamp= */
123
);
index
.
remove
(
"name1"
);
Map
<
String
,
CacheFileMetadata
>
all
=
index
.
getAll
();
assertThat
(
all
.
size
()).
isEqualTo
(
1
);
CacheFileMetadata
metadata
=
all
.
get
(
"name1"
);
assertThat
(
metadata
).
isNull
();
metadata
=
all
.
get
(
"name2"
);
assertThat
(
metadata
).
isNotNull
();
assertThat
(
metadata
.
length
).
isEqualTo
(
789
);
assertThat
(
metadata
.
lastTouchTimestamp
).
isEqualTo
(
123
);
index
.
remove
(
"name2"
);
all
=
index
.
getAll
();
assertThat
(
all
).
isEmpty
();
metadata
=
all
.
get
(
"name2"
);
assertThat
(
metadata
).
isNull
();
}
@Test
public
void
insertAndRemoveAll
()
throws
DatabaseIOException
{
CacheFileMetadataIndex
index
=
newInitializedIndex
();
index
.
set
(
"name1"
,
/* length= */
123
,
/* lastTouchTimestamp= */
456
);
index
.
set
(
"name2"
,
/* length= */
789
,
/* lastTouchTimestamp= */
123
);
HashSet
<
String
>
namesToRemove
=
new
HashSet
<>();
namesToRemove
.
add
(
"name1"
);
namesToRemove
.
add
(
"name2"
);
index
.
removeAll
(
namesToRemove
);
Map
<
String
,
CacheFileMetadata
>
all
=
index
.
getAll
();
assertThat
(
all
.
isEmpty
()).
isTrue
();
CacheFileMetadata
metadata
=
all
.
get
(
"name1"
);
assertThat
(
metadata
).
isNull
();
metadata
=
all
.
get
(
"name2"
);
assertThat
(
metadata
).
isNull
();
}
@Test
public
void
insertAndReplace
()
throws
DatabaseIOException
{
CacheFileMetadataIndex
index
=
newInitializedIndex
();
index
.
set
(
"name1"
,
/* length= */
123
,
/* lastTouchTimestamp= */
456
);
index
.
set
(
"name1"
,
/* length= */
789
,
/* lastTouchTimestamp= */
123
);
Map
<
String
,
CacheFileMetadata
>
all
=
index
.
getAll
();
assertThat
(
all
.
size
()).
isEqualTo
(
1
);
CacheFileMetadata
metadata
=
all
.
get
(
"name1"
);
assertThat
(
metadata
).
isNotNull
();
assertThat
(
metadata
.
length
).
isEqualTo
(
789
);
assertThat
(
metadata
.
lastTouchTimestamp
).
isEqualTo
(
123
);
}
private
static
CacheFileMetadataIndex
newInitializedIndex
()
throws
DatabaseIOException
{
CacheFileMetadataIndex
index
=
new
CacheFileMetadataIndex
(
TestUtil
.
getInMemoryDatabaseProvider
());
index
.
initialize
(
/* uid= */
1234
);
return
index
;
}
}
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