Search in sources :

Example 1 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class AlluxioBlockStoreTest method getInStreamUfsMockLocaltion.

@Test
public void getInStreamUfsMockLocaltion() throws Exception {
    try (Closeable c = new ConfigurationRule(PropertyKey.USER_UFS_BLOCK_READ_LOCATION_POLICY, MockBlockLocationPolicy.class.getTypeName(), sConf).toResource()) {
        WorkerNetAddress worker1 = new WorkerNetAddress().setHost("worker1");
        WorkerNetAddress worker2 = new WorkerNetAddress().setHost("worker2");
        BlockInfo info = new BlockInfo().setBlockId(0);
        URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(true).setBlockIds(Collections.singletonList(0L)).setFileBlockInfos(Collections.singletonList(new FileBlockInfo().setBlockInfo(info))));
        OpenFilePOptions readOptions = OpenFilePOptions.newBuilder().build();
        InStreamOptions options = new InStreamOptions(dummyStatus, readOptions, sConf);
        ((MockBlockLocationPolicy) options.getUfsReadLocationPolicy()).setHosts(Arrays.asList(worker1, worker2));
        when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(new BlockInfo());
        when(mContext.getCachedWorkers()).thenReturn(Lists.newArrayList(new BlockWorkerInfo(worker1, -1, -1), new BlockWorkerInfo(worker2, -1, -1)));
        // Location policy chooses worker1 first.
        assertEquals(worker1, mBlockStore.getInStream(BLOCK_ID, options).getAddress());
        // Location policy chooses worker2 second.
        assertEquals(worker2, mBlockStore.getInStream(BLOCK_ID, options).getAddress());
    }
}
Also used : FileInfo(alluxio.wire.FileInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) Closeable(java.io.Closeable) URIStatus(alluxio.client.file.URIStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) ConfigurationRule(alluxio.ConfigurationRule) InStreamOptions(alluxio.client.file.options.InStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class AbstractFileSystemTest method hadoopShouldLoadFileSystemWhenConfigured.

@Test
public void hadoopShouldLoadFileSystemWhenConfigured() throws Exception {
    org.apache.hadoop.conf.Configuration conf = getConf();
    URI uri = URI.create(Constants.HEADER + "localhost:19998/tmp/path.txt");
    Map<PropertyKey, Object> properties = new HashMap<>();
    properties.put(PropertyKey.MASTER_HOSTNAME, uri.getHost());
    properties.put(PropertyKey.MASTER_RPC_PORT, Integer.toString(uri.getPort()));
    properties.put(PropertyKey.ZOOKEEPER_ENABLED, false);
    properties.put(PropertyKey.ZOOKEEPER_ADDRESS, null);
    try (Closeable c = new ConfigurationRule(properties, mConfiguration).toResource()) {
        final org.apache.hadoop.fs.FileSystem fs = org.apache.hadoop.fs.FileSystem.get(uri, conf);
        assertTrue(fs instanceof FileSystem);
    }
}
Also used : HashMap(java.util.HashMap) Closeable(java.io.Closeable) URI(java.net.URI) AlluxioURI(alluxio.AlluxioURI) Configuration(org.apache.hadoop.conf.Configuration) ConfigurationRule(alluxio.ConfigurationRule) PropertyKey(alluxio.conf.PropertyKey) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class AbstractFileSystemTest method getBlockLocationsNoUfsLocationsWithFallback.

@Test
public void getBlockLocationsNoUfsLocationsWithFallback() throws Exception {
    WorkerNetAddress worker1 = new WorkerNetAddress().setHost("worker1").setDataPort(1234);
    WorkerNetAddress worker2 = new WorkerNetAddress().setHost("worker2").setDataPort(1234);
    List<WorkerNetAddress> blockWorkers = Arrays.asList();
    List<String> ufsLocations = Arrays.asList();
    List<WorkerNetAddress> allWorkers = Arrays.asList(worker1, worker2);
    List<WorkerNetAddress> expectedWorkers = Arrays.asList(worker1, worker2);
    try (Closeable conf = new ConfigurationRule(PropertyKey.USER_UFS_BLOCK_LOCATION_ALL_FALLBACK_ENABLED, true, mConfiguration).toResource()) {
        verifyBlockLocations(blockWorkers, ufsLocations, allWorkers, expectedWorkers);
    }
}
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 4 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class TieredIdentityFactoryTest method fromScript.

@Test
public void fromScript() throws Exception {
    String scriptPath = setupScript("node=myhost,rack=myrack,custom=mycustom", mFolder.newFile());
    try (Closeable c = new ConfigurationRule(ImmutableMap.of(PropertyKey.LOCALITY_ORDER, "node,rack,custom", 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"), new LocalityTier("custom", "mycustom")));
        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 5 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class TieredIdentityFactoryTest method overrideScript.

@Test
public void overrideScript() throws Exception {
    String scriptPath = setupScript("node=myhost,rack=myrack,custom=mycustom", mFolder.newFile());
    try (Closeable c = new ConfigurationRule(ImmutableMap.of(Template.LOCALITY_TIER.format("node"), "overridden", PropertyKey.LOCALITY_ORDER, "node,rack,custom", PropertyKey.LOCALITY_SCRIPT, scriptPath), mConfiguration).toResource()) {
        TieredIdentity identity = TieredIdentityFactory.create(mConfiguration);
        TieredIdentity expected = new TieredIdentity(Arrays.asList(new LocalityTier("node", "overridden"), new LocalityTier("rack", "myrack"), new LocalityTier("custom", "mycustom")));
        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)

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