2b16d71d4e7bbe7cdb0f4c4ca5b9abf22e920c73
[policy/apex-pdp.git] / testsuites / integration / integration-uservice-test / src / test / java / org / onap / policy / apex / testsuites / integration / uservice / adapt / kafka / TestKafkaXmlEventProducer.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.testsuites.integration.uservice.adapt.kafka;
22
23 import java.util.Properties;
24
25 import org.apache.kafka.clients.producer.KafkaProducer;
26 import org.apache.kafka.clients.producer.Producer;
27 import org.apache.kafka.clients.producer.ProducerRecord;
28 import org.onap.policy.apex.plugins.event.protocol.xml.jaxb.XMLApexEvent;
29 import org.onap.policy.apex.plugins.event.protocol.xml.jaxb.XMLApexEventData;
30
31 /**
32  * The Class TestKafkaXmlEventProducer.
33  *
34  * @author Liam Fallon (liam.fallon@ericsson.com)
35  */
36 public class TestKafkaXmlEventProducer {
37
38     /**
39      * The main method.
40      *
41      * @param args the arguments
42      */
43     public static void main(final String[] args) {
44         final Properties props = new Properties();
45         props.put("bootstrap.servers", "localhost:49092");
46         props.put("acks", "all");
47         props.put("retries", 0);
48         props.put("batch.size", 16384);
49         props.put("linger.ms", 1);
50         props.put("buffer.memory", 33554432);
51         props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
52         props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
53
54         final XMLApexEvent xmlEvent = new XMLApexEvent();
55         xmlEvent.setName("XMLEvent-1");
56         xmlEvent.setVersion("0.0.1");
57         xmlEvent.getData().add(new XMLApexEventData("Data-1", "Data Value -1"));
58
59         final Producer<String, String> producer = new KafkaProducer<String, String>(props);
60         for (int i = 0; i < 100; i++) {
61             xmlEvent.setName("XMLEvent" + Integer.toString(i));
62             xmlEvent.setVersion("0.0.1");
63             xmlEvent.getData()
64                     .add(new XMLApexEventData("Data" + Integer.toString(i), "Data Value " + Integer.toString(i)));
65
66             producer.send(new ProducerRecord<String, String>("apex-in-0", xmlEvent.getName(), xmlEvent.toString()));
67         }
68         producer.close();
69     }
70 }