Skip to content

Commit

Permalink
Clean up and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Jan 18, 2020
1 parent 54f4152 commit 3479e4f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 41 deletions.
6 changes: 2 additions & 4 deletions src/main/java/org/kohsuke/github/Requester.java
Original file line number Diff line number Diff line change
Expand Up @@ -890,10 +890,8 @@ private <T> T parse(Class<T> type, T instance, int timeouts) throws IOException
// If we see a 404 with an ETag we treat it as corrupt and make new request with
// caching headers overridden to force refresh.
// If we tried this once already, don't try again.
if (Objects.equals(uc.getRequestMethod(), "GET")
&& uc.getHeaderField("ETag") != null
&& !Objects.equals(uc.getRequestProperty("Cache-Control"), "no-cache")
&& timeouts > 0) {
if (Objects.equals(uc.getRequestMethod(), "GET") && uc.getHeaderField("ETag") != null
&& !Objects.equals(uc.getRequestProperty("Cache-Control"), "no-cache") && timeouts > 0) {
setupConnection(uc.getURL());
// Setting "Cache-Control" to "no-cache" stops the cache from supplying
// "If-Modified-Since" or "If-None-Match" values.
Expand Down
20 changes: 3 additions & 17 deletions src/test/java/org/kohsuke/github/extras/GitHubCachingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
import com.squareup.okhttp.OkUrlFactory;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.kohsuke.github.AbstractGitHubWireMockTest;
import org.kohsuke.github.GHContent;
import org.kohsuke.github.GHException;
import org.kohsuke.github.GHFileNotFoundException;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHPullRequest;
Expand All @@ -21,9 +18,6 @@

import java.io.File;
import java.io.IOException;
import java.util.List;

import static org.hamcrest.core.Is.is;

/**
* Test showing the behavior of OkHttpConnector cache with GitHub 404 responses.
Expand Down Expand Up @@ -58,18 +52,10 @@ public void setupRepo() throws Exception {
}
}

@Test
public void OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error_runnable() throws Exception {

requireProxy("This test method can be run locally for debugging and analyzing.");
OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error();
}

@Test
public void OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error() throws Exception {
// ISSUE #669
// requireProxy("For clarity. Will switch to snapshot shortly.");
// snapshotNotAllowed();
snapshotNotAllowed();

OkHttpClient client = createClient(true);
OkHttpConnector connector = new OkHttpConnector(new OkUrlFactory(client));
Expand Down Expand Up @@ -176,8 +162,8 @@ private OkHttpClient createClient(boolean useCache) throws IOException {
OkHttpClient client = new OkHttpClient();

if (useCache) {
File cacheDir = new File("target/cache/" + baseFilesClassPath + "/" + mockGitHub.getMethodName()
+ clientCount++);
File cacheDir = new File(
"target/cache/" + baseFilesClassPath + "/" + mockGitHub.getMethodName() + clientCount++);
cacheDir.mkdirs();
FileUtils.cleanDirectory(cacheDir);
Cache cache = new Cache(cacheDir, 100 * 1024L * 1024L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
import okhttp3.OkHttpClient;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.kohsuke.github.AbstractGitHubWireMockTest;
import org.kohsuke.github.GHContent;
import org.kohsuke.github.GHException;
import org.kohsuke.github.GHFileNotFoundException;
import org.kohsuke.github.GHIssueState;
import org.kohsuke.github.GHPullRequest;
Expand All @@ -20,9 +17,6 @@

import java.io.File;
import java.io.IOException;
import java.util.List;

import static org.hamcrest.core.Is.is;

/**
* Test showing the behavior of OkHttpConnector cache with GitHub 404 responses.
Expand All @@ -40,8 +34,8 @@ public GitHubCachingTest() {
@Override
protected WireMockConfiguration getWireMockOptions() {
return super.getWireMockOptions()
// Use the same data files as the 2.x test
.usingFilesUnderDirectory(baseRecordPath.replace("/okhttp3/", "/"))
// Use the same data files as the 2.x test
.usingFilesUnderDirectory(baseRecordPath.replace("/okhttp3/", "/"))
.extensions(ResponseTemplateTransformer.builder().global(true).maxCacheEntries(0L).build());
}

Expand All @@ -59,19 +53,10 @@ public void setupRepo() throws Exception {
}
}

@Test
public void OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error_runnable() throws Exception {

requireProxy("This test method can be run locally for debugging and analyzing.");
OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error();
}

// @Ignore("The wiremock snapshot files attached to this test method show what was sent to and from the server during a run, but they aren't re-runnable - not templated.")
@Test
public void OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error() throws Exception {
// ISSUE #669
// requireProxy("For clarity. Will switch to snapshot shortly.");
// snapshotNotAllowed();
snapshotNotAllowed();

OkHttpClient client = createClient(true);
OkHttpConnector connector = new OkHttpConnector(client);
Expand Down Expand Up @@ -178,8 +163,8 @@ private OkHttpClient createClient(boolean useCache) throws IOException {
OkHttpClient.Builder builder = new OkHttpClient().newBuilder();

if (useCache) {
File cacheDir = new File("target/cache/" + baseFilesClassPath + "/" + mockGitHub.getMethodName()
+ clientCount++);
File cacheDir = new File(
"target/cache/" + baseFilesClassPath + "/" + mockGitHub.getMethodName() + clientCount++);
cacheDir.mkdirs();
FileUtils.cleanDirectory(cacheDir);
Cache cache = new Cache(cacheDir, 100 * 1024L * 1024L);
Expand Down

0 comments on commit 3479e4f

Please sign in to comment.