@Test void testLoadAll_withDuplicates() { ClassLoader classLoader1 = new TestClassLoader(); ClassLoader classLoader2 = new TestClassLoader(); ClassLoader classLoader3 = new TestClassLoader(); TestTask duplicateTask1 = new TestTask(); TestTask duplicateTask2 = new TestTask(); TestTask uniqueTask = new TestTask(); Map<String, ClassLoader> modules = ImmutableMap.of("source1", classLoader1, "source2", classLoader2, "source3", classLoader3); Map<ClassLoader, Map<String, SdkRunnableTask<?, ?>>> tasksPerClassLoader = ImmutableMap.of( classLoader1, ImmutableMap.of("dupTask1", duplicateTask1, "unqTask", uniqueTask), classLoader2, ImmutableMap.of("dupTask1", duplicateTask1, "dupTask2", duplicateTask2), classLoader3, ImmutableMap.of("dupTask2", duplicateTask2)); RuntimeException exception = assertThrows( RuntimeException.class, () -> ExecuteLocalLoader.loadAll( modules, (cl, __) -> tasksPerClassLoader.get(cl), emptyMap())); assertEquals( "Found duplicate items among the modules: " + "{dupTask1 -> [source1, source2]}; {dupTask2 -> [source2, source3]}", exception.getMessage()); }
@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);  }