|
16 | 16 |
|
17 | 17 | package okhttp3;
|
18 | 18 |
|
19 |
| -import java.io.File; |
20 | 19 | import java.io.IOException;
|
21 | 20 | import java.net.CookieManager;
|
22 | 21 | import java.net.HttpURLConnection;
|
|
25 | 24 | import java.security.cert.Certificate;
|
26 | 25 | import java.text.DateFormat;
|
27 | 26 | import java.text.SimpleDateFormat;
|
| 27 | +import java.util.ArrayList; |
28 | 28 | import java.util.Date;
|
29 | 29 | import java.util.Iterator;
|
30 | 30 | import java.util.List;
|
|
44 | 44 | import okio.Buffer;
|
45 | 45 | import okio.BufferedSink;
|
46 | 46 | import okio.BufferedSource;
|
| 47 | +import okio.FileSystem; |
| 48 | +import okio.ForwardingFileSystem; |
47 | 49 | import okio.GzipSink;
|
48 | 50 | import okio.Okio;
|
49 | 51 | import okio.Path;
|
@@ -84,6 +86,7 @@ public final class CacheTest {
|
84 | 86 | platform.assumeNotBouncyCastle();
|
85 | 87 |
|
86 | 88 | server.setProtocolNegotiationEnabled(false);
|
| 89 | + fileSystem.emulateUnix(); |
87 | 90 | cache = new Cache(Path.get("/cache/"), Integer.MAX_VALUE, fileSystem);
|
88 | 91 | client = clientTestRule.newClientBuilder()
|
89 | 92 | .cache(cache)
|
@@ -2610,6 +2613,53 @@ private RecordedRequest assertConditionallyCached(MockResponse response) throws
|
2610 | 2613 | lastModifiedDate);
|
2611 | 2614 | }
|
2612 | 2615 |
|
| 2616 | + @Test |
| 2617 | + public void testPublicPathConstructor() throws IOException { |
| 2618 | + List<String> events = new ArrayList<>(); |
| 2619 | + |
| 2620 | + fileSystem.createDirectories(cache.directoryPath()); |
| 2621 | + |
| 2622 | + fileSystem.createDirectories(cache.directoryPath()); |
| 2623 | + |
| 2624 | + FileSystem loggingFileSystem = new ForwardingFileSystem(fileSystem) { |
| 2625 | + @Override |
| 2626 | + public Path onPathParameter(Path path, java.lang.String functionName, java.lang.String parameterName) { |
| 2627 | + events.add(functionName + ":" + path); |
| 2628 | + return path; |
| 2629 | + } |
| 2630 | + |
| 2631 | + @Override |
| 2632 | + public Path onPathResult(Path path, java.lang.String functionName) { |
| 2633 | + events.add(functionName + ":" + path); |
| 2634 | + return path; |
| 2635 | + } |
| 2636 | + }; |
| 2637 | + Path path = Path.get("/cache"); |
| 2638 | + Cache c = new Cache(path, 100000L, loggingFileSystem); |
| 2639 | + |
| 2640 | + assertThat(c.directoryPath()).isEqualTo(path); |
| 2641 | + |
| 2642 | + c.size(); |
| 2643 | + |
| 2644 | + assertThat(events).containsExactly("metadataOrNull:/cache/journal.bkp", |
| 2645 | + "metadataOrNull:/cache", |
| 2646 | + "sink:/cache/journal.bkp", |
| 2647 | + "delete:/cache/journal.bkp", |
| 2648 | + "metadataOrNull:/cache/journal", |
| 2649 | + "metadataOrNull:/cache", |
| 2650 | + "sink:/cache/journal.tmp", |
| 2651 | + "metadataOrNull:/cache/journal", |
| 2652 | + "atomicMove:/cache/journal.tmp", |
| 2653 | + "atomicMove:/cache/journal", |
| 2654 | + "appendingSink:/cache/journal"); |
| 2655 | + |
| 2656 | + events.clear(); |
| 2657 | + |
| 2658 | + c.size(); |
| 2659 | + |
| 2660 | + assertThat(events).isEmpty(); |
| 2661 | + } |
| 2662 | + |
2613 | 2663 | private void assertFullyCached(MockResponse response) throws Exception {
|
2614 | 2664 | server.enqueue(response.setBody("A"));
|
2615 | 2665 | server.enqueue(response.setBody("B"));
|
|
0 commit comments