Search in sources :

Example 16 with SystemPropertyRule

use of alluxio.SystemPropertyRule in project alluxio by Alluxio.

the class FileSystemFactoryTest method zkFileSystemCacheTest.

@Test
public void zkFileSystemCacheTest() {
    Map<String, String> sysProps = new HashMap<>();
    sysProps.put(PropertyKey.ZOOKEEPER_ENABLED.getName(), Boolean.toString(true));
    sysProps.put(PropertyKey.ZOOKEEPER_ADDRESS.getName(), "zk@192.168.0.5");
    sysProps.put(PropertyKey.ZOOKEEPER_ELECTION_PATH.getName(), "/alluxio/leader");
    try (Closeable p = new SystemPropertyRule(sysProps).toResource()) {
        ConfigurationUtils.reloadProperties();
        InstancedConfiguration conf = new InstancedConfiguration(ConfigurationUtils.defaults());
        MasterInquireClient.ConnectDetails connectDetails = MasterInquireClient.Factory.getConnectDetails(conf);
        // Make sure we have a Zookeeper authority
        assertTrue(connectDetails.toAuthority() instanceof ZookeeperAuthority);
        fileSystemCacheTest();
    } catch (IOException e) {
        fail("Unable to set system properties");
    }
}
Also used : MasterInquireClient(alluxio.master.MasterInquireClient) InstancedConfiguration(alluxio.conf.InstancedConfiguration) ZookeeperAuthority(alluxio.uri.ZookeeperAuthority) HashMap(java.util.HashMap) SystemPropertyRule(alluxio.SystemPropertyRule) Closeable(java.io.Closeable) IOException(java.io.IOException) Test(org.junit.Test)

Example 17 with SystemPropertyRule

use of alluxio.SystemPropertyRule in project alluxio by Alluxio.

the class InstancedConfigurationTest method noWhitespaceTrailingInSiteProperties.

@Test
public void noWhitespaceTrailingInSiteProperties() throws Exception {
    Properties siteProps = new Properties();
    siteProps.setProperty(PropertyKey.MASTER_HOSTNAME.toString(), " host-1 ");
    siteProps.setProperty(PropertyKey.WEB_THREADS.toString(), "\t123\t");
    File propsFile = mFolder.newFile(Constants.SITE_PROPERTIES);
    siteProps.store(new FileOutputStream(propsFile), "tmp site properties file");
    // Avoid interference from system properties. Reset SITE_CONF_DIR to include the temp
    // site-properties file
    HashMap<String, String> sysProps = new HashMap<>();
    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("host-1", mConfiguration.get(PropertyKey.MASTER_HOSTNAME));
        assertEquals("123", mConfiguration.get(PropertyKey.WEB_THREADS));
    }
}
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 18 with SystemPropertyRule

use of alluxio.SystemPropertyRule in project alluxio by Alluxio.

the class InstancedConfigurationTest method defaultLoggerCorrectlyLoaded.

@Test
public void defaultLoggerCorrectlyLoaded() throws Exception {
    // Avoid interference from system properties. site-properties will not be loaded during tests
    try (Closeable p = new SystemPropertyRule(PropertyKey.LOGGER_TYPE.toString(), null).toResource()) {
        String loggerType = mConfiguration.getString(PropertyKey.LOGGER_TYPE);
        assertEquals("Console", loggerType);
    }
}
Also used : SystemPropertyRule(alluxio.SystemPropertyRule) Closeable(java.io.Closeable) Test(org.junit.Test)

Example 19 with SystemPropertyRule

use of alluxio.SystemPropertyRule in project alluxio by Alluxio.

the class InstancedConfigurationTest method sitePropertiesLoadedNotInTest.

@Test
public void sitePropertiesLoadedNotInTest() throws Exception {
    Properties props = new Properties();
    props.setProperty(PropertyKey.LOGGER_TYPE.toString(), "TEST_LOGGER");
    File propsFile = mFolder.newFile(Constants.SITE_PROPERTIES);
    props.store(new FileOutputStream(propsFile), "ignored header");
    // Avoid interference from system properties. Reset SITE_CONF_DIR to include the temp
    // site-properties file
    HashMap<String, String> sysProps = new HashMap<>();
    sysProps.put(PropertyKey.LOGGER_TYPE.toString(), null);
    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("TEST_LOGGER", mConfiguration.get(PropertyKey.LOGGER_TYPE));
    }
}
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 20 with SystemPropertyRule

use of alluxio.SystemPropertyRule in project alluxio by Alluxio.

the class InstancedConfigurationTest method noPropertiesAnywhere.

@Test
public void noPropertiesAnywhere() throws Exception {
    try (Closeable p = new SystemPropertyRule(PropertyKey.TEST_MODE.toString(), "false").toResource()) {
        mConfiguration.unset(PropertyKey.SITE_CONF_DIR);
        resetConf();
        assertEquals("0.0.0.0", mConfiguration.get(PropertyKey.PROXY_WEB_BIND_HOST));
    }
}
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