當前位置: 首頁>>代碼示例>>Java>>正文


Java StreamSink類代碼示例

本文整理匯總了Java中org.apache.flink.streaming.api.operators.StreamSink的典型用法代碼示例。如果您正苦於以下問題:Java StreamSink類的具體用法?Java StreamSink怎麽用?Java StreamSink使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StreamSink類屬於org.apache.flink.streaming.api.operators包,在下文中一共展示了StreamSink類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testThrowErrorOnSnapshot

import org.apache.flink.streaming.api.operators.StreamSink; //導入依賴的package包/類
@Test(timeout = 5000)
public void testThrowErrorOnSnapshot() throws Exception {
	TestCassandraSink casSinkFunc = new TestCassandraSink();

	OneInputStreamOperatorTestHarness<String, Object> testHarness =
		new OneInputStreamOperatorTestHarness<>(new StreamSink<>(casSinkFunc));

	testHarness.open();

	Exception cause = new RuntimeException();
	casSinkFunc.setResultFuture(ResultSetFutures.fromCompletableFuture(FutureUtils.getFailedFuture(cause)));

	casSinkFunc.invoke("hello");

	try {
		testHarness.snapshot(123L, 123L);

		Assert.fail();
	} catch (Exception e) {
		Assert.assertTrue(e.getCause() instanceof IOException);
		Assert.assertEquals(cause, e.getCause().getCause());
		Assert.assertEquals(0, casSinkFunc.getNumOfPendingRecords());
	}

	testHarness.close();
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:27,代碼來源:CassandraSinkBaseTest.java

示例2: createTestHarness

import org.apache.flink.streaming.api.operators.StreamSink; //導入依賴的package包/類
private OneInputStreamOperatorTestHarness<Integer, Object> createTestHarness(
	String topic,
	int maxParallelism,
	int parallelism,
	int subtaskIndex) throws Exception {
	Properties properties = createProperties();

	FlinkKafkaProducer011<Integer> kafkaProducer = new FlinkKafkaProducer011<>(
		topic,
		integerKeyedSerializationSchema,
		properties,
		FlinkKafkaProducer011.Semantic.EXACTLY_ONCE);

	return new OneInputStreamOperatorTestHarness<>(
		new StreamSink<>(kafkaProducer),
		maxParallelism,
		parallelism,
		subtaskIndex,
		IntSerializer.INSTANCE);
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:21,代碼來源:FlinkKafkaProducer011Tests.java

示例3: testDoesNotWaitForPendingRequestsIfFlushingDisabled

import org.apache.flink.streaming.api.operators.StreamSink; //導入依賴的package包/類
/**
 * This test is meant to assure that testAtLeastOnceSink is valid by testing that if flushing is disabled,
 * the snapshot method does indeed finishes without waiting for pending requests;
 * we set a timeout because the test will not finish if the logic is broken.
 */
@Test(timeout = 5000)
public void testDoesNotWaitForPendingRequestsIfFlushingDisabled() throws Exception {
	final DummyElasticsearchSink<String> sink = new DummyElasticsearchSink<>(
		new HashMap<String, String>(), new SimpleSinkFunction<String>(), new DummyRetryFailureHandler());
	sink.disableFlushOnCheckpoint(); // disable flushing

	final OneInputStreamOperatorTestHarness<String, Object> testHarness =
		new OneInputStreamOperatorTestHarness<>(new StreamSink<>(sink));

	testHarness.open();

	// setup the next bulk request, and let bulk request succeed
	sink.setMockItemFailuresListForNextBulkItemResponses(Collections.singletonList(new Exception("artificial failure for record")));
	testHarness.processElement(new StreamRecord<>("msg-1"));
	verify(sink.getMockBulkProcessor(), times(1)).add(any(ActionRequest.class));

	// the snapshot should not block even though we haven't flushed the bulk request
	testHarness.snapshot(1L, 1000L);

	testHarness.close();
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:27,代碼來源:ElasticsearchSinkBaseTest.java

示例4: testDoesNotWaitForPendingRecordsIfFlushingDisabled

import org.apache.flink.streaming.api.operators.StreamSink; //導入依賴的package包/類
/**
 * This test is meant to assure that testAtLeastOnceProducer is valid by testing that if flushing is disabled,
 * the snapshot method does indeed finishes without waiting for pending records;
 * we set a timeout because the test will not finish if the logic is broken.
 */
@SuppressWarnings("unchecked")
@Test(timeout = 5000)
public void testDoesNotWaitForPendingRecordsIfFlushingDisabled() throws Throwable {
	final DummyFlinkKafkaProducer<String> producer = new DummyFlinkKafkaProducer<>(
		FakeStandardProducerConfig.get(), new KeyedSerializationSchemaWrapper<>(new SimpleStringSchema()), null);
	producer.setFlushOnCheckpoint(false);

	final KafkaProducer<?, ?> mockProducer = producer.getMockKafkaProducer();

	final OneInputStreamOperatorTestHarness<String, Object> testHarness =
		new OneInputStreamOperatorTestHarness<>(new StreamSink<>(producer));

	testHarness.open();

	testHarness.processElement(new StreamRecord<>("msg"));

	// make sure that all callbacks have not been completed
	verify(mockProducer, times(1)).send(any(ProducerRecord.class), any(Callback.class));

	// should return even if there are pending records
	testHarness.snapshot(123L, 123L);

	testHarness.close();
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:30,代碼來源:FlinkKafkaProducerBaseTest.java

示例5: testAppendTableSink

import org.apache.flink.streaming.api.operators.StreamSink; //導入依賴的package包/類
@Test
public void testAppendTableSink() throws IOException {
	JDBCAppendTableSink sink = JDBCAppendTableSink.builder()
		.setDrivername("foo")
		.setDBUrl("bar")
		.setQuery("insert into %s (id) values (?)")
		.setParameterTypes(FIELD_TYPES)
		.build();

	StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

	DataStream<Row> ds = env.fromCollection(Collections.singleton(Row.of("foo")), ROW_TYPE);
	sink.emitDataStream(ds);

	Collection<Integer> sinkIds = env.getStreamGraph().getSinkIDs();
	assertEquals(1, sinkIds.size());
	int sinkId = sinkIds.iterator().next();

	StreamSink planSink = (StreamSink) env.getStreamGraph().getStreamNode(sinkId).getOperator();
	assertTrue(planSink.getUserFunction() instanceof JDBCSinkFunction);

	JDBCSinkFunction sinkFunction = (JDBCSinkFunction) planSink.getUserFunction();
	assertSame(sink.getOutputFormat(), sinkFunction.outputFormat);
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:25,代碼來源:JDBCAppendTableSinkTest.java

示例6: addSink

import org.apache.flink.streaming.api.operators.StreamSink; //導入依賴的package包/類
/**
 * Adds the given sink to this DataStream. Only streams with sinks added
 * will be executed once the {@link StreamExecutionEnvironment#execute()}
 * method is called.
 *
 * @param sinkFunction
 *            The object containing the sink's invoke function.
 * @return The closed DataStream.
 */
public DataStreamSink<T> addSink(SinkFunction<T> sinkFunction) {

	// read the output type of the input Transform to coax out errors about MissingTypeInfo
	transformation.getOutputType();

	// configure the type if needed
	if (sinkFunction instanceof InputTypeConfigurable) {
		((InputTypeConfigurable) sinkFunction).setInputType(getType(), getExecutionConfig());
	}

	StreamSink<T> sinkOperator = new StreamSink<>(clean(sinkFunction));

	DataStreamSink<T> sink = new DataStreamSink<>(this, sinkOperator);

	getExecutionEnvironment().addOperator(sink.getTransformation());
	return sink;
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:27,代碼來源:DataStream.java

示例7: getProducerSink

import org.apache.flink.streaming.api.operators.StreamSink; //導入依賴的package包/類
@Override
public <T> StreamSink<T> getProducerSink(
		String topic,
		KeyedSerializationSchema<T> serSchema,
		Properties props,
		FlinkKafkaPartitioner<T> partitioner) {
	FlinkKafkaProducer09<T> prod = new FlinkKafkaProducer09<>(topic, serSchema, props, partitioner);
	prod.setFlushOnCheckpoint(true);
	return new StreamSink<>(prod);
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:11,代碼來源:KafkaTestEnvironmentImpl.java

示例8: testWaitForPendingUpdatesOnSnapshot

import org.apache.flink.streaming.api.operators.StreamSink; //導入依賴的package包/類
@Test(timeout = 5000)
public void testWaitForPendingUpdatesOnSnapshot() throws Exception {
	TestCassandraSink casSinkFunc = new TestCassandraSink();

	OneInputStreamOperatorTestHarness<String, Object> testHarness =
		new OneInputStreamOperatorTestHarness<>(new StreamSink<>(casSinkFunc));

	testHarness.open();

	CompletableFuture<ResultSet> completableFuture = new CompletableFuture<>();
	ResultSetFuture resultSetFuture = ResultSetFutures.fromCompletableFuture(completableFuture);
	casSinkFunc.setResultFuture(resultSetFuture);

	casSinkFunc.invoke("hello");
	Assert.assertEquals(1, casSinkFunc.getNumOfPendingRecords());

	Thread t = new CheckedThread("Flink-CassandraSinkBaseTest") {
		@Override
		public void go() throws Exception {
			testHarness.snapshot(123L, 123L);
		}
	};
	t.start();
	while (t.getState() != Thread.State.WAITING) {
		Thread.sleep(5);
	}

	Assert.assertEquals(1, casSinkFunc.getNumOfPendingRecords());
	completableFuture.complete(null);
	Assert.assertEquals(0, casSinkFunc.getNumOfPendingRecords());

	testHarness.close();
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:34,代碼來源:CassandraSinkBaseTest.java

示例9: testWaitForPendingUpdatesOnClose

import org.apache.flink.streaming.api.operators.StreamSink; //導入依賴的package包/類
@Test(timeout = 5000)
public void testWaitForPendingUpdatesOnClose() throws Exception {
	TestCassandraSink casSinkFunc = new TestCassandraSink();

	OneInputStreamOperatorTestHarness<String, Object> testHarness =
		new OneInputStreamOperatorTestHarness<>(new StreamSink<>(casSinkFunc));

	testHarness.open();

	CompletableFuture<ResultSet> completableFuture = new CompletableFuture<>();
	ResultSetFuture resultSetFuture = ResultSetFutures.fromCompletableFuture(completableFuture);
	casSinkFunc.setResultFuture(resultSetFuture);

	casSinkFunc.invoke("hello");
	Assert.assertEquals(1, casSinkFunc.getNumOfPendingRecords());

	Thread t = new CheckedThread("Flink-CassandraSinkBaseTest") {
		@Override
		public void go() throws Exception {
			testHarness.close();
		}
	};
	t.start();
	while (t.getState() != Thread.State.WAITING) {
		Thread.sleep(5);
	}

	Assert.assertEquals(1, casSinkFunc.getNumOfPendingRecords());
	completableFuture.complete(null);
	Assert.assertEquals(0, casSinkFunc.getNumOfPendingRecords());
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:32,代碼來源:CassandraSinkBaseTest.java

示例10: getProducerSink

import org.apache.flink.streaming.api.operators.StreamSink; //導入依賴的package包/類
@Override
public <T> StreamSink<T> getProducerSink(
		String topic,
		KeyedSerializationSchema<T> serSchema,
		Properties props,
		FlinkKafkaPartitioner<T> partitioner) {
	FlinkKafkaProducer08<T> prod = new FlinkKafkaProducer08<>(
			topic,
			serSchema,
			props,
			partitioner);
	prod.setFlushOnCheckpoint(true);
	return new StreamSink<>(prod);
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:15,代碼來源:KafkaTestEnvironmentImpl.java

示例11: getProducerSink

import org.apache.flink.streaming.api.operators.StreamSink; //導入依賴的package包/類
@Override
public <T> StreamSink<T> getProducerSink(String topic, KeyedSerializationSchema<T> serSchema, Properties props, FlinkKafkaPartitioner<T> partitioner) {
	return new StreamSink<>(new FlinkKafkaProducer011<>(
		topic,
		serSchema,
		props,
		Optional.ofNullable(partitioner),
		producerSemantic,
		FlinkKafkaProducer011.DEFAULT_KAFKA_PRODUCERS_POOL_SIZE));
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:11,代碼來源:KafkaTestEnvironmentImpl.java

示例12: testItemFailureRethrownOnInvoke

import org.apache.flink.streaming.api.operators.StreamSink; //導入依賴的package包/類
/** Tests that any item failure in the listener callbacks is rethrown on an immediately following invoke call. */
@Test
public void testItemFailureRethrownOnInvoke() throws Throwable {
	final DummyElasticsearchSink<String> sink = new DummyElasticsearchSink<>(
		new HashMap<String, String>(), new SimpleSinkFunction<String>(), new NoOpFailureHandler());

	final OneInputStreamOperatorTestHarness<String, Object> testHarness =
		new OneInputStreamOperatorTestHarness<>(new StreamSink<>(sink));

	testHarness.open();

	// setup the next bulk request, and its mock item failures
	sink.setMockItemFailuresListForNextBulkItemResponses(Collections.singletonList(new Exception("artificial failure for record")));
	testHarness.processElement(new StreamRecord<>("msg"));
	verify(sink.getMockBulkProcessor(), times(1)).add(any(ActionRequest.class));

	// manually execute the next bulk request
	sink.manualBulkRequestWithAllPendingRequests();

	try {
		testHarness.processElement(new StreamRecord<>("next msg"));
	} catch (Exception e) {
		// the invoke should have failed with the failure
		Assert.assertTrue(e.getCause().getMessage().contains("artificial failure for record"));

		// test succeeded
		return;
	}

	Assert.fail();
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:32,代碼來源:ElasticsearchSinkBaseTest.java

示例13: testItemFailureRethrownOnCheckpoint

import org.apache.flink.streaming.api.operators.StreamSink; //導入依賴的package包/類
/** Tests that any item failure in the listener callbacks is rethrown on an immediately following checkpoint. */
@Test
public void testItemFailureRethrownOnCheckpoint() throws Throwable {
	final DummyElasticsearchSink<String> sink = new DummyElasticsearchSink<>(
		new HashMap<String, String>(), new SimpleSinkFunction<String>(), new NoOpFailureHandler());

	final OneInputStreamOperatorTestHarness<String, Object> testHarness =
		new OneInputStreamOperatorTestHarness<>(new StreamSink<>(sink));

	testHarness.open();

	// setup the next bulk request, and its mock item failures
	sink.setMockItemFailuresListForNextBulkItemResponses(Collections.singletonList(new Exception("artificial failure for record")));
	testHarness.processElement(new StreamRecord<>("msg"));
	verify(sink.getMockBulkProcessor(), times(1)).add(any(ActionRequest.class));

	// manually execute the next bulk request
	sink.manualBulkRequestWithAllPendingRequests();

	try {
		testHarness.snapshot(1L, 1000L);
	} catch (Exception e) {
		// the snapshot should have failed with the failure
		Assert.assertTrue(e.getCause().getCause().getMessage().contains("artificial failure for record"));

		// test succeeded
		return;
	}

	Assert.fail();
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:32,代碼來源:ElasticsearchSinkBaseTest.java

示例14: testBulkFailureRethrownOnInvoke

import org.apache.flink.streaming.api.operators.StreamSink; //導入依賴的package包/類
/** Tests that any bulk failure in the listener callbacks is rethrown on an immediately following invoke call. */
@Test
public void testBulkFailureRethrownOnInvoke() throws Throwable {
	final DummyElasticsearchSink<String> sink = new DummyElasticsearchSink<>(
		new HashMap<String, String>(), new SimpleSinkFunction<String>(), new NoOpFailureHandler());

	final OneInputStreamOperatorTestHarness<String, Object> testHarness =
		new OneInputStreamOperatorTestHarness<>(new StreamSink<>(sink));

	testHarness.open();

	// setup the next bulk request, and let the whole bulk request fail
	sink.setFailNextBulkRequestCompletely(new Exception("artificial failure for bulk request"));
	testHarness.processElement(new StreamRecord<>("msg"));
	verify(sink.getMockBulkProcessor(), times(1)).add(any(ActionRequest.class));

	// manually execute the next bulk request
	sink.manualBulkRequestWithAllPendingRequests();

	try {
		testHarness.processElement(new StreamRecord<>("next msg"));
	} catch (Exception e) {
		// the invoke should have failed with the bulk request failure
		Assert.assertTrue(e.getCause().getMessage().contains("artificial failure for bulk request"));

		// test succeeded
		return;
	}

	Assert.fail();
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:32,代碼來源:ElasticsearchSinkBaseTest.java

示例15: testBulkFailureRethrownOnCheckpoint

import org.apache.flink.streaming.api.operators.StreamSink; //導入依賴的package包/類
/** Tests that any bulk failure in the listener callbacks is rethrown on an immediately following checkpoint. */
@Test
public void testBulkFailureRethrownOnCheckpoint() throws Throwable {
	final DummyElasticsearchSink<String> sink = new DummyElasticsearchSink<>(
		new HashMap<String, String>(), new SimpleSinkFunction<String>(), new NoOpFailureHandler());

	final OneInputStreamOperatorTestHarness<String, Object> testHarness =
		new OneInputStreamOperatorTestHarness<>(new StreamSink<>(sink));

	testHarness.open();

	// setup the next bulk request, and let the whole bulk request fail
	sink.setFailNextBulkRequestCompletely(new Exception("artificial failure for bulk request"));
	testHarness.processElement(new StreamRecord<>("msg"));
	verify(sink.getMockBulkProcessor(), times(1)).add(any(ActionRequest.class));

	// manually execute the next bulk request
	sink.manualBulkRequestWithAllPendingRequests();

	try {
		testHarness.snapshot(1L, 1000L);
	} catch (Exception e) {
		// the snapshot should have failed with the bulk request failure
		Assert.assertTrue(e.getCause().getCause().getMessage().contains("artificial failure for bulk request"));

		// test succeeded
		return;
	}

	Assert.fail();
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:32,代碼來源:ElasticsearchSinkBaseTest.java


注:本文中的org.apache.flink.streaming.api.operators.StreamSink類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。