Best Testcontainers-java code snippet using org.testcontainers.couchbase.CouchbaseContainer.configureExternalPorts
Source:CouchbaseContainer.java
...216 timePhase("initializeIsEnterprise", this::initializeIsEnterprise);217 timePhase("renameNode", this::renameNode);218 timePhase("initializeServices", this::initializeServices);219 timePhase("configureAdminUser", this::configureAdminUser);220 timePhase("configureExternalPorts", this::configureExternalPorts);221 if (enabledServices.contains(CouchbaseService.INDEX)) {222 timePhase("configureIndexer", this::configureIndexer);223 }224 }225 @Override226 protected void containerIsStarted(InspectContainerResponse containerInfo) {227 timePhase("createBuckets", this::createBuckets);228 logger().info("Couchbase container is ready! UI available at http://{}:{}", getHost(), getMappedPort(MGMT_PORT));229 }230 /**231 * Before we can start configuring the host, we need to wait until the cluster manager is listening.232 */233 private void waitUntilNodeIsOnline() {234 new HttpWaitStrategy()235 .forPort(MGMT_PORT)236 .forPath("/pools")237 .forStatusCode(200)238 .waitUntilReady(this);239 }240 /**241 * Fetches edition (enterprise or community) of started container.242 */243 private void initializeIsEnterprise() {244 @Cleanup Response response = doHttpRequest(MGMT_PORT, "/pools", "GET", null, true);245 try {246 isEnterprise = MAPPER.readTree(response.body().string()).get("isEnterprise").asBoolean();247 } catch (IOException e) {248 throw new IllegalStateException("Couchbase /pools did not return valid JSON");249 }250 if (!isEnterprise && enabledServices.contains(CouchbaseService.ANALYTICS)) {251 throw new IllegalStateException("The Analytics Service is only supported with the Enterprise version");252 }253 }254 /**255 * Rebinds/renames the internal hostname.256 * <p>257 * To make sure the internal hostname is different from the external (alternate) address and the SDK can pick it258 * up automatically, we bind the internal hostname to the internal IP address.259 */260 private void renameNode() {261 logger().debug("Renaming Couchbase Node from localhost to {}", getHost());262 @Cleanup Response response = doHttpRequest(MGMT_PORT, "/node/controller/rename", "POST", new FormBody.Builder()263 .add("hostname", getInternalIpAddress())264 .build(), false265 );266 checkSuccessfulResponse(response, "Could not rename couchbase node");267 }268 /**269 * Initializes services based on the configured enabled services.270 */271 private void initializeServices() {272 logger().debug("Initializing couchbase services on host: {}", enabledServices);273 final String services = enabledServices274 .stream()275 .map(CouchbaseService::getIdentifier)276 .collect(Collectors.joining(","));277 @Cleanup Response response = doHttpRequest(MGMT_PORT, "/node/controller/setupServices", "POST", new FormBody.Builder()278 .add("services", services)279 .build(), false280 );281 checkSuccessfulResponse(response, "Could not enable couchbase services");282 }283 /**284 * Configures the admin user on the couchbase node.285 * <p>286 * After this stage, all subsequent API calls need to have the basic auth header set.287 */288 private void configureAdminUser() {289 logger().debug("Configuring couchbase admin user with username: \"{}\"", username);290 @Cleanup Response response = doHttpRequest(MGMT_PORT, "/settings/web", "POST", new FormBody.Builder()291 .add("username", username)292 .add("password", password)293 .add("port", Integer.toString(MGMT_PORT))294 .build(), false);295 checkSuccessfulResponse(response, "Could not configure couchbase admin user");296 }297 /**298 * Configures the external ports for SDK access.299 * <p>300 * Since the internal ports are not accessible from outside the container, this code configures the "external"301 * hostname and services to align with the mapped ports. The SDK will pick it up and then automatically connect302 * to those ports. Note that for all services non-ssl and ssl ports are configured.303 */304 private void configureExternalPorts() {305 logger().debug("Mapping external ports to the alternate address configuration");306 final FormBody.Builder builder = new FormBody.Builder();307 builder.add("hostname", getHost());308 builder.add("mgmt", Integer.toString(getMappedPort(MGMT_PORT)));309 builder.add("mgmtSSL", Integer.toString(getMappedPort(MGMT_SSL_PORT)));310 if (enabledServices.contains(CouchbaseService.KV)) {311 builder.add("kv", Integer.toString(getMappedPort(KV_PORT)));312 builder.add("kvSSL", Integer.toString(getMappedPort(KV_SSL_PORT)));313 builder.add("capi", Integer.toString(getMappedPort(VIEW_PORT)));314 builder.add("capiSSL", Integer.toString(getMappedPort(VIEW_SSL_PORT)));315 }316 if (enabledServices.contains(CouchbaseService.QUERY)) {317 builder.add("n1ql", Integer.toString(getMappedPort(QUERY_PORT)));318 builder.add("n1qlSSL", Integer.toString(getMappedPort(QUERY_SSL_PORT)));...
configureExternalPorts
Using AI Code Generation
1import org.testcontainers.couchbase.CouchbaseContainer2def couchbase = new CouchbaseContainer("couchbase:5.5.1")3couchbase.configureExternalPorts(8091, 8092, 8093, 8094, 11210, 11207, 11211, 18091, 18092, 18093, 18094, 18095, 18096)4couchbase.start()5import org.testcontainers.couchbase.CouchbaseContainer6def couchbase = new CouchbaseContainer("couchbase:5.5.1")7couchbase.configureExternalPorts(8091, 8092, 8093, 8094, 11210, 11207, 11211, 18091, 18092, 18093, 18094, 18095, 18096)8couchbase.start()9import org.testcontainers.couchbase.CouchbaseContainer10def couchbase = new CouchbaseContainer("couchbase:5.5.1")11couchbase.configureExternalPorts(8091, 8092, 8093, 8094, 11210, 11207, 11211, 18091, 18092, 18093, 18094, 18095, 18096)12couchbase.start()13import org.testcontainers.couchbase.CouchbaseContainer14def couchbase = new CouchbaseContainer("couchbase:5.5.1")15couchbase.configureExternalPorts(8091, 8092, 8093, 8094, 11210, 11207, 11211, 18091, 18092, 18093, 18094, 18095, 18096)16couchbase.start()17import org.testcontainers.couchbase.CouchbaseContainer18def couchbase = new CouchbaseContainer("couchbase:5.5.1")19couchbase.configureExternalPorts(
configureExternalPorts
Using AI Code Generation
1CouchbaseContainer couchbase = new CouchbaseContainer("couchbase/server:5.5.1")2 .withNewBucket(DefaultBucketSettings.builder()3 .enableFlush(true)4 .name("test")5 .password("test")6 .quota(100)7 .build())8 .withNewBucket(DefaultBucketSettings.builder()9 .enableFlush(true)10 .name("test2")11 .password("test2")12 .quota(100)13 .build());14couchbase.configureExternalPorts();15CouchbaseContainer couchbase = new CouchbaseContainer("couchbase/server:5.5.1")16 .withNewBucket(DefaultBucketSettings.builder()17 .enableFlush(true)18 .name("test")19 .password("test")20 .quota(100)21 .build())22 .withNewBucket(DefaultBucketSettings.builder()23 .enableFlush(true)24 .name("test2")25 .password("test2")26 .quota(100)27 .build());28couchbase.configureExternalPorts();29CouchbaseContainer#withNewBucket(BucketSettings)30CouchbaseContainer#configureExternalPorts()31CouchbaseContainer#getCouchbasePort()32CouchbaseContainer#getQueryPort()
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!