Search in sources :

Example 11 with WorkerNetAddress

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());
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) ArrayList(java.util.ArrayList) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) Test(org.junit.Test)

Example 12 with WorkerNetAddress

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());
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) ArrayList(java.util.ArrayList) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) Test(org.junit.Test)

Example 13 with WorkerNetAddress

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);
    }
}
Also used : BlockInfo(alluxio.wire.BlockInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) RemoteBlockInStream(alluxio.client.block.RemoteBlockInStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 14 with WorkerNetAddress

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);
    }
}
Also used : BlockInfo(alluxio.wire.BlockInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) RemoteBlockInStream(alluxio.client.block.RemoteBlockInStream) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 15 with WorkerNetAddress

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>>());
}
Also used : JournalFactory(alluxio.master.journal.JournalFactory) BlockMaster(alluxio.master.block.BlockMaster) WorkerNetAddress(alluxio.wire.WorkerNetAddress) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

WorkerNetAddress (alluxio.wire.WorkerNetAddress)30 BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)15 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)7 AlluxioURI (alluxio.AlluxioURI)6 AlluxioException (alluxio.exception.AlluxioException)5 BlockInfo (alluxio.wire.BlockInfo)5 RemoteBlockInStream (alluxio.client.block.RemoteBlockInStream)4 InetSocketAddress (java.net.InetSocketAddress)4 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)2 OutStreamOptions (alluxio.client.file.options.OutStreamOptions)2 FileWriteLocationPolicy (alluxio.client.file.policy.FileWriteLocationPolicy)2 BlockLocation (alluxio.wire.BlockLocation)2 FileInfo (alluxio.wire.FileInfo)2 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 BlockMasterClient (alluxio.client.block.BlockMasterClient)1 BufferedBlockOutStream (alluxio.client.block.BufferedBlockOutStream)1 TestBufferedBlockOutStream (alluxio.client.block.TestBufferedBlockOutStream)1