Java Code Examples for org.apache.flink.runtime.testingUtils.TestingUtils#defaultExecutor()

The following examples show how to use org.apache.flink.runtime.testingUtils.TestingUtils#defaultExecutor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobSubmitHandlerTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerializationFailureHandling() throws Exception {
	final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
	DispatcherGateway mockGateway = new TestingDispatcherGateway.Builder()
		.setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get()))
		.build();

	JobSubmitHandler handler = new JobSubmitHandler(
		() -> CompletableFuture.completedFuture(mockGateway),
		RpcUtils.INF_TIMEOUT,
		Collections.emptyMap(),
		TestingUtils.defaultExecutor(),
		configuration);

	JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.toString(), Collections.emptyList(), Collections.emptyList());

	try {
		handler.handleRequest(new HandlerRequest<>(request, EmptyMessageParameters.getInstance()), mockGateway);
		Assert.fail();
	} catch (RestHandlerException rhe) {
		Assert.assertEquals(HttpResponseStatus.BAD_REQUEST, rhe.getHttpResponseStatus());
	}
}
 
Example 2
Source File: JobSubmitHandlerTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
public void testSuccessfulJobSubmission() throws Exception {
	final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
	try (ObjectOutputStream objectOut = new ObjectOutputStream(Files.newOutputStream(jobGraphFile))) {
		objectOut.writeObject(new JobGraph("testjob"));
	}

	TestingDispatcherGateway.Builder builder = new TestingDispatcherGateway.Builder();
	builder
		.setBlobServerPort(blobServer.getPort())
		.setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get()))
		.setHostname("localhost");
	DispatcherGateway mockGateway = builder.build();

	JobSubmitHandler handler = new JobSubmitHandler(
		() -> CompletableFuture.completedFuture(mockGateway),
		RpcUtils.INF_TIMEOUT,
		Collections.emptyMap(),
		TestingUtils.defaultExecutor(),
		configuration);

	JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.getFileName().toString(), Collections.emptyList(), Collections.emptyList());

	handler.handleRequest(new HandlerRequest<>(request, EmptyMessageParameters.getInstance(), Collections.emptyMap(), Collections.emptyMap(), Collections.singleton(jobGraphFile.toFile())), mockGateway)
		.get();
}
 
Example 3
Source File: ZooKeeperLeaderRetrievalTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws Exception {
	testingServer = new TestingServer();

	config = new Configuration();
	config.setString(HighAvailabilityOptions.HA_MODE, "zookeeper");
	config.setString(HighAvailabilityOptions.HA_ZOOKEEPER_QUORUM, testingServer.getConnectString());

	CuratorFramework client = ZooKeeperUtils.startCuratorFramework(config);

	highAvailabilityServices = new ZooKeeperHaServices(
		client,
		TestingUtils.defaultExecutor(),
		config,
		new VoidBlobStore());
}
 
Example 4
Source File: JobConfigHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void handleRequest_executionConfigWithSecretValues_excludesSecretValuesFromResponse() throws HandlerRequestException {
	final JobConfigHandler jobConfigHandler = new JobConfigHandler(
		() -> null,
		TestingUtils.TIMEOUT(),
		Collections.emptyMap(),
		JobConfigHeaders.getInstance(),
		new DefaultExecutionGraphCache(TestingUtils.TIMEOUT(), TestingUtils.TIMEOUT()),
		TestingUtils.defaultExecutor());

	final Map<String, String> globalJobParameters = new HashMap<>();
	globalJobParameters.put("foobar", "barfoo");
	globalJobParameters.put("bar.secret.foo", "my secret");
	globalJobParameters.put("password.to.my.safe", "12345");

	final ArchivedExecutionConfig archivedExecutionConfig = new ArchivedExecutionConfigBuilder()
		.setGlobalJobParameters(globalJobParameters)
		.build();
	final AccessExecutionGraph archivedExecutionGraph = new ArchivedExecutionGraphBuilder()
		.setArchivedExecutionConfig(archivedExecutionConfig)
		.build();
	final HandlerRequest<EmptyRequestBody, JobMessageParameters> handlerRequest = createRequest(archivedExecutionGraph.getJobID());

	final JobConfigInfo jobConfigInfoResponse = jobConfigHandler.handleRequest(handlerRequest, archivedExecutionGraph);

	final Map<String, String> filteredGlobalJobParameters = filterSecretValues(globalJobParameters);

	assertThat(jobConfigInfoResponse.getExecutionConfigInfo().getGlobalJobParameters(), is(equalTo(filteredGlobalJobParameters)));
}
 
Example 5
Source File: JobSubmitHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testRejectionOnCountMismatch() throws Exception {
	final Path jobGraphFile = TEMPORARY_FOLDER.newFile().toPath();
	try (ObjectOutputStream objectOut = new ObjectOutputStream(Files.newOutputStream(jobGraphFile))) {
		objectOut.writeObject(new JobGraph("testjob"));
	}
	final Path countExceedingFile = TEMPORARY_FOLDER.newFile().toPath();

	TestingDispatcherGateway.Builder builder = new TestingDispatcherGateway.Builder();
	builder
		.setBlobServerPort(blobServer.getPort())
		.setSubmitFunction(jobGraph -> CompletableFuture.completedFuture(Acknowledge.get()))
		.setHostname("localhost");
	DispatcherGateway mockGateway = builder.build();

	JobSubmitHandler handler = new JobSubmitHandler(
		() -> CompletableFuture.completedFuture(mockGateway),
		RpcUtils.INF_TIMEOUT,
		Collections.emptyMap(),
		TestingUtils.defaultExecutor(),
		configuration);

	JobSubmitRequestBody request = new JobSubmitRequestBody(jobGraphFile.getFileName().toString(), Collections.emptyList(), Collections.emptyList());

	try {
		handler.handleRequest(new HandlerRequest<>(request, EmptyMessageParameters.getInstance(), Collections.emptyMap(), Collections.emptyMap(), Arrays.asList(jobGraphFile.toFile(), countExceedingFile.toFile())), mockGateway)
			.get();
	} catch (Exception e) {
		ExceptionUtils.findThrowable(e, candidate -> candidate instanceof RestHandlerException && candidate.getMessage().contains("count"));
	}
}
 
Example 6
Source File: JobExceptionsHandlerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetJobExceptionsInfo() throws HandlerRequestException {
	final JobExceptionsHandler jobExceptionsHandler = new JobExceptionsHandler(
		() -> null,
		TestingUtils.TIMEOUT(),
		Collections.emptyMap(),
		JobExceptionsHeaders.getInstance(),
		new DefaultExecutionGraphCache(TestingUtils.TIMEOUT(), TestingUtils.TIMEOUT()),
		TestingUtils.defaultExecutor());
	final int numExceptions = 20;
	final AccessExecutionGraph archivedExecutionGraph = createAccessExecutionGraph(numExceptions);
	checkExceptionLimit(jobExceptionsHandler, archivedExecutionGraph, numExceptions, 10);
	checkExceptionLimit(jobExceptionsHandler, archivedExecutionGraph, numExceptions, numExceptions);
	checkExceptionLimit(jobExceptionsHandler, archivedExecutionGraph, numExceptions, 30);
}
 
Example 7
Source File: TestingJobManagerSharedServicesBuilder.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public TestingJobManagerSharedServicesBuilder() {
	scheduledExecutorService = TestingUtils.defaultExecutor();
	libraryCacheManager = ContextClassLoaderLibraryCacheManager.INSTANCE;
	restartStrategyFactory = new NoOrFixedIfCheckpointingEnabledRestartStrategyFactory();
	stackTraceSampleCoordinator = mock(StackTraceSampleCoordinator.class);
	backPressureStatsTracker = VoidBackPressureStatsTracker.INSTANCE;
	blobWriter = VoidBlobWriter.getInstance();
}
 
Example 8
Source File: PointwisePatternTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private ExecutionGraph getDummyExecutionGraph() throws Exception {
	return new ExecutionGraph(
		TestingUtils.defaultExecutor(),
		TestingUtils.defaultExecutor(),
		new JobID(),
		"Test Job Sample Name",
		new Configuration(),
		new SerializedValue<>(new ExecutionConfig()),
		AkkaUtils.getDefaultTimeout(),
		new NoRestartStrategy(),
		new TestingSlotProvider(ignored -> new CompletableFuture<>()));
}
 
Example 9
Source File: TaskManagerReleaseInSlotManagerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that idle task managers time out after the configured timeout. A timed out task manager
 * will be removed from the slot manager and the resource manager will be notified about the
 * timeout, if it can be released.
 */
@Test
public void testTaskManagerTimeout() throws Exception {
	Executor executor = TestingUtils.defaultExecutor();
	canBeReleasedFuture.set(CompletableFuture.completedFuture(true));
	try (SlotManager slotManager = SlotManagerBuilder
		.newBuilder()
		.setTaskManagerTimeout(Time.milliseconds(10L))
		.build()) {

		slotManager.start(resourceManagerId, executor, resourceManagerActions);
		executor.execute(() -> slotManager.registerTaskManager(taskManagerConnection, slotReport));
		assertThat(releaseFuture.get(), is(equalTo(taskManagerConnection.getInstanceID())));
	}
}
 
Example 10
Source File: ExecutionGraphConstructionTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testCannotConnectWrongOrder() throws Exception {
	final JobID jobId = new JobID();
	final String jobName = "Test Job Sample Name";
	final Configuration cfg = new Configuration();
	
	JobVertex v1 = new JobVertex("vertex1");
	JobVertex v2 = new JobVertex("vertex2");
	JobVertex v3 = new JobVertex("vertex3");
	JobVertex v4 = new JobVertex("vertex4");
	JobVertex v5 = new JobVertex("vertex5");
	
	v1.setParallelism(5);
	v2.setParallelism(7);
	v3.setParallelism(2);
	v4.setParallelism(11);
	v5.setParallelism(4);

	v1.setInvokableClass(AbstractInvokable.class);
	v2.setInvokableClass(AbstractInvokable.class);
	v3.setInvokableClass(AbstractInvokable.class);
	v4.setInvokableClass(AbstractInvokable.class);
	v5.setInvokableClass(AbstractInvokable.class);

	v2.connectNewDataSetAsInput(v1, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
	v4.connectNewDataSetAsInput(v2, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
	v4.connectNewDataSetAsInput(v3, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
	v5.connectNewDataSetAsInput(v4, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
	v5.connectNewDataSetAsInput(v3, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
	
	List<JobVertex> ordered = new ArrayList<JobVertex>(Arrays.asList(v1, v2, v3, v5, v4));

	ExecutionGraph eg = new ExecutionGraph(
		TestingUtils.defaultExecutor(),
		TestingUtils.defaultExecutor(),
		jobId, 
		jobName, 
		cfg,
		new SerializedValue<>(new ExecutionConfig()),
		AkkaUtils.getDefaultTimeout(),
		new NoRestartStrategy(),
		new TestingSlotProvider(ignored -> new CompletableFuture<>()));
	try {
		eg.attachJobGraph(ordered);
		fail("Attached wrong jobgraph");
	}
	catch (JobException e) {
		// expected
	}
}
 
Example 11
Source File: RetryingRegistrationTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testRetryConnectOnFailure() throws Exception {
	final String testId = "laissez les bon temps roulez";
	final UUID leaderId = UUID.randomUUID();

	ExecutorService executor = TestingUtils.defaultExecutor();
	TestRegistrationGateway testGateway = new TestRegistrationGateway(new TestRegistrationSuccess(testId));

	try {
		// RPC service that fails upon the first connection, but succeeds on the second
		RpcService rpc = mock(RpcService.class);
		when(rpc.connect(anyString(), any(Class.class))).thenReturn(
				FutureUtils.completedExceptionally(new Exception("test connect failure")),  // first connection attempt fails
				CompletableFuture.completedFuture(testGateway)                         // second connection attempt succeeds
		);
		when(rpc.getExecutor()).thenReturn(executor);
		when(rpc.scheduleRunnable(any(Runnable.class), anyLong(), any(TimeUnit.class))).thenAnswer(
			(InvocationOnMock invocation) -> {
				final Runnable runnable = invocation.getArgument(0);
				final long delay = invocation.getArgument(1);
				final TimeUnit timeUnit = invocation.getArgument(2);
				return TestingUtils.defaultScheduledExecutor().schedule(runnable, delay, timeUnit);
			});

		TestRetryingRegistration registration = new TestRetryingRegistration(rpc, "foobar address", leaderId);

		long start = System.currentTimeMillis();

		registration.startRegistration();

		Tuple2<TestRegistrationGateway, TestRegistrationSuccess> success =
			registration.getFuture().get(10L, TimeUnit.SECONDS);

		// measure the duration of the registration --> should be longer than the error delay
		long duration = System.currentTimeMillis() - start;

		assertTrue(
			"The registration should have failed the first time. Thus the duration should be longer than at least a single error delay.",
			duration > TestRetryingRegistration.DELAY_ON_ERROR);

		// validate correct invocation and result
		assertEquals(testId, success.f1.getCorrelationId());
		assertEquals(leaderId, testGateway.getInvocations().take().leaderId());
	}
	finally {
		testGateway.stop();
	}
}
 
Example 12
Source File: RestClientMultipartTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setupClient() throws ConfigurationException {
	restClient = new RestClient(RestClientConfiguration.fromConfiguration(new Configuration()), TestingUtils.defaultExecutor());
}
 
Example 13
Source File: RestClientTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that we fail the operation if the remote connection closes.
 */
@Test
public void testConnectionClosedHandling() throws Exception {
	final Configuration config = new Configuration();
	config.setLong(RestOptions.IDLENESS_TIMEOUT, 5000L);
	try (final ServerSocket serverSocket = new ServerSocket(0);
		final RestClient restClient = new RestClient(RestClientConfiguration.fromConfiguration(config), TestingUtils.defaultExecutor())) {

		final String targetAddress = "localhost";
		final int targetPort = serverSocket.getLocalPort();

		// start server
		final CompletableFuture<Socket> socketCompletableFuture = CompletableFuture.supplyAsync(CheckedSupplier.unchecked(serverSocket::accept));

		final CompletableFuture<EmptyResponseBody> responseFuture = restClient.sendRequest(
			targetAddress,
			targetPort,
			new TestMessageHeaders(),
			EmptyMessageParameters.getInstance(),
			EmptyRequestBody.getInstance(),
			Collections.emptyList());

		Socket connectionSocket = null;

		try {
			connectionSocket = socketCompletableFuture.get(TIMEOUT, TimeUnit.SECONDS);
		} catch (TimeoutException ignored) {
			// could not establish a server connection --> see that the response failed
			socketCompletableFuture.cancel(true);
		}

		if (connectionSocket != null) {
			// close connection
			connectionSocket.close();
		}

		try {
			responseFuture.get();
		} catch (ExecutionException ee) {
			if (!ExceptionUtils.findThrowable(ee, IOException.class).isPresent()) {
				throw ee;
			}
		}
	}
}
 
Example 14
Source File: RestClientTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that we fail the operation if the client closes.
 */
@Test
public void testRestClientClosedHandling() throws Exception {
	final Configuration config = new Configuration();
	config.setLong(RestOptions.IDLENESS_TIMEOUT, 5000L);

	Socket connectionSocket = null;

	try (final ServerSocket serverSocket = new ServerSocket(0);
		final RestClient restClient = new RestClient(RestClientConfiguration.fromConfiguration(config), TestingUtils.defaultExecutor())) {

		final String targetAddress = "localhost";
		final int targetPort = serverSocket.getLocalPort();

		// start server
		final CompletableFuture<Socket> socketCompletableFuture = CompletableFuture.supplyAsync(CheckedSupplier.unchecked(serverSocket::accept));

		final CompletableFuture<EmptyResponseBody> responseFuture = restClient.sendRequest(
			targetAddress,
			targetPort,
			new TestMessageHeaders(),
			EmptyMessageParameters.getInstance(),
			EmptyRequestBody.getInstance(),
			Collections.emptyList());

		try {
			connectionSocket = socketCompletableFuture.get(TIMEOUT, TimeUnit.SECONDS);
		} catch (TimeoutException ignored) {
			// could not establish a server connection --> see that the response failed
			socketCompletableFuture.cancel(true);
		}

		restClient.close();

		try {
			responseFuture.get();
		} catch (ExecutionException ee) {
			if (!ExceptionUtils.findThrowable(ee, IOException.class).isPresent()) {
				throw ee;
			}
		}
	} finally {
		if (connectionSocket != null) {
			connectionSocket.close();
		}
	}
}
 
Example 15
Source File: ExecutionGraphConstructionTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testCannotConnectWrongOrder() throws Exception {
	final JobID jobId = new JobID();
	final String jobName = "Test Job Sample Name";
	final Configuration cfg = new Configuration();
	
	JobVertex v1 = new JobVertex("vertex1");
	JobVertex v2 = new JobVertex("vertex2");
	JobVertex v3 = new JobVertex("vertex3");
	JobVertex v4 = new JobVertex("vertex4");
	JobVertex v5 = new JobVertex("vertex5");
	
	v1.setParallelism(5);
	v2.setParallelism(7);
	v3.setParallelism(2);
	v4.setParallelism(11);
	v5.setParallelism(4);

	v1.setInvokableClass(AbstractInvokable.class);
	v2.setInvokableClass(AbstractInvokable.class);
	v3.setInvokableClass(AbstractInvokable.class);
	v4.setInvokableClass(AbstractInvokable.class);
	v5.setInvokableClass(AbstractInvokable.class);

	v2.connectNewDataSetAsInput(v1, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
	v4.connectNewDataSetAsInput(v2, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
	v4.connectNewDataSetAsInput(v3, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
	v5.connectNewDataSetAsInput(v4, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
	v5.connectNewDataSetAsInput(v3, DistributionPattern.ALL_TO_ALL, ResultPartitionType.PIPELINED);
	
	List<JobVertex> ordered = new ArrayList<JobVertex>(Arrays.asList(v1, v2, v3, v5, v4));

	ExecutionGraph eg = new ExecutionGraph(
		TestingUtils.defaultExecutor(),
		TestingUtils.defaultExecutor(),
		jobId, 
		jobName, 
		cfg,
		new SerializedValue<>(new ExecutionConfig()),
		AkkaUtils.getDefaultTimeout(),
		new NoRestartStrategy(),
		new TestingSlotProvider(ignored -> new CompletableFuture<>()));
	try {
		eg.attachJobGraph(ordered);
		fail("Attached wrong jobgraph");
	}
	catch (JobException e) {
		// expected
	}
}
 
Example 16
Source File: RetryingRegistrationTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testRetryConnectOnFailure() throws Exception {
	final String testId = "laissez les bon temps roulez";
	final UUID leaderId = UUID.randomUUID();

	ExecutorService executor = TestingUtils.defaultExecutor();
	TestRegistrationGateway testGateway = new TestRegistrationGateway(new TestRegistrationSuccess(testId));

	try {
		// RPC service that fails upon the first connection, but succeeds on the second
		RpcService rpc = mock(RpcService.class);
		when(rpc.connect(anyString(), any(Class.class))).thenReturn(
				FutureUtils.completedExceptionally(new Exception("test connect failure")),  // first connection attempt fails
				CompletableFuture.completedFuture(testGateway)                         // second connection attempt succeeds
		);
		when(rpc.getExecutor()).thenReturn(executor);
		when(rpc.scheduleRunnable(any(Runnable.class), anyLong(), any(TimeUnit.class))).thenAnswer(
			(InvocationOnMock invocation) -> {
				final Runnable runnable = invocation.getArgument(0);
				final long delay = invocation.getArgument(1);
				final TimeUnit timeUnit = invocation.getArgument(2);
				return TestingUtils.defaultScheduledExecutor().schedule(runnable, delay, timeUnit);
			});

		TestRetryingRegistration registration = new TestRetryingRegistration(rpc, "foobar address", leaderId);

		long start = System.currentTimeMillis();

		registration.startRegistration();

		Tuple2<TestRegistrationGateway, TestRegistrationSuccess> success =
			registration.getFuture().get(10L, TimeUnit.SECONDS);

		// measure the duration of the registration --> should be longer than the error delay
		long duration = System.currentTimeMillis() - start;

		assertTrue(
			"The registration should have failed the first time. Thus the duration should be longer than at least a single error delay.",
			duration > TestRetryingRegistration.DELAY_ON_ERROR);

		// validate correct invocation and result
		assertEquals(testId, success.f1.getCorrelationId());
		assertEquals(leaderId, testGateway.getInvocations().take().leaderId());
	}
	finally {
		testGateway.stop();
	}
}
 
Example 17
Source File: SubtaskExecutionAttemptAccumulatorsHandlerTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testHandleRequest() throws Exception {

	// Instance the handler.
	final RestHandlerConfiguration restHandlerConfiguration = RestHandlerConfiguration.fromConfiguration(new Configuration());

	final SubtaskExecutionAttemptAccumulatorsHandler handler = new SubtaskExecutionAttemptAccumulatorsHandler(
		() -> null,
		Time.milliseconds(100L),
		Collections.emptyMap(),
		SubtaskExecutionAttemptAccumulatorsHeaders.getInstance(),
		new ExecutionGraphCache(
			restHandlerConfiguration.getTimeout(),
			Time.milliseconds(restHandlerConfiguration.getRefreshInterval())),
		TestingUtils.defaultExecutor());

	// Instance a empty request.
	final HandlerRequest<EmptyRequestBody, SubtaskAttemptMessageParameters> request = new HandlerRequest<>(
		EmptyRequestBody.getInstance(),
		new SubtaskAttemptMessageParameters()
	);

	final Map<String, OptionalFailure<Accumulator<?, ?>>> userAccumulators = new HashMap<>(3);
	userAccumulators.put("IntCounter", OptionalFailure.of(new IntCounter(10)));
	userAccumulators.put("LongCounter", OptionalFailure.of(new LongCounter(100L)));
	userAccumulators.put("Failure", OptionalFailure.ofFailure(new FlinkRuntimeException("Test")));

	// Instance the expected result.
	final StringifiedAccumulatorResult[] accumulatorResults =
		StringifiedAccumulatorResult.stringifyAccumulatorResults(userAccumulators);

	final int attemptNum = 1;
	final int subtaskIndex = 2;

	// Instance the tested execution.
	final ArchivedExecution execution = new ArchivedExecution(
		accumulatorResults,
		null,
		new ExecutionAttemptID(),
		attemptNum,
		ExecutionState.FINISHED,
		null,
		null,
		null,
		subtaskIndex,
		new long[ExecutionState.values().length]);

	// Invoke tested method.
	final SubtaskExecutionAttemptAccumulatorsInfo accumulatorsInfo = handler.handleRequest(request, execution);

	final ArrayList<UserAccumulator> userAccumulatorList = new ArrayList<>(userAccumulators.size());
	for (StringifiedAccumulatorResult accumulatorResult : accumulatorResults) {
		userAccumulatorList.add(
			new UserAccumulator(
				accumulatorResult.getName(),
				accumulatorResult.getType(),
				accumulatorResult.getValue()));
	}

	final SubtaskExecutionAttemptAccumulatorsInfo expected = new SubtaskExecutionAttemptAccumulatorsInfo(
		subtaskIndex,
		attemptNum,
		execution.getAttemptId().toString(),
		userAccumulatorList);

	// Verify.
	assertEquals(expected, accumulatorsInfo);
}
 
Example 18
Source File: FailoverRegionTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that if a task reports the result of its preceding task is failed,
 * its preceding task will be considered as failed, and start to failover
 * TODO: as the report part is not finished yet, this case is ignored temporarily
 * @throws Exception
 */
@Ignore
@Test
public void testSucceedingNoticePreceding() throws Exception {
	final JobID jobId = new JobID();
	final String jobName = "Test Job Sample Name";

	final SimpleSlotProvider slotProvider = new SimpleSlotProvider(jobId, 14);

	JobVertex v1 = new JobVertex("vertex1");
	JobVertex v2 = new JobVertex("vertex2");

	v1.setParallelism(1);
	v2.setParallelism(1);

	v1.setInvokableClass(AbstractInvokable.class);
	v2.setInvokableClass(AbstractInvokable.class);

	v2.connectNewDataSetAsInput(v1, DistributionPattern.ALL_TO_ALL, ResultPartitionType.BLOCKING);

	List<JobVertex> ordered = new ArrayList<>(Arrays.asList(v1, v2));

	ExecutionGraph eg = new ExecutionGraph(
		new DummyJobInformation(
			jobId,
			jobName),
		TestingUtils.defaultExecutor(),
		TestingUtils.defaultExecutor(),
		AkkaUtils.getDefaultTimeout(),
		new InfiniteDelayRestartStrategy(10),
		new FailoverPipelinedRegionWithDirectExecutor(),
		slotProvider);
	try {
		eg.attachJobGraph(ordered);
	}
	catch (JobException e) {
		e.printStackTrace();
		fail("Job failed with exception: " + e.getMessage());
	}
	eg.setScheduleMode(ScheduleMode.EAGER);
	eg.scheduleForExecution();
	RestartPipelinedRegionStrategy strategy = (RestartPipelinedRegionStrategy)eg.getFailoverStrategy();

	ExecutionVertex ev11 = eg.getJobVertex(v2.getID()).getTaskVertices()[0];
	ExecutionVertex ev21 = eg.getJobVertex(v2.getID()).getTaskVertices()[0];
	ev21.getCurrentExecutionAttempt().fail(new Exception("Fail with v1"));

	assertEquals(JobStatus.CANCELLING, strategy.getFailoverRegion(ev21).getState());
	assertEquals(JobStatus.CANCELLING, strategy.getFailoverRegion(ev11).getState());
}
 
Example 19
Source File: VertexSlotSharingTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testAssignSlotSharingGroup() {
	try {
		JobVertex v1 = new JobVertex("v1");
		JobVertex v2 = new JobVertex("v2");
		JobVertex v3 = new JobVertex("v3");
		JobVertex v4 = new JobVertex("v4");
		JobVertex v5 = new JobVertex("v5");
		
		v1.setParallelism(4);
		v2.setParallelism(5);
		v3.setParallelism(7);
		v4.setParallelism(1);
		v5.setParallelism(11);

		v1.setInvokableClass(AbstractInvokable.class);
		v2.setInvokableClass(AbstractInvokable.class);
		v3.setInvokableClass(AbstractInvokable.class);
		v4.setInvokableClass(AbstractInvokable.class);
		v5.setInvokableClass(AbstractInvokable.class);

		v2.connectNewDataSetAsInput(v1, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
		v5.connectNewDataSetAsInput(v4, DistributionPattern.POINTWISE, ResultPartitionType.PIPELINED);
		
		SlotSharingGroup jg1 = new SlotSharingGroup();
		v2.setSlotSharingGroup(jg1);
		v3.setSlotSharingGroup(jg1);
		
		SlotSharingGroup jg2 = new SlotSharingGroup();
		v4.setSlotSharingGroup(jg2);
		v5.setSlotSharingGroup(jg2);
		
		List<JobVertex> vertices = new ArrayList<JobVertex>(Arrays.asList(v1, v2, v3, v4, v5));
		
		ExecutionGraph eg = new ExecutionGraph(
			TestingUtils.defaultExecutor(),
			TestingUtils.defaultExecutor(),
			new JobID(),
			"test job",
			new Configuration(),
			new SerializedValue<>(new ExecutionConfig()),
			AkkaUtils.getDefaultTimeout(),
			new NoRestartStrategy(),
			new TestingSlotProvider(ignored -> new CompletableFuture<>()));
		eg.attachJobGraph(vertices);
		
		// verify that the vertices are all in the same slot sharing group
		SlotSharingGroup group1 = null;
		SlotSharingGroup group2 = null;
		
		// verify that v1 tasks have no slot sharing group
		assertNull(eg.getJobVertex(v1.getID()).getSlotSharingGroup());
		
		// v2 and v3 are shared
		group1 = eg.getJobVertex(v2.getID()).getSlotSharingGroup();
		assertNotNull(group1);
		assertEquals(group1, eg.getJobVertex(v3.getID()).getSlotSharingGroup());
		
		assertEquals(2, group1.getJobVertexIds().size());
		assertTrue(group1.getJobVertexIds().contains(v2.getID()));
		assertTrue(group1.getJobVertexIds().contains(v3.getID()));
		
		// v4 and v5 are shared
		group2 = eg.getJobVertex(v4.getID()).getSlotSharingGroup();
		assertNotNull(group2);
		assertEquals(group2, eg.getJobVertex(v5.getID()).getSlotSharingGroup());
		
		assertEquals(2, group1.getJobVertexIds().size());
		assertTrue(group2.getJobVertexIds().contains(v4.getID()));
		assertTrue(group2.getJobVertexIds().contains(v5.getID()));
	}
	catch (Exception e) {
		e.printStackTrace();
		fail(e.getMessage());
	}
}
 
Example 20
Source File: JarSubmissionITCase.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
JarHandlers(final Path jarDir, final TestingDispatcherGateway restfulGateway) {
	final GatewayRetriever<TestingDispatcherGateway> gatewayRetriever = () -> CompletableFuture.completedFuture(restfulGateway);
	final Time timeout = Time.seconds(10);
	final Map<String, String> responseHeaders = Collections.emptyMap();
	final Executor executor = TestingUtils.defaultExecutor();

	uploadHandler = new JarUploadHandler(
		gatewayRetriever,
		timeout,
		responseHeaders,
		JarUploadHeaders.getInstance(),
		jarDir,
		executor);

	listHandler = new JarListHandler(
		gatewayRetriever,
		timeout,
		responseHeaders,
		JarListHeaders.getInstance(),
		CompletableFuture.completedFuture("shazam://localhost:12345"),
		jarDir.toFile(),
		executor);

	planHandler = new JarPlanHandler(
		gatewayRetriever,
		timeout,
		responseHeaders,
		JarPlanHeaders.getInstance(),
		jarDir,
		new Configuration(),
		executor);

	runHandler = new JarRunHandler(
		gatewayRetriever,
		timeout,
		responseHeaders,
		JarRunHeaders.getInstance(),
		jarDir,
		new Configuration(),
		executor);

	deleteHandler = new JarDeleteHandler(
		gatewayRetriever,
		timeout,
		responseHeaders,
		JarDeleteHeaders.getInstance(),
		jarDir,
		executor);
}