Search in sources :

Example 26 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class GroupMappingServiceTest method group.

/**
 * Tests the {@link GroupMappingService#getGroups(String)} method.
 */
@Test
public void group() throws Throwable {
    String userName = "alluxio-user1";
    InstancedConfiguration conf = new InstancedConfiguration(ConfigurationUtils.defaults());
    try (Closeable mConfigurationRule = new ConfigurationRule(PropertyKey.SECURITY_GROUP_MAPPING_CLASS, IdentityUserGroupsMapping.class.getName(), conf).toResource()) {
        GroupMappingService groups = GroupMappingService.Factory.get(conf);
        assertNotNull(groups);
        assertNotNull(groups.getGroups(userName));
        assertEquals(groups.getGroups(userName).size(), 1);
        assertEquals(groups.getGroups(userName).get(0), userName);
    }
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) Closeable(java.io.Closeable) ConfigurationRule(alluxio.ConfigurationRule) Test(org.junit.Test)

Example 27 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class UnderFileSystemConfigurationTest method getValueWhenGlobalConfOverridesPropertyWithDefaultValue.

@Test
public void getValueWhenGlobalConfOverridesPropertyWithDefaultValue() throws Exception {
    // Set property in global configuration
    try (Closeable c = new ConfigurationRule(PropertyKey.UNDERFS_LISTING_LENGTH, "2000", mConfiguration).toResource()) {
        UnderFileSystemConfiguration conf = UnderFileSystemConfiguration.defaults(mConfiguration);
        assertEquals("2000", conf.get(PropertyKey.UNDERFS_LISTING_LENGTH));
    }
}
Also used : Closeable(java.io.Closeable) ConfigurationRule(alluxio.ConfigurationRule) Test(org.junit.Test)

Example 28 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class UfsInputStreamCacheTest method releaseExpiredDifferentFile.

@Test
public void releaseExpiredDifferentFile() throws Exception {
    try (Closeable r = new ConfigurationRule(new HashMap<PropertyKey, Object>() {

        {
            put(PropertyKey.WORKER_UFS_INSTREAM_CACHE_EXPIRARTION_TIME, "2");
        }
    }, ServerConfiguration.global()).toResource()) {
        mManager = new UfsInputStreamCache();
        // check out a stream
        InputStream instream = mManager.acquire(mUfs, FILE_NAME, FILE_ID, OpenOptions.defaults().setOffset(2));
        // wait a bit for a stream to be expired
        Thread.sleep(100);
        // check out another stream should trigger the timeout
        mManager.acquire(mUfs, FILE_NAME + "2", FILE_ID + 1, OpenOptions.defaults().setOffset(4));
        // wait a bit so release occurs after removal listener
        Thread.sleep(100);
        mManager.release(instream);
        // verify the stream was closed once
        verify(mSeekableInStreams[0], timeout(2000).times(1)).close();
    }
}
Also used : HashMap(java.util.HashMap) SeekableUnderFileInputStream(alluxio.underfs.SeekableUnderFileInputStream) InputStream(java.io.InputStream) Closeable(java.io.Closeable) ConfigurationRule(alluxio.ConfigurationRule) Test(org.junit.Test)

Example 29 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class UfsInputStreamCacheTest method concurrencyWithExpiration.

@Test
public void concurrencyWithExpiration() throws Exception {
    try (Closeable r = new ConfigurationRule(new HashMap<PropertyKey, Object>() {

        {
            put(PropertyKey.WORKER_UFS_INSTREAM_CACHE_EXPIRARTION_TIME, "20");
        }
    }, ServerConfiguration.global()).toResource()) {
        mManager = new UfsInputStreamCache();
        List<Thread> threads = new ArrayList<>();
        int numCheckOutPerThread = 4;
        for (int i = 0; i < mNumOfInputStreams / numCheckOutPerThread; i++) {
            Runnable runnable = () -> {
                for (int j = 0; j < numCheckOutPerThread; j++) {
                    InputStream instream;
                    try {
                        instream = mManager.acquire(mUfs, FILE_NAME, FILE_ID, OpenOptions.defaults().setOffset(j));
                        mManager.release(instream);
                        Thread.sleep(200);
                    } catch (Exception e) {
                        // the input streams created should not be more than mNumOfInputStreams
                        Assert.fail("input stream check in and out failed." + e);
                    }
                }
            };
            threads.add(new Thread(runnable));
        }
        ConcurrencyUtils.assertConcurrent(threads, 30);
        // ensure at least one expired in stream is closed
        verify(mSeekableInStreams[0], timeout(2000)).close();
    }
}
Also used : HashMap(java.util.HashMap) SeekableUnderFileInputStream(alluxio.underfs.SeekableUnderFileInputStream) InputStream(java.io.InputStream) Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) ConfigurationRule(alluxio.ConfigurationRule) Test(org.junit.Test)

Example 30 with ConfigurationRule

use of alluxio.ConfigurationRule in project alluxio by Alluxio.

the class UfsInputStreamCacheTest method expire.

@Test
public void expire() throws Exception {
    try (Closeable r = new ConfigurationRule(new HashMap<PropertyKey, Object>() {

        {
            put(PropertyKey.WORKER_UFS_INSTREAM_CACHE_EXPIRARTION_TIME, "2");
        }
    }, ServerConfiguration.global()).toResource()) {
        mManager = new UfsInputStreamCache();
        // check out a stream
        InputStream instream = mManager.acquire(mUfs, FILE_NAME, FILE_ID, OpenOptions.defaults().setOffset(2));
        // check in back
        mManager.release(instream);
        Thread.sleep(10);
        // check out another stream should trigger the timeout
        mManager.acquire(mUfs, FILE_NAME, FILE_ID, OpenOptions.defaults().setOffset(4));
        verify(mSeekableInStreams[0], timeout(2000).times(1)).close();
    }
}
Also used : HashMap(java.util.HashMap) SeekableUnderFileInputStream(alluxio.underfs.SeekableUnderFileInputStream) InputStream(java.io.InputStream) 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