Search in sources :

Example 1 with LocalTransportAddress

use of org.elasticsearch.common.transport.LocalTransportAddress in project flink by apache.

the class ElasticsearchSinkITCase method testDeprecatedIndexRequestBuilderVariant.

/**
	 * Tests that behaviour of the deprecated {@link IndexRequestBuilder} constructor works properly.
	 */
@Test
public void testDeprecatedIndexRequestBuilderVariant() throws Exception {
    final String index = "index-req-builder-test-index";
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStreamSource<Tuple2<Integer, String>> source = env.addSource(new SourceSinkDataTestKit.TestDataSourceFunction());
    Map<String, String> userConfig = new HashMap<>();
    // This instructs the sink to emit after every element, otherwise they would be buffered
    userConfig.put(ElasticsearchSinkBase.CONFIG_KEY_BULK_FLUSH_MAX_ACTIONS, "1");
    userConfig.put("cluster.name", CLUSTER_NAME);
    userConfig.put("node.local", "true");
    List<TransportAddress> transports = Lists.newArrayList();
    transports.add(new LocalTransportAddress("1"));
    source.addSink(new ElasticsearchSink<>(userConfig, transports, new TestIndexRequestBuilder(index)));
    env.execute("Elasticsearch Deprecated IndexRequestBuilder Bridge Test");
    // verify the results
    Client client = embeddedNodeEnv.getClient();
    SourceSinkDataTestKit.verifyProducedSinkData(client, index);
    client.close();
}
Also used : LocalTransportAddress(org.elasticsearch.common.transport.LocalTransportAddress) HashMap(java.util.HashMap) TransportAddress(org.elasticsearch.common.transport.TransportAddress) LocalTransportAddress(org.elasticsearch.common.transport.LocalTransportAddress) Tuple2(org.apache.flink.api.java.tuple.Tuple2) SourceSinkDataTestKit(org.apache.flink.streaming.connectors.elasticsearch.testutils.SourceSinkDataTestKit) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Client(org.elasticsearch.client.Client) Test(org.junit.Test)

Example 2 with LocalTransportAddress

use of org.elasticsearch.common.transport.LocalTransportAddress in project flink by apache.

the class ElasticsearchSinkITCase method createElasticsearchSinkForEmbeddedNode.

@Override
protected <T> ElasticsearchSinkBase<T> createElasticsearchSinkForEmbeddedNode(Map<String, String> userConfig, ElasticsearchSinkFunction<T> elasticsearchSinkFunction) throws Exception {
    // Elasticsearch 1.x requires this setting when using
    // LocalTransportAddress to connect to a local embedded node
    userConfig.put("node.local", "true");
    List<TransportAddress> transports = Lists.newArrayList();
    transports.add(new LocalTransportAddress("1"));
    return new ElasticsearchSink<>(userConfig, transports, elasticsearchSinkFunction);
}
Also used : LocalTransportAddress(org.elasticsearch.common.transport.LocalTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) LocalTransportAddress(org.elasticsearch.common.transport.LocalTransportAddress)

Aggregations

LocalTransportAddress (org.elasticsearch.common.transport.LocalTransportAddress)2 TransportAddress (org.elasticsearch.common.transport.TransportAddress)2 HashMap (java.util.HashMap)1 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1 SourceSinkDataTestKit (org.apache.flink.streaming.connectors.elasticsearch.testutils.SourceSinkDataTestKit)1 Client (org.elasticsearch.client.Client)1 Test (org.junit.Test)1