use of alluxio.worker.WorkerProcess in project alluxio by Alluxio.
the class AbstractLocalAlluxioCluster method startWorkers.
/**
* Configures and starts the worker(s).
*/
public void startWorkers() throws Exception {
mWorkers = new ArrayList<>();
for (int i = 0; i < mNumWorkers; i++) {
mWorkers.add(WorkerProcess.Factory.create());
}
for (final WorkerProcess worker : mWorkers) {
Runnable runWorker = () -> {
try {
worker.start();
} catch (InterruptedException e) {
// this is expected
} catch (Exception e) {
// Log the exception as the RuntimeException will be caught and handled silently by
// JUnit
LOG.error("Start worker error", e);
throw new RuntimeException(e + " \n Start Worker Error \n" + e.getMessage(), e);
}
};
Thread thread = new Thread(runWorker);
thread.setName("WorkerThread-" + System.identityHashCode(thread));
mWorkerThreads.add(thread);
thread.start();
}
for (WorkerProcess worker : mWorkers) {
TestUtils.waitForReady(worker);
}
}
use of alluxio.worker.WorkerProcess in project alluxio by Alluxio.
the class AbstractLocalAlluxioCluster method stopWorkers.
/**
* Stops the workers.
*/
public void stopWorkers() throws Exception {
if (mWorkers == null) {
return;
}
for (WorkerProcess worker : mWorkers) {
worker.stop();
}
for (Thread thread : mWorkerThreads) {
while (thread.isAlive()) {
LOG.info("Stopping thread {}.", thread.getName());
thread.interrupt();
thread.join(1000);
}
}
mWorkerThreads.clear();
// forget all the workers in the master
LocalAlluxioMaster master = getLocalAlluxioMaster();
if (master != null) {
DefaultBlockMaster bm = (DefaultBlockMaster) master.getMasterProcess().getMaster(BlockMaster.class);
bm.forgetAllWorkers();
}
}
use of alluxio.worker.WorkerProcess in project alluxio by Alluxio.
the class LocalFirstPolicyIntegrationTest method test.
@Test
public void test() throws Exception {
AlluxioMasterProcess master = AlluxioMasterProcess.Factory.create();
WorkerProcess worker1 = AlluxioWorkerProcess.Factory.create(TieredIdentityFactory.fromString("node=node1,rack=rack1", ServerConfiguration.global()));
WorkerProcess worker2 = AlluxioWorkerProcess.Factory.create(TieredIdentityFactory.fromString("node=node2,rack=rack2", ServerConfiguration.global()));
runProcess(mExecutor, master);
runProcess(mExecutor, worker1);
runProcess(mExecutor, worker2);
TestUtils.waitForReady(master);
TestUtils.waitForReady(worker1);
TestUtils.waitForReady(worker2);
FileSystem fs = FileSystem.Factory.create(ServerConfiguration.global());
// Write to the worker in node1
{
Whitebox.setInternalState(TieredIdentityFactory.class, "sInstance", TieredIdentityFactory.fromString("node=node1,rack=rack1", ServerConfiguration.global()));
try {
FileSystemTestUtils.createByteFile(fs, "/file1", WritePType.MUST_CACHE, 100);
} finally {
Whitebox.setInternalState(TieredIdentityFactory.class, "sInstance", (Object) null);
}
BlockWorker blockWorker1 = worker1.getWorker(BlockWorker.class);
BlockWorker blockWorker2 = worker2.getWorker(BlockWorker.class);
assertEquals(100, blockWorker1.getStoreMeta().getUsedBytes());
assertEquals(0, blockWorker2.getStoreMeta().getUsedBytes());
}
// Write to the worker in rack2
{
Whitebox.setInternalState(TieredIdentityFactory.class, "sInstance", TieredIdentityFactory.fromString("node=node3,rack=rack2", ServerConfiguration.global()));
try {
FileSystemTestUtils.createByteFile(fs, "/file2", WritePType.MUST_CACHE, 10);
} finally {
Whitebox.setInternalState(TieredIdentityFactory.class, "sInstance", (Object) null);
}
BlockWorker blockWorker1 = worker1.getWorker(BlockWorker.class);
BlockWorker blockWorker2 = worker2.getWorker(BlockWorker.class);
assertEquals(100, blockWorker1.getStoreMeta().getUsedBytes());
assertEquals(10, blockWorker2.getStoreMeta().getUsedBytes());
}
}
Aggregations