-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathContainer.java
More file actions
88 lines (71 loc) · 2.38 KB
/
Copy pathContainer.java
File metadata and controls
88 lines (71 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package io.weaviate.containers;
import java.util.Arrays;
import java.util.List;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.lifecycle.Startable;
import io.weaviate.client6.v1.api.WeaviateClient;
public class Container {
public static final Weaviate WEAVIATE = Weaviate.createDefault();
public static final Model2Vec MODEL2VEC = Model2Vec.createDefault();
public static final Img2VecNeural IMG2VEC_NEURAL = Img2VecNeural.createDefault();
public static final MinIo MINIO = MinIo.createDefault();
public static ContainerGroup compose(Weaviate weaviate, GenericContainer<?>... containers) {
return new ContainerGroup(weaviate, containers);
}
public static TestRule asTestRule(Startable container) {
return new PerTestSuite(container);
};
public static class ContainerGroup implements Startable {
private final Weaviate weaviate;
private final List<GenericContainer<?>> containers;
private ContainerGroup(Weaviate weaviate, GenericContainer<?>... containers) {
this.weaviate = weaviate;
this.containers = Arrays.asList(containers);
weaviate.dependsOn(containers);
setSharedNetwork();
}
public WeaviateClient getClient() {
return weaviate.getClient();
}
@Override
public void start() {
weaviate.start(); // testcontainers will resolve dependencies
}
@Override
public void stop() {
weaviate.stop();
containers.forEach(GenericContainer::stop);
}
private void setSharedNetwork() {
weaviate.setNetwork(Network.SHARED);
containers.forEach(c -> c.setNetwork(Network.SHARED));
}
public TestRule asTestRule() {
return new PerTestSuite(this);
};
}
public static class PerTestSuite implements TestRule {
private final Startable container;
public PerTestSuite(Startable container) {
this.container = container;
}
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
container.start();
base.evaluate();
} finally {
container.stop();
}
}
};
}
}
}