LocalExecutableRegistryImpl implements ExecutableRegistry { @Override public Executable getTask(String taskIdentifier) { final Executable cachedExecutable = this.identifierToMethodMap.get(taskIdentifier); if (cachedExecutable == null) { try { final MethodId methodId = MethodId.fromIdentifier(taskIdentifier.substring(0, taskIdentifier.lastIndexOf('_'))); final Class<?> clazz = Class.forName(methodId.getClassName()); final Object classInstance = this.injector.getInstance(clazz); final Method methodToInvoke = clazz.getDeclaredMethod(methodId.getMethodName(), methodId.getParameterTypes()); final Task taskAnnotation = methodToInvoke.getAnnotationsByType(Task.class)[0]; return new ExecutableImpl(classInstance, methodToInvoke, taskAnnotation.timeout()); } catch (ClassNotFoundException | NoSuchMethodException e) { throw new UnknownIdentifierException("Could not load method corresponding to the given task identifier:" + taskIdentifier); } } return cachedExecutable; } @Inject  LocalExecutableRegistryImpl(Injector injector);  LocalExecutableRegistryImpl(Map<String, Executable> identifierToMethodMap, Injector injector); @Override Executable getTask(String taskIdentifier); @Override Method getHook(String hookIdentifier); @Override void registerTask(String taskIdentifier, Executable method); @Override void unregisterTask(String taskIdentifier);  }
@Test public void testTaskRetrieval_shouldTryToRetrieveNonRegisteredMethods() throws Exception { when(injector.getInstance(any(Class.class))).thenReturn(simpleWorkflowForTest); final Executable expectedExecutable = new ExecutableImpl(simpleWorkflowForTest, simpleWorkflowForTest.getClass().getDeclaredMethod("simpleStringModifyingTask", StringEvent.class), 2000l); assertThat( localExecutableRegistry.getTask("com.flipkart.flux.client.intercept.SimpleWorkflowForTest_simpleStringModifyingTask_com.flipkart.flux.client.intercept.SimpleWorkflowForTest$StringEvent_com.flipkart.flux.client.intercept.SimpleWorkflowForTest$StringEvent_version1")) .isEqualTo(expectedExecutable); org.mockito.Mockito.verify(injector,times(1)).getInstance(Class.forName("com.flipkart.flux.client.intercept.SimpleWorkflowForTest")); }
@Test(expected = UnknownIdentifierException.class) public void testTaskRetrieval_shouldBombOnUnknownClasses() throws Exception { localExecutableRegistry.getTask("com.Foo.NonExistent.Class_someMethodName_com.Foo.NonExistant.SomeReturnType_version1"); }
@Test(expected = UnknownIdentifierException.class) public void testTaskRetrieval_shouldBombOnIncorrectSignatures() throws Exception { final SimpleWorkflowForTest mockSimpleWorkflow = new SimpleWorkflowForTest(); when(injector.getInstance(any(Class.class))).thenReturn(mockSimpleWorkflow); localExecutableRegistry.getTask("com.flipkart.flux.client.intercept.SimpleWorkflowForTest_simpleStringModifyingTask_java.lang.String_java.lang.String_java.lang.String"); }
@Test(expected = UnknownIdentifierException.class) public void testTaskRetrieval_shouldBombOnIncorrectMethodNames() throws Exception { final SimpleWorkflowForTest mockSimpleWorkflow = new SimpleWorkflowForTest(); when(injector.getInstance(any(Class.class))).thenReturn(mockSimpleWorkflow); localExecutableRegistry.getTask("com.flipkart.flux.client.intercept.SimpleWorkflowForTest_simpleStringModifyingTaskChangedName_java.lang.String_java.lang.String"); }