Search in sources :

Example 6 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class TieredIdentityFactoryTest method fromScriptClasspath.

@Test
public void fromScriptClasspath() throws Exception {
    String customScriptName = "my-alluxio-locality.sh";
    File dir = mFolder.newFolder("fromScriptClasspath");
    CommonUtils.classLoadURL(dir.getCanonicalPath());
    File script = new File(dir, customScriptName);
    setupScript("node=myhost,rack=myrack,custom=mycustom", script);
    try (Closeable c = new ConfigurationRule(ImmutableMap.of(PropertyKey.LOCALITY_ORDER, "node,rack,custom", PropertyKey.LOCALITY_SCRIPT, customScriptName), mConfiguration).toResource()) {
        TieredIdentity identity = TieredIdentityFactory.create(mConfiguration);
        TieredIdentity expected = new TieredIdentity(Arrays.asList(new LocalityTier("node", "myhost"), new LocalityTier("rack", "myrack"), new LocalityTier("custom", "mycustom")));
        assertEquals(expected, identity);
    }
    script.delete();
}
Also used : TieredIdentity(alluxio.wire.TieredIdentity) Closeable(java.io.Closeable) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) ConfigurationRule(alluxio.ConfigurationRule) LocalityTier(alluxio.wire.TieredIdentity.LocalityTier) Test(org.junit.Test)

Example 7 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class TieredIdentityFactoryTest method outOfOrderScript.

@Test
public void outOfOrderScript() throws Exception {
    String scriptPath = setupScript("rack=myrack,node=myhost", mFolder.newFile());
    try (Closeable c = new ConfigurationRule(ImmutableMap.of(PropertyKey.LOCALITY_SCRIPT, scriptPath), mConfiguration).toResource()) {
        TieredIdentity identity = TieredIdentityFactory.create(mConfiguration);
        TieredIdentity expected = new TieredIdentity(Arrays.asList(new LocalityTier("node", "myhost"), new LocalityTier("rack", "myrack")));
        assertEquals(expected, identity);
    }
}
Also used : TieredIdentity(alluxio.wire.TieredIdentity) Closeable(java.io.Closeable) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ConfigurationRule(alluxio.ConfigurationRule) LocalityTier(alluxio.wire.TieredIdentity.LocalityTier) Test(org.junit.Test)

Example 8 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class UnderFileSystemConfigurationTest method getValueWhenGlobalConfHasProperty.

@Test
public void getValueWhenGlobalConfHasProperty() throws Exception {
    // Set property in global configuration
    try (Closeable c = new ConfigurationRule(PropertyKey.S3A_ACCESS_KEY, "bar", mConfiguration).toResource()) {
        Random random = new Random();
        boolean readOnly = random.nextBoolean();
        boolean shared = random.nextBoolean();
        UnderFileSystemConfiguration conf = UnderFileSystemConfiguration.defaults(ConfigurationTestUtils.defaults()).setReadOnly(readOnly).setShared(shared);
        assertEquals(readOnly, conf.isReadOnly());
        assertEquals(shared, conf.isShared());
        assertEquals("bar", mConfiguration.get(PropertyKey.S3A_ACCESS_KEY));
        conf = UnderFileSystemConfiguration.defaults(ConfigurationTestUtils.defaults()).setReadOnly(readOnly).setShared(shared).createMountSpecificConf(ImmutableMap.of(PropertyKey.S3A_ACCESS_KEY.toString(), "foo"));
        assertEquals(readOnly, conf.isReadOnly());
        assertEquals(shared, conf.isShared());
        assertEquals("foo", conf.get(PropertyKey.S3A_ACCESS_KEY));
    }
}
Also used : Random(java.util.Random) Closeable(java.io.Closeable) ConfigurationRule(alluxio.ConfigurationRule) Test(org.junit.Test)

Example 9 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class UnderFileSystemConfigurationTest method getValueWhenGlobalConfHasNotProperty.

@Test
public void getValueWhenGlobalConfHasNotProperty() throws Exception {
    // Set property in global configuration
    try (Closeable c = new ConfigurationRule(PropertyKey.S3A_ACCESS_KEY, null, mConfiguration).toResource()) {
        Random random = new Random();
        boolean readOnly = random.nextBoolean();
        boolean shared = random.nextBoolean();
        UnderFileSystemConfiguration conf = UnderFileSystemConfiguration.defaults(mConfiguration).setReadOnly(readOnly).setShared(shared);
        try {
            conf.get(PropertyKey.S3A_ACCESS_KEY);
            fail("this key should not exist");
        } catch (Exception e) {
        // expect to pass
        }
        UnderFileSystemConfiguration conf2 = conf.createMountSpecificConf(ImmutableMap.of(PropertyKey.S3A_ACCESS_KEY.toString(), "foo"));
        assertEquals(readOnly, conf2.isReadOnly());
        assertEquals(shared, conf2.isShared());
        assertEquals("foo", conf2.get(PropertyKey.S3A_ACCESS_KEY));
    }
}
Also used : Random(java.util.Random) Closeable(java.io.Closeable) ConfigurationRule(alluxio.ConfigurationRule) Test(org.junit.Test)

Example 10 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class UnderFileSystemConfigurationTest method containsWhenGlobalConfHasNotProperty.

@Test
public void containsWhenGlobalConfHasNotProperty() throws Exception {
    // Unset property in global configuration
    try (Closeable c = new ConfigurationRule(PropertyKey.S3A_ACCESS_KEY, null, mConfiguration).toResource()) {
        Random random = new Random();
        boolean readOnly = random.nextBoolean();
        boolean shared = random.nextBoolean();
        UnderFileSystemConfiguration conf = UnderFileSystemConfiguration.defaults(mConfiguration).setReadOnly(readOnly).setShared(shared);
        assertFalse(conf.isSet(PropertyKey.S3A_ACCESS_KEY));
        UnderFileSystemConfiguration conf2 = conf.createMountSpecificConf(ImmutableMap.of(PropertyKey.S3A_ACCESS_KEY.toString(), "foo"));
        assertEquals(readOnly, conf2.isReadOnly());
        assertEquals(shared, conf2.isShared());
        assertTrue(conf2.isSet(PropertyKey.S3A_ACCESS_KEY));
    }
}
Also used : Random(java.util.Random) Closeable(java.io.Closeable) ConfigurationRule(alluxio.ConfigurationRule) Test(org.junit.Test)

Aggregations

ConfigurationRule (alluxio.ConfigurationRule)42 Closeable (java.io.Closeable)42 Test (org.junit.Test)40 HashMap (java.util.HashMap)16 File (java.io.File)6 AlluxioURI (alluxio.AlluxioURI)5 PropertyKey (alluxio.conf.PropertyKey)5 SeekableUnderFileInputStream (alluxio.underfs.SeekableUnderFileInputStream)5 TieredIdentity (alluxio.wire.TieredIdentity)5 InputStream (java.io.InputStream)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 UnderFileSystemConfiguration (alluxio.underfs.UnderFileSystemConfiguration)4 LocalityTier (alluxio.wire.TieredIdentity.LocalityTier)4 WorkerNetAddress (alluxio.wire.WorkerNetAddress)4 Random (java.util.Random)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 URIStatus (alluxio.client.file.URIStatus)3 CreateFilePOptions (alluxio.grpc.CreateFilePOptions)2 SetAttributePOptions (alluxio.grpc.SetAttributePOptions)2 ConnectDetails (alluxio.master.MasterInquireClient.ConnectDetails)2