This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new fecb5da12d Fixes #9218. Fall back to the Weaviate mock backend when
the real API is not configured
fecb5da12d is described below
commit fecb5da12d0d38810fc6dce5cf5f71c42ba20fcd
Author: Jiří Ondrušek <[email protected]>
AuthorDate: Wed Sep 23 22:54:21 2026 +0200
Fixes #9218. Fall back to the Weaviate mock backend when the real API is
not configured
WeaviateTestResource threw an IllegalStateException when
CAMEL_QUARKUS_START_MOCK_BACKEND=false was set without WEAVIATE_API_KEY
and WEAVIATE_HOST. It now starts the Weaviate container in that case,
like the Kubernetes tests, and logs a warning so the fallback is not
silent. The real backend is used only when the mock backend is disabled
and both variables are set; setting the variables alone no longer
selects the real backend.
Co-authored-by: Claude Fable 5.1 <[email protected]>
---
integration-tests/weaviate/README.adoc | 5 ++-
.../weaviate/it/WeaviateTestResource.java | 51 ++++++++++++----------
2 files changed, 31 insertions(+), 25 deletions(-)
diff --git a/integration-tests/weaviate/README.adoc
b/integration-tests/weaviate/README.adoc
index 1d440f9c25..60a64408f4 100644
--- a/integration-tests/weaviate/README.adoc
+++ b/integration-tests/weaviate/README.adoc
@@ -2,10 +2,13 @@ The Weaviate integration tests use docker test container by
default.
To run the `camel-quarkus-weaviate` integration tests against the real API,
you must first create a Weaviate account and cluster (https://weaviate.io/).
-Set the following environment variables:
+Disable the mock backend and set the following environment variables:
[source,shell]
----
+export CAMEL_QUARKUS_START_MOCK_BACKEND=false
export WEAVIATE_API_KEY=#your-weaviate-apikey
export WEAVIATE_HOST=#your-weaviate-host
----
+
+If the mock backend is disabled but the Weaviate variables are missing, the
tests fall back to the docker test container.
diff --git
a/integration-tests/weaviate/src/test/java/org/apache/camel/quarkus/component/weaviate/it/WeaviateTestResource.java
b/integration-tests/weaviate/src/test/java/org/apache/camel/quarkus/component/weaviate/it/WeaviateTestResource.java
index cd37189b21..132c9c8a12 100644
---
a/integration-tests/weaviate/src/test/java/org/apache/camel/quarkus/component/weaviate/it/WeaviateTestResource.java
+++
b/integration-tests/weaviate/src/test/java/org/apache/camel/quarkus/component/weaviate/it/WeaviateTestResource.java
@@ -19,16 +19,18 @@ package org.apache.camel.quarkus.component.weaviate.it;
import java.time.Duration;
import java.util.Collections;
import java.util.Map;
-import java.util.Optional;
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
import org.apache.camel.quarkus.test.mock.backend.MockBackendUtils;
+import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
+import org.jboss.logging.Logger;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.weaviate.WeaviateContainer;
public class WeaviateTestResource implements
QuarkusTestResourceLifecycleManager {
+ private static final Logger LOG =
Logger.getLogger(WeaviateTestResource.class);
private static final int GRPC_PORT = 50051;
private static final DockerImageName WEAVIATE_IMAGE = DockerImageName
@@ -40,32 +42,22 @@ public class WeaviateTestResource implements
QuarkusTestResourceLifecycleManager
@Override
public Map<String, String> start() {
- Optional<String> apiKey =
ConfigProvider.getConfig().getOptionalValue(WeaviateResource.WEAVIATE_API_KEY_ENV,
- String.class);
- Optional<String> hostKey =
ConfigProvider.getConfig().getOptionalValue(WeaviateResource.WEAVIATE_HOST_ENV,
- String.class);
-
- final boolean startMockBackend =
MockBackendUtils.startMockBackend(false);
- final boolean realApiProvided = apiKey.isPresent() &&
hostKey.isPresent();
- final boolean usingMockBackend = startMockBackend && !realApiProvided;
-
- if (usingMockBackend) {
- MockBackendUtils.logMockBackendUsed();
- container.start();
-
- return Map.of(
- WeaviateResource.WEAVIATE_CONTAINER_ADDRESS,
container.getHttpHostAddress(),
- WeaviateResource.WEAVIATE_CONTAINER_GRPC_HOST,
container.getHost(),
- WeaviateResource.WEAVIATE_CONTAINER_GRPC_PORT,
String.valueOf(container.getMappedPort(GRPC_PORT)));
- } else if (!startMockBackend && !realApiProvided) {
- throw new IllegalStateException(
- "Set %s and %s env vars if you set
CAMEL_QUARKUS_START_MOCK_BACKEND=false"
- .formatted(WeaviateResource.WEAVIATE_API_KEY_ENV,
WeaviateResource.WEAVIATE_HOST_ENV));
- } else {
+ if (isRealBackendEnabled()) {
MockBackendUtils.logRealBackendUsed();
+ return Collections.emptyMap();
}
- return Collections.emptyMap();
+ if (!MockBackendUtils.startMockBackend()) {
+ LOG.warnf("Mock backend is disabled but %s and/or %s are not set,
falling back to the Weaviate container",
+ WeaviateResource.WEAVIATE_API_KEY_ENV,
WeaviateResource.WEAVIATE_HOST_ENV);
+ }
+ MockBackendUtils.logMockBackendUsed();
+ container.start();
+
+ return Map.of(
+ WeaviateResource.WEAVIATE_CONTAINER_ADDRESS,
container.getHttpHostAddress(),
+ WeaviateResource.WEAVIATE_CONTAINER_GRPC_HOST,
container.getHost(),
+ WeaviateResource.WEAVIATE_CONTAINER_GRPC_PORT,
String.valueOf(container.getMappedPort(GRPC_PORT)));
}
@Override
@@ -74,4 +66,15 @@ public class WeaviateTestResource implements
QuarkusTestResourceLifecycleManager
container.stop();
}
}
+
+ /**
+ * The real backend is used only when the mock backend is disabled and the
real API credentials are provided.
+ * Otherwise, the test falls back to the mock backend (container).
+ */
+ private static boolean isRealBackendEnabled() {
+ Config config = ConfigProvider.getConfig();
+ return !MockBackendUtils.startMockBackend()
+ &&
config.getOptionalValue(WeaviateResource.WEAVIATE_API_KEY_ENV,
String.class).isPresent()
+ && config.getOptionalValue(WeaviateResource.WEAVIATE_HOST_ENV,
String.class).isPresent();
+ }
}