Skip to content

Commit 6ca4156

Browse files
markpollackleijendary
authored andcommitted
Replace static initalization block in BaseOllamaIT
The static block was introducing side effects when doing scans of classpath for AOT and seems to have been the cause of a failing test. Updated github actions to use ~/.testcontainers.properties to enable container resuse Signed-off-by: leijendary <[email protected]>
1 parent 63daa5f commit 6ca4156

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ jobs:
2525
distribution: 'temurin'
2626
cache: 'maven'
2727

28+
- name: Configure Testcontainers
29+
run: |
30+
echo "testcontainers.reuse.enable=true" > $HOME/.testcontainers.properties
31+
2832
# - name: Cache Docker images.
2933
# uses: ScribeMD/[email protected]
3034
# with:

spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/ollama/BaseOllamaIT.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.ai.autoconfigure.ollama;
1818

19+
import org.junit.jupiter.api.AfterAll;
20+
import org.junit.jupiter.api.BeforeAll;
1921
import org.testcontainers.ollama.OllamaContainer;
2022

2123
import java.time.Duration;
@@ -27,11 +29,26 @@
2729

2830
public class BaseOllamaIT {
2931

30-
public static final OllamaContainer ollamaContainer;
32+
private static OllamaContainer ollamaContainer;
3133

3234
// Toggle for running tests locally on native Ollama for a faster feedback loop.
3335
private static final boolean useTestcontainers = true;
3436

37+
@BeforeAll
38+
public static void setUp() {
39+
if (useTestcontainers && !isDisabled()) {
40+
ollamaContainer = new OllamaContainer(OllamaImage.IMAGE).withReuse(true);
41+
ollamaContainer.start();
42+
}
43+
}
44+
45+
@AfterAll
46+
public static void tearDown() {
47+
if (ollamaContainer != null) {
48+
ollamaContainer.stop();
49+
}
50+
}
51+
3552
/**
3653
* Change the return value to false in order to run multiple Ollama IT tests locally
3754
* reusing the same container image.
@@ -61,9 +78,4 @@ public static String buildConnectionWithModel(String model) {
6178
return baseUrl;
6279
}
6380

64-
static {
65-
ollamaContainer = new OllamaContainer(OllamaImage.IMAGE).withReuse(true);
66-
ollamaContainer.start();
67-
}
68-
6981
}

0 commit comments

Comments
 (0)