21
21
import java .util .Collections ;
22
22
import java .util .List ;
23
23
import java .util .UUID ;
24
- import java .util .stream .Collectors ;
25
24
26
25
import io .milvus .client .MilvusServiceClient ;
27
26
import io .milvus .param .ConnectParam ;
28
27
import io .milvus .param .IndexType ;
29
28
import io .milvus .param .MetricType ;
30
29
import org .junit .jupiter .api .AfterAll ;
30
+ import org .junit .jupiter .api .BeforeAll ;
31
31
import org .junit .jupiter .params .ParameterizedTest ;
32
32
import org .junit .jupiter .params .provider .ValueSource ;
33
33
import org .testcontainers .containers .DockerComposeContainer ;
34
34
import org .testcontainers .containers .wait .strategy .Wait ;
35
- import org .testcontainers .junit .jupiter .Container ;
36
35
import org .testcontainers .junit .jupiter .Testcontainers ;
37
36
38
37
import org .springframework .ai .autoconfigure .openai .OpenAiAutoConfiguration ;
56
55
@ Testcontainers
57
56
public class MilvusVectorStoreIT {
58
57
59
- @ Container
60
- public static DockerComposeContainer milvusContainer = new DockerComposeContainer (
61
- new File ("src/test/resources/docker-compose.yml" ))
62
- .withExposedService ("standalone" , 19530 )
63
- .withExposedService ("standalone" , 9091 ,
64
- Wait .forHttp ("/healthz" ).forPort (9091 ).forStatusCode (200 ).forStatusCode (401 ))
65
- .waitingFor ("standalone" ,
66
- Wait .forLogMessage (".*Proxy successfully started.*\\ s" , 1 ).withStartupTimeout (Duration .ofSeconds (100 )));
58
+ private static DockerComposeContainer milvusContainer ;
59
+
60
+ private static final File TEMP_FOLDER = new File ("target/test-" + UUID .randomUUID ().toString ());
67
61
68
62
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner ()
69
63
.withUserConfiguration (TestApplication .class )
@@ -77,9 +71,25 @@ public class MilvusVectorStoreIT {
77
71
"Great Depression Great Depression Great Depression Great Depression Great Depression Great Depression" ,
78
72
Collections .singletonMap ("meta2" , "meta2" )));
79
73
74
+ @ BeforeAll
75
+ public static void beforeAll () {
76
+ FileSystemUtils .deleteRecursively (TEMP_FOLDER );
77
+ TEMP_FOLDER .mkdirs ();
78
+
79
+ milvusContainer = new DockerComposeContainer (new File ("src/test/resources/docker-compose.yml" ))
80
+ .withEnv ("DOCKER_VOLUME_DIRECTORY" , TEMP_FOLDER .getAbsolutePath ())
81
+ .withExposedService ("standalone" , 19530 )
82
+ .withExposedService ("standalone" , 9091 ,
83
+ Wait .forHttp ("/healthz" ).forPort (9091 ).forStatusCode (200 ).forStatusCode (401 ))
84
+ .waitingFor ("standalone" , Wait .forLogMessage (".*Proxy successfully started.*\\ s" , 1 )
85
+ .withStartupTimeout (Duration .ofSeconds (100 )));
86
+ milvusContainer .start ();
87
+ }
88
+
80
89
@ AfterAll
81
90
public static void afterAll () {
82
- FileSystemUtils .deleteRecursively (new File ("src/test/resources/volumes" ));
91
+ milvusContainer .stop ();
92
+ FileSystemUtils .deleteRecursively (TEMP_FOLDER );
83
93
}
84
94
85
95
private void resetCollection (VectorStore vectorStore ) {
@@ -113,7 +123,7 @@ public void addAndSearchTest(String metricType) {
113
123
assertThat (resultDoc .getMetadata ()).containsKey ("distance" );
114
124
115
125
// Remove all documents from the store
116
- vectorStore .delete (documents .stream ().map (doc -> doc .getId ()).collect ( Collectors . toList () ));
126
+ vectorStore .delete (documents .stream ().map (doc -> doc .getId ()).toList ());
117
127
118
128
List <Document > results2 = vectorStore .similaritySearch ("Hello" , 1 );
119
129
assertThat (results2 ).hasSize (0 );
@@ -184,11 +194,11 @@ public void searchThresholdTest(String metricType) {
184
194
185
195
List <Float > distances = fullResult .stream ()
186
196
.map (doc -> (Float ) doc .getMetadata ().get ("distance" ))
187
- .collect ( Collectors . toList () );
197
+ .toList ();
188
198
189
199
assertThat (distances ).hasSize (3 );
190
200
191
- List <Document > results = vectorStore .similaritySearch ("Great" , 5 , (1 - (distances .get (0 ) + 0.01 )));
201
+ List <Document > results = vectorStore .similaritySearch ("Great" , 5 , (1 - (distances .get (0 ) + 0.001 )));
192
202
193
203
assertThat (results ).hasSize (1 );
194
204
Document resultDoc = results .get (0 );
0 commit comments