Java Code Examples for org.apache.flink.runtime.operators.testutils.InfiniteInputIterator

The following examples show how to use org.apache.flink.runtime.operators.testutils.InfiniteInputIterator. These examples are extracted from open source projects. 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 Project: Flink-CEPplus   Source File: DataSinkTaskTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testCancelDataSinkTask() throws Exception {
	super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
	super.addInput(new InfiniteInputIterator(), 0);

	final DataSinkTask<Record> testTask = new DataSinkTask<>(this.mockEnv);
	Configuration stubParams = new Configuration();
	super.getTaskConfig().setStubParameters(stubParams);

	File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());

	super.registerFileOutputTask(MockOutputFormat.class, tempTestFile.toURI().toString());

	Thread taskRunner = new Thread() {
		@Override
		public void run() {
			try {
				testTask.invoke();
			} catch (Exception ie) {
				ie.printStackTrace();
				Assert.fail("Task threw exception although it was properly canceled");
			}
		}
	};
	taskRunner.start();
	
	// wait until the task created the file
	long deadline = System.currentTimeMillis() + 60000;
	while (!tempTestFile.exists() && System.currentTimeMillis() < deadline) {
		Thread.sleep(10);
	}
	assertTrue("Task did not create file within 60 seconds", tempTestFile.exists());
	
	// cancel the task
	Thread.sleep(500);
	testTask.cancel();
	taskRunner.interrupt();
	
	// wait for the canceling to complete
	taskRunner.join();

	// assert that temp file was created
	assertFalse("Temp output file has not been removed", tempTestFile.exists());
}
 
Example 2
Source Project: flink   Source File: DataSinkTaskTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testCancelDataSinkTask() throws Exception {
	super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
	super.addInput(new InfiniteInputIterator(), 0);

	final DataSinkTask<Record> testTask = new DataSinkTask<>(this.mockEnv);
	Configuration stubParams = new Configuration();

	File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());

	super.registerFileOutputTask(MockOutputFormat.class, tempTestFile.toURI().toString(), stubParams);

	Thread taskRunner = new Thread() {
		@Override
		public void run() {
			try {
				testTask.invoke();
			} catch (Exception ie) {
				ie.printStackTrace();
				Assert.fail("Task threw exception although it was properly canceled");
			}
		}
	};
	taskRunner.start();
	
	// wait until the task created the file
	long deadline = System.currentTimeMillis() + 60000;
	while (!tempTestFile.exists() && System.currentTimeMillis() < deadline) {
		Thread.sleep(10);
	}
	assertTrue("Task did not create file within 60 seconds", tempTestFile.exists());
	
	// cancel the task
	Thread.sleep(500);
	testTask.cancel();
	taskRunner.interrupt();
	
	// wait for the canceling to complete
	taskRunner.join();

	// assert that temp file was created
	assertFalse("Temp output file has not been removed", tempTestFile.exists());
}
 
Example 3
Source Project: flink   Source File: DataSinkTaskTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testCancelDataSinkTask() throws Exception {
	super.initEnvironment(MEMORY_MANAGER_SIZE, NETWORK_BUFFER_SIZE);
	super.addInput(new InfiniteInputIterator(), 0);

	final DataSinkTask<Record> testTask = new DataSinkTask<>(this.mockEnv);
	Configuration stubParams = new Configuration();

	File tempTestFile = new File(tempFolder.getRoot(), UUID.randomUUID().toString());

	super.registerFileOutputTask(MockOutputFormat.class, tempTestFile.toURI().toString(), stubParams);

	Thread taskRunner = new Thread() {
		@Override
		public void run() {
			try {
				testTask.invoke();
			} catch (Exception ie) {
				ie.printStackTrace();
				Assert.fail("Task threw exception although it was properly canceled");
			}
		}
	};
	taskRunner.start();
	
	// wait until the task created the file
	long deadline = System.currentTimeMillis() + 60000;
	while (!tempTestFile.exists() && System.currentTimeMillis() < deadline) {
		Thread.sleep(10);
	}
	assertTrue("Task did not create file within 60 seconds", tempTestFile.exists());
	
	// cancel the task
	Thread.sleep(500);
	testTask.cancel();
	taskRunner.interrupt();
	
	// wait for the canceling to complete
	taskRunner.join();

	// assert that temp file was created
	assertFalse("Temp output file has not been removed", tempTestFile.exists());
}