Skip to content

Commit

Permalink
Merge branch 'main' into bug/#1269
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman authored Nov 2, 2021
2 parents 9c6efb6 + 913a2ed commit 87b726e
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<spotbugs.version>4.4.2</spotbugs.version>
<spotbugs-maven-plugin.failOnError>true</spotbugs-maven-plugin.failOnError>
<hamcrest.version>2.2</hamcrest.version>
<okhttp3.version>4.4.1</okhttp3.version>
<okhttp3.version>4.9.2</okhttp3.version>
<okio.version>2.10.0</okio.version>
<!-- Using this as the minimum bar for code coverage. Adding methods without covering them will fail this. -->
<jacoco.coverage.target.bundle.method>0.70</jacoco.coverage.target.bundle.method>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.kohsuke.github.AbstractGitHubWireMockTest;
Expand Down Expand Up @@ -67,6 +68,7 @@ public OkHttpConnectorTest() {
private static int maxAgeNoneHitCount = 11;

private GHRateLimit rateLimitBefore;
private Cache cache = null;

@Override
protected WireMockConfiguration getWireMockOptions() {
Expand All @@ -88,6 +90,13 @@ public void setupRepo() throws Exception {
}
}

@After
public void deleteCache() throws IOException {
if (cache != null) {
cache.delete();
}
}

@Test
public void DefaultConnector() throws Exception {

Expand Down Expand Up @@ -120,7 +129,6 @@ public void OkHttpConnector_NoCache() throws Exception {

checkRequestAndLimit(okhttpNetworkRequestCount, okhttpRateLimitUsed);

Cache cache = client.cache();
assertThat("Cache", cache, is(nullValue()));
}

Expand All @@ -147,8 +155,6 @@ public void OkHttpConnector_Cache_MaxAgeNone() throws Exception {

checkRequestAndLimit(maxAgeNoneNetworkRequestCount, maxAgeNoneRateLimitUsed);

Cache cache = client.cache();

// NOTE: this is actually bad.
// This elevated hit count is the stale requests returning bad data took longer to detect a change.
assertThat("getHitCount", cache.hitCount(), is(maxAgeNoneHitCount));
Expand Down Expand Up @@ -176,7 +182,6 @@ public void OkHttpConnector_Cache_MaxAge_Three() throws Exception {

checkRequestAndLimit(maxAgeThreeNetworkRequestCount, maxAgeThreeRateLimitUsed);

Cache cache = client.cache();
assertThat("getHitCount", cache.hitCount(), is(maxAgeThreeHitCount));
}

Expand All @@ -202,7 +207,6 @@ public void OkHttpConnector_Cache_MaxAgeDefault_Zero() throws Exception {

checkRequestAndLimit(maxAgeZeroNetworkRequestCount, maxAgeZeroRateLimitUsed);

Cache cache = client.cache();
assertThat("getHitCount", cache.hitCount(), is(maxAgeZeroHitCount));
}

Expand All @@ -228,7 +232,7 @@ private OkHttpClient createClient(boolean useCache) throws IOException {
File cacheDir = new File("target/cache/" + baseFilesClassPath + "/" + mockGitHub.getMethodName());
cacheDir.mkdirs();
FileUtils.cleanDirectory(cacheDir);
Cache cache = new Cache(cacheDir, 100 * 1024L * 1024L);
cache = new Cache(cacheDir, 100 * 1024L * 1024L);

builder.cache(cache);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"name": "repos_hub4j-test-org_github-api",
"request": {
"url": "/repos/hub4j-test-org/github-api",
"method": "GET"
"method": "GET",
"headers": {
"If-None-Match": {
"absent" : true
}
}
},
"response": {
"status": 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"method": "GET",
"headers": {
"If-None-Match": {
"equalTo": "\"4f508593b64df214fee8f6ab42df633c\""
"matches": "^(W/)?\"4f508593b64df214fee8f6ab42df633c\"$"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"method": "GET",
"headers": {
"If-None-Match": {
"equalTo": "\"4f508593b64df214fee8f6ab42df633c\""
"matches": "^(W/)?\"4f508593b64df214fee8f6ab42df633c\"$"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"method": "GET",
"headers": {
"If-None-Match": {
"equalTo": "\"4f508593b64df214fee8f6ab42df633c\""
"matches": "^(W/)?\"4f508593b64df214fee8f6ab42df633c\"$"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"method": "GET",
"headers": {
"If-None-Match": {
"equalTo": "\"31f73a7ecc35bbecec125851ce166af4\""
"matches": "^(W/)?\"31f73a7ecc35bbecec125851ce166af4\"$"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"method": "GET",
"headers": {
"If-None-Match": {
"equalTo": "\"31f73a7ecc35bbecec125851ce166af4\""
"matches": "^(W/)?\"31f73a7ecc35bbecec125851ce166af4\"$"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"name": "repos_hub4j-test-org_github-api",
"request": {
"url": "/repos/hub4j-test-org/github-api",
"method": "GET"
"method": "GET",
"headers": {
"If-None-Match": {
"absent" : true
}
}
},
"response": {
"status": 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"method": "GET",
"headers": {
"If-None-Match": {
"equalTo": "\"295ae3430c604f3d10b6eb145fe511b5\""
"matches": "^(W/)?\"295ae3430c604f3d10b6eb145fe511b5\"$"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"method": "GET",
"headers": {
"If-None-Match": {
"equalTo": "\"295ae3430c604f3d10b6eb145fe511b5\""
"matches": "^(W/)?\"295ae3430c604f3d10b6eb145fe511b5\"$"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"name": "repos_hub4j-test-org_github-api",
"request": {
"url": "/repos/hub4j-test-org/github-api",
"method": "GET"
"method": "GET",
"headers": {
"If-None-Match": {
"matches": "^(W/)?\"295ae3430c604f3d10b6eb145fe511b5\"$"
}
}
},
"response": {
"status": 304,
Expand Down

0 comments on commit 87b726e

Please sign in to comment.