Search in sources :

Example 11 with RunnableTaskRequest

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);
}
Also used : MetricValues(io.cdap.cdap.api.metrics.MetricValues) RunnableTaskRequest(io.cdap.cdap.api.service.worker.RunnableTaskRequest) Test(org.junit.Test)

Example 12 with RunnableTaskRequest

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"));
}
Also used : MetricValues(io.cdap.cdap.api.metrics.MetricValues) RunnableTaskRequest(io.cdap.cdap.api.service.worker.RunnableTaskRequest) Test(org.junit.Test)

Example 13 with RunnableTaskRequest

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"));
}
Also used : MetricValues(io.cdap.cdap.api.metrics.MetricValues) RunnableTaskRequest(io.cdap.cdap.api.service.worker.RunnableTaskRequest) Test(org.junit.Test)

Example 14 with RunnableTaskRequest

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());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) HttpResponse(io.cdap.common.http.HttpResponse) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService) URI(java.net.URI) RunnableTaskRequest(io.cdap.cdap.api.service.worker.RunnableTaskRequest) Test(org.junit.Test)

Example 15 with RunnableTaskRequest

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);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) HttpResponse(io.cdap.common.http.HttpResponse) BasicThrowable(io.cdap.cdap.proto.BasicThrowable) URI(java.net.URI) RunnableTaskRequest(io.cdap.cdap.api.service.worker.RunnableTaskRequest) Test(org.junit.Test)

Aggregations

RunnableTaskRequest (io.cdap.cdap.api.service.worker.RunnableTaskRequest)36 Test (org.junit.Test)24 DefaultHttpRequestConfig (io.cdap.cdap.common.http.DefaultHttpRequestConfig)14 HttpResponse (io.cdap.common.http.HttpResponse)12 MetricValues (io.cdap.cdap.api.metrics.MetricValues)10 InetSocketAddress (java.net.InetSocketAddress)10 URI (java.net.URI)10 ArtifactId (io.cdap.cdap.api.artifact.ArtifactId)4 RemoteExecutionException (io.cdap.cdap.api.service.worker.RemoteExecutionException)4 RemoteTaskException (io.cdap.cdap.api.service.worker.RemoteTaskException)4 RunnableTaskContext (io.cdap.cdap.api.service.worker.RunnableTaskContext)4 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)4 SConfiguration (io.cdap.cdap.common.conf.SConfiguration)4 NoOpMetricsCollectionService (io.cdap.cdap.common.metrics.NoOpMetricsCollectionService)4 IOException (java.io.IOException)4 InMemoryDiscoveryService (org.apache.twill.discovery.InMemoryDiscoveryService)4 Gson (com.google.gson.Gson)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 Injector (com.google.inject.Injector)2 ArtifactVersion (io.cdap.cdap.api.artifact.ArtifactVersion)2