use of alluxio.SystemPropertyRule in project alluxio by Alluxio.
the class InstancedConfigurationTest method source.
@Test
public void source() throws Exception {
Properties siteProps = new Properties();
File propsFile = mFolder.newFile(Constants.SITE_PROPERTIES);
siteProps.setProperty(PropertyKey.MASTER_HOSTNAME.toString(), "host-1");
siteProps.setProperty(PropertyKey.MASTER_WEB_PORT.toString(), "1234");
siteProps.store(new FileOutputStream(propsFile), "tmp site properties file");
Map<String, String> sysProps = new HashMap<>();
sysProps.put(PropertyKey.LOGS_DIR.toString(), "/tmp/logs1");
sysProps.put(PropertyKey.MASTER_WEB_PORT.toString(), "4321");
sysProps.put(PropertyKey.SITE_CONF_DIR.toString(), mFolder.getRoot().getAbsolutePath());
sysProps.put(PropertyKey.TEST_MODE.toString(), "false");
try (Closeable p = new SystemPropertyRule(sysProps).toResource()) {
resetConf();
// set only in site prop
assertEquals(Source.Type.SITE_PROPERTY, mConfiguration.getSource(PropertyKey.MASTER_HOSTNAME).getType());
// set both in site and system prop
assertEquals(Source.SYSTEM_PROPERTY, mConfiguration.getSource(PropertyKey.MASTER_WEB_PORT));
// set only in system prop
assertEquals(Source.SYSTEM_PROPERTY, mConfiguration.getSource(PropertyKey.LOGS_DIR));
// set neither in system prop
assertEquals(Source.DEFAULT, mConfiguration.getSource(PropertyKey.MASTER_RPC_PORT));
}
}
use of alluxio.SystemPropertyRule in project alluxio by Alluxio.
the class InstancedConfigurationTest method validateTieredLocality.
@Test
public void validateTieredLocality() throws Exception {
// Pre-load the Configuration class so that the exception is thrown when we call init(), not
// during class loading.
resetConf();
HashMap<String, String> sysProps = new HashMap<>();
sysProps.put(Template.LOCALITY_TIER.format("unknownTier").toString(), "val");
try (Closeable p = new SystemPropertyRule(sysProps).toResource()) {
mThrown.expect(IllegalStateException.class);
mThrown.expectMessage("Tier unknownTier is configured by alluxio.locality.unknownTier, but " + "does not exist in the tier list [node, rack] configured by alluxio.locality.order");
resetConf();
}
}
use of alluxio.SystemPropertyRule in project alluxio by Alluxio.
the class InstancedConfigurationTest method setIgnoredPropertiesInSystemProperties.
@Test
public void setIgnoredPropertiesInSystemProperties() throws Exception {
Properties siteProps = new Properties();
File propsFile = mFolder.newFile(Constants.SITE_PROPERTIES);
siteProps.store(new FileOutputStream(propsFile), "tmp site properties file");
Map<String, String> sysProps = new HashMap<>();
sysProps.put(PropertyKey.LOGS_DIR.toString(), "/tmp/logs1");
sysProps.put(PropertyKey.SITE_CONF_DIR.toString(), mFolder.getRoot().getAbsolutePath());
sysProps.put(PropertyKey.TEST_MODE.toString(), "false");
try (Closeable p = new SystemPropertyRule(sysProps).toResource()) {
resetConf();
assertEquals(Source.SYSTEM_PROPERTY, mConfiguration.getSource(PropertyKey.LOGS_DIR));
assertEquals("/tmp/logs1", mConfiguration.get(PropertyKey.LOGS_DIR));
}
}
use of alluxio.SystemPropertyRule in project alluxio by Alluxio.
the class InstancedConfigurationTest method findPropertiesFileClasspath.
@Test
public void findPropertiesFileClasspath() throws Exception {
try (Closeable p = new SystemPropertyRule(PropertyKey.TEST_MODE.toString(), "false").toResource()) {
File dir = AlluxioTestDirectory.createTemporaryDirectory("findPropertiesFileClasspath");
CommonUtils.classLoadURL(dir.getCanonicalPath());
File props = new File(dir, "alluxio-site.properties");
try (BufferedWriter writer = Files.newBufferedWriter(props.toPath())) {
writer.write(String.format("%s=%s", PropertyKey.MASTER_HOSTNAME, "test_hostname"));
}
resetConf();
assertEquals("test_hostname", mConfiguration.get(PropertyKey.MASTER_HOSTNAME));
assertEquals(Source.siteProperty(props.getCanonicalPath()), mConfiguration.getSource(PropertyKey.MASTER_HOSTNAME));
props.delete();
}
}
use of alluxio.SystemPropertyRule in project alluxio by Alluxio.
the class InstancedConfigurationTest method unknownTieredStorageAlias.
@Test
public void unknownTieredStorageAlias() throws Exception {
for (String alias : Arrays.asList("mem", "ssd", "hdd", "unknown")) {
try (Closeable p = new SystemPropertyRule("alluxio.worker.tieredstore.level0.alias", alias).toResource()) {
resetConf();
mConfiguration.validate();
fail("Should have thrown a runtime exception when using an unknown tier alias");
} catch (RuntimeException e) {
assertTrue(e.getMessage().contains(String.format("Alias \"%s\" on tier 0 on worker (configured by %s) is not found " + "in global tiered", alias, Template.WORKER_TIERED_STORE_LEVEL_ALIAS.format(0))));
}
}
}
Aggregations