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;
}
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();
}
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());
}
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);
}
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());
}
Aggregations