Search in sources :

Example 31 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class BlockInStreamTest method createShortCircuitDisabled.

@Test
public void createShortCircuitDisabled() throws Exception {
    try (Closeable c = new ConfigurationRule(PropertyKey.USER_SHORT_CIRCUIT_ENABLED, false, mConf).toResource()) {
        WorkerNetAddress dataSource = new WorkerNetAddress();
        when(mMockContext.getClientContext()).thenReturn(ClientContext.create(mConf));
        BlockInStream.BlockInStreamSource dataSourceType = BlockInStream.BlockInStreamSource.NODE_LOCAL;
        BlockInStream stream = BlockInStream.create(mMockContext, mInfo, dataSource, dataSourceType, mOptions);
        assertEquals(GrpcDataReader.Factory.class.getName(), stream.getDataReaderFactory().getClass().getName());
    }
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) Closeable(java.io.Closeable) ConfigurationRule(alluxio.ConfigurationRule) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 32 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class FormatTest method formatWorkerDeleteFileSameName.

@Test
public void formatWorkerDeleteFileSameName() throws Exception {
    final int storageLevels = 3;
    String workerDataFolder;
    final File[] dirs = new File[] { mTemporaryFolder.newFolder("level0"), mTemporaryFolder.newFolder("level1"), mTemporaryFolder.newFolder("level2") };
    // Have files of same name as the target worker data dir in each tier
    for (File dir : dirs) {
        workerDataFolder = CommonUtils.getWorkerDataDirectory(dir.getPath(), ServerConfiguration.global());
        FileUtils.createFile(workerDataFolder);
    }
    try (Closeable r = new ConfigurationRule(new HashMap<PropertyKey, Object>() {

        {
            put(PropertyKey.WORKER_TIERED_STORE_LEVEL0_DIRS_PATH, dirs[0].getPath());
            put(PropertyKey.WORKER_TIERED_STORE_LEVEL1_DIRS_PATH, dirs[1].getPath());
            put(PropertyKey.WORKER_TIERED_STORE_LEVEL2_DIRS_PATH, dirs[2].getPath());
            put(PropertyKey.WORKER_TIERED_STORE_LEVELS, storageLevels);
        }
    }, ServerConfiguration.global()).toResource()) {
        final String perms = ServerConfiguration.getString(PropertyKey.WORKER_DATA_FOLDER_PERMISSIONS);
        Format.format(Format.Mode.WORKER, ServerConfiguration.global());
        for (File dir : dirs) {
            workerDataFolder = CommonUtils.getWorkerDataDirectory(dir.getPath(), ServerConfiguration.global());
            assertTrue(Files.isDirectory(Paths.get(workerDataFolder)));
            assertEquals(PosixFilePermissions.fromString(perms), Files.getPosixFilePermissions(Paths.get(workerDataFolder)));
            try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(workerDataFolder))) {
                for (Path child : directoryStream) {
                    fail("No sub dirs or files are expected in " + child.toString());
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) Closeable(java.io.Closeable) File(java.io.File) ConfigurationRule(alluxio.ConfigurationRule) Test(org.junit.Test)

Example 33 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class FormatTest method formatWorker.

@Test
public void formatWorker() throws Exception {
    final int storageLevels = 3;
    final String perms = "rwx------";
    String workerDataFolder;
    final File[] dirs = new File[] { mTemporaryFolder.newFolder("level0"), mTemporaryFolder.newFolder("level1"), mTemporaryFolder.newFolder("level2") };
    for (File dir : dirs) {
        workerDataFolder = CommonUtils.getWorkerDataDirectory(dir.getPath(), ServerConfiguration.global());
        FileUtils.createDir(PathUtils.concatPath(workerDataFolder, "subdir"));
        FileUtils.createFile(PathUtils.concatPath(workerDataFolder, "file"));
    }
    try (Closeable r = new ConfigurationRule(new HashMap<PropertyKey, Object>() {

        {
            put(PropertyKey.WORKER_TIERED_STORE_LEVEL0_DIRS_PATH, dirs[0].getPath());
            put(PropertyKey.WORKER_TIERED_STORE_LEVEL1_DIRS_PATH, dirs[1].getPath());
            put(PropertyKey.WORKER_TIERED_STORE_LEVEL2_DIRS_PATH, dirs[2].getPath());
            put(PropertyKey.WORKER_TIERED_STORE_LEVELS, String.valueOf(storageLevels));
            put(PropertyKey.WORKER_DATA_FOLDER_PERMISSIONS, perms);
        }
    }, ServerConfiguration.global()).toResource()) {
        Format.format(Format.Mode.WORKER, ServerConfiguration.global());
        for (File dir : dirs) {
            workerDataFolder = CommonUtils.getWorkerDataDirectory(dir.getPath(), ServerConfiguration.global());
            assertTrue(FileUtils.exists(dir.getPath()));
            assertTrue(FileUtils.exists(workerDataFolder));
            assertEquals(PosixFilePermissions.fromString(perms), Files.getPosixFilePermissions(Paths.get(workerDataFolder)));
            try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(workerDataFolder))) {
                for (Path child : directoryStream) {
                    fail("No sub dirs or files are expected in " + child.toString());
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) Closeable(java.io.Closeable) File(java.io.File) ConfigurationRule(alluxio.ConfigurationRule) Test(org.junit.Test)

Example 34 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class S3AUnderFileSystemTest method createCredentialsFromConf.

@Test
public void createCredentialsFromConf() throws Exception {
    Map<PropertyKey, Object> conf = new HashMap<>();
    conf.put(PropertyKey.S3A_ACCESS_KEY, "key1");
    conf.put(PropertyKey.S3A_SECRET_KEY, "key2");
    try (Closeable c = new ConfigurationRule(conf, sConf).toResource()) {
        UnderFileSystemConfiguration ufsConf = UnderFileSystemConfiguration.defaults(sConf);
        AWSCredentialsProvider credentialsProvider = S3AUnderFileSystem.createAwsCredentialsProvider(ufsConf);
        Assert.assertEquals("key1", credentialsProvider.getCredentials().getAWSAccessKeyId());
        Assert.assertEquals("key2", credentialsProvider.getCredentials().getAWSSecretKey());
        Assert.assertTrue(credentialsProvider instanceof AWSStaticCredentialsProvider);
    }
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) HashMap(java.util.HashMap) UnderFileSystemConfiguration(alluxio.underfs.UnderFileSystemConfiguration) Closeable(java.io.Closeable) ConfigurationRule(alluxio.ConfigurationRule) PropertyKey(alluxio.conf.PropertyKey) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) Test(org.junit.Test)

Example 35 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class S3AUnderFileSystemTest method createCredentialsFromDefault.

@Test
public void createCredentialsFromDefault() throws Exception {
    // Unset AWS properties if present
    Map<PropertyKey, Object> conf = new HashMap<>();
    conf.put(PropertyKey.S3A_ACCESS_KEY, null);
    conf.put(PropertyKey.S3A_SECRET_KEY, null);
    try (Closeable c = new ConfigurationRule(conf, sConf).toResource()) {
        UnderFileSystemConfiguration ufsConf = UnderFileSystemConfiguration.defaults(sConf);
        AWSCredentialsProvider credentialsProvider = S3AUnderFileSystem.createAwsCredentialsProvider(ufsConf);
        Assert.assertTrue(credentialsProvider instanceof DefaultAWSCredentialsProviderChain);
    }
}
Also used : DefaultAWSCredentialsProviderChain(com.amazonaws.auth.DefaultAWSCredentialsProviderChain) HashMap(java.util.HashMap) UnderFileSystemConfiguration(alluxio.underfs.UnderFileSystemConfiguration) Closeable(java.io.Closeable) ConfigurationRule(alluxio.ConfigurationRule) PropertyKey(alluxio.conf.PropertyKey) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) 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