Search in sources :

Example 1 with ClientContext

use of alluxio.ClientContext in project alluxio by Alluxio.

the class FileSystemContext method create.

/**
 * This method is provided for testing, use the {@link FileSystemContext#create} methods. The
 * returned context object will not be cached automatically.
 *
 * @param subject the parent subject, set to null if not present
 * @param masterInquireClient the client to use for determining the master; note that if the
 *        context is reset, this client will be replaced with a new masterInquireClient based on
 *        the original configuration.
 * @param alluxioConf Alluxio configuration
 * @return the context
 */
@VisibleForTesting
public static FileSystemContext create(Subject subject, MasterInquireClient masterInquireClient, AlluxioConfiguration alluxioConf) {
    FileSystemContext context = new FileSystemContext(alluxioConf, null);
    ClientContext ctx = ClientContext.create(subject, alluxioConf);
    context.init(ctx, masterInquireClient);
    return context;
}
Also used : ClientContext(alluxio.ClientContext) MasterClientContext(alluxio.master.MasterClientContext) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with ClientContext

use of alluxio.ClientContext in project alluxio by Alluxio.

the class OutStreamOptionsTest method equalsTest.

@Test
public void equalsTest() throws Exception {
    ClientContext clientContext = ClientContext.create(mConf);
    new EqualsTester().addEqualityGroup(OutStreamOptions.defaults(clientContext), OutStreamOptions.defaults(clientContext)).testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) ClientContext(alluxio.ClientContext) Test(org.junit.Test)

Example 3 with ClientContext

use of alluxio.ClientContext in project alluxio by Alluxio.

the class OutStreamOptionsTest method defaults.

/**
 * Tests that building an {@link OutStreamOptions} with the defaults works.
 */
@Test
public void defaults() throws IOException {
    AlluxioStorageType alluxioType = AlluxioStorageType.STORE;
    UnderStorageType ufsType = UnderStorageType.SYNC_PERSIST;
    mConf.set(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT, "64MB");
    mConf.set(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, WriteType.CACHE_THROUGH.toString());
    mConf.set(PropertyKey.USER_FILE_WRITE_TIER_DEFAULT, Constants.LAST_TIER);
    mConf.set(PropertyKey.SECURITY_GROUP_MAPPING_CLASS, FakeUserGroupsMapping.class.getName());
    Subject subject = new Subject();
    subject.getPrincipals().add(new User("test_user"));
    ClientContext clientContext = ClientContext.create(subject, mConf);
    OutStreamOptions options = OutStreamOptions.defaults(clientContext);
    assertEquals(alluxioType, options.getAlluxioStorageType());
    assertEquals(64 * Constants.MB, options.getBlockSizeBytes());
    assertTrue(options.getLocationPolicy() instanceof LocalFirstPolicy);
    assertEquals("test_user", options.getOwner());
    assertEquals("test_group", options.getGroup());
    assertEquals(ModeUtils.applyFileUMask(Mode.defaults(), mConf.getString(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)), options.getMode());
    assertEquals(Constants.NO_TTL, options.getCommonOptions().getTtl());
    assertEquals(TtlAction.DELETE, options.getCommonOptions().getTtlAction());
    assertEquals(ufsType, options.getUnderStorageType());
    assertEquals(WriteType.CACHE_THROUGH, options.getWriteType());
    assertEquals(Constants.LAST_TIER, options.getWriteTier());
}
Also used : UnderStorageType(alluxio.client.UnderStorageType) User(alluxio.security.User) ClientContext(alluxio.ClientContext) LocalFirstPolicy(alluxio.client.block.policy.LocalFirstPolicy) AlluxioStorageType(alluxio.client.AlluxioStorageType) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 4 with ClientContext

use of alluxio.ClientContext in project alluxio by Alluxio.

the class MetricsHeartbeatContextTest method testCancelFuture.

@Test
public void testCancelFuture() {
    Map<MasterInquireClient.ConnectDetails, MetricsHeartbeatContext> map = getContextMap();
    assertTrue(map.isEmpty());
    ScheduledFuture<?> future = Mockito.mock(ScheduledFuture.class);
    when(future.cancel(any(Boolean.class))).thenReturn(true);
    InstancedConfiguration conf = ConfigurationTestUtils.defaults();
    conf.set(PropertyKey.USER_RPC_RETRY_MAX_DURATION, "1s");
    ClientContext ctx = ClientContext.create(conf);
    MasterInquireClient client = MasterInquireClient.Factory.create(ctx.getClusterConf(), ctx.getUserState());
    MetricsHeartbeatContext.addHeartbeat(ctx, client);
    assertFalse(map.isEmpty());
    map.forEach((addr, heartbeat) -> {
        ScheduledFuture<?> realFuture = Whitebox.getInternalState(heartbeat, "mMetricsMasterHeartbeatTask");
        // Should be created and scheduled
        assertNotNull(realFuture);
        // Scheduled indefinitely
        assertFalse(realFuture.isDone());
        Whitebox.setInternalState(heartbeat, "mMetricsMasterHeartbeatTask", future);
        // Cancel the real one once replaced with a mock.
        realFuture.cancel(false);
    });
    MetricsHeartbeatContext.removeHeartbeat(ctx);
    // Make sure the future is canceled afterwards
    verify(future).cancel(false);
}
Also used : MasterInquireClient(alluxio.master.MasterInquireClient) InstancedConfiguration(alluxio.conf.InstancedConfiguration) ClientContext(alluxio.ClientContext) Test(org.junit.Test)

Example 5 with ClientContext

use of alluxio.ClientContext in project alluxio by Alluxio.

the class MetricsHeartbeatContextTest method testContextCounter.

@Test
public void testContextCounter() {
    Map<MasterInquireClient.ConnectDetails, MetricsHeartbeatContext> map = getContextMap();
    assertTrue(map.isEmpty());
    InstancedConfiguration conf = ConfigurationTestUtils.defaults();
    conf.set(PropertyKey.USER_RPC_RETRY_MAX_DURATION, "1s");
    ClientContext ctx = ClientContext.create(conf);
    MasterInquireClient client = MasterInquireClient.Factory.create(ctx.getClusterConf(), ctx.getUserState());
    MetricsHeartbeatContext.addHeartbeat(ctx, client);
    assertFalse(map.isEmpty());
    map.forEach((details, context) -> assertEquals(1, (int) Whitebox.getInternalState(context, "mCtxCount")));
    MetricsHeartbeatContext.addHeartbeat(ctx, client);
    map.forEach((details, context) -> assertEquals(2, (int) Whitebox.getInternalState(context, "mCtxCount")));
    conf = ConfigurationTestUtils.defaults();
    conf.set(PropertyKey.USER_RPC_RETRY_MAX_DURATION, "1s");
    conf.set(PropertyKey.MASTER_RPC_ADDRESSES, "master1:19998,master2:19998,master3:19998");
    ClientContext haCtx = ClientContext.create(conf);
    MetricsHeartbeatContext.addHeartbeat(haCtx, MasterInquireClient.Factory.create(conf, haCtx.getUserState()));
    assertEquals(2, map.size());
    MetricsHeartbeatContext.removeHeartbeat(ctx);
    assertEquals(2, map.size());
    map.forEach((details, context) -> assertEquals(1, (int) Whitebox.getInternalState(context, "mCtxCount")));
    assertNotNull(getInternalExecutor());
    MetricsHeartbeatContext.removeHeartbeat(ctx);
    MetricsHeartbeatContext.removeHeartbeat(haCtx);
    assertNull(getInternalExecutor());
    assertTrue(map.isEmpty());
}
Also used : MasterInquireClient(alluxio.master.MasterInquireClient) InstancedConfiguration(alluxio.conf.InstancedConfiguration) ClientContext(alluxio.ClientContext) Test(org.junit.Test)

Aggregations

ClientContext (alluxio.ClientContext)20 Test (org.junit.Test)12 MasterClientContext (alluxio.master.MasterClientContext)7 MasterInquireClient (alluxio.master.MasterInquireClient)6 InstancedConfiguration (alluxio.conf.InstancedConfiguration)4 JobMasterClientContext (alluxio.worker.job.JobMasterClientContext)3 IOException (java.io.IOException)3 BlockMasterClient (alluxio.client.block.BlockMasterClient)2 FileSystemContext (alluxio.client.file.FileSystemContext)2 BlockMasterInfo (alluxio.wire.BlockMasterInfo)2 HashSet (java.util.HashSet)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 SystemPropertyRule (alluxio.SystemPropertyRule)1 FuseShell (alluxio.cli.FuseShell)1 Context (alluxio.cli.fsadmin.command.Context)1 AlluxioStorageType (alluxio.client.AlluxioStorageType)1 UnderStorageType (alluxio.client.UnderStorageType)1 WriteType (alluxio.client.WriteType)1 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)1 RetryHandlingBlockMasterClient (alluxio.client.block.RetryHandlingBlockMasterClient)1