-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TEST] MessageProducer · Consumer를 이용한 간단한 메시지 발행 및 소비에 대한 테스트 코드 작성
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/test/java/io/oeid/mogakgo/core/kafka/producer/SimpleKafkaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.oeid.mogakgo.core.kafka.producer; | ||
Check failure on line 1 in src/test/java/io/oeid/mogakgo/core/kafka/producer/SimpleKafkaTest.java GitHub Actions / JUnit Test ReportSimpleKafkaTest.name()
Raw output
|
||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.oeid.mogakgo.core.properties.kafka.MessageConsumer; | ||
import io.oeid.mogakgo.core.properties.kafka.MessageProducer; | ||
import io.oeid.mogakgo.domain.event.Event; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.kafka.test.context.EmbeddedKafka; | ||
|
||
@SpringBootTest | ||
@EmbeddedKafka(partitions = 3, | ||
brokerProperties = { | ||
"listeners=PLAINTEXT://localhost:9092" | ||
}, | ||
ports = { 9092 }) | ||
public class SimpleKafkaTest { | ||
|
||
@Autowired | ||
private MessageProducer messageProducer; | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@Autowired | ||
private MessageConsumer messageConsumer; | ||
|
||
@Test | ||
void name() throws Exception { | ||
// given | ||
Event event = Event.idOf(1L); | ||
String payload = objectMapper.writeValueAsString(event); | ||
|
||
// when | ||
messageProducer.sendMessage("my-topic", payload); | ||
Thread.sleep(2000); | ||
|
||
// then | ||
org.junit.jupiter.api.Assertions.assertNotEquals(0, messageConsumer.getEventRepo().size()); | ||
} | ||
} |