Search in sources :

Example 1 with LookupRetryStrategy

use of org.apache.flink.runtime.query.AkkaKvStateLocationLookupService.LookupRetryStrategy in project flink by apache.

the class AkkaKvStateLocationLookupServiceTest method testRetryOnUnknownJobManager.

/**
	 * Tests that lookups are retried when no leader notification is available.
	 */
@Test
public void testRetryOnUnknownJobManager() throws Exception {
    final Queue<LookupRetryStrategy> retryStrategies = new LinkedBlockingQueue<>();
    LookupRetryStrategyFactory retryStrategy = new LookupRetryStrategyFactory() {

        @Override
        public LookupRetryStrategy createRetryStrategy() {
            return retryStrategies.poll();
        }
    };
    final TestingLeaderRetrievalService leaderRetrievalService = new TestingLeaderRetrievalService();
    AkkaKvStateLocationLookupService lookupService = new AkkaKvStateLocationLookupService(leaderRetrievalService, testActorSystem, TIMEOUT, retryStrategy);
    lookupService.start();
    //
    // Test call to retry
    //
    final AtomicBoolean hasRetried = new AtomicBoolean();
    retryStrategies.add(new LookupRetryStrategy() {

        @Override
        public FiniteDuration getRetryDelay() {
            return FiniteDuration.Zero();
        }

        @Override
        public boolean tryRetry() {
            if (hasRetried.compareAndSet(false, true)) {
                return true;
            }
            return false;
        }
    });
    Future<KvStateLocation> locationFuture = lookupService.getKvStateLookupInfo(new JobID(), "yessir");
    Await.ready(locationFuture, TIMEOUT);
    assertTrue("Did not retry ", hasRetried.get());
    //
    // Test leader notification after retry
    //
    Queue<LookupKvStateLocation> received = new LinkedBlockingQueue<>();
    KvStateLocation expected = new KvStateLocation(new JobID(), new JobVertexID(), 12122, "garlic");
    ActorRef testActor = LookupResponseActor.create(received, null, expected);
    final String testActorAddress = AkkaUtils.getAkkaURL(testActorSystem, testActor);
    retryStrategies.add(new LookupRetryStrategy() {

        @Override
        public FiniteDuration getRetryDelay() {
            return FiniteDuration.apply(100, TimeUnit.MILLISECONDS);
        }

        @Override
        public boolean tryRetry() {
            leaderRetrievalService.notifyListener(testActorAddress, null);
            return true;
        }
    });
    KvStateLocation location = Await.result(lookupService.getKvStateLookupInfo(new JobID(), "yessir"), TIMEOUT);
    assertEquals(expected, location);
}
Also used : LookupRetryStrategyFactory(org.apache.flink.runtime.query.AkkaKvStateLocationLookupService.LookupRetryStrategyFactory) TestingLeaderRetrievalService(org.apache.flink.runtime.leaderelection.TestingLeaderRetrievalService) ActorRef(akka.actor.ActorRef) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) FiniteDuration(scala.concurrent.duration.FiniteDuration) LookupRetryStrategy(org.apache.flink.runtime.query.AkkaKvStateLocationLookupService.LookupRetryStrategy) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) LookupKvStateLocation(org.apache.flink.runtime.query.KvStateMessage.LookupKvStateLocation) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LookupKvStateLocation(org.apache.flink.runtime.query.KvStateMessage.LookupKvStateLocation) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

ActorRef (akka.actor.ActorRef)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 JobID (org.apache.flink.api.common.JobID)1 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)1 TestingLeaderRetrievalService (org.apache.flink.runtime.leaderelection.TestingLeaderRetrievalService)1 LookupRetryStrategy (org.apache.flink.runtime.query.AkkaKvStateLocationLookupService.LookupRetryStrategy)1 LookupRetryStrategyFactory (org.apache.flink.runtime.query.AkkaKvStateLocationLookupService.LookupRetryStrategyFactory)1 LookupKvStateLocation (org.apache.flink.runtime.query.KvStateMessage.LookupKvStateLocation)1 Test (org.junit.Test)1 FiniteDuration (scala.concurrent.duration.FiniteDuration)1