Skip to content

Commit

Permalink
testing memory issue
Browse files Browse the repository at this point in the history
  • Loading branch information
srrangarajan committed Jul 31, 2022
1 parent 46026e9 commit a2e8134
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
24 changes: 12 additions & 12 deletions evcache-core/src/main/java/com/netflix/evcache/EVCacheImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -577,21 +577,22 @@ private <T> T handleInMemoryException(Exception e) throws Exception {
}

private <T> CompletableFuture<T> doAsyncGet(EVCacheKey evcKey, Transcoder<T> tc) {
CompletableFuture<T> completableFuture = new CompletableFuture<>();
CompletableFuture<T> errorFuture = new CompletableFuture<>();
final boolean throwExc = doThrowException();
//Building the client
EVCacheClient client = buildEvCacheClient(throwExc, Call.COMPLETABLE_FUTURE_GET, completableFuture);
if (completableFuture.isCompletedExceptionally() || client == null) {
EVCacheClient client = buildEvCacheClient(throwExc, Call.COMPLETABLE_FUTURE_GET, errorFuture);
if (errorFuture.isCompletedExceptionally() || client == null) {
if (client == null ) {
completableFuture.complete(null);
errorFuture.complete(null);
}
return completableFuture;
return errorFuture;
}
//Building the start event
EVCacheEvent event = buildAndStartEvent(client, Collections.singletonList(evcKey), throwExc, completableFuture);
if (completableFuture.isCompletedExceptionally()) {
return completableFuture;
EVCacheEvent event = buildAndStartEvent(client, Collections.singletonList(evcKey), throwExc, errorFuture);
if (errorFuture.isCompletedExceptionally()) {
return errorFuture;
}
errorFuture.cancel(false);

final long start = EVCacheMetricsFactory.getInstance().getRegistry().clock().wallTime();
StringBuilder status = new StringBuilder(EVCacheMetricsFactory.SUCCESS);
Expand Down Expand Up @@ -1236,17 +1237,16 @@ private <T> CompletableFuture<T> getAsyncData(EVCacheClient client,
final Transcoder<T> transcoder = (tc == null) ? ((_transcoder == null) ? (Transcoder<T>) client.getTranscoder() : (Transcoder<T>) _transcoder) : tc;
String hashKey = evcKey.getHashKey(client.isDuetClient(), client.getHashingAlgorithm(), client.shouldEncodeHashKey(), client.getMaxDigestBytes(), client.getMaxHashLength(), client.getBaseEncoder());
String canonicalKey = evcKey.getCanonicalKey(client.isDuetClient());
CompletableFuture<T> result;

if (hashKey != null) {
result = client.getAsync(hashKey, evcacheValueTranscoder)
return client.getAsync(hashKey, evcacheValueTranscoder)
.thenApply(val -> getData(transcoder, canonicalKey, val))
.exceptionally(ex -> handleClientException(hashKey, ex));

} else {
result = client.getAsync(canonicalKey, transcoder)
return client.getAsync(canonicalKey, transcoder)
.exceptionally(ex -> handleClientException(canonicalKey, ex));
}
return result;
}

private <T> T handleClientException(String evcKey, Throwable ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ private CompletableFuture<T> handleTimeoutException() {
}

public CompletableFuture<T> getAsync(long timeout, TimeUnit units) {
CompletableFuture<T> future = new CompletableFuture<>();
CompletableFuture<T> future = makeFutureWithTimeout(timeout, units);
doAsyncGet(future);
return future.handle((data, ex) -> {
if (ex != null) {
Expand All @@ -312,15 +312,17 @@ public CompletableFuture<T> getAsync(long timeout, TimeUnit units) {
});
}

private void doAsyncGet(CompletableFuture<T> cf) {
this.addListener((EVCacheGetOperationListener<T>) future -> {
private EVCacheGetOperationListener<T> doAsyncGet(CompletableFuture<T> cf) {
EVCacheGetOperationListener<T> listener = future -> {
try {
T result = future.get();
cf.complete(result);
} catch (Exception t) {
cf.completeExceptionally(t);
}
});
};
this.addListener(listener);
return listener;
}

public Single<T> get(long duration, TimeUnit units, boolean throwException, boolean hasZF, Scheduler scheduler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void testGet() throws Exception {

@Test(dependsOnMethods = { "testInsert" })
public void testCompletableFutureGet() throws Exception {
for (int i = 0; i < 1000000; i++) {
for (int i = 0; i < 10000000; i++) {
final String val = completableFutureGet(i, evCache);
//assertNotNull(val);
}
Expand Down

0 comments on commit a2e8134

Please sign in to comment.