use of alluxio.wire.WorkerNetAddress in project alluxio by Alluxio.
the class LocalFirstAvoidEvictionPolicyTest method getLocalFirst.
/**
* Tests that the local host is returned first.
*/
@Test
public void getLocalFirst() {
String localhostName = NetworkAddressUtils.getLocalHostName();
LocalFirstAvoidEvictionPolicy policy = new LocalFirstAvoidEvictionPolicy();
List<BlockWorkerInfo> workerInfoList = new ArrayList<>();
workerInfoList.add(new BlockWorkerInfo(new WorkerNetAddress().setHost("worker1").setRpcPort(PORT).setDataPort(PORT).setWebPort(PORT), Constants.GB, 0));
workerInfoList.add(new BlockWorkerInfo(new WorkerNetAddress().setHost(localhostName).setRpcPort(PORT).setDataPort(PORT).setWebPort(PORT), Constants.GB, 0));
Assert.assertEquals(localhostName, policy.getWorkerForNextBlock(workerInfoList, Constants.MB).getHost());
}
use of alluxio.wire.WorkerNetAddress in project alluxio by Alluxio.
the class LocalFirstPolicyTest method getLocalFirst.
/**
* Tests that the local host is returned first.
*/
@Test
public void getLocalFirst() {
String localhostName = NetworkAddressUtils.getLocalHostName();
LocalFirstPolicy policy = new LocalFirstPolicy();
List<BlockWorkerInfo> workerInfoList = new ArrayList<>();
workerInfoList.add(new BlockWorkerInfo(new WorkerNetAddress().setHost("worker1").setRpcPort(PORT).setDataPort(PORT).setWebPort(PORT), Constants.GB, 0));
workerInfoList.add(new BlockWorkerInfo(new WorkerNetAddress().setHost(localhostName).setRpcPort(PORT).setDataPort(PORT).setWebPort(PORT), Constants.GB, 0));
Assert.assertEquals(localhostName, policy.getWorkerForNextBlock(workerInfoList, Constants.MB).getHost());
}
use of alluxio.wire.WorkerNetAddress in project alluxio by Alluxio.
the class RemoteBlockInStreamIntegrationTest method readTest5.
/**
* Tests {@link RemoteBlockInStream#read(byte[])}. Read from remote data server.
*/
@Test
public void readTest5() throws Exception {
String uniqPath = PathUtils.uniqPath();
for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
AlluxioURI uri = new AlluxioURI(uniqPath + "/file_" + k);
FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteAlluxio, k);
long blockId = mFileSystem.getStatus(uri).getBlockIds().get(0);
BlockInfo info = AlluxioBlockStore.create().getInfo(blockId);
WorkerNetAddress workerAddr = info.getLocations().get(0).getWorkerAddress();
RemoteBlockInStream is = RemoteBlockInStream.create(info.getBlockId(), info.getLength(), workerAddr, FileSystemContext.INSTANCE, InStreamOptions.defaults());
byte[] ret = new byte[k];
int start = 0;
while (start < k) {
int read = is.read(ret);
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(start, read, ret));
start += read;
}
is.close();
Assert.assertTrue(mFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
}
}
use of alluxio.wire.WorkerNetAddress in project alluxio by Alluxio.
the class RemoteBlockInStreamIntegrationTest method readTest4.
/**
* Tests {@link RemoteBlockInStream#read()}. Read from remote data server.
*/
@Test
public void readTest4() throws Exception {
String uniqPath = PathUtils.uniqPath();
for (int k = MIN_LEN + DELTA; k <= MAX_LEN; k += DELTA) {
AlluxioURI uri = new AlluxioURI(uniqPath + "/file_" + k);
FileSystemTestUtils.createByteFile(mFileSystem, uri, mWriteAlluxio, k);
long blockId = mFileSystem.getStatus(uri).getBlockIds().get(0);
AlluxioBlockStore blockStore = AlluxioBlockStore.create();
BlockInfo info = blockStore.getInfo(blockId);
WorkerNetAddress workerAddr = info.getLocations().get(0).getWorkerAddress();
RemoteBlockInStream is = RemoteBlockInStream.create(info.getBlockId(), info.getLength(), workerAddr, FileSystemContext.INSTANCE, InStreamOptions.defaults());
byte[] ret = new byte[k];
int value = is.read();
int cnt = 0;
while (value != -1) {
Assert.assertTrue(value >= 0);
Assert.assertTrue(value < 256);
ret[cnt++] = (byte) value;
value = is.read();
}
Assert.assertEquals(cnt, k);
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
Assert.assertTrue(mFileSystem.getStatus(uri).getInMemoryPercentage() == 100);
}
}
use of alluxio.wire.WorkerNetAddress in project alluxio by Alluxio.
the class FileSystemMasterTest method startServices.
private void startServices() throws Exception {
JournalFactory journalFactory = new JournalFactory.ReadWrite(mJournalFolder);
mBlockMaster = new BlockMaster(journalFactory);
mExecutorService = Executors.newFixedThreadPool(2, ThreadFactoryUtils.build("FileSystemMasterTest-%d", true));
mFileSystemMaster = new FileSystemMaster(mBlockMaster, journalFactory, ExecutorServiceFactories.constantExecutorServiceFactory(mExecutorService));
mBlockMaster.start(true);
mFileSystemMaster.start(true);
// set up workers
mWorkerId1 = mBlockMaster.getWorkerId(new WorkerNetAddress().setHost("localhost").setRpcPort(80).setDataPort(81).setWebPort(82));
mBlockMaster.workerRegister(mWorkerId1, Arrays.asList("MEM", "SSD"), ImmutableMap.of("MEM", (long) Constants.MB, "SSD", (long) Constants.MB), ImmutableMap.of("MEM", (long) Constants.KB, "SSD", (long) Constants.KB), new HashMap<String, List<Long>>());
mWorkerId2 = mBlockMaster.getWorkerId(new WorkerNetAddress().setHost("remote").setRpcPort(80).setDataPort(81).setWebPort(82));
mBlockMaster.workerRegister(mWorkerId2, Arrays.asList("MEM", "SSD"), ImmutableMap.of("MEM", (long) Constants.MB, "SSD", (long) Constants.MB), ImmutableMap.of("MEM", (long) Constants.KB, "SSD", (long) Constants.KB), new HashMap<String, List<Long>>());
}
Aggregations