Skip to content

Commit

Permalink
IGNITE-5994 IgniteInternalCache.invokeAsync().get() can return null
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Vinogradov <av@apache.org>
  • Loading branch information
SharplEr authored and anton-vinogradov committed Apr 24, 2018
1 parent e31d2fc commit 65a4256
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2573,10 +2573,10 @@ private <T> EntryProcessorResult<T> invoke0(
if (resMap != null) {
assert resMap.isEmpty() || resMap.size() == 1 : resMap.size();

return resMap.isEmpty() ? null : resMap.values().iterator().next();
return resMap.isEmpty() ? new CacheInvokeResult<>() : resMap.values().iterator().next();
}

return null;
return new CacheInvokeResult<>();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1445,9 +1445,7 @@ private <T> IgniteInternalFuture<T> invokeAsync0(K key, EntryProcessor<K, V, T>
@Override public T applyx(IgniteInternalFuture<EntryProcessorResult<T>> fut1)
throws IgniteCheckedException {
try {
EntryProcessorResult<T> res = fut1.get();

return res != null ? res.get() : null;
return fut1.get().get();
}
catch (RuntimeException e) {
throw new GridClosureException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,9 +783,7 @@ private <T> IgniteInternalFuture<T> asyncOp(final CO<IgniteInternalFuture<T>> op
throws IgniteCheckedException {
IgniteInternalFuture<EntryProcessorResult<T>> invokeFut = invoke0(false, key, entryProcessor, args);

EntryProcessorResult<T> res = invokeFut.get();

return res != null ? res : new CacheInvokeResult<T>();
return invokeFut.get();
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -840,7 +838,8 @@ private <T> IgniteInternalFuture<EntryProcessorResult<T>> invoke0(
if (resMap != null) {
assert resMap.isEmpty() || resMap.size() == 1 : resMap.size();

EntryProcessorResult<T> res = resMap.isEmpty() ? null : resMap.values().iterator().next();
EntryProcessorResult<T> res =
resMap.isEmpty() ? new CacheInvokeResult<>() : resMap.values().iterator().next();

if (res instanceof CacheInvokeResult) {
CacheInvokeResult invokeRes = (CacheInvokeResult)res;
Expand All @@ -853,7 +852,7 @@ private <T> IgniteInternalFuture<EntryProcessorResult<T>> invoke0(
return res;
}

return null;
return new CacheInvokeResult<>();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,7 @@ private Map<K, V> getAllInternal(@Nullable Collection<? extends K> keys,
@Override public <T> EntryProcessorResult<T> invoke(K key,
EntryProcessor<K, V, T> entryProcessor,
Object... args) throws IgniteCheckedException {
EntryProcessorResult<T> res = invokeAsync(key, entryProcessor, args).get();

return res != null ? res : new CacheInvokeResult<T>();
return invokeAsync(key, entryProcessor, args).get();
}

/** {@inheritDoc} */
Expand Down Expand Up @@ -613,10 +611,10 @@ private Map<K, V> getAllInternal(@Nullable Collection<? extends K> keys,
if (resMap != null) {
assert resMap.isEmpty() || resMap.size() == 1 : resMap.size();

return resMap.isEmpty() ? null : resMap.values().iterator().next();
return resMap.isEmpty() ? new CacheInvokeResult<>() : resMap.values().iterator().next();
}

return null;
return new CacheInvokeResult<>();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ public void testInvoke() throws Exception {
}
}

/**
* @throws Exception If failed.
*/
public void testInternalInvokeNullable() throws Exception {
IgniteInternalCache<Integer, Integer> cache = grid(0).cachex(DEFAULT_CACHE_NAME);

EntryProcessor<Integer, Integer, Void> processor = new NullableProcessor();

for (final Integer key : keys()) {
log.info("Test invoke with a nullable result [key=" + key + ']');

EntryProcessorResult<Void> result = cache.invoke(key, processor);
EntryProcessorResult<Void> resultAsync = cache.invokeAsync(key, processor).get();

assertNotNull(result);
assertNotNull(resultAsync);

assertNull(result.get());
assertNull(resultAsync.get());
}
}

/**
* @param cache Cache.
* @param txMode Not null transaction concurrency mode if explicit transaction should be started.
Expand Down Expand Up @@ -768,6 +790,17 @@ private static class ExceptionProcessor implements EntryProcessor<Integer, Integ
}
}

/**
* EntryProcessor which always returns {@code null}.
*/
private static class NullableProcessor implements EntryProcessor<Integer, Integer, Void> {
/** {@inheritDoc} */
@Override public Void process(MutableEntry<Integer, Integer> e,
Object... arguments) throws EntryProcessorException {
return null;
}
}

/**
*
*/
Expand Down

0 comments on commit 65a4256

Please sign in to comment.