Search in sources :

Example 11 with ClientContext

use of alluxio.ClientContext in project alluxio by Alluxio.

the class OutStreamOptionsTest method fields.

/**
 * Tests getting and setting fields.
 */
@Test
public void fields() throws Exception {
    Random random = new Random();
    long blockSize = random.nextLong();
    BlockLocationPolicy locationPolicy = new RoundRobinPolicy(mConf);
    String owner = CommonUtils.randomAlphaNumString(10);
    String group = CommonUtils.randomAlphaNumString(10);
    Mode mode = new Mode((short) random.nextInt());
    int ttl = 5;
    TtlAction ttlAction = TtlAction.FREE;
    int writeTier = random.nextInt();
    WriteType writeType = WriteType.NONE;
    mConf.set(PropertyKey.USER_FILE_CREATE_TTL, ttl);
    mConf.set(PropertyKey.USER_FILE_CREATE_TTL_ACTION, ttlAction);
    ClientContext clientContext = ClientContext.create(mConf);
    OutStreamOptions options = OutStreamOptions.defaults(clientContext);
    options.setBlockSizeBytes(blockSize);
    options.setLocationPolicy(locationPolicy);
    options.setOwner(owner);
    options.setGroup(group);
    options.setMode(mode);
    options.setWriteTier(writeTier);
    options.setWriteType(writeType);
    assertEquals(blockSize, options.getBlockSizeBytes());
    assertEquals(locationPolicy, options.getLocationPolicy());
    assertEquals(owner, options.getOwner());
    assertEquals(group, options.getGroup());
    assertEquals(mode, options.getMode());
    assertEquals(ttl, options.getCommonOptions().getTtl());
    assertEquals(ttlAction, options.getCommonOptions().getTtlAction());
    assertEquals(writeTier, options.getWriteTier());
    assertEquals(writeType.getAlluxioStorageType(), options.getAlluxioStorageType());
    assertEquals(writeType.getUnderStorageType(), options.getUnderStorageType());
}
Also used : TtlAction(alluxio.grpc.TtlAction) Random(java.util.Random) WriteType(alluxio.client.WriteType) Mode(alluxio.security.authorization.Mode) ClientContext(alluxio.ClientContext) BlockLocationPolicy(alluxio.client.block.policy.BlockLocationPolicy) RoundRobinPolicy(alluxio.client.block.policy.RoundRobinPolicy) Test(org.junit.Test)

Example 12 with ClientContext

use of alluxio.ClientContext in project alluxio by Alluxio.

the class MetricsHeartbeatContextTest method testExecutorInitialized.

@Test
public void testExecutorInitialized() {
    InstancedConfiguration conf = ConfigurationTestUtils.defaults();
    conf.set(PropertyKey.MASTER_HOSTNAME, "localhost");
    conf.set(PropertyKey.USER_RPC_RETRY_MAX_DURATION, "1s");
    ClientContext ctx = ClientContext.create(conf);
    MasterInquireClient client = MasterInquireClient.Factory.create(ctx.getClusterConf(), ctx.getUserState());
    // Add and delete a single context, make sure it is non null after adding, and then null after
    // removing
    MetricsHeartbeatContext.addHeartbeat(ctx, client);
    assertNotNull(getInternalExecutor());
    MetricsHeartbeatContext.removeHeartbeat(ctx);
    assertNull(getInternalExecutor());
    // Add a few, then remove and check for the state in between
    MetricsHeartbeatContext.addHeartbeat(ctx, client);
    MetricsHeartbeatContext.addHeartbeat(ctx, client);
    MetricsHeartbeatContext.addHeartbeat(ctx, client);
    MetricsHeartbeatContext.addHeartbeat(ctx, client);
    assertNotNull(getInternalExecutor());
    MetricsHeartbeatContext.removeHeartbeat(ctx);
    assertNotNull(getInternalExecutor());
    MetricsHeartbeatContext.removeHeartbeat(ctx);
    assertNotNull(getInternalExecutor());
    MetricsHeartbeatContext.removeHeartbeat(ctx);
    assertNotNull(getInternalExecutor());
    MetricsHeartbeatContext.removeHeartbeat(ctx);
    assertNull(getInternalExecutor());
}
Also used : MasterInquireClient(alluxio.master.MasterInquireClient) InstancedConfiguration(alluxio.conf.InstancedConfiguration) ClientContext(alluxio.ClientContext) Test(org.junit.Test)

Example 13 with ClientContext

use of alluxio.ClientContext in project alluxio by Alluxio.

the class StressJobServiceBench method prepare.

@Override
public void prepare() throws Exception {
    mFsContext = FileSystemContext.create(new InstancedConfiguration(ConfigurationUtils.defaults()));
    final ClientContext clientContext = mFsContext.getClientContext();
    mJobMasterClient = JobMasterClient.Factory.create(JobMasterClientContext.newBuilder(clientContext).build());
}
Also used : InstancedConfiguration(alluxio.conf.InstancedConfiguration) ClientContext(alluxio.ClientContext) JobMasterClientContext(alluxio.worker.job.JobMasterClientContext)

Example 14 with ClientContext

use of alluxio.ClientContext in project alluxio by Alluxio.

the class FileSystemMasterClientPoolTest method create.

@Test
public void create() throws Exception {
    AlluxioConfiguration conf = ConfigurationTestUtils.defaults();
    FileSystemMasterClient expectedClient = Mockito.mock(FileSystemMasterClient.class);
    PowerMockito.mockStatic(FileSystemMasterClient.Factory.class);
    Mockito.when(FileSystemMasterClient.Factory.create(Mockito.any(MasterClientContext.class))).thenReturn(expectedClient);
    FileSystemMasterClient client;
    ClientContext clientContext = ClientContext.create(conf);
    MasterInquireClient masterInquireClient = MasterInquireClient.Factory.create(conf, clientContext.getUserState());
    MasterClientContext masterClientContext = MasterClientContext.newBuilder(clientContext).setMasterInquireClient(masterInquireClient).build();
    try (FileSystemMasterClientPool pool = new FileSystemMasterClientPool(masterClientContext)) {
        client = pool.acquire();
        assertEquals(expectedClient, client);
        pool.release(client);
    }
    Mockito.verify(client).close();
}
Also used : MasterInquireClient(alluxio.master.MasterInquireClient) MasterClientContext(alluxio.master.MasterClientContext) MasterClientContext(alluxio.master.MasterClientContext) ClientContext(alluxio.ClientContext) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with ClientContext

use of alluxio.ClientContext in project alluxio by Alluxio.

the class BlockMasterClientPoolTest method create.

@Test
public void create() throws Exception {
    BlockMasterClient expectedClient = mock(BlockMasterClient.class);
    PowerMockito.mockStatic(BlockMasterClient.Factory.class);
    when(BlockMasterClient.Factory.create(any(MasterClientContext.class))).thenReturn(expectedClient);
    BlockMasterClient client;
    ClientContext clientContext = ClientContext.create(mConf);
    MasterInquireClient masterInquireClient = MasterInquireClient.Factory.create(mConf, clientContext.getUserState());
    MasterClientContext masterClientContext = MasterClientContext.newBuilder(clientContext).setMasterInquireClient(masterInquireClient).build();
    try (BlockMasterClientPool pool = new BlockMasterClientPool(masterClientContext)) {
        client = pool.acquire();
        assertEquals(expectedClient, client);
        pool.release(client);
    }
    verify(client).close();
}
Also used : MasterInquireClient(alluxio.master.MasterInquireClient) MasterClientContext(alluxio.master.MasterClientContext) MasterClientContext(alluxio.master.MasterClientContext) ClientContext(alluxio.ClientContext) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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