I am trying to deploy my code in gitlab.
It has a unit test class to test my Kafka producer.
It runs properly in local. But when I try to build it in gitlab it gets failed because of a test.
com.project.kafka.KafkaUtilTest > classMethod FAILED
org.I0Itec.zkclient.exception.ZkTimeoutException
But I don't have a test called classMethod anywhere in the test.
Why is this happening and how to resolve this?
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = TestApplication.class)
@ActiveProfiles("test")
@EmbeddedKafka
public class KafkaUtilTest {
private static String TOPIC = "PE";
@Autowired
KafkaUtil kafkaUtil;
@Autowired
ConfigurationProperties configProperties;
Request request;
Response response;
Consumer<String, Object> consumer;
HashMap<String, String> expectedHeaderValueMap;
@ClassRule
public static EmbeddedKafkaRule embeddedKafkarule = new EmbeddedKafkaRule(1, true, TOPIC);
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.setProperty("spring.kafka.producer.bootstrap-servers",
embeddedKafkarule.getEmbeddedKafka().getBrokersAsString());
}
@Before
public void init() {
readFile("0211");
expectedHeaderValueMap = getExpectedHeaderValueMap();
Map<String, Object> consumerConfigs = new HashMap<>(
KafkaTestUtils.consumerProps("consumer", "true", embeddedKafkarule.getEmbeddedKafka()));
consumerConfigs.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
consumerConfigs.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, JsonDeserializer.class);
consumer = new DefaultKafkaConsumerFactory<String, Object>(consumerConfigs).createConsumer();
List<String> topics = new ArrayList<>();
topics.add(TOPIC);
TopicPartition topicPartition1 = new TopicPartition(TOPIC, 0);
TopicPartition topicPartition2 = new TopicPartition(TOPIC, 1);
List<TopicPartition> topicPartitions = new ArrayList<TopicPartition>();
topicPartitions.add(topicPartition1);
topicPartitions.add(topicPartition2);
consumer.assign(topicPartitions);
consumer.seekToBeginning(topicPartitions);
}
@Test
public void testPublish() throws Exception {
kafkaUtil.publishToKafka(request, response);
kafkaUtil.kafkaTemplate.flush();
ConsumerRecord<String, Object> consumedRecord = KafkaTestUtils.getSingleRecord(consumer, TOPIC);
assertRecord(consumedRecord);
}
private void readFile(String testSequenceNo) {
ObjectMapper om = new ObjectMapper();
try {
request = om.readValue(
this.getClass().getClassLoader().getResourceAsStream(
"requests/request" + testSequenceNo + ".json"),
SchedulingCallRequestDTO.class);
} catch (IOException e) {
e.printStackTrace();
}
try {
response = om.readValue(this.getClass().getClassLoader().getResourceAsStream(
"responsesv2/response" + testSequenceNo + ".json"),
ScheduleOrderResponseDTOv2.class);
} catch (IOException e) {
e.printStackTrace();
}
}
}
This is my test.
I have removed the assertion part to reduce the size