TransportsUtil { public static boolean invokeFunction(List<Decoder<? extends Object, ?>> decoders, List<FunctionWrapper> functions, Class<?> implementedType, Object instanceType, String functionName, FunctionResolver resolver) { return invokeFunction(Event.MESSAGE, decoders, functions, implementedType, instanceType, functionName, resolver); }  static boolean invokeFunction(List<Decoder<? extends Object, ?>> decoders,
                                         List<FunctionWrapper> functions,
                                         Class<?> implementedType,
                                         Object instanceType,
                                         String functionName,
                                         FunctionResolver resolver); static boolean invokeFunction(Event e,
                                         List<Decoder<? extends Object, ?>> decoders,
                                         List<FunctionWrapper> functions,
                                         Class<?> implementedType,
                                         Object instanceType,
                                         String functionName,
                                         FunctionResolver resolver); static boolean matchFunction(Object instanceType,
                                        Class[] typeArguments,
                                        Class<?> implementedType,
                                        FunctionResolver resolver,
                                        String originalMessage,
                                        Object functionName,
                                        FunctionWrapper wrapper,
                                        Function f); static List<Object> matchDecoder(Event e, Object instanceType, List<Decoder<? extends Object, ?>> decoders, List<Object> decodedObjects);  }
@Test public void testInvokeFunctionWithTrackMessageSizeDecoder_NormalMessages() throws Exception { List<String> originalMessages = createMessages(3); List<String> modifiableMessages = new ArrayList<>(originalMessages); CountDownLatch latch = new CountDownLatch(originalMessages.size()); List<Decoder<?, ?>> decoders = withTrackMessageSizeDecoder(); List<FunctionWrapper> functions = withMessageFunction(modifiableMessages, latch); for (String message : originalMessages) { assertTrue(TransportsUtil.invokeFunction(decoders, functions, String.class, withLengthPrefixed(message), FUNCTION_NAME_MESSAGE, FunctionResolver.DEFAULT)); } assertTrue(latch.await(5, TimeUnit.SECONDS)); assertTrue(modifiableMessages.isEmpty()); }
@Test public void testInvokeFunctionWithTrackMessageSizeDecoder_CombinedMessages() throws Exception { List<String> originalMessages = createMessages(5); List<String> modifiableMessages = new ArrayList<>(originalMessages); CountDownLatch latch = new CountDownLatch(modifiableMessages.size()); List<Decoder<?, ?>> decoders = withTrackMessageSizeDecoder(); List<FunctionWrapper> functions = withMessageFunction(modifiableMessages, latch); String firstMessage = originalMessages.get(0); String combinedMessages = ""; for (String message : originalMessages.subList(1, originalMessages.size())) { combinedMessages += withLengthPrefixed(message); } assertTrue(TransportsUtil.invokeFunction(decoders, functions, String.class, withLengthPrefixed(firstMessage), FUNCTION_NAME_MESSAGE, FunctionResolver.DEFAULT)); assertTrue(TransportsUtil.invokeFunction(decoders, functions, String.class, combinedMessages, FUNCTION_NAME_MESSAGE, FunctionResolver.DEFAULT)); assertTrue(latch.await(3, TimeUnit.SECONDS), "latch count was " + latch.getCount()); assertTrue(modifiableMessages.isEmpty()); }