Search in sources :

Example 16 with Configuration

use of org.apache.flink.configuration.Configuration in project flink by apache.

the class ZooKeeperLeaderRetrievalTest method testConnectingAddressRetrievalWithDelayedLeaderElection.

/**
	 * Tests that LeaderRetrievalUtils.findConnectingAdress finds the correct connecting address
	 * in case of an old leader address in ZooKeeper and a subsequent election of a new leader.
	 * The findConnectingAddress should block until the new leader has been elected and his
	 * address has been written to ZooKeeper.
	 */
@Test
public void testConnectingAddressRetrievalWithDelayedLeaderElection() throws Exception {
    FiniteDuration timeout = new FiniteDuration(1, TimeUnit.MINUTES);
    Configuration config = new Configuration();
    long sleepingTime = 1000;
    config.setString(HighAvailabilityOptions.HA_MODE, "zookeeper");
    config.setString(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, testingServer.getConnectString());
    LeaderElectionService leaderElectionService = null;
    LeaderElectionService faultyLeaderElectionService;
    ServerSocket serverSocket;
    InetAddress localHost;
    Thread thread;
    CuratorFramework[] client = new CuratorFramework[2];
    try {
        client[0] = ZooKeeperUtils.startCuratorFramework(config);
        client[1] = ZooKeeperUtils.startCuratorFramework(config);
        String wrongHostPort = NetUtils.unresolvedHostAndPortToNormalizedString("1.1.1.1", 1234);
        String wrongAddress = JobManager.getRemoteJobManagerAkkaURL(AkkaUtils.getAkkaProtocol(config), wrongHostPort, Option.<String>empty());
        try {
            localHost = InetAddress.getLocalHost();
            serverSocket = new ServerSocket(0, 50, localHost);
        } catch (UnknownHostException e) {
            // may happen if disconnected. skip test.
            System.err.println("Skipping 'testNetworkInterfaceSelection' test.");
            return;
        } catch (IOException e) {
            // may happen in certain test setups, skip test.
            System.err.println("Skipping 'testNetworkInterfaceSelection' test.");
            return;
        }
        InetSocketAddress correctInetSocketAddress = new InetSocketAddress(localHost, serverSocket.getLocalPort());
        String hostPort = NetUtils.unresolvedHostAndPortToNormalizedString(localHost.getHostName(), correctInetSocketAddress.getPort());
        String correctAddress = JobManager.getRemoteJobManagerAkkaURL(AkkaUtils.getAkkaProtocol(config), hostPort, Option.<String>empty());
        faultyLeaderElectionService = ZooKeeperUtils.createLeaderElectionService(client[0], config);
        TestingContender wrongLeaderAddressContender = new TestingContender(wrongAddress, faultyLeaderElectionService);
        faultyLeaderElectionService.start(wrongLeaderAddressContender);
        FindConnectingAddress findConnectingAddress = new FindConnectingAddress(config, timeout);
        thread = new Thread(findConnectingAddress);
        thread.start();
        leaderElectionService = ZooKeeperUtils.createLeaderElectionService(client[1], config);
        TestingContender correctLeaderAddressContender = new TestingContender(correctAddress, leaderElectionService);
        Thread.sleep(sleepingTime);
        faultyLeaderElectionService.stop();
        leaderElectionService.start(correctLeaderAddressContender);
        thread.join();
        InetAddress result = findConnectingAddress.getInetAddress();
        // check that we can connect to the localHost
        Socket socket = new Socket();
        try {
            // port 0 = let the OS choose the port
            SocketAddress bindP = new InetSocketAddress(result, 0);
            // machine
            socket.bind(bindP);
            socket.connect(correctInetSocketAddress, 1000);
        } finally {
            socket.close();
        }
    } finally {
        if (leaderElectionService != null) {
            leaderElectionService.stop();
        }
        if (client[0] != null) {
            client[0].close();
        }
        if (client[1] != null) {
            client[1].close();
        }
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) FiniteDuration(scala.concurrent.duration.FiniteDuration) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) CuratorFramework(org.apache.curator.framework.CuratorFramework) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Example 17 with Configuration

use of org.apache.flink.configuration.Configuration in project flink by apache.

the class ZooKeeperLeaderRetrievalTest method testTimeoutOfFindConnectingAddress.

/**
	 * Tests that the LeaderRetrievalUtils.findConnectingAddress stops trying to find the
	 * connecting address if no leader address has been specified. The call should return
	 * then InetAddress.getLocalHost().
	 */
@Test
public void testTimeoutOfFindConnectingAddress() throws Exception {
    Configuration config = new Configuration();
    config.setString(HighAvailabilityOptions.HA_MODE, "zookeeper");
    config.setString(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, testingServer.getConnectString());
    FiniteDuration timeout = new FiniteDuration(10, TimeUnit.SECONDS);
    LeaderRetrievalService leaderRetrievalService = LeaderRetrievalUtils.createLeaderRetrievalService(config);
    InetAddress result = LeaderRetrievalUtils.findConnectingAddress(leaderRetrievalService, timeout);
    assertEquals(InetAddress.getLocalHost(), result);
}
Also used : Configuration(org.apache.flink.configuration.Configuration) LeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService) FiniteDuration(scala.concurrent.duration.FiniteDuration) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 18 with Configuration

use of org.apache.flink.configuration.Configuration in project flink by apache.

the class JobManagerLeaderElectionTest method testLeaderElection.

/**
	 * Tests that a single JobManager is elected as the leader by ZooKeeper.
	 */
@Test
public void testLeaderElection() throws Exception {
    final Configuration configuration = ZooKeeperTestUtils.createZooKeeperHAConfig(testingServer.getConnectString(), tempFolder.getRoot().getPath());
    ActorRef jm = null;
    try {
        Props jmProps = createJobManagerProps(configuration);
        jm = actorSystem.actorOf(jmProps);
        Future<Object> leaderFuture = Patterns.ask(jm, TestingJobManagerMessages.getNotifyWhenLeader(), timeout);
        Await.ready(leaderFuture, duration);
    } finally {
        TestingUtils.stopActor(jm);
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) ActorRef(akka.actor.ActorRef) Props(akka.actor.Props) Test(org.junit.Test)

Example 19 with Configuration

use of org.apache.flink.configuration.Configuration in project flink by apache.

the class LeaderChangeJobRecoveryTest method before.

@Before
public void before() throws TimeoutException, InterruptedException {
    Tasks.BlockingOnceReceiver$.MODULE$.blocking_$eq(true);
    configuration = new Configuration();
    configuration.setInteger(ConfigConstants.LOCAL_NUMBER_JOB_MANAGER, 1);
    configuration.setInteger(ConfigConstants.LOCAL_NUMBER_TASK_MANAGER, numTMs);
    configuration.setInteger(ConfigConstants.TASK_MANAGER_NUM_TASK_SLOTS, numSlotsPerTM);
    configuration.setString(ConfigConstants.RESTART_STRATEGY, "fixeddelay");
    configuration.setInteger(ConfigConstants.RESTART_STRATEGY_FIXED_DELAY_ATTEMPTS, 9999);
    configuration.setString(ConfigConstants.RESTART_STRATEGY_FIXED_DELAY_DELAY, "100 milli");
    cluster = new LeaderElectionRetrievalTestingCluster(configuration, true, false);
    cluster.start(false);
    // wait for actors to be alive so that they have started their leader retrieval service
    cluster.waitForActorsToBeAlive();
}
Also used : Configuration(org.apache.flink.configuration.Configuration) Before(org.junit.Before)

Example 20 with Configuration

use of org.apache.flink.configuration.Configuration in project flink by apache.

the class LeaderChangeStateCleanupTest method before.

@Before
public void before() throws Exception {
    Tasks.BlockingOnceReceiver$.MODULE$.blocking_$eq(true);
    configuration = new Configuration();
    configuration.setInteger(ConfigConstants.LOCAL_NUMBER_JOB_MANAGER, numJMs);
    configuration.setInteger(ConfigConstants.LOCAL_NUMBER_TASK_MANAGER, numTMs);
    configuration.setInteger(ConfigConstants.TASK_MANAGER_NUM_TASK_SLOTS, numSlotsPerTM);
    cluster = new LeaderElectionRetrievalTestingCluster(configuration, true, false);
    // TaskManagers don't have to register at the JobManager
    cluster.start(false);
    // we only wait until all actors are alive
    cluster.waitForActorsToBeAlive();
}
Also used : Configuration(org.apache.flink.configuration.Configuration) Before(org.junit.Before)

Aggregations

Configuration (org.apache.flink.configuration.Configuration)630 Test (org.junit.Test)452 IOException (java.io.IOException)137 FileInputSplit (org.apache.flink.core.fs.FileInputSplit)93 File (java.io.File)92 JobID (org.apache.flink.api.common.JobID)74 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)68 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)49 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)46 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)45 Path (org.apache.flink.core.fs.Path)44 ActorRef (akka.actor.ActorRef)43 ArrayList (java.util.ArrayList)43 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)39 FiniteDuration (scala.concurrent.duration.FiniteDuration)38 LocalFlinkMiniCluster (org.apache.flink.runtime.minicluster.LocalFlinkMiniCluster)36 BeforeClass (org.junit.BeforeClass)35 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)33 MetricRegistry (org.apache.flink.runtime.metrics.MetricRegistry)33 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)32