Skip to content

Commit 80f3419

Browse files
authored
Merge pull request #4 from wego/service-name
Add Service name
2 parents 452b47a + 4259927 commit 80f3419

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

build.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ group 'com.wego'
22
version '1.0.1'
33

44
apply plugin: 'java'
5+
apply plugin: 'maven'
6+
apply plugin: 'checkstyle'
57

68
sourceCompatibility = '1.8'
79
targetCompatibility = '1.8'
@@ -10,10 +12,6 @@ task wrapper(type: Wrapper) {
1012
gradleVersion = '2.8'
1113
}
1214

13-
apply plugin: 'maven'
14-
15-
apply plugin: 'checkstyle'
16-
1715
repositories {
1816
mavenCentral()
1917
}

src/main/java/com/wego/httpcache/services/impl/AsyncHttpCacheServiceImpl.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717

1818
public class AsyncHttpCacheServiceImpl implements AsyncHttpCacheService {
1919

20-
@Inject
21-
private CachedResponseService cachedResponseService;
22-
20+
private static final String DELIMITER = ":";
21+
@Inject private CachedResponseService cachedResponseService;
22+
private String serviceName;
2323
private AsyncHttpClient asyncHttpClient;
24-
2524
private long ttl;
2625

2726
@Inject
28-
public AsyncHttpCacheServiceImpl(@Assisted AsyncHttpClient asyncHttpClient, @Assisted long ttl) {
27+
public AsyncHttpCacheServiceImpl(
28+
@Assisted String serviceName, @Assisted AsyncHttpClient asyncHttpClient, @Assisted long ttl) {
29+
this.serviceName = serviceName;
2930
this.asyncHttpClient = asyncHttpClient;
3031
this.ttl = ttl;
3132
}
@@ -59,10 +60,9 @@ public Optional<ListenableFuture<Response>> executeRequest(
5960
private String buildResponseId(Request request) {
6061
String requestStringId =
6162
StringUtils.join(
62-
request,
63-
request.getStringData(),
64-
Lists.newArrayList(request.getCookies()).toString());
65-
return String.valueOf(MurmurHash.hash64A(requestStringId.getBytes(), 0));
63+
request, request.getStringData(), Lists.newArrayList(request.getCookies()).toString());
64+
return StringUtils.joinWith(
65+
DELIMITER, serviceName, String.valueOf(MurmurHash.hash64A(requestStringId.getBytes(), 0)));
6666
}
6767

6868
private AsyncCompletionHandlerBase buildCachingHandler(

src/test/java/com/wego/httpcache/services/impl/TestAsyncHttpCacheServiceImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
@RunWith(MockitoJUnitRunner.class)
4545
public class TestAsyncHttpCacheServiceImpl {
4646

47+
private final static String SERVICE_NAME = "Service Name";
48+
4749
private static long CACHING_TTL = 60;
4850
@Rule
4951
public WireMockRule wireMockRule = new WireMockRule(8089);
@@ -53,7 +55,7 @@ public class TestAsyncHttpCacheServiceImpl {
5355

5456
@InjectMocks
5557
private AsyncHttpCacheService asyncHttpCacheService =
56-
new AsyncHttpCacheServiceImpl(asyncHttpClient, CACHING_TTL);
58+
new AsyncHttpCacheServiceImpl(SERVICE_NAME, asyncHttpClient, CACHING_TTL);
5759

5860
@Mock
5961
private CachedResponseService cachedResponseService;
@@ -235,6 +237,7 @@ public void buildResponseId_returnsDifferentIdsForDifferentRequest() throws Exce
235237
.collect(Collectors.toList());
236238

237239
assertThat(Sets.newHashSet(responseIds).size()).isEqualTo(13);
240+
assertThat(responseIds.get(0)).startsWith(SERVICE_NAME);
238241
}
239242

240243
@Test

0 commit comments

Comments
 (0)