@Test void testLoadAll_withoutDuplicates() { ClassLoader classLoader1 = new TestClassLoader(); ClassLoader classLoader2 = new TestClassLoader(); TestTask task1 = new TestTask(); TestTask task2 = new TestTask(); Map<String, ClassLoader> modules = ImmutableMap.of("source1", classLoader1, "source2", classLoader2); Map<ClassLoader, Map<String, SdkRunnableTask<?, ?>>> tasksPerClassLoader = ImmutableMap.of( classLoader1, ImmutableMap.of("task1", task1), classLoader2, ImmutableMap.of("task2", task2)); Map<String, SdkRunnableTask<?, ?>> tasksByName = ExecuteLocalLoader.loadAll(modules, (cl, __) -> tasksPerClassLoader.get(cl), emptyMap()); assertEquals(ImmutableMap.of("task1", task1, "task2", task2), tasksByName); }
@VisibleForTesting static <ItemT> Map<String, ItemT> loadAll( Map<String, ClassLoader> modules, BiFunction<ClassLoader, Map<String, String>, Map<String, ItemT>> loader, Map<String, String> env) { Map<String, Map<String, ItemT>> loadedItemsBySource = modules.entrySet().stream() .map(mod -> Maps.immutableEntry(mod.getKey(), loader.apply(mod.getValue(), env))) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); verifyNoDuplicateItems(loadedItemsBySource); return loadedItemsBySource.values().stream() .flatMap(items -> items.entrySet().stream()) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); }
ExecuteLocalLoader { @VisibleForTesting static <ItemT> Map<String, ItemT> loadAll( Map<String, ClassLoader> modules, BiFunction<ClassLoader, Map<String, String>, Map<String, ItemT>> loader, Map<String, String> env) { Map<String, Map<String, ItemT>> loadedItemsBySource = modules.entrySet().stream() .map(mod -> Maps.immutableEntry(mod.getKey(), loader.apply(mod.getValue(), env))) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); verifyNoDuplicateItems(loadedItemsBySource); return loadedItemsBySource.values().stream() .flatMap(items -> items.entrySet().stream()) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); } }
ExecuteLocalLoader { @VisibleForTesting static <ItemT> Map<String, ItemT> loadAll( Map<String, ClassLoader> modules, BiFunction<ClassLoader, Map<String, String>, Map<String, ItemT>> loader, Map<String, String> env) { Map<String, Map<String, ItemT>> loadedItemsBySource = modules.entrySet().stream() .map(mod -> Maps.immutableEntry(mod.getKey(), loader.apply(mod.getValue(), env))) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); verifyNoDuplicateItems(loadedItemsBySource); return loadedItemsBySource.values().stream() .flatMap(items -> items.entrySet().stream()) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); }  }
ExecuteLocalLoader { @VisibleForTesting static <ItemT> Map<String, ItemT> loadAll( Map<String, ClassLoader> modules, BiFunction<ClassLoader, Map<String, String>, Map<String, ItemT>> loader, Map<String, String> env) { Map<String, Map<String, ItemT>> loadedItemsBySource = modules.entrySet().stream() .map(mod -> Maps.immutableEntry(mod.getKey(), loader.apply(mod.getValue(), env))) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); verifyNoDuplicateItems(loadedItemsBySource); return loadedItemsBySource.values().stream() .flatMap(items -> items.entrySet().stream()) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); }  static Map<String, ClassLoader> loadModules(String packageDir); static Map<String, RunnableTask> loadTasks(
      Map<String, ClassLoader> modules, Map<String, String> env); static Map<String, WorkflowTemplate> loadWorkflows(
      Map<String, ClassLoader> modules, Map<String, String> env); }
ExecuteLocalLoader { @VisibleForTesting static <ItemT> Map<String, ItemT> loadAll( Map<String, ClassLoader> modules, BiFunction<ClassLoader, Map<String, String>, Map<String, ItemT>> loader, Map<String, String> env) { Map<String, Map<String, ItemT>> loadedItemsBySource = modules.entrySet().stream() .map(mod -> Maps.immutableEntry(mod.getKey(), loader.apply(mod.getValue(), env))) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); verifyNoDuplicateItems(loadedItemsBySource); return loadedItemsBySource.values().stream() .flatMap(items -> items.entrySet().stream()) .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); }  static Map<String, ClassLoader> loadModules(String packageDir); static Map<String, RunnableTask> loadTasks(
      Map<String, ClassLoader> modules, Map<String, String> env); static Map<String, WorkflowTemplate> loadWorkflows(
      Map<String, ClassLoader> modules, Map<String, String> env);  }