|
22 | 22 | import com.couchbase.client.java.env.CouchbaseEnvironment; |
23 | 23 | import com.couchbase.client.java.env.DefaultCouchbaseEnvironment; |
24 | 24 | import com.couchbase.client.java.query.Index; |
| 25 | +import lombok.AllArgsConstructor; |
25 | 26 | import lombok.Getter; |
| 27 | +import lombok.experimental.Wither; |
26 | 28 | import org.testcontainers.containers.GenericContainer; |
27 | 29 | import org.testcontainers.containers.wait.HttpWaitStrategy; |
28 | 30 |
|
|
40 | 42 | * <p> |
41 | 43 | * Optimized by ctayeb |
42 | 44 | */ |
| 45 | +@AllArgsConstructor |
43 | 46 | public class CouchbaseContainer<SELF extends CouchbaseContainer<SELF>> extends GenericContainer<SELF> { |
44 | 47 |
|
| 48 | + @Wither |
45 | 49 | private String memoryQuota = "300"; |
46 | 50 |
|
| 51 | + @Wither |
47 | 52 | private String indexMemoryQuota = "300"; |
48 | 53 |
|
| 54 | + @Wither |
49 | 55 | private String clusterUsername = "Administrator"; |
50 | 56 |
|
| 57 | + @Wither |
51 | 58 | private String clusterPassword = "password"; |
52 | 59 |
|
| 60 | + @Wither |
53 | 61 | private boolean keyValue = true; |
54 | 62 |
|
55 | 63 | @Getter |
| 64 | + @Wither |
56 | 65 | private boolean query = true; |
57 | 66 |
|
58 | 67 | @Getter |
| 68 | + @Wither |
59 | 69 | private boolean index = true; |
60 | 70 |
|
61 | 71 | @Getter |
| 72 | + @Wither |
62 | 73 | private boolean primaryIndex = true; |
63 | 74 |
|
64 | 75 | @Getter |
| 76 | + @Wither |
65 | 77 | private boolean fts = false; |
66 | 78 |
|
| 79 | + @Wither |
67 | 80 | private boolean beerSample = false; |
68 | 81 |
|
| 82 | + @Wither |
69 | 83 | private boolean travelSample = false; |
70 | 84 |
|
| 85 | + @Wither |
71 | 86 | private boolean gamesIMSample = false; |
72 | 87 |
|
73 | | - private CouchbaseEnvironment couchbaseEnvironment; |
| 88 | + @Getter(lazy = true) |
| 89 | + private final CouchbaseEnvironment couchbaseEnvironment = createCouchbaseEnvironment(); |
74 | 90 |
|
75 | | - private CouchbaseCluster couchbaseCluster; |
| 91 | + @Getter(lazy = true) |
| 92 | + private final CouchbaseCluster couchbaseCluster = createCouchbaseCluster(); |
76 | 93 |
|
77 | 94 | private List<BucketSettings> newBuckets = new ArrayList<>(); |
78 | 95 |
|
@@ -106,92 +123,11 @@ protected void configure() { |
106 | 123 | setWaitStrategy(new HttpWaitStrategy().forPath("/ui/index.html#/")); |
107 | 124 | } |
108 | 125 |
|
109 | | - public CouchbaseEnvironment getCouchbaseEnvironment() { |
110 | | - if (couchbaseEnvironment == null) { |
111 | | - initCluster(); |
112 | | - couchbaseEnvironment = DefaultCouchbaseEnvironment.builder() |
113 | | - .bootstrapCarrierDirectPort(getMappedPort(11210)) |
114 | | - .bootstrapCarrierSslPort(getMappedPort(11207)) |
115 | | - .bootstrapHttpDirectPort(getMappedPort(8091)) |
116 | | - .bootstrapHttpSslPort(getMappedPort(18091)) |
117 | | - .build(); |
118 | | - } |
119 | | - return couchbaseEnvironment; |
120 | | - } |
121 | | - |
122 | | - public CouchbaseCluster getCouchbaseCluster() { |
123 | | - if (couchbaseCluster == null) { |
124 | | - couchbaseCluster = CouchbaseCluster.create(getCouchbaseEnvironment(), getContainerIpAddress()); |
125 | | - } |
126 | | - return couchbaseCluster; |
127 | | - } |
128 | | - |
129 | | - public SELF withClusterUsername(String username) { |
130 | | - this.clusterUsername = username; |
131 | | - return self(); |
132 | | - } |
133 | | - |
134 | | - public SELF withClusterPassword(String password) { |
135 | | - this.clusterPassword = password; |
136 | | - return self(); |
137 | | - } |
138 | | - |
139 | | - public SELF withMemoryQuota(String memoryQuota) { |
140 | | - this.memoryQuota = memoryQuota; |
141 | | - return self(); |
142 | | - } |
143 | | - |
144 | | - public SELF withIndexMemoryQuota(String indexMemoryQuota) { |
145 | | - this.indexMemoryQuota = indexMemoryQuota; |
146 | | - return self(); |
147 | | - } |
148 | | - |
149 | | - public SELF withKeyValue(boolean withKV) { |
150 | | - this.keyValue = withKV; |
151 | | - return self(); |
152 | | - } |
153 | | - |
154 | | - public SELF withIndex(boolean withIndex) { |
155 | | - this.index = withIndex; |
156 | | - return self(); |
157 | | - } |
158 | | - |
159 | | - public SELF withPrimaryIndex(boolean primaryIndex) { |
160 | | - this.primaryIndex = primaryIndex; |
161 | | - return self(); |
162 | | - } |
163 | | - |
164 | | - public SELF withQuery(boolean withQuery) { |
165 | | - this.query = withQuery; |
166 | | - return self(); |
167 | | - } |
168 | | - |
169 | | - public SELF withFTS(boolean withFTS) { |
170 | | - this.fts = withFTS; |
171 | | - return self(); |
172 | | - } |
173 | | - |
174 | | - public SELF withTravelSample() { |
175 | | - this.travelSample = true; |
176 | | - return self(); |
177 | | - } |
178 | | - |
179 | | - public SELF withBeerSample() { |
180 | | - this.beerSample = true; |
181 | | - return self(); |
182 | | - } |
183 | | - |
184 | | - public SELF withGamesIMSample() { |
185 | | - this.gamesIMSample = true; |
186 | | - return self(); |
187 | | - } |
188 | | - |
189 | 126 | public SELF withNewBucket(BucketSettings bucketSettings) { |
190 | 127 | newBuckets.add(bucketSettings); |
191 | 128 | return self(); |
192 | 129 | } |
193 | 130 |
|
194 | | - |
195 | 131 | public void initCluster() { |
196 | 132 | urlBase = String.format("http://%s:%s", getContainerIpAddress(), getMappedPort(8091)); |
197 | 133 | try { |
@@ -295,4 +231,17 @@ public void start() { |
295 | 231 | } |
296 | 232 | } |
297 | 233 |
|
| 234 | + private CouchbaseCluster createCouchbaseCluster() { |
| 235 | + return CouchbaseCluster.create(getCouchbaseEnvironment(), getContainerIpAddress()); |
| 236 | + } |
| 237 | + |
| 238 | + private DefaultCouchbaseEnvironment createCouchbaseEnvironment() { |
| 239 | + initCluster(); |
| 240 | + return DefaultCouchbaseEnvironment.builder() |
| 241 | + .bootstrapCarrierDirectPort(getMappedPort(11210)) |
| 242 | + .bootstrapCarrierSslPort(getMappedPort(11207)) |
| 243 | + .bootstrapHttpDirectPort(getMappedPort(8091)) |
| 244 | + .bootstrapHttpSslPort(getMappedPort(18091)) |
| 245 | + .build(); |
| 246 | + } |
298 | 247 | } |
0 commit comments