Skip to content

Add Service name #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ group 'com.wego'
version '1.0.1'

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'checkstyle'

sourceCompatibility = '1.8'
targetCompatibility = '1.8'
Expand All @@ -10,10 +12,6 @@ task wrapper(type: Wrapper) {
gradleVersion = '2.8'
}

apply plugin: 'maven'

apply plugin: 'checkstyle'

repositories {
mavenCentral()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@

public class AsyncHttpCacheServiceImpl implements AsyncHttpCacheService {

@Inject
private CachedResponseService cachedResponseService;

private static final String DELIMITER = ":";
@Inject private CachedResponseService cachedResponseService;
private String serviceName;
private AsyncHttpClient asyncHttpClient;

private long ttl;

@Inject
public AsyncHttpCacheServiceImpl(@Assisted AsyncHttpClient asyncHttpClient, @Assisted long ttl) {
public AsyncHttpCacheServiceImpl(
@Assisted String serviceName, @Assisted AsyncHttpClient asyncHttpClient, @Assisted long ttl) {
this.serviceName = serviceName;
this.asyncHttpClient = asyncHttpClient;
this.ttl = ttl;
}
Expand Down Expand Up @@ -59,10 +60,9 @@ public Optional<ListenableFuture<Response>> executeRequest(
private String buildResponseId(Request request) {
String requestStringId =
StringUtils.join(
request,
request.getStringData(),
Lists.newArrayList(request.getCookies()).toString());
return String.valueOf(MurmurHash.hash64A(requestStringId.getBytes(), 0));
request, request.getStringData(), Lists.newArrayList(request.getCookies()).toString());
return StringUtils.joinWith(
DELIMITER, serviceName, String.valueOf(MurmurHash.hash64A(requestStringId.getBytes(), 0)));
}

private AsyncCompletionHandlerBase buildCachingHandler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
@RunWith(MockitoJUnitRunner.class)
public class TestAsyncHttpCacheServiceImpl {

private final static String SERVICE_NAME = "Service Name";

private static long CACHING_TTL = 60;
@Rule
public WireMockRule wireMockRule = new WireMockRule(8089);
Expand All @@ -53,7 +55,7 @@ public class TestAsyncHttpCacheServiceImpl {

@InjectMocks
private AsyncHttpCacheService asyncHttpCacheService =
new AsyncHttpCacheServiceImpl(asyncHttpClient, CACHING_TTL);
new AsyncHttpCacheServiceImpl(SERVICE_NAME, asyncHttpClient, CACHING_TTL);

@Mock
private CachedResponseService cachedResponseService;
Expand Down Expand Up @@ -235,6 +237,7 @@ public void buildResponseId_returnsDifferentIdsForDifferentRequest() throws Exce
.collect(Collectors.toList());

assertThat(Sets.newHashSet(responseIds).size()).isEqualTo(13);
assertThat(responseIds.get(0)).startsWith(SERVICE_NAME);
}

@Test
Expand Down