@Test public void testGetBrokerConfig() { Map<String, String> srcConfigMap = new HashMap<>(); srcConfigMap.put("gobblin.broker.key1", "value1"); // Test global namespace, "gobblin.broker" Config brokerConfig = SharedResourcesBrokerFactory.getBrokerConfig(ConfigFactory.parseMap(srcConfigMap)); Config expectedConfig = ConfigFactory.parseMap(ImmutableMap.of("key1", "value1")); Assert.assertEquals(brokerConfig, expectedConfig); // Test extra namespace, "gobblin.shared" srcConfigMap.put("gobblin.shared.key2", "value2"); srcConfigMap.put("gobblin.brokerNamespaces", "gobblin.shared"); brokerConfig = SharedResourcesBrokerFactory.getBrokerConfig(ConfigFactory.parseMap(srcConfigMap)); expectedConfig = ConfigFactory.parseMap(ImmutableMap.of("key1", "value1","key2", "value2")); Assert.assertEquals(brokerConfig, expectedConfig); // Test a list of extra namespaces, configurations are respected in order srcConfigMap.put("gobblin.shared.key2", "value2"); srcConfigMap.put("gobblin.shared.key3", "value3"); srcConfigMap.put("gobblin.shared2.key3", "value3x"); srcConfigMap.put("gobblin.shared2.key4", "value4"); srcConfigMap.put("gobblin.brokerNamespaces", "gobblin.shared, gobblin.shared2"); brokerConfig = SharedResourcesBrokerFactory.getBrokerConfig(ConfigFactory.parseMap(srcConfigMap)); expectedConfig = ConfigFactory.parseMap(ImmutableMap.of("key1", "value1", "key2", "value2", "key3", "value3", "key4", "value4")); Assert.assertEquals(brokerConfig, expectedConfig); }
/** * Create a root {@link SharedResourcesBroker}. Subscoped brokers should be built using * {@link SharedResourcesBroker#newSubscopedBuilder(ScopeInstance)}. * * In general, this method will be called only once per application, and all other brokers will Nbe children of the root * application broker. * * @param config The global configuration of the broker. * @param globalScope The scope of the root broker. * @param <S> The {@link ScopeType} DAG used for this broker tree. */ public static <S extends ScopeType<S>> SharedResourcesBrokerImpl<S> createDefaultTopLevelBroker(Config config, ScopeInstance<S> globalScope) { if (!globalScope.getType().equals(globalScope.getType().rootScope())) { throw new IllegalArgumentException(String.format("The top level broker must be created at the root scope type. " + "%s is not a root scope type.", globalScope.getType())); } ScopeWrapper<S> scopeWrapper = new ScopeWrapper<>(globalScope.getType(), globalScope, Lists.<ScopeWrapper<S>>newArrayList()); return new SharedResourcesBrokerImpl<>(new DefaultBrokerCache<S>(), scopeWrapper, Lists.newArrayList(new SharedResourcesBrokerImpl.ScopedConfig<>(globalScope.getType(), getBrokerConfig(addSystemConfigurationToConfig(config)))), ImmutableMap.of(globalScope.getType(), scopeWrapper)); }
/** * Create a root {@link SharedResourcesBroker}. Subscoped brokers should be built using * {@link SharedResourcesBroker#newSubscopedBuilder(ScopeInstance)}. * * In general, this method will be called only once per application, and all other brokers will Nbe children of the root * application broker. * * @param config The global configuration of the broker. * @param globalScope The scope of the root broker. * @param <S> The {@link ScopeType} DAG used for this broker tree. */ public static <S extends ScopeType<S>> SharedResourcesBrokerImpl<S> createDefaultTopLevelBroker(Config config, ScopeInstance<S> globalScope) { if (!globalScope.getType().equals(globalScope.getType().rootScope())) { throw new IllegalArgumentException(String.format("The top level broker must be created at the root scope type. " + "%s is not a root scope type.", globalScope.getType())); } ScopeWrapper<S> scopeWrapper = new ScopeWrapper<>(globalScope.getType(), globalScope, Lists.<ScopeWrapper<S>>newArrayList()); return new SharedResourcesBrokerImpl<>(new DefaultBrokerCache<S>(), scopeWrapper, Lists.newArrayList(new SharedResourcesBrokerImpl.ScopedConfig<>(globalScope.getType(), getBrokerConfig(addSystemConfigurationToConfig(config)))), ImmutableMap.of(globalScope.getType(), scopeWrapper)); }