testcontainers-spring-boot icon indicating copy to clipboard operation
testcontainers-spring-boot copied to clipboard

[Error] reuseContainer does not work for embedded-kafka

Open arturk9 opened this issue 2 years ago • 6 comments

Hello,

It seems like embedded-kafka keeps spawning new containers, even if reuseContainer flag is set to true. Please take a look at the code sample below:

https://github.com/arturk9/kafka-reuse-demo

Reproduction steps:

  1. run ./gradlew build multiple times in short interval
  2. reuse has no effect - new containers are spawned each time
screenshot

Would it be possible to add support for embedded-kafka containers reuse?

Thank you in advance :)

arturk9 avatar Feb 08 '23 11:02 arturk9

Hi @arturk9,

Could you try version 3.0.0-RC5 and give feedback if the problem is gone ?

Fameing avatar Apr 21 '23 16:04 Fameing

hello @Fameing

Once upgraded to 3.0.0-RC5, both containers mongo and kafka are not reused. I did some debugging, seems like the configuration is correct and "shouldBeReused" flag is set to true properly for both containers, but each execution still spawns new containers. After upgrading, not only new kafka container is created, but it seems like mongodb is no longer reusable.

Zrzut ekranu 2023-04-24 o 08 27 27

Zrzut ekranu 2023-04-24 o 08 27 12

The following condition is also evaluated as true: Zrzut ekranu 2023-04-24 o 08 32 09

Is there anything I am missing in the config?

arturk9 avatar Apr 24 '23 06:04 arturk9

Hi @arturk9 and @Fameing Faced the same problem with kafka. In my case I have configuration through the bootstrap.yaml file. Found out that reusing container is working as expected in case if we get rid of network for kafka. I just manually sets null to kafkaNetwork() bean through the debugger. But still I didn't found how to remove network property when I'm using bootstrap.yml configuration not static

image image

Chismur avatar Apr 24 '23 15:04 Chismur

Thank you, I also found a problem that using Network for a container generates a different hash. This problem is related to testcontainer-java.

Fameing avatar Apr 24 '23 17:04 Fameing

@Fameing Is it possible somehow to avoid network generation for Kafka through bootstrap config file? Or this is not possible for now?

Thanks in advance!

Chismur avatar Apr 25 '23 08:04 Chismur

@arturk9 @Fameing My suggestion as a temporary workaround is to override bean kafkaNetwork (set this bean to null) as described here https://stackoverflow.com/questions/68898220/spring-boot-boostrap-bean-override

Chismur avatar Apr 25 '23 13:04 Chismur