use of io.cdap.cdap.api.service.worker.RunnableTaskRequest in project cdap by caskdata.
the class RemoteTaskExecutorTest method testRetryMetrics.
@Test
public void testRetryMetrics() throws Exception {
// Remove the service registration
registered.cancel();
RemoteTaskExecutor remoteTaskExecutor = new RemoteTaskExecutor(cConf, mockMetricsCollector, remoteClientFactory, RemoteTaskExecutor.Type.TASK_WORKER);
RunnableTaskRequest runnableTaskRequest = RunnableTaskRequest.getBuilder(ValidRunnableClass.class.getName()).withParam("param").build();
try {
remoteTaskExecutor.runTask(runnableTaskRequest);
} catch (Exception e) {
}
mockMetricsCollector.stopAndWait();
Assert.assertSame(1, published.size());
// check the metrics are present
MetricValues metricValues = published.get(0);
Assert.assertTrue(hasMetric(metricValues, Constants.Metrics.TaskWorker.CLIENT_REQUEST_COUNT));
Assert.assertTrue(hasMetric(metricValues, Constants.Metrics.TaskWorker.CLIENT_REQUEST_LATENCY_MS));
Assert.assertEquals("failure", metricValues.getTags().get(Constants.Metrics.Tag.STATUS));
int retryCount = Integer.parseInt(metricValues.getTags().get(Constants.Metrics.Tag.TRIES));
Assert.assertTrue(retryCount > 1);
}
use of io.cdap.cdap.api.service.worker.RunnableTaskRequest in project cdap by caskdata.
the class RemoteTaskExecutorTest method testFailedMetrics.
@Test
public void testFailedMetrics() throws Exception {
RemoteTaskExecutor remoteTaskExecutor = new RemoteTaskExecutor(cConf, mockMetricsCollector, remoteClientFactory, RemoteTaskExecutor.Type.TASK_WORKER);
RunnableTaskRequest runnableTaskRequest = RunnableTaskRequest.getBuilder(InValidRunnableClass.class.getName()).withParam("param").build();
try {
remoteTaskExecutor.runTask(runnableTaskRequest);
} catch (Exception e) {
}
mockMetricsCollector.stopAndWait();
Assert.assertSame(1, published.size());
// check the metrics are present
MetricValues metricValues = published.get(0);
Assert.assertTrue(hasMetric(metricValues, Constants.Metrics.TaskWorker.CLIENT_REQUEST_LATENCY_MS));
Assert.assertTrue(hasMetric(metricValues, Constants.Metrics.TaskWorker.CLIENT_REQUEST_COUNT));
// check the clz tag is set correctly
Assert.assertEquals(InValidRunnableClass.class.getName(), metricValues.getTags().get("clz"));
}
use of io.cdap.cdap.api.service.worker.RunnableTaskRequest in project cdap by caskdata.
the class RemoteTaskExecutorTest method testSuccessMetrics.
@Test
public void testSuccessMetrics() throws Exception {
RemoteTaskExecutor remoteTaskExecutor = new RemoteTaskExecutor(cConf, mockMetricsCollector, remoteClientFactory, RemoteTaskExecutor.Type.TASK_WORKER);
RunnableTaskRequest runnableTaskRequest = RunnableTaskRequest.getBuilder(ValidRunnableClass.class.getName()).withParam("param").build();
remoteTaskExecutor.runTask(runnableTaskRequest);
mockMetricsCollector.stopAndWait();
Assert.assertSame(1, published.size());
// check the metrics are present
MetricValues metricValues = published.get(0);
Assert.assertTrue(hasMetric(metricValues, Constants.Metrics.TaskWorker.CLIENT_REQUEST_LATENCY_MS));
Assert.assertTrue(hasMetric(metricValues, Constants.Metrics.TaskWorker.CLIENT_REQUEST_COUNT));
// check the clz tag is set correctly
Assert.assertEquals(ValidRunnableClass.class.getName(), metricValues.getTags().get("clz"));
}
use of io.cdap.cdap.api.service.worker.RunnableTaskRequest in project cdap by cdapio.
the class TaskWorkerServiceTest method testPeriodicRestartWithInflightRequest.
@Test
public void testPeriodicRestartWithInflightRequest() throws IOException {
CConfiguration cConf = createCConf();
SConfiguration sConf = createSConf();
cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_REQUEST_COUNT, 10);
cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_DURATION_SECOND, 2);
TaskWorkerService taskWorkerService = new TaskWorkerService(cConf, sConf, new InMemoryDiscoveryService(), (namespaceId, retryStrategy) -> null, new NoOpMetricsCollectionService());
serviceCompletionFuture = TaskWorkerTestUtil.getServiceCompletionFuture(taskWorkerService);
// start the service
taskWorkerService.startAndWait();
InetSocketAddress addr = taskWorkerService.getBindAddress();
URI uri = URI.create(String.format("http://%s:%s", addr.getHostName(), addr.getPort()));
// Post valid request
String want = "5000";
RunnableTaskRequest req = RunnableTaskRequest.getBuilder(TestRunnableClass.class.getName()).withParam(want).build();
String reqBody = GSON.toJson(req);
HttpResponse response = HttpRequests.execute(HttpRequest.post(uri.resolve("/v3Internal/worker/run").toURL()).withBody(reqBody).build(), new DefaultHttpRequestConfig(false));
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
Assert.assertEquals(want, response.getResponseBodyAsString());
TaskWorkerTestUtil.waitForServiceCompletion(serviceCompletionFuture);
Assert.assertEquals(Service.State.TERMINATED, taskWorkerService.state());
}
use of io.cdap.cdap.api.service.worker.RunnableTaskRequest in project cdap by cdapio.
the class TaskWorkerServiceTest method testStartAndStopWithInvalidRequest.
@Test
public void testStartAndStopWithInvalidRequest() throws Exception {
InetSocketAddress addr = taskWorkerService.getBindAddress();
URI uri = URI.create(String.format("http://%s:%s", addr.getHostName(), addr.getPort()));
// Post invalid request
RunnableTaskRequest noClassReq = RunnableTaskRequest.getBuilder("NoClass").build();
String reqBody = GSON.toJson(noClassReq);
HttpResponse response = HttpRequests.execute(HttpRequest.post(uri.resolve("/v3Internal/worker/run").toURL()).withBody(reqBody).build(), new DefaultHttpRequestConfig(false));
Assert.assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode());
BasicThrowable basicThrowable;
basicThrowable = GSON.fromJson(response.getResponseBodyAsString(), BasicThrowable.class);
Assert.assertTrue(basicThrowable.getClassName().contains("java.lang.ClassNotFoundException"));
Assert.assertNotNull(basicThrowable.getMessage());
Assert.assertTrue(basicThrowable.getMessage().contains("NoClass"));
Assert.assertNotEquals(basicThrowable.getStackTraces().length, 0);
}
Aggregations