Search in sources :

Example 16 with JavaTestKit

use of akka.testkit.JavaTestKit in project flink by apache.

the class AccumulatorLiveITCase method notifyTaskManagerOfAccumulatorUpdate.

/**
	 * Notify task manager of accumulator update and wait until the Heartbeat containing the message
	 * has been reported.
	 */
public static void notifyTaskManagerOfAccumulatorUpdate() {
    new JavaTestKit(system) {

        {
            Timeout timeout = new Timeout(TIMEOUT);
            Future<Object> ask = Patterns.ask(taskManager, new TestingTaskManagerMessages.AccumulatorsChanged(jobID), timeout);
            try {
                Await.result(ask, timeout.duration());
            } catch (Exception e) {
                fail("Failed to notify task manager of accumulator update.");
            }
        }
    };
}
Also used : Timeout(akka.util.Timeout) JavaTestKit(akka.testkit.JavaTestKit) TestingTaskManagerMessages(org.apache.flink.runtime.testingUtils.TestingTaskManagerMessages) IOException(java.io.IOException)

Example 17 with JavaTestKit

use of akka.testkit.JavaTestKit in project flink by apache.

the class YARNHighAvailabilityITCase method testMultipleAMKill.

/**
	 * Tests that the application master can be killed multiple times and that the surviving
	 * TaskManager successfully reconnects to the newly started JobManager.
	 * @throws Exception
	 */
@Test
public void testMultipleAMKill() throws Exception {
    final int numberKillingAttempts = numberApplicationAttempts - 1;
    TestingYarnClusterDescriptor flinkYarnClient = new TestingYarnClusterDescriptor();
    Assert.assertNotNull("unable to get yarn client", flinkYarnClient);
    flinkYarnClient.setTaskManagerCount(1);
    flinkYarnClient.setJobManagerMemory(768);
    flinkYarnClient.setTaskManagerMemory(1024);
    flinkYarnClient.setLocalJarPath(new Path(flinkUberjar.getAbsolutePath()));
    flinkYarnClient.addShipFiles(Arrays.asList(flinkLibFolder.listFiles()));
    String confDirPath = System.getenv(ConfigConstants.ENV_FLINK_CONF_DIR);
    flinkYarnClient.setConfigurationDirectory(confDirPath);
    String fsStateHandlePath = temp.getRoot().getPath();
    // load the configuration
    File configDirectory = new File(confDirPath);
    GlobalConfiguration.loadConfiguration(configDirectory.getAbsolutePath());
    flinkYarnClient.setFlinkConfiguration(GlobalConfiguration.loadConfiguration());
    flinkYarnClient.setDynamicPropertiesEncoded("recovery.mode=zookeeper@@recovery.zookeeper.quorum=" + zkServer.getConnectString() + "@@yarn.application-attempts=" + numberApplicationAttempts + "@@" + CoreOptions.STATE_BACKEND + "=FILESYSTEM" + "@@" + FsStateBackendFactory.CHECKPOINT_DIRECTORY_URI_CONF_KEY + "=" + fsStateHandlePath + "/checkpoints" + "@@" + HighAvailabilityOptions.HA_STORAGE_PATH.key() + "=" + fsStateHandlePath + "/recovery");
    flinkYarnClient.setConfigurationFilePath(new Path(confDirPath + File.separator + "flink-conf.yaml"));
    ClusterClient yarnCluster = null;
    final FiniteDuration timeout = new FiniteDuration(2, TimeUnit.MINUTES);
    try {
        yarnCluster = flinkYarnClient.deploy();
        final Configuration config = yarnCluster.getFlinkConfiguration();
        new JavaTestKit(actorSystem) {

            {
                for (int attempt = 0; attempt < numberKillingAttempts; attempt++) {
                    new Within(timeout) {

                        @Override
                        protected void run() {
                            try {
                                LeaderRetrievalService lrs = LeaderRetrievalUtils.createLeaderRetrievalService(config);
                                ActorGateway gateway = LeaderRetrievalUtils.retrieveLeaderGateway(lrs, actorSystem, timeout);
                                ActorGateway selfGateway = new AkkaActorGateway(getRef(), gateway.leaderSessionID());
                                gateway.tell(new TestingJobManagerMessages.NotifyWhenAtLeastNumTaskManagerAreRegistered(1), selfGateway);
                                expectMsgEquals(Acknowledge.get());
                                gateway.tell(PoisonPill.getInstance());
                            } catch (Exception e) {
                                throw new AssertionError("Could not complete test.", e);
                            }
                        }
                    };
                }
                new Within(timeout) {

                    @Override
                    protected void run() {
                        try {
                            LeaderRetrievalService lrs = LeaderRetrievalUtils.createLeaderRetrievalService(config);
                            ActorGateway gateway2 = LeaderRetrievalUtils.retrieveLeaderGateway(lrs, actorSystem, timeout);
                            ActorGateway selfGateway = new AkkaActorGateway(getRef(), gateway2.leaderSessionID());
                            gateway2.tell(new TestingJobManagerMessages.NotifyWhenAtLeastNumTaskManagerAreRegistered(1), selfGateway);
                            expectMsgEquals(Acknowledge.get());
                        } catch (Exception e) {
                            throw new AssertionError("Could not complete test.", e);
                        }
                    }
                };
            }
        };
    } finally {
        if (yarnCluster != null) {
            yarnCluster.shutdown();
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AkkaActorGateway(org.apache.flink.runtime.instance.AkkaActorGateway) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.flink.configuration.Configuration) GlobalConfiguration(org.apache.flink.configuration.GlobalConfiguration) FiniteDuration(scala.concurrent.duration.FiniteDuration) ClusterClient(org.apache.flink.client.program.ClusterClient) TestingJobManagerMessages(org.apache.flink.runtime.testingUtils.TestingJobManagerMessages) LeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService) AkkaActorGateway(org.apache.flink.runtime.instance.AkkaActorGateway) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) File(java.io.File) JavaTestKit(akka.testkit.JavaTestKit) Test(org.junit.Test)

Example 18 with JavaTestKit

use of akka.testkit.JavaTestKit in project flink by apache.

the class InstanceManagerTest method testInstanceRegistering.

@Test
public void testInstanceRegistering() {
    try {
        InstanceManager cm = new InstanceManager();
        final int dataPort = 20000;
        HardwareDescription hardwareDescription = HardwareDescription.extractFromSystem(4096);
        InetAddress address = InetAddress.getByName("127.0.0.1");
        // register three instances
        ResourceID resID1 = ResourceID.generate();
        ResourceID resID2 = ResourceID.generate();
        ResourceID resID3 = ResourceID.generate();
        TaskManagerLocation ici1 = new TaskManagerLocation(resID1, address, dataPort);
        TaskManagerLocation ici2 = new TaskManagerLocation(resID2, address, dataPort + 15);
        TaskManagerLocation ici3 = new TaskManagerLocation(resID3, address, dataPort + 30);
        final JavaTestKit probe1 = new JavaTestKit(system);
        final JavaTestKit probe2 = new JavaTestKit(system);
        final JavaTestKit probe3 = new JavaTestKit(system);
        cm.registerTaskManager(new ActorTaskManagerGateway(new AkkaActorGateway(probe1.getRef(), leaderSessionID)), ici1, hardwareDescription, 1);
        cm.registerTaskManager(new ActorTaskManagerGateway(new AkkaActorGateway(probe2.getRef(), leaderSessionID)), ici2, hardwareDescription, 2);
        cm.registerTaskManager(new ActorTaskManagerGateway(new AkkaActorGateway(probe3.getRef(), leaderSessionID)), ici3, hardwareDescription, 5);
        assertEquals(3, cm.getNumberOfRegisteredTaskManagers());
        assertEquals(8, cm.getTotalNumberOfSlots());
        Collection<Instance> instances = cm.getAllRegisteredInstances();
        Set<TaskManagerLocation> taskManagerLocations = new HashSet<TaskManagerLocation>();
        for (Instance instance : instances) {
            taskManagerLocations.add(instance.getTaskManagerLocation());
        }
        assertTrue(taskManagerLocations.contains(ici1));
        assertTrue(taskManagerLocations.contains(ici2));
        assertTrue(taskManagerLocations.contains(ici3));
        cm.shutdown();
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        Assert.fail("Test erroneous: " + e.getMessage());
    }
}
Also used : TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) ActorTaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) InetAddress(java.net.InetAddress) JavaTestKit(akka.testkit.JavaTestKit) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 19 with JavaTestKit

use of akka.testkit.JavaTestKit in project flink by apache.

the class InstanceManagerTest method testShutdown.

@Test
public void testShutdown() {
    try {
        InstanceManager cm = new InstanceManager();
        cm.shutdown();
        try {
            ResourceID resID = ResourceID.generate();
            HardwareDescription resources = HardwareDescription.extractFromSystem(4096);
            InetAddress address = InetAddress.getByName("127.0.0.1");
            TaskManagerLocation ici = new TaskManagerLocation(resID, address, 20000);
            JavaTestKit probe = new JavaTestKit(system);
            cm.registerTaskManager(new ActorTaskManagerGateway(new AkkaActorGateway(probe.getRef(), leaderSessionID)), ici, resources, 1);
            fail("Should raise exception in shutdown state");
        } catch (IllegalStateException e) {
        // expected
        }
        assertFalse(cm.reportHeartBeat(new InstanceID()));
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        Assert.fail("Test erroneous: " + e.getMessage());
    }
}
Also used : ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) InetAddress(java.net.InetAddress) JavaTestKit(akka.testkit.JavaTestKit) ActorTaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway) Test(org.junit.Test)

Example 20 with JavaTestKit

use of akka.testkit.JavaTestKit in project flink by apache.

the class InstanceManagerTest method testReportHeartbeat.

@Test
public void testReportHeartbeat() {
    try {
        InstanceManager cm = new InstanceManager();
        final int dataPort = 20000;
        ResourceID resID1 = ResourceID.generate();
        ResourceID resID2 = ResourceID.generate();
        ResourceID resID3 = ResourceID.generate();
        HardwareDescription hardwareDescription = HardwareDescription.extractFromSystem(4096);
        InetAddress address = InetAddress.getByName("127.0.0.1");
        // register three instances
        TaskManagerLocation ici1 = new TaskManagerLocation(resID1, address, dataPort);
        TaskManagerLocation ici2 = new TaskManagerLocation(resID2, address, dataPort + 1);
        TaskManagerLocation ici3 = new TaskManagerLocation(resID3, address, dataPort + 2);
        JavaTestKit probe1 = new JavaTestKit(system);
        JavaTestKit probe2 = new JavaTestKit(system);
        JavaTestKit probe3 = new JavaTestKit(system);
        InstanceID instanceID1 = cm.registerTaskManager(new ActorTaskManagerGateway(new AkkaActorGateway(probe1.getRef(), leaderSessionID)), ici1, hardwareDescription, 1);
        InstanceID instanceID2 = cm.registerTaskManager(new ActorTaskManagerGateway(new AkkaActorGateway(probe2.getRef(), leaderSessionID)), ici2, hardwareDescription, 1);
        InstanceID instanceID3 = cm.registerTaskManager(new ActorTaskManagerGateway(new AkkaActorGateway(probe3.getRef(), leaderSessionID)), ici3, hardwareDescription, 1);
        // report some immediate heart beats
        assertTrue(cm.reportHeartBeat(instanceID1));
        assertTrue(cm.reportHeartBeat(instanceID2));
        assertTrue(cm.reportHeartBeat(instanceID3));
        // report heart beat for non-existing instance
        assertFalse(cm.reportHeartBeat(new InstanceID()));
        final long WAIT = 200;
        CommonTestUtils.sleepUninterruptibly(WAIT);
        Iterator<Instance> it = cm.getAllRegisteredInstances().iterator();
        Instance instance1 = it.next();
        long h1 = instance1.getLastHeartBeat();
        long h2 = it.next().getLastHeartBeat();
        long h3 = it.next().getLastHeartBeat();
        // send one heart beat again and verify that the
        assertTrue(cm.reportHeartBeat(instance1.getId()));
        long newH1 = instance1.getLastHeartBeat();
        long now = System.currentTimeMillis();
        assertTrue(now - h1 >= WAIT);
        assertTrue(now - h2 >= WAIT);
        assertTrue(now - h3 >= WAIT);
        assertTrue(now - newH1 <= WAIT);
        cm.shutdown();
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        Assert.fail("Test erroneous: " + e.getMessage());
    }
}
Also used : TaskManagerLocation(org.apache.flink.runtime.taskmanager.TaskManagerLocation) ActorTaskManagerGateway(org.apache.flink.runtime.jobmanager.slots.ActorTaskManagerGateway) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) InetAddress(java.net.InetAddress) JavaTestKit(akka.testkit.JavaTestKit) Test(org.junit.Test)

Aggregations

JavaTestKit (akka.testkit.JavaTestKit)49 Test (org.junit.Test)47 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)34 Configuration (org.apache.flink.configuration.Configuration)26 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)23 JobID (org.apache.flink.api.common.JobID)17 ActorRef (akka.actor.ActorRef)16 TaskManagerServicesConfiguration (org.apache.flink.runtime.taskexecutor.TaskManagerServicesConfiguration)13 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)12 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)12 IOException (java.io.IOException)11 TaskDeploymentDescriptor (org.apache.flink.runtime.deployment.TaskDeploymentDescriptor)11 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)11 FiniteDuration (scala.concurrent.duration.FiniteDuration)11 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)10 PartitionNotFoundException (org.apache.flink.runtime.io.network.partition.PartitionNotFoundException)10 SubmitTask (org.apache.flink.runtime.messages.TaskMessages.SubmitTask)10 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)9 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)9 TestingTaskManagerMessages (org.apache.flink.runtime.testingUtils.TestingTaskManagerMessages)9