Search in sources :

Example 1 with MetricsAssert

use of org.apache.gobblin.metrics.test.MetricsAssert in project incubator-gobblin by apache.

the class TestInMemoryJobCatalog method testMetrics.

@SuppressWarnings("unchecked")
@Test
public void testMetrics() throws Exception {
    final Logger log = LoggerFactory.getLogger(getClass().getSimpleName() + ".testMetrics");
    InMemoryJobCatalog cat = new InMemoryJobCatalog(Optional.of(log), Optional.<MetricContext>absent(), true);
    cat.startAsync();
    cat.awaitRunning(1, TimeUnit.SECONDS);
    MetricsAssert ma = new MetricsAssert(cat.getMetricContext());
    JobSpec js1_1 = JobSpec.builder("test:job1").withVersion("1").build();
    JobSpec js1_2 = JobSpec.builder("test:job1").withVersion("2").build();
    JobSpec js1_3 = JobSpec.builder("test:job1").withVersion("3").build();
    JobSpec js2 = JobSpec.builder("test:job2").withVersion("1").build();
    cat.put(js1_1);
    Assert.assertEquals(cat.getMetrics().getNumActiveJobs().getValue().intValue(), 1);
    Assert.assertEquals(cat.getMetrics().getTotalAddCalls().getValue().longValue(), 1);
    Assert.assertEquals(cat.getMetrics().getTotalUpdateCalls().getValue().longValue(), 0);
    Assert.assertEquals(cat.getMetrics().getTotalDeleteCalls().getValue().longValue(), 0);
    ma.assertEvent(Predicates.and(MetricsAssert.eqEventNamespace(JobCatalog.class.getName()), MetricsAssert.eqEventName(JobCatalog.StandardMetrics.TRACKING_EVENT_NAME), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.OPERATION_TYPE_META, JobCatalog.StandardMetrics.JOB_ADDED_OPERATION_TYPE), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.JOB_SPEC_URI_META, js1_1.getUri().toString()), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.JOB_SPEC_VERSION_META, js1_1.getVersion())), 100, TimeUnit.MILLISECONDS);
    cat.put(js1_2);
    Assert.assertEquals(cat.getMetrics().getNumActiveJobs().getValue().intValue(), 1);
    Assert.assertEquals(cat.getMetrics().getTotalAddCalls().getValue().longValue(), 1);
    Assert.assertEquals(cat.getMetrics().getTotalUpdateCalls().getValue().longValue(), 1);
    Assert.assertEquals(cat.getMetrics().getTotalDeleteCalls().getValue().longValue(), 0);
    ma.assertEvent(Predicates.and(MetricsAssert.eqEventNamespace(JobCatalog.class.getName()), MetricsAssert.eqEventName(JobCatalog.StandardMetrics.TRACKING_EVENT_NAME), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.OPERATION_TYPE_META, JobCatalog.StandardMetrics.JOB_UPDATED_OPERATION_TYPE), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.JOB_SPEC_URI_META, js1_2.getUri().toString()), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.JOB_SPEC_VERSION_META, js1_2.getVersion())), 100, TimeUnit.MILLISECONDS);
    cat.put(js2);
    Assert.assertEquals(cat.getMetrics().getNumActiveJobs().getValue().intValue(), 2);
    Assert.assertEquals(cat.getMetrics().getTotalAddCalls().getValue().longValue(), 2);
    Assert.assertEquals(cat.getMetrics().getTotalUpdateCalls().getValue().longValue(), 1);
    Assert.assertEquals(cat.getMetrics().getTotalDeleteCalls().getValue().longValue(), 0);
    ma.assertEvent(Predicates.and(MetricsAssert.eqEventNamespace(JobCatalog.class.getName()), MetricsAssert.eqEventName(JobCatalog.StandardMetrics.TRACKING_EVENT_NAME), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.OPERATION_TYPE_META, JobCatalog.StandardMetrics.JOB_ADDED_OPERATION_TYPE), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.JOB_SPEC_URI_META, js2.getUri().toString()), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.JOB_SPEC_VERSION_META, js2.getVersion())), 100, TimeUnit.MILLISECONDS);
    cat.put(js1_3);
    Assert.assertEquals(cat.getMetrics().getNumActiveJobs().getValue().intValue(), 2);
    Assert.assertEquals(cat.getMetrics().getTotalAddCalls().getValue().longValue(), 2);
    Assert.assertEquals(cat.getMetrics().getTotalUpdateCalls().getValue().longValue(), 2);
    Assert.assertEquals(cat.getMetrics().getTotalDeleteCalls().getValue().longValue(), 0);
    ma.assertEvent(Predicates.and(MetricsAssert.eqEventNamespace(JobCatalog.class.getName()), MetricsAssert.eqEventName(JobCatalog.StandardMetrics.TRACKING_EVENT_NAME), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.OPERATION_TYPE_META, JobCatalog.StandardMetrics.JOB_UPDATED_OPERATION_TYPE), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.JOB_SPEC_URI_META, js1_3.getUri().toString()), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.JOB_SPEC_VERSION_META, js1_3.getVersion())), 100, TimeUnit.MILLISECONDS);
    cat.remove(js2.getUri());
    Assert.assertEquals(cat.getMetrics().getNumActiveJobs().getValue().intValue(), 1);
    Assert.assertEquals(cat.getMetrics().getTotalAddCalls().getValue().longValue(), 2);
    Assert.assertEquals(cat.getMetrics().getTotalUpdateCalls().getValue().longValue(), 2);
    Assert.assertEquals(cat.getMetrics().getTotalDeleteCalls().getValue().longValue(), 1);
    ma.assertEvent(Predicates.and(MetricsAssert.eqEventNamespace(JobCatalog.class.getName()), MetricsAssert.eqEventName(JobCatalog.StandardMetrics.TRACKING_EVENT_NAME), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.OPERATION_TYPE_META, JobCatalog.StandardMetrics.JOB_DELETED_OPERATION_TYPE), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.JOB_SPEC_URI_META, js2.getUri().toString()), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.JOB_SPEC_VERSION_META, js2.getVersion())), 100, TimeUnit.MILLISECONDS);
    cat.remove(new URI("test:dummy_job"));
    Assert.assertEquals(cat.getMetrics().getNumActiveJobs().getValue().intValue(), 1);
    Assert.assertEquals(cat.getMetrics().getTotalAddCalls().getValue().longValue(), 2);
    Assert.assertEquals(cat.getMetrics().getTotalUpdateCalls().getValue().longValue(), 2);
    Assert.assertEquals(cat.getMetrics().getTotalDeleteCalls().getValue().longValue(), 1);
    cat.remove(js1_3.getUri());
    Assert.assertEquals(cat.getMetrics().getNumActiveJobs().getValue().intValue(), 0);
    Assert.assertEquals(cat.getMetrics().getTotalAddCalls().getValue().longValue(), 2);
    Assert.assertEquals(cat.getMetrics().getTotalUpdateCalls().getValue().longValue(), 2);
    Assert.assertEquals(cat.getMetrics().getTotalDeleteCalls().getValue().longValue(), 2);
    ma.assertEvent(Predicates.and(MetricsAssert.eqEventNamespace(JobCatalog.class.getName()), MetricsAssert.eqEventName(JobCatalog.StandardMetrics.TRACKING_EVENT_NAME), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.OPERATION_TYPE_META, JobCatalog.StandardMetrics.JOB_DELETED_OPERATION_TYPE), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.JOB_SPEC_URI_META, js1_3.getUri().toString()), MetricsAssert.eqEventMetdata(GobblinMetricsKeys.JOB_SPEC_VERSION_META, js1_3.getVersion())), 100, TimeUnit.MILLISECONDS);
    cat.stopAsync();
    cat.awaitTerminated(1, TimeUnit.SECONDS);
}
Also used : MetricsAssert(org.apache.gobblin.metrics.test.MetricsAssert) JobSpec(org.apache.gobblin.runtime.api.JobSpec) Logger(org.slf4j.Logger) JobCatalog(org.apache.gobblin.runtime.api.JobCatalog) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

URI (java.net.URI)1 MetricsAssert (org.apache.gobblin.metrics.test.MetricsAssert)1 JobCatalog (org.apache.gobblin.runtime.api.JobCatalog)1 JobSpec (org.apache.gobblin.runtime.api.JobSpec)1 Logger (org.slf4j.Logger)1 Test (org.testng.annotations.Test)1