Commit 305d8aa0 by olly Committed by Oliver Woodman

Improve ExoCacheTest.

- Use FakeDataSource as the upstream source.
- Actually validate that caching is happening (i.e. reads happen
  on the upstream source only if the data hasn't been read through
  the CacheDataSource already).
- Move FakeClock to sit alongside the other Fake classes.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=118555903
parent 6cc507aa
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.google.android.exoplayer.util; package com.google.android.exoplayer.testutil;
import com.google.android.exoplayer.util.Clock;
/** /**
* A {@link Clock} that returns a fixed value specified in the constructor. * A {@link Clock} that returns a fixed value specified in the constructor.
......
...@@ -42,6 +42,7 @@ import java.util.ArrayList; ...@@ -42,6 +42,7 @@ import java.util.ArrayList;
public final class FakeDataSource implements DataSource { public final class FakeDataSource implements DataSource {
private final ArrayList<Segment> segments; private final ArrayList<Segment> segments;
private final ArrayList<DataSpec> openedDataSpecs;
private final boolean simulateUnknownLength; private final boolean simulateUnknownLength;
private final long totalLength; private final long totalLength;
...@@ -59,6 +60,7 @@ public final class FakeDataSource implements DataSource { ...@@ -59,6 +60,7 @@ public final class FakeDataSource implements DataSource {
totalLength += segment.length; totalLength += segment.length;
} }
this.totalLength = totalLength; this.totalLength = totalLength;
openedDataSpecs = new ArrayList<DataSpec>();
} }
@Override @Override
...@@ -67,11 +69,12 @@ public final class FakeDataSource implements DataSource { ...@@ -67,11 +69,12 @@ public final class FakeDataSource implements DataSource {
// DataSpec requires a matching close call even if open fails. // DataSpec requires a matching close call even if open fails.
opened = true; opened = true;
uri = dataSpec.uri; uri = dataSpec.uri;
openedDataSpecs.add(dataSpec);
// If the source knows that the request is unsatisfiable then fail. // If the source knows that the request is unsatisfiable then fail.
if (dataSpec.position >= totalLength) { if (dataSpec.position >= totalLength) {
throw new IOException("Unsatisfiable position"); throw new IOException("Unsatisfiable position");
} else if (dataSpec.length != C.LENGTH_UNBOUNDED } else if (dataSpec.length != C.LENGTH_UNBOUNDED
&& dataSpec.position + dataSpec.length >= totalLength) { && dataSpec.position + dataSpec.length > totalLength) {
throw new IOException("Unsatisfiable range"); throw new IOException("Unsatisfiable range");
} }
// Scan through the segments, configuring them for the current read. // Scan through the segments, configuring them for the current read.
...@@ -148,6 +151,17 @@ public final class FakeDataSource implements DataSource { ...@@ -148,6 +151,17 @@ public final class FakeDataSource implements DataSource {
} }
} }
/**
* @return The {@link DataSpec} instances passed to {@link #open(DataSpec)} since the last call
* to this method.
*/
public DataSpec[] getAndClearOpenedDataSpecs() {
DataSpec[] dataSpecs = new DataSpec[openedDataSpecs.size()];
openedDataSpecs.toArray(dataSpecs);
openedDataSpecs.clear();
return dataSpecs;
}
private static class Segment { private static class Segment {
public final IOException exception; public final IOException exception;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment