Search in sources :

Example 1 with InjectClusterClient

use of org.apache.flink.test.junit5.InjectClusterClient in project flink by apache.

the class JMXJobManagerMetricTest method testJobManagerJMXMetricAccess.

/**
 * Tests that metrics registered on the JobManager are actually accessible via JMX.
 */
@Test
void testJobManagerJMXMetricAccess(@InjectClusterClient ClusterClient<?> client) throws Exception {
    Deadline deadline = Deadline.now().plus(Duration.ofMinutes(2));
    try {
        JobVertex sourceJobVertex = new JobVertex("Source");
        sourceJobVertex.setInvokableClass(BlockingInvokable.class);
        sourceJobVertex.setParallelism(1);
        final JobCheckpointingSettings jobCheckpointingSettings = new JobCheckpointingSettings(new CheckpointCoordinatorConfiguration(500, 500, 50, 5, CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION, true, false, 0, 0), null);
        final JobGraph jobGraph = JobGraphBuilder.newStreamingJobGraphBuilder().setJobName("TestingJob").addJobVertex(sourceJobVertex).setJobCheckpointingSettings(jobCheckpointingSettings).build();
        client.submitJob(jobGraph).get();
        FutureUtils.retrySuccessfulWithDelay(() -> client.getJobStatus(jobGraph.getJobID()), Time.milliseconds(10), deadline, status -> status == JobStatus.RUNNING, TestingUtils.defaultScheduledExecutor()).get(deadline.timeLeft().toMillis(), TimeUnit.MILLISECONDS);
        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        Set<ObjectName> nameSet = mBeanServer.queryNames(new ObjectName("org.apache.flink.jobmanager.job.lastCheckpointSize:job_name=TestingJob,*"), null);
        assertThat(nameSet).hasSize(1);
        assertThat(mBeanServer.getAttribute(nameSet.iterator().next(), "Value")).isEqualTo(-1L);
        BlockingInvokable.unblock();
    } finally {
        BlockingInvokable.unblock();
    }
}
Also used : OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) Deadline(org.apache.flink.api.common.time.Deadline) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) CheckpointCoordinatorConfiguration(org.apache.flink.runtime.jobgraph.tasks.CheckpointCoordinatorConfiguration) JobStatus(org.apache.flink.api.common.JobStatus) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) InjectClusterClient(org.apache.flink.test.junit5.InjectClusterClient) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) MBeanServer(javax.management.MBeanServer) Duration(java.time.Duration) ConfigConstants(org.apache.flink.configuration.ConfigConstants) ManagementFactory(java.lang.management.ManagementFactory) JobCheckpointingSettings(org.apache.flink.runtime.jobgraph.tasks.JobCheckpointingSettings) JobGraphBuilder(org.apache.flink.runtime.jobgraph.JobGraphBuilder) Configuration(org.apache.flink.configuration.Configuration) AbstractInvokable(org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable) MiniClusterExtension(org.apache.flink.test.junit5.MiniClusterExtension) Set(java.util.Set) MetricOptions(org.apache.flink.configuration.MetricOptions) ObjectName(javax.management.ObjectName) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) TestingUtils(org.apache.flink.testutils.TestingUtils) ClusterClient(org.apache.flink.client.program.ClusterClient) JMXReporter(org.apache.flink.metrics.jmx.JMXReporter) Time(org.apache.flink.api.common.time.Time) CheckpointRetentionPolicy(org.apache.flink.runtime.checkpoint.CheckpointRetentionPolicy) Environment(org.apache.flink.runtime.execution.Environment) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) Deadline(org.apache.flink.api.common.time.Deadline) JobCheckpointingSettings(org.apache.flink.runtime.jobgraph.tasks.JobCheckpointingSettings) CheckpointCoordinatorConfiguration(org.apache.flink.runtime.jobgraph.tasks.CheckpointCoordinatorConfiguration) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.jupiter.api.Test)

Aggregations

ManagementFactory (java.lang.management.ManagementFactory)1 Duration (java.time.Duration)1 Set (java.util.Set)1 TimeUnit (java.util.concurrent.TimeUnit)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 JobStatus (org.apache.flink.api.common.JobStatus)1 Deadline (org.apache.flink.api.common.time.Deadline)1 Time (org.apache.flink.api.common.time.Time)1 ClusterClient (org.apache.flink.client.program.ClusterClient)1 ConfigConstants (org.apache.flink.configuration.ConfigConstants)1 Configuration (org.apache.flink.configuration.Configuration)1 MetricOptions (org.apache.flink.configuration.MetricOptions)1 OneShotLatch (org.apache.flink.core.testutils.OneShotLatch)1 JMXReporter (org.apache.flink.metrics.jmx.JMXReporter)1 CheckpointRetentionPolicy (org.apache.flink.runtime.checkpoint.CheckpointRetentionPolicy)1 Environment (org.apache.flink.runtime.execution.Environment)1 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)1 JobGraphBuilder (org.apache.flink.runtime.jobgraph.JobGraphBuilder)1 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)1