albertogpz commented on code in PR #7493: URL: https://github.com/apache/geode/pull/7493#discussion_r872093981
########## geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/PRClientServerRegionFunctionExecutionNoSingleHopDistributedTest.java: ########## @@ -657,191 +710,162 @@ private static void serverMultiKeyExecutionOnASingleBucket(Boolean isByName) { } DistributedSystem.setThreadsSocketPolicy(false); for (String o : testKeysSet) { - try { - Set<String> singleKeySet = Collections.singleton(o); - Function function = new TestFunction(true, TEST_FUNCTION2); - FunctionService.registerFunction(function); - Execution dataSet = FunctionService.onRegion(region); - ResultCollector rc1 = execute(dataSet, singleKeySet, Boolean.TRUE, function, isByName); - List l = ((List) rc1.getResult()); - assertEquals(1, l.size()); - - ResultCollector rc2 = - execute(dataSet, singleKeySet, new HashSet<>(singleKeySet), function, isByName); - List l2 = ((List) rc2.getResult()); - - assertEquals(1, l2.size()); - List subList = (List) l2.iterator().next(); - assertEquals(1, subList.size()); - assertEquals(region.get(singleKeySet.iterator().next()), subList.iterator().next()); - } catch (Exception expected) { - logger.info("Exception : " + expected.getMessage()); - expected.printStackTrace(); - fail("Test failed after the put operation"); - } + Set<String> singleKeySet = Collections.singleton(o); + Function<Object> function = new TestFunction<>(true, TEST_FUNCTION2); + FunctionService.registerFunction(function); + Execution dataSet = FunctionService.onRegion(region); + ResultCollector<?, ?> rc1 = execute(dataSet, singleKeySet, Boolean.TRUE, function, isByName); + List<?> l = (List<?>) rc1.getResult(); + assertThat(l).hasSize(1); + + ResultCollector<?, ?> rc2 = + execute(dataSet, singleKeySet, new HashSet<>(singleKeySet), function, isByName); + List<?> l2 = (List<?>) rc2.getResult(); + + assertThat(l2).hasSize(1); + List<Integer> subList = (List<Integer>) l2.iterator().next(); + assertThat(subList).hasSize(1); + assertThat(subList).containsOnly(region.get(singleKeySet.iterator().next())); } } private static void serverMultiKeyExecution(Boolean isByName) { Region<String, Integer> region = cache.getRegion(PartitionedRegionName); - assertNotNull(region); + assertThat(region).isNotNull(); final HashSet<String> testKeysSet = new HashSet<>(); for (int i = (totalNumBuckets * 2); i > 0; i--) { testKeysSet.add("execKey-" + i); } DistributedSystem.setThreadsSocketPolicy(false); - Function function = new TestFunction(true, TEST_FUNCTION2); + Function<Object> function = new TestFunction<>(true, TEST_FUNCTION2); FunctionService.registerFunction(function); Execution dataSet = FunctionService.onRegion(region); - try { - int j = 0; - HashSet<Integer> origVals = new HashSet<>(); - for (String element : testKeysSet) { - Integer val = j++; - origVals.add(val); - region.put(element, val); - } - ResultCollector rc1 = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName); - List l = ((List) rc1.getResult()); - logger.info("Result size : " + l.size()); - assertEquals(3, l.size()); - for (Object item : l) { - assertEquals(Boolean.TRUE, item); - } - ResultCollector rc2 = execute(dataSet, testKeysSet, testKeysSet, function, isByName); - List l2 = ((List) rc2.getResult()); - assertEquals(3, l2.size()); - HashSet<Integer> foundVals = new HashSet<>(); - for (Object value : l2) { - ArrayList subL = (ArrayList) value; - assertTrue(subL.size() > 0); - for (Object o : subL) { - assertTrue(foundVals.add((Integer) o)); - } - } - assertEquals(origVals, foundVals); - - } catch (Exception e) { - Assert.fail("Test failed after the put operation", e); + int j = 0; + HashSet<Integer> origVals = new HashSet<>(); + for (String element : testKeysSet) { + Integer val = j++; + origVals.add(val); + region.put(element, val); + } + ResultCollector<?, ?> rc1 = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName); + List<?> l = (List<?>) rc1.getResult(); + assertThat(l).hasSize(3); + for (Object item : l) { + assertThat(item).isEqualTo(Boolean.TRUE); + } + ResultCollector<?, ?> rc2 = execute(dataSet, testKeysSet, testKeysSet, function, isByName); + List<?> l2 = (List<?>) rc2.getResult(); + assertThat(l2).hasSize(3); + HashSet<Integer> foundVals = new HashSet<>(); + for (Object value : l2) { + List<?> subL = (List<?>) value; + assertThat(subL).hasSizeGreaterThan(0); + for (Object o : subL) { + assertThat(foundVals.add((Integer) o)).isTrue(); + } } + assertThat(foundVals).containsExactlyInAnyOrderElementsOf(origVals); } private static void serverMultiKeyExecutionSocketTimeOut(Boolean isByName) { Region<String, Integer> region = cache.getRegion(PartitionedRegionName); - assertNotNull(region); + assertThat(region).isNotNull(); final HashSet<String> testKeysSet = new HashSet<>(); for (int i = (totalNumBuckets * 2); i > 0; i--) { testKeysSet.add("execKey-" + i); } DistributedSystem.setThreadsSocketPolicy(false); - Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_SOCKET_TIMEOUT); + Function<Object> function = new TestFunction<>(true, TestFunction.TEST_FUNCTION_SOCKET_TIMEOUT); FunctionService.registerFunction(function); Execution dataSet = FunctionService.onRegion(region); - try { - int j = 0; - for (String value : testKeysSet) { - Integer val = j++; - region.put(value, val); - } - ResultCollector rc1 = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName); - List l = ((List) rc1.getResult()); - logger.info("Result size : " + l.size()); - assertEquals(3, l.size()); - for (Object o : l) { - assertEquals(Boolean.TRUE, o); - } - - } catch (Exception e) { - Assert.fail("Test failed after the function execution", e); + int j = 0; + for (String value : testKeysSet) { + Integer val = j++; + region.put(value, val); + } + ResultCollector<?, ?> rc1 = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName); + List<?> l = (List<?>) rc1.getResult(); + logger.info("Result size : " + l.size()); + assertThat(l).hasSize(3); + for (Object o : l) { + assertThat(o).isEqualTo(Boolean.TRUE); } } private static void serverSingleKeyExecutionSocketTimeOut(Boolean isByName) { Region<String, Integer> region = cache.getRegion(PartitionedRegionName); - assertNotNull(region); + assertThat(region).isNotNull(); final String testKey = "execKey"; final Set<String> testKeysSet = new HashSet<>(); testKeysSet.add(testKey); DistributedSystem.setThreadsSocketPolicy(false); - Function function = new TestFunction(true, TestFunction.TEST_FUNCTION_SOCKET_TIMEOUT); + Function<Object> function = new TestFunction<>(true, TestFunction.TEST_FUNCTION_SOCKET_TIMEOUT); FunctionService.registerFunction(function); Execution dataSet = FunctionService.onRegion(region); region.put(testKey, 1); - try { - ResultCollector rs = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName); - assertEquals(Boolean.TRUE, ((List) rs.getResult()).get(0)); - ResultCollector rs2 = execute(dataSet, testKeysSet, testKey, function, isByName); - assertEquals(testKey, ((List) rs2.getResult()).get(0)); + ResultCollector<?, ?> rs = execute(dataSet, testKeysSet, Boolean.TRUE, function, isByName); + assertThat(((List<?>) rs.getResult()).get(0)).isEqualTo(Boolean.TRUE); - } catch (Exception ex) { - ex.printStackTrace(); - logger.info("Exception : ", ex); - Assert.fail("Test failed after the put operation", ex); - } + ResultCollector<?, ?> rs2 = execute(dataSet, testKeysSet, testKey, function, isByName); + assertThat(((List<?>) rs2.getResult()).get(0)).isEqualTo(testKey); } private static void serverMultiKeyExecution_Inline() { Region<String, Integer> region = cache.getRegion(PartitionedRegionName); - assertNotNull(region); + assertThat(region).isNotNull(); final HashSet<String> testKeysSet = new HashSet<>(); for (int i = (totalNumBuckets * 2); i > 0; i--) { testKeysSet.add("execKey-" + i); } DistributedSystem.setThreadsSocketPolicy(false); Execution dataSet = FunctionService.onRegion(region); - try { - int j = 0; - for (String value : testKeysSet) { - Integer val = j++; - region.put(value, val); - } - ResultCollector rc1 = - dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(new FunctionAdapter() { - @Override - public void execute(FunctionContext context) { - @SuppressWarnings("unchecked") - final ResultSender<Object> resultSender = context.getResultSender(); - if (context.getArguments() instanceof String) { - resultSender.lastResult("Success"); - } else if (context.getArguments() instanceof Boolean) { - resultSender.lastResult(Boolean.TRUE); - } - } - @Override - public String getId() { - return getClass().getName(); + int j = 0; + for (String value : testKeysSet) { + Integer val = j++; + region.put(value, val); + } + ResultCollector<?, ?> rc1 = + dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(new FunctionAdapter() { + @Override + public void execute(FunctionContext context) { + @SuppressWarnings("unchecked") Review Comment: Yes, it is. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@geode.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org