How to use getInternalIpAddress method of org.testcontainers.couchbase.CouchbaseContainer class

Best Testcontainers-java code snippet using org.testcontainers.couchbase.CouchbaseContainer.getInternalIpAddress

Source:CouchbaseContainer.java Github

copy

Full Screen

...182 */183 private void renameNode() {184 logger().debug("Renaming Couchbase Node from localhost to {}", getContainerIpAddress());185 Response response = doHttpRequest(MGMT_PORT, "/node/controller/rename", "POST", new FormBody.Builder()186 .add("hostname", getInternalIpAddress())187 .build(), false188 );189 checkSuccessfulResponse(response, "Could not rename couchbase node");190 }191 /**192 * Initializes services based on the configured enabled services.193 */194 private void initializeServices() {195 logger().debug("Initializing couchbase services on host: {}", enabledServices);196 final String services = enabledServices.stream().map(s -> {197 switch (s) {198 case KV: return "kv";199 case QUERY: return "n1ql";200 case INDEX: return "index";201 case SEARCH: return "fts";202 default: throw new IllegalStateException("Unknown service!");203 }204 }).collect(Collectors.joining(","));205 Response response = doHttpRequest(MGMT_PORT, "/node/controller/setupServices", "POST", new FormBody.Builder()206 .add("services", services)207 .build(), false208 );209 checkSuccessfulResponse(response, "Could not enable couchbase services");210 }211 /**212 * Configures the admin user on the couchbase node.213 * <p>214 * After this stage, all subsequent API calls need to have the basic auth header set.215 */216 private void configureAdminUser() {217 logger().debug("Configuring couchbase admin user with username: \"{}\"", username);218 Response response = doHttpRequest(MGMT_PORT, "/settings/web", "POST", new FormBody.Builder()219 .add("username", username)220 .add("password", password)221 .add("port", Integer.toString(MGMT_PORT))222 .build(), false);223 checkSuccessfulResponse(response, "Could not configure couchbase admin user");224 }225 /**226 * Configures the external ports for SDK access.227 * <p>228 * Since the internal ports are not accessible from outside the container, this code configures the "external"229 * hostname and services to align with the mapped ports. The SDK will pick it up and then automatically connect230 * to those ports. Note that for all services non-ssl and ssl ports are configured.231 */232 private void configureExternalPorts() {233 logger().debug("Mapping external ports to the alternate address configuration");234 final FormBody.Builder builder = new FormBody.Builder();235 builder.add("hostname", getContainerIpAddress());236 builder.add("mgmt", Integer.toString(getMappedPort(MGMT_PORT)));237 builder.add("mgmtSSL", Integer.toString(getMappedPort(MGMT_SSL_PORT)));238 if (enabledServices.contains(CouchbaseService.KV)) {239 builder.add("kv", Integer.toString(getMappedPort(KV_PORT)));240 builder.add("kvSSL", Integer.toString(getMappedPort(KV_SSL_PORT)));241 builder.add("capi", Integer.toString(getMappedPort(VIEW_PORT)));242 builder.add("capiSSL", Integer.toString(getMappedPort(VIEW_SSL_PORT)));243 }244 if (enabledServices.contains(CouchbaseService.QUERY)) {245 builder.add("n1ql", Integer.toString(getMappedPort(QUERY_PORT)));246 builder.add("n1qlSSL", Integer.toString(getMappedPort(QUERY_SSL_PORT)));247 }248 if (enabledServices.contains(CouchbaseService.SEARCH)) {249 builder.add("fts", Integer.toString(getMappedPort(SEARCH_PORT)));250 builder.add("ftsSSL", Integer.toString(getMappedPort(SEARCH_SSL_PORT)));251 }252 final Response response = doHttpRequest(253 MGMT_PORT,254 "/node/controller/setupAlternateAddresses/external",255 "PUT",256 builder.build(),257 true258 );259 checkSuccessfulResponse(response, "Could not configure external ports");260 }261 /**262 * Configures the indexer service so that indexes can be created later on the bucket.263 */264 private void configureIndexer() {265 logger().debug("Configuring the indexer service");266 Response response = doHttpRequest(MGMT_PORT, "/settings/indexes", "POST", new FormBody.Builder()267 .add("storageMode", "memory_optimized")268 .build(), true269 );270 checkSuccessfulResponse(response, "Could not configure the indexing service");271 }272 /**273 * Based on the user-configured bucket definitions, creating buckets and corresponding indexes if needed.274 */275 private void createBuckets() {276 logger().debug("Creating " + buckets.size() + " buckets (and corresponding indexes).");277 for (BucketDefinition bucket : buckets) {278 logger().debug("Creating bucket \"" + bucket.getName() + "\"");279 Response response = doHttpRequest(MGMT_PORT, "/pools/default/buckets", "POST", new FormBody.Builder()280 .add("name", bucket.getName())281 .add("ramQuotaMB", Integer.toString(bucket.getQuota()))282 .build(), true);283 checkSuccessfulResponse(response, "Could not create bucket " + bucket.getName());284 new HttpWaitStrategy()285 .forPath("/pools/default/buckets/" + bucket.getName())286 .forPort(MGMT_PORT)287 .withBasicCredentials(username, password)288 .forStatusCode(200)289 .waitUntilReady(this);290 if (bucket.hasPrimaryIndex()) {291 if (enabledServices.contains(CouchbaseService.QUERY)) {292 Response queryResponse = doHttpRequest(QUERY_PORT, "/query/service", "POST", new FormBody.Builder()293 .add("statement", "CREATE PRIMARY INDEX on `" + bucket.getName() + "`")294 .build(), true);295 checkSuccessfulResponse(queryResponse, "Could not create primary index for bucket " + bucket.getName());296 } else {297 logger().info("Primary index creation for bucket " + bucket.getName() + " ignored, since QUERY service is not present.");298 }299 }300 }301 }302 /**303 * Helper method to extract the internal IP address based on the network configuration.304 */305 private String getInternalIpAddress() {306 return getContainerInfo().getNetworkSettings().getNetworks().values().stream()307 .findFirst()308 .map(ContainerNetwork::getIpAddress)309 .orElseThrow(() -> new IllegalStateException("No network available to extract the internal IP from!"));310 }311 /**312 * Helper method to check if the response is successful and release the body if needed.313 *314 * @param response the response to check.315 * @param message the message that should be part of the exception of not successful.316 */317 private void checkSuccessfulResponse(final Response response, final String message) {318 try {319 if (!response.isSuccessful()) {...

Full Screen

Full Screen

getInternalIpAddress

Using AI Code Generation

copy

Full Screen

1public CouchbaseContainer couchbase = new CouchbaseContainer()2 .withClusterAdmin("Administrator", "password")3 .withNewBucket(DefaultBucketSettings.builder()4 .enableFlush(true)5 .name("test")6 .quota(100)7 .type(BucketType.COUCHBASE)8 .build());9public void test() {10 String ipAddress = couchbase.getInternalIpAddress();11}12Example 2: Using the getMappedPort() method13public int getMappedPort(int originalPort)14import org.junit.Rule;15import org.junit.Test;16import org.testcontainers.couchbase.CouchbaseContainer;17public class CouchbaseContainerDemo {18 public CouchbaseContainer couchbase = new CouchbaseContainer()19 .withClusterAdmin("Administrator", "password")20 .withNewBucket(DefaultBucketSettings.builder()21 .enableFlush(true)22 .name("test")23 .quota(100)24 .type(BucketType.COUCHBASE)25 .build());26 public void test() {27 String ipAddress = couchbase.getInternalIpAddress();28 int mappedPort = couchbase.getMappedPort(8091);29 System.out.println("IP Address: " + ipAddress + "Mapped Port: " + mappedPort);30 }31}32Example 3: Using the getTestQueryString() method33public String getTestQueryString()34import org.junit.Rule;35import org.junit.Test;36import org.testcontainers.couchbase.CouchbaseContainer;37public class CouchbaseContainerDemo {38 public CouchbaseContainer couchbase = new CouchbaseContainer()39 .withClusterAdmin("Administrator", "password")40 .withNewBucket(DefaultBucketSettings.builder()41 .enableFlush(true)42 .name("test")43 .quota(100)44 .type(BucketType.COUCHBASE)45 .build());46 public void test() {

Full Screen

Full Screen

getInternalIpAddress

Using AI Code Generation

copy

Full Screen

1CouchbaseContainer container = new CouchbaseContainer("couchbase:6.0.1")2 .withNewBucket(DefaultBucketSettings.builder()3 .enableFlush(true)4 .name("test")5 .password("test")6 .quota(100)7 .build());8container.start();9String ipAddress = container.getInternalIpAddress();10System.out.println(ipAddress);11container.stop();

Full Screen

Full Screen

getInternalIpAddress

Using AI Code Generation

copy

Full Screen

1CouchbaseContainer couchbase = new CouchbaseContainer("couchbase:6.5.1")2 .withNewBucket(DefaultBucketSettings.builder()3 .enableFlush(true)4 .name("test")5 .quota(100)6 .build());7couchbase.start();8String ipAddress = couchbase.getInternalIpAddress();9couchbase.stop();

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful