/** * Gets a list from a comma separated property with support for overrides, defaulting to Append behavior * * @param property the property * @return the list */ public List<String> getConfigList( String property ) { return getConfigList( property, ListOverrideType.APPEND ); }
/** * Gets a list from a comma separated property with support for overrides, defaulting to Overlay behavior * * @param property the property * @return the list */ public Set<String> getConfigSet( String property ) { return getConfigSet( property, SetOverrideType.OVERLAY ); }
@Test public void testGetPrefixedProperties2ShimConfig() { shimProperties.setProperty( "java.system.flatclass", "false" ); shimProperties.setProperty( "mr1.java.system.flatclass", "true" ); shimProperties.setProperty( "hbase.java.system.flatclass", "green" ); shimProperties.setProperty( ShimProperties.SHIM_CP_CONFIG, "mr1,hbase" ); assertEquals( "green", shimProperties.getPrefixedProperties( "java.system" ).get( "flatclass" ) ); }
/** * Returns a map of key -> value of all shim properties with the given prefix (the prefix is removed) * * @param prefix the prefix to look for * @return a map of key -> value of all shim properties with the given prefix (the prefix is removed) */ public Map<String, String> getPrefixedProperties( String prefix ) { List<String> propertyPrefixes = new ArrayList<String>(); propertyPrefixes.add( prefix + "." ); for ( String shimConfig : getShimConfigs() ) { propertyPrefixes.add( shimConfig + "." + prefix.trim() + "." ); } Map<String, String> prefixedProperties = new HashMap<String, String>(); for ( String currentPrefix : propertyPrefixes ) { for ( String propertyName : stringPropertyNames() ) { if ( propertyName.startsWith( currentPrefix ) ) { prefixedProperties.put( propertyName.substring( currentPrefix.length() ), super.getProperty( propertyName ) ); } } } return prefixedProperties; } }
@Test public void testGetPrefixedOsPropertiesWindowsAndShimConfigTrumpsWindowsConfig() { when( windowsChecker.isWindows() ).thenReturn( true ); shimProperties.setProperty( "java.system.flatclass", "false" ); shimProperties.setProperty( "windows.java.system.flatclass", "false" ); shimProperties.setProperty( "mr1.java.system.flatclass", "false" ); shimProperties.setProperty( "windows.mr1.java.system.flatclass", "true" ); shimProperties.setProperty( ShimProperties.SHIM_CP_CONFIG, "mr1" ); assertEquals( "true", shimProperties.getProperty( "java.system.flatclass" ) ); } }
@Test public void testGetConfigListReplaceWithNoRootConfig() { List<String> shimConfig = new ArrayList<String>( Arrays.asList( "1", "two", "tres" ) ); shimProperties.setProperty( "mr1.propName", join( ",", shimConfig ) ); assertEquals( new ArrayList<String>(), shimProperties.getConfigList( "propName", ListOverrideType.REPLACE ) ); shimProperties.setProperty( ShimProperties.SHIM_CP_CONFIG, "mr1" ); assertEquals( shimConfig, shimProperties.getConfigList( "propName", ListOverrideType.REPLACE ) ); }
@Test public void testGetConfigSetReplaceWithShimConfig() { Set<String> rootConfig = new HashSet<String>( Arrays.asList( "one", "b", "iii" ) ); Set<String> shimConfig = new HashSet<String>( Arrays.asList( "1", "two", "tres" ) ); shimProperties.setProperty( "propName", join( ",", rootConfig ) ); shimProperties.setProperty( "mr1.propName", join( ",", shimConfig ) ); shimProperties.setProperty( ShimProperties.SHIM_CP_CONFIG, "mr1" ); assertEquals( shimConfig, shimProperties.getConfigSet( "propName", SetOverrideType.REPLACE ) ); }
ShimProperties configurationProperties = new ShimProperties(); try { FileObject configFile = folder.getChild( CONFIG_PROPERTIES_FILE ); if ( configFile != null ) { configurationProperties.putAll( loadProperties( configFile ) ); for ( Entry<String, String> entry : configurationProperties.getPrefixedProperties( "java.system" ).entrySet() ) { System.setProperty( entry.getKey(), entry.getValue() ); configurationProperties.getProperty( CONFIG_PROPERTY_CLASSPATH ) ); .getProperty( CONFIG_PROPERTY_IGNORE_CLASSES ); String[] ignoredClasses = null; if ( !StringUtil.isEmpty( ignoredClassesProperty ) ) { .getClassLoader(), classpathElements, configurationProperties, ignoredClasses ); verifyClasses( cl, configurationProperties.getProperty( "required.classes" ), configurationProperties.getProperty( "name" ) ); String name = configurationProperties.getProperty( CONFIG_PROPERTY_NAME, id ); registerNativeLibraryPaths( configurationProperties.getProperty( CONFIG_PROPERTY_LIBRARY_PATH ) );
List<URL> jars = findJarsIn( root, 3, configurationProperties.getConfigSet( SHIM_CLASSPATH_IGNORE ) ); jars = filterJars( jars, configurationProperties.getProperty( CONFIG_PROPERTY_EXCLUDE_JARS ) );
@Before public void setup() { windowsChecker = mock( WindowsChecker.class ); shimProperties = new ShimProperties( windowsChecker ); }
@Override public String getProperty( String key ) { List<String> configProperties = getShimConfigProperties( key ); for ( int i = configProperties.size() - 1; i >= 0; i-- ) { String property = configProperties.get( i ); if ( property != null ) { property = property.trim(); if ( property.length() > 0 ) { return property; } } } return super.getProperty( key ); }
private List<String> getShimConfigProperties( String property ) { List<String> shimConfigProperties = new ArrayList<String>(); for ( String config : getShimConfigs() ) { shimConfigProperties.add( super.getProperty( config + "." + property ) ); } return shimConfigProperties; }
@Test public void testGetConfigListReplaceWithShimConfig() { List<String> rootConfig = new ArrayList<String>( Arrays.asList( "one", "b", "iii" ) ); List<String> shimConfig = new ArrayList<String>( Arrays.asList( "1", "two", "tres" ) ); shimProperties.setProperty( "propName", join( ",", rootConfig ) ); shimProperties.setProperty( "mr1.propName", join( ",", shimConfig ) ); shimProperties.setProperty( ShimProperties.SHIM_CP_CONFIG, "mr1" ); assertEquals( shimConfig, shimProperties.getConfigList( "propName", ListOverrideType.REPLACE ) ); }
@Test public void testGetConfigSetOverlayWithNoRootConfig() { Set<String> shimConfig = new HashSet<String>( Arrays.asList( "1", "two", "tres" ) ); shimProperties.setProperty( "mr1.propName", join( ",", shimConfig ) ); assertEquals( new HashSet<String>(), shimProperties.getConfigSet( "propName", SetOverrideType.OVERLAY ) ); shimProperties.setProperty( ShimProperties.SHIM_CP_CONFIG, "mr1" ); assertEquals( shimConfig, shimProperties.getConfigSet( "propName", SetOverrideType.OVERLAY ) ); }
@Test public void testGetPrefixedOsPropertiesWindowsShimConfigTrumpedBySetConfig() { when( windowsChecker.isWindows() ).thenReturn( true ); shimProperties.setProperty( "java.system.flatclass", "false" ); shimProperties.setProperty( "windows.java.system.flatclass", "false" ); shimProperties.setProperty( "mr1.java.system.flatclass", "true" ); shimProperties.setProperty( ShimProperties.SHIM_CP_CONFIG, "mr1" ); assertEquals( "true", shimProperties.getProperty( "java.system.flatclass" ) ); }
@Test( expected = ConfigurationException.class ) public void createConfigurationLoader_null_root() throws ConfigurationException { HadoopConfigurationLocator locator = new HadoopConfigurationLocator(); locator.createConfigurationLoader( null, null, null, new ShimProperties() ); }
List<String> shimConfigValues = getShimConfigProperties( property ); Set<String> shimProperties = new HashSet<String>();
@Test public void testGetConfigListAppendWithShimConfig() { List<String> rootConfig = new ArrayList<String>( Arrays.asList( "one", "b", "iii" ) ); List<String> shimConfig = new ArrayList<String>( Arrays.asList( "1", "two", "tres" ) ); List<String> combinedList = new ArrayList<String>( rootConfig ); combinedList.addAll( shimConfig ); shimProperties.setProperty( "propName", join( ",", rootConfig ) ); shimProperties.setProperty( "mr1.propName", join( ",", shimConfig ) ); shimProperties.setProperty( ShimProperties.SHIM_CP_CONFIG, "mr1" ); assertEquals( combinedList, shimProperties.getConfigList( "propName", ListOverrideType.APPEND ) ); }
@Test public void testGetConfigSetOverlayWithShimConfig() { Set<String> rootConfig = new HashSet<String>( Arrays.asList( "one", "b", "iii" ) ); Set<String> shimConfig = new HashSet<String>( Arrays.asList( "1", "two", "tres" ) ); Set<String> combinedConfig = new HashSet<String>( rootConfig ); combinedConfig.addAll( shimConfig ); shimProperties.setProperty( "propName", join( ",", rootConfig ) ); shimProperties.setProperty( "mr1.propName", join( ",", shimConfig ) ); shimProperties.setProperty( ShimProperties.SHIM_CP_CONFIG, "mr1" ); assertEquals( combinedConfig, shimProperties.getConfigSet( "propName", SetOverrideType.OVERLAY ) ); }
@Test public void testGetPrefixedOsPropertiesLinuxShimConfig() { when( windowsChecker.isWindows() ).thenReturn( false ); shimProperties.setProperty( "java.system.flatclass", "false" ); shimProperties.setProperty( "linux.java.system.flatclass", "true" ); assertEquals( "true", shimProperties.getProperty( "java.system.flatclass" ) ); }