use of org.apache.storm.metric.StormMetricsRegistry in project storm by apache.
the class LogCleanerTest method testPerWorkerDirectoryCleanup.
/**
* cleaner deletes oldest files in each worker dir if files are larger than per-dir quota.
*/
@Test
public void testPerWorkerDirectoryCleanup() throws IOException {
long nowMillis = Time.currentTimeMillis();
try (TmpPath testDir = new TmpPath()) {
Files.createDirectories(testDir.getFile().toPath());
Path rootDir = createDir(testDir.getFile().toPath(), "workers-artifacts");
Path topo1Dir = createDir(rootDir, "topo1");
Path topo2Dir = createDir(rootDir, "topo2");
Path port1Dir = createDir(topo1Dir, "port1");
Path port2Dir = createDir(topo1Dir, "port2");
Path port3Dir = createDir(topo2Dir, "port3");
Seq.range(0, 10).forEach(idx -> createFile(port1Dir, "A" + idx, nowMillis + 100 * idx, 200));
Seq.range(0, 10).forEach(idx -> createFile(port2Dir, "B" + idx, nowMillis + 100 * idx, 200));
Seq.range(0, 10).forEach(idx -> createFile(port3Dir, "C" + idx, nowMillis + 100 * idx, 200));
Map<String, Object> conf = Utils.readStormConfig();
StormMetricsRegistry metricRegistry = new StormMetricsRegistry();
WorkerLogs workerLogs = new WorkerLogs(conf, rootDir, metricRegistry);
LogCleaner logCleaner = new LogCleaner(conf, workerLogs, new DirectoryCleaner(metricRegistry), rootDir, metricRegistry);
List<Integer> deletedFiles = logCleaner.perWorkerDirCleanup(1200).stream().map(deletionMeta -> deletionMeta.deletedFiles).collect(toList());
assertEquals(Integer.valueOf(4), deletedFiles.get(0));
assertEquals(Integer.valueOf(4), deletedFiles.get(1));
assertEquals(Integer.valueOf(4), deletedFiles.get(deletedFiles.size() - 1));
}
}
use of org.apache.storm.metric.StormMetricsRegistry in project storm by apache.
the class DRPCServerTest method testFailedThrift.
@Test
public void testFailedThrift() throws Exception {
Map<String, Object> conf = getConf(0, 0, null);
try (DRPCServer server = new DRPCServer(conf, new StormMetricsRegistry())) {
server.start();
try (DRPCClient client = new DRPCClient(conf, "localhost", server.getDrpcPort());
DRPCInvocationsClient invoke = new DRPCInvocationsClient(conf, "localhost", server.getDrpcInvokePort())) {
Future<String> found = exec.submit(() -> client.getClient().execute("testing", "test"));
DRPCRequest request = getNextAvailableRequest(invoke, "testing");
assertNotNull(request);
assertEquals("test", request.get_func_args());
assertNotNull(request.get_request_id());
invoke.failRequest(request.get_request_id());
try {
found.get(1000, TimeUnit.MILLISECONDS);
fail("exec did not throw an exception");
} catch (ExecutionException e) {
Throwable t = e.getCause();
assertEquals(t.getClass(), DRPCExecutionException.class);
// Don't know a better way to validate that it failed.
assertEquals("Request failed", ((DRPCExecutionException) t).get_msg());
}
}
}
}
use of org.apache.storm.metric.StormMetricsRegistry in project storm by apache.
the class DRPCServerTest method testGoodHttpGet.
@Test
public void testGoodHttpGet() throws Exception {
LOG.info("STARTING HTTP GET TEST...");
Map<String, Object> conf = getConf(0, 0, 0);
try (DRPCServer server = new DRPCServer(conf, new StormMetricsRegistry())) {
server.start();
// TODO need a better way to do this
Thread.sleep(2000);
try (DRPCInvocationsClient invoke = new DRPCInvocationsClient(conf, "localhost", server.getDrpcInvokePort())) {
final Future<String> found = exec.submit(() -> doGet(server.getHttpServerPort(), "testing", "test"));
DRPCRequest request = getNextAvailableRequest(invoke, "testing");
assertNotNull(request);
assertEquals("test", request.get_func_args());
assertNotNull(request.get_request_id());
invoke.result(request.get_request_id(), "tested");
String result = found.get(1000, TimeUnit.MILLISECONDS);
assertEquals("tested", result);
}
}
}
use of org.apache.storm.metric.StormMetricsRegistry in project storm by apache.
the class DRPCServerTest method testGoodThrift.
@Test
public void testGoodThrift() throws Exception {
Map<String, Object> conf = getConf(0, 0, null);
try (DRPCServer server = new DRPCServer(conf, new StormMetricsRegistry())) {
server.start();
try (DRPCClient client = new DRPCClient(conf, "localhost", server.getDrpcPort());
DRPCInvocationsClient invoke = new DRPCInvocationsClient(conf, "localhost", server.getDrpcInvokePort())) {
final Future<String> found = exec.submit(() -> client.getClient().execute("testing", "test"));
DRPCRequest request = getNextAvailableRequest(invoke, "testing");
assertNotNull(request);
assertEquals("test", request.get_func_args());
assertNotNull(request.get_request_id());
invoke.result(request.get_request_id(), "tested");
String result = found.get(1000, TimeUnit.MILLISECONDS);
assertEquals("tested", result);
}
}
}
use of org.apache.storm.metric.StormMetricsRegistry in project storm by apache.
the class LogviewerLogPageHandlerTest method testListLogFiles.
/**
* list-log-files filter selects the correct log files to return.
*/
@Test
public void testListLogFiles() throws IOException {
String rootPath = Files.createTempDirectory("workers-artifacts").toFile().getCanonicalPath();
File file1 = new File(String.join(File.separator, rootPath, "topoA", "1111"), "worker.log");
File file2 = new File(String.join(File.separator, rootPath, "topoA", "2222"), "worker.log");
File file3 = new File(String.join(File.separator, rootPath, "topoB", "1111"), "worker.log");
file1.getParentFile().mkdirs();
file2.getParentFile().mkdirs();
file3.getParentFile().mkdirs();
file1.createNewFile();
file2.createNewFile();
file3.createNewFile();
String origin = "www.origin.server.net";
Map<String, Object> stormConf = Utils.readStormConfig();
StormMetricsRegistry metricsRegistry = new StormMetricsRegistry();
LogviewerLogPageHandler handler = new LogviewerLogPageHandler(rootPath, rootPath, new WorkerLogs(stormConf, Paths.get(rootPath), metricsRegistry), new ResourceAuthorizer(stormConf), metricsRegistry);
final Response expectedAll = LogviewerResponseBuilder.buildSuccessJsonResponse(Lists.newArrayList("topoA/port1/worker.log", "topoA/port2/worker.log", "topoB/port1/worker.log"), null, origin);
final Response expectedFilterPort = LogviewerResponseBuilder.buildSuccessJsonResponse(Lists.newArrayList("topoA/port1/worker.log", "topoB/port1/worker.log"), null, origin);
final Response expectedFilterTopoId = LogviewerResponseBuilder.buildSuccessJsonResponse(Lists.newArrayList("topoB/port1/worker.log"), null, origin);
final Response returnedAll = handler.listLogFiles("user", null, null, null, origin);
final Response returnedFilterPort = handler.listLogFiles("user", 1111, null, null, origin);
final Response returnedFilterTopoId = handler.listLogFiles("user", null, "topoB", null, origin);
Utils.forceDelete(rootPath);
assertEqualsJsonResponse(expectedAll, returnedAll, List.class);
assertEqualsJsonResponse(expectedFilterPort, returnedFilterPort, List.class);
assertEqualsJsonResponse(expectedFilterTopoId, returnedFilterTopoId, List.class);
}
Aggregations