TerrapinUploaderOptions { public static TerrapinUploaderOptions initFromSystemProperties() { Properties properties = System.getProperties(); TerrapinUploaderOptions options = new TerrapinUploaderOptions(); options.terrapinZkQuorum = properties.getProperty("terrapin.zk_quorum"); options.terrapinNamenode = properties.getProperty("terrapin.namenode"); options.terrapinCluster = properties.getProperty("terrapin.cluster"); options.terrapinFileSet = properties.getProperty("fileset"); if (options.terrapinFileSet != null) { LOG.warn("Property fileset is deprecated. Please use terrapin.fileset."); } else { options.terrapinFileSet = properties.getProperty("terrapin.fileset"); } String s = properties.getProperty("terrapin.num_versions"); try { if (s != null) { options.loadOptions.setNumVersionsToKeep(Integer.parseInt(s)); } } catch (NumberFormatException e) { LOG.error("Invalid num versions : " + s + ". Using num versions as 1."); options.loadOptions.setNumVersionsToKeep(1); } options.loadOptions.setPartitioner(Enum.valueOf(PartitionerType.class, properties.getProperty("terrapin.partitioner", "MODULUS"))); return options; } TerrapinUploaderOptions(); static TerrapinUploaderOptions initFromSystemProperties(); void validate(); public String terrapinZkQuorum; public String terrapinNamenode; public String terrapinCluster; public String terrapinFileSet; public Options loadOptions; }
@Test @PrepareForTest(TerrapinUploaderOptions.class) public void testInitFromSystemProperties() { PowerMockito.mockStatic(System.class); Properties props = new Properties(); props.put("terrapin.zk_quorum", "test_quorum"); props.put("terrapin.namenode", "test_namenode"); props.put("terrapin.cluster", "test_cluster"); props.put("terrapin.fileset", "test_fileset"); props.put("terrapin.num_versions", "4"); props.put("terrapin.partitioner", PartitionerType.CASCADING.name()); when(System.getProperties()).thenReturn(props); TerrapinUploaderOptions options = TerrapinUploaderOptions.initFromSystemProperties(); options.validate(); assertEquals(props.get("terrapin.zk_quorum"), options.terrapinZkQuorum); assertEquals(props.get("terrapin.namenode"), options.terrapinNamenode); assertEquals(props.get("terrapin.cluster"), options.terrapinCluster); assertEquals(props.get("terrapin.fileset"), options.terrapinFileSet); assertEquals(Integer.valueOf((String) props.get("terrapin.num_versions")), Integer.valueOf(options.loadOptions.getNumVersionsToKeep())); assertEquals(props.get("terrapin.partitioner"), options.loadOptions.partitioner.name()); }