2

I need to switch off the Cassandra database connectivity/health test at startup of the Quarkus application. The application starts successfully, only if it can reach the database. I need to switch it off only for tests, e.g. when I run tests with maven (mvn clean install). Is there a way to configure it in the application.properties or somewhere else?

Thanks in advance! :-)

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
F4k3d
  • 653
  • 1
  • 10
  • 29

3 Answers3

1

I don't believe it is possible to do that because it doesn't make sense to do so.

Part of the startup sequence of your application is to connect to the database. If it cannot connect to the DB, the app won't start. That's normal behaviour by design.

As a side note, I'm going to reach out to the devs who are contributors to the Cassandra-Quarkus extension and get them to reply directly to your post. Cheers!

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
1

You can use Quarkus profiles to change which Cassandra database your tests connect to. For example,

%prod.quarkus.cassandra.contact-points=my-cassandra:9042
%dev.quarkus.cassandra.contact-points=127.0.0.1:9042

That might get you part of the way. As Erick Ramirez says, completely disabling the Cassandra parts of the application will have some downsides in terms of test coverage (and test realism). For many Quarkus extensions, there are dev services which will automatically stand up an instance of the dependency when tests are run, and in dev mode. It doesn't look like that's been implemented for the Cassandra extension yet. As an alternative, you might be able to use the testcontainers Cassandra support. It's more work than having Quarkus dev services do it 'for free', but not impossible.

Holly Cummins
  • 10,767
  • 3
  • 23
  • 25
0

Sorry for the late answer. Are you using eager init? If so, you could try using lazy init instead:

quarkus.cassandra.init.eager-init=false

When lazy init is used, the Cassandra session bean won't be created until required by the application. Read more about this here.

adutra
  • 4,231
  • 1
  • 20
  • 18
  • Thanks. I tried it but it is not working. The quarkus application isn't starting, if the database isn't available. – F4k3d Jul 23 '22 at 16:16