Search in sources :

Example 6 with SystemPropertyRule

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));
    }
}
Also used : HashMap(java.util.HashMap) SystemPropertyRule(alluxio.SystemPropertyRule) FileOutputStream(java.io.FileOutputStream) Closeable(java.io.Closeable) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 7 with SystemPropertyRule

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();
    }
}
Also used : HashMap(java.util.HashMap) SystemPropertyRule(alluxio.SystemPropertyRule) Closeable(java.io.Closeable) Test(org.junit.Test)

Example 8 with SystemPropertyRule

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));
    }
}
Also used : HashMap(java.util.HashMap) SystemPropertyRule(alluxio.SystemPropertyRule) FileOutputStream(java.io.FileOutputStream) Closeable(java.io.Closeable) Properties(java.util.Properties) File(java.io.File) Test(org.junit.Test)

Example 9 with SystemPropertyRule

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();
    }
}
Also used : SystemPropertyRule(alluxio.SystemPropertyRule) Closeable(java.io.Closeable) File(java.io.File) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 10 with SystemPropertyRule

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))));
        }
    }
}
Also used : SystemPropertyRule(alluxio.SystemPropertyRule) Closeable(java.io.Closeable) Test(org.junit.Test)

Aggregations

SystemPropertyRule (alluxio.SystemPropertyRule)24 Closeable (java.io.Closeable)24 Test (org.junit.Test)24 HashMap (java.util.HashMap)13 File (java.io.File)9 FileOutputStream (java.io.FileOutputStream)6 Properties (java.util.Properties)6 AlluxioURI (alluxio.AlluxioURI)3 AbstractFileSystemShellTest (alluxio.client.cli.fs.AbstractFileSystemShellTest)3 FileSystemShellUtilsTest (alluxio.client.cli.fs.FileSystemShellUtilsTest)3 InstancedConfiguration (alluxio.conf.InstancedConfiguration)2 MasterInquireClient (alluxio.master.MasterInquireClient)2 IOException (java.io.IOException)2 URI (java.net.URI)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ClientContext (alluxio.ClientContext)1 MultiMasterAuthority (alluxio.uri.MultiMasterAuthority)1 ZookeeperAuthority (alluxio.uri.ZookeeperAuthority)1 BufferedWriter (java.io.BufferedWriter)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1