4646@ AllArgsConstructor
4747public class CouchbaseContainer <SELF extends CouchbaseContainer <SELF >> extends GenericContainer <SELF > {
4848
49+ //<editor-fold desc="Ports">
50+ private static final int BINARY_PORT = 11210 ;
51+ private static final int BINARY_SSL_PORT = 11207 ;
52+ private static final int CONFIG_PORT = 8091 ;
53+ private static final int CONFIG_SSL_PORT = 18091 ;
54+ private static final int VIEW_PORT = 8092 ;
55+ private static final int VIEW_SSL_PORT = 18092 ;
56+ private static final int QUERY_PORT = 8093 ;
57+ private static final int QUERY_SSL_PORT = 18093 ;
58+ private static final int SEARCH_PORT = 8094 ;
59+ private static final int SEARCH_SSL_PORT = 18094 ;
60+ //</editor-fold>
61+
62+ @ Getter
63+ @ Wither
64+ private boolean ssl = false ;
65+
4966 @ Wither
5067 private String memoryQuota = "300" ;
5168
@@ -113,13 +130,29 @@ public CouchbaseContainer(String containerName) {
113130
114131 @ Override
115132 protected Integer getLivenessCheckPort () {
116- return getMappedPort (8091 );
133+ return getMappedPort (CONFIG_PORT );
117134 }
118135
119136 @ Override
120137 protected void configure () {
121138 // Configurable ports
122- addExposedPorts (8091 , 18091 , 8092 , 18092 , 8093 , 18093 , 8094 , 18094 , 8095 , 18095 , 11207 , 11210 , 11211 );
139+ if (isSsl ()) {
140+ addExposedPorts (CONFIG_SSL_PORT , VIEW_SSL_PORT , BINARY_SSL_PORT );
141+ } else {
142+ addExposedPorts (CONFIG_PORT , VIEW_PORT , BINARY_PORT );
143+ }
144+ if (isQuery ()) {
145+ addExposedPort (QUERY_PORT );
146+ if (isSsl ()) {
147+ addExposedPort (QUERY_SSL_PORT );
148+ }
149+ }
150+ if (isFts ()) {
151+ addExposedPort (SEARCH_PORT );
152+ if (isSsl ()) {
153+ addExposedPort (SEARCH_SSL_PORT );
154+ }
155+ }
123156 setWaitStrategy (new HttpWaitStrategy ().forPath ("/ui/index.html#/" ));
124157 }
125158
@@ -129,7 +162,7 @@ public SELF withNewBucket(BucketSettings bucketSettings) {
129162 }
130163
131164 public void initCluster () {
132- urlBase = String .format ("http://%s:%s" , getContainerIpAddress (), getMappedPort (8091 ));
165+ urlBase = String .format ("http://%s:%s" , getContainerIpAddress (), getMappedPort (CONFIG_PORT ));
133166 try {
134167 String poolURL = "/pools/default" ;
135168 String poolPayload = "memoryQuota=" + URLEncoder .encode (memoryQuota , "UTF-8" ) + "&indexMemoryQuota=" + URLEncoder .encode (indexMemoryQuota , "UTF-8" );
@@ -237,34 +270,45 @@ private CouchbaseCluster createCouchbaseCluster() {
237270
238271 private DefaultCouchbaseEnvironment createCouchbaseEnvironment () {
239272 initCluster ();
240- return DefaultCouchbaseEnvironment .builder ()
241- .bootstrapCarrierDirectPort (getMappedPort (11210 ))
242- .bootstrapCarrierSslPort (getMappedPort (11207 ))
243- .bootstrapHttpDirectPort (getMappedPort (8091 ))
244- .bootstrapHttpSslPort (getMappedPort (18091 ))
245- .build ();
273+ DefaultCouchbaseEnvironment .Builder builder = DefaultCouchbaseEnvironment .builder ()
274+ .sslEnabled (ssl );
275+ if (isSsl ()) {
276+ builder
277+ .bootstrapCarrierSslPort (getMappedPort (BINARY_SSL_PORT ))
278+ .bootstrapHttpSslPort (getMappedPort (CONFIG_SSL_PORT ));
279+ } else {
280+ builder
281+ .bootstrapCarrierDirectPort (getMappedPort (BINARY_PORT ))
282+ .bootstrapHttpDirectPort (getMappedPort (CONFIG_PORT ));
283+ }
284+ return builder .build ();
246285 }
247286
248287 private PortInfo createPortInfo () {
249288 DefaultPortInfo portInfo = new DefaultPortInfo (new HashMap <>(), null );
250289 try {
251- portInfo .ports ().put (ServiceType .VIEW , getMappedPort (8092 ));
252- portInfo .sslPorts ().put (ServiceType .VIEW , getMappedPort (18092 ));
253- portInfo .ports ().put (ServiceType .CONFIG , getMappedPort (8091 ));
254- portInfo .sslPorts ().put (ServiceType .CONFIG , getMappedPort (18091 ));
255- portInfo .ports ().put (ServiceType .BINARY , getMappedPort (11210 ));
256- portInfo .sslPorts ().put (ServiceType .BINARY , getMappedPort (11207 ));
290+ portInfo .ports ().put (ServiceType .VIEW , getMappedPort (VIEW_PORT ));
291+ portInfo .ports ().put (ServiceType .CONFIG , getMappedPort (CONFIG_PORT ));
292+ portInfo .ports ().put (ServiceType .BINARY , getMappedPort (BINARY_PORT ));
293+ if (isSsl ()) {
294+ portInfo .sslPorts ().put (ServiceType .BINARY , getMappedPort (BINARY_SSL_PORT ));
295+ portInfo .sslPorts ().put (ServiceType .CONFIG , getMappedPort (CONFIG_SSL_PORT ));
296+ portInfo .sslPorts ().put (ServiceType .VIEW , getMappedPort (VIEW_SSL_PORT ));
297+ }
257298 if (isQuery ()) {
258- portInfo .ports ().put (ServiceType .QUERY , getMappedPort (8093 ));
259- portInfo .sslPorts ().put (ServiceType .QUERY , getMappedPort (18093 ));
299+ portInfo .ports ().put (ServiceType .QUERY , getMappedPort (QUERY_PORT ));
300+ if (isSsl ()) {
301+ portInfo .sslPorts ().put (ServiceType .QUERY , getMappedPort (QUERY_SSL_PORT ));
302+ }
260303 }
261- if (isFts ()) {
262- portInfo .ports ().put (ServiceType .SEARCH , getMappedPort (8094 ));
263- portInfo .sslPorts ().put (ServiceType .SEARCH , getMappedPort (18094 ));
304+ if (isFts ()) {
305+ portInfo .ports ().put (ServiceType .SEARCH , getMappedPort (SEARCH_PORT ));
306+ if (isSsl ()) {
307+ portInfo .sslPorts ().put (ServiceType .SEARCH , getMappedPort (SEARCH_SSL_PORT ));
308+ }
264309 }
265-
266310 } catch (IllegalStateException e ) {
267- logger ().warn ("Container not started yet" );
311+ logger ().warn (e . getMessage () );
268312 }
269313 return portInfo ;
270314 }
0 commit comments