TouchReplicatedRegionEntriesFunction implements Function, Declarable, DataSerializable { @Override @SuppressWarnings("unchecked") public void execute(FunctionContext context) { Object[] arguments = (Object[]) context.getArguments(); Cache cache = context.getCache(); String regionName = (String) arguments[0]; Set<String> keys = (Set<String>) arguments[1]; if (cache.getLogger().fineEnabled()) { String builder = "Function " + ID + " received request to touch " + regionName + "->" + keys; cache.getLogger().fine(builder); } Region region = cache.getRegion(regionName); if (region != null) { region.getAll(keys); } context.getResultSender().lastResult(true); }  @Override @SuppressWarnings("unchecked") void execute(FunctionContext context); @Override // the actual regionName used in the function body is passed in as an function arugment, // this regionName is not really used in function. Hence requiring DATA:READ on all regions Collection<ResourcePermission> getRequiredPermissions(String regionName); @Override String getId(); @Override boolean optimizeForWrite(); @Override boolean isHA(); @Override boolean hasResult(); @Override void toData(DataOutput out); @Override void fromData(DataInput in); static final String ID; }
@Test public void executeDoesNotThrowExceptionWithProperlyDefinedContext() { when(cache.getRegion(regionName)).thenReturn(region); function.execute(context); verify(region).getAll(keys); verify(resultSender).lastResult(true); }
@Test public void executeDoesNotThrowExceptionWithProperlyDefinedContextAndNullRegion() { when(cache.getRegion(regionName)).thenReturn(null); function.execute(context); verify(region, times(0)).getAll(keys); verify(resultSender).lastResult(true); }