use of org.apache.storm.daemon.supervisor.SupervisorUtils in project storm by apache.
the class WorkerLogsTest method testIdentifyWorkerLogDirs.
/**
* Build up workerid-workerlogdir map for the old workers' dirs.
*/
@Test
public void testIdentifyWorkerLogDirs() throws Exception {
try (TmpPath testDir = new TmpPath()) {
Path port1Dir = Files.createDirectories(testDir.getFile().toPath().resolve("workers-artifacts/topo1/port1"));
Path metaFile = Files.createFile(testDir.getFile().toPath().resolve("worker.yaml"));
String expId = "id12345";
SortedSet<Path> expected = new TreeSet<>();
expected.add(port1Dir);
SupervisorUtils mockedSupervisorUtils = mock(SupervisorUtils.class);
SupervisorUtils.setInstance(mockedSupervisorUtils);
Map<String, Object> stormConf = Utils.readStormConfig();
WorkerLogs workerLogs = new WorkerLogs(stormConf, port1Dir, new StormMetricsRegistry()) {
@Override
public Optional<Path> getMetadataFileForWorkerLogDir(Path logDir) throws IOException {
return Optional.of(metaFile);
}
@Override
public String getWorkerIdFromMetadataFile(Path metaFile) {
return expId;
}
};
when(mockedSupervisorUtils.readWorkerHeartbeatsImpl(anyMap())).thenReturn(null);
assertEquals(expected, workerLogs.getLogDirs(Collections.singleton(port1Dir), (wid) -> true));
} finally {
SupervisorUtils.resetInstance();
}
}
use of org.apache.storm.daemon.supervisor.SupervisorUtils in project storm by apache.
the class LogCleanerTest method testGetDeadWorkerDirs.
/**
* return directories for workers that are not alive.
*/
@Test
public void testGetDeadWorkerDirs() throws Exception {
Map<String, Object> stormConf = Utils.readStormConfig();
stormConf.put(SUPERVISOR_WORKER_TIMEOUT_SECS, 5);
LSWorkerHeartbeat hb = new LSWorkerHeartbeat();
hb.set_time_secs(1);
Map<String, LSWorkerHeartbeat> idToHb = Collections.singletonMap("42", hb);
int nowSecs = 2;
try (TmpPath testDir = new TmpPath()) {
Path unexpectedDir1 = createDir(testDir.getFile().toPath(), "dir1");
Path expectedDir2 = createDir(testDir.getFile().toPath(), "dir2");
Path expectedDir3 = createDir(testDir.getFile().toPath(), "dir3");
Set<Path> logDirs = Sets.newSet(unexpectedDir1, expectedDir2, expectedDir3);
SupervisorUtils mockedSupervisorUtils = mock(SupervisorUtils.class);
SupervisorUtils.setInstance(mockedSupervisorUtils);
Map<String, Object> conf = Utils.readStormConfig();
StormMetricsRegistry metricRegistry = new StormMetricsRegistry();
WorkerLogs stubbedWorkerLogs = new WorkerLogs(conf, Paths.get(""), metricRegistry) {
@Override
public SortedSet<Path> getLogDirs(Set<Path> logDirs, Predicate<String> predicate) {
TreeSet<Path> ret = new TreeSet<>();
if (predicate.test("42")) {
ret.add(unexpectedDir1);
}
if (predicate.test("007")) {
ret.add(expectedDir2);
}
if (predicate.test("")) {
ret.add(expectedDir3);
}
return ret;
}
};
LogCleaner logCleaner = new LogCleaner(conf, stubbedWorkerLogs, new DirectoryCleaner(metricRegistry), null, metricRegistry);
when(mockedSupervisorUtils.readWorkerHeartbeatsImpl(anyMap())).thenReturn(idToHb);
assertEquals(Sets.newSet(expectedDir2, expectedDir3), logCleaner.getDeadWorkerDirs(nowSecs, logDirs));
} finally {
SupervisorUtils.resetInstance();
}
}
Aggregations