Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x: Add integration test for address resolution #323

Draft
wants to merge 1 commit into
base: scylla-4.x
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.datastax.oss.driver.core;

import static org.assertj.core.api.Assertions.assertThat;

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
import com.datastax.oss.driver.api.core.config.TypedDriverOption;
import com.datastax.oss.driver.api.core.metadata.Node;
import com.datastax.oss.driver.api.testinfra.ccm.CcmBridge;
import com.datastax.oss.driver.internal.core.config.typesafe.DefaultProgrammaticDriverConfigLoaderBuilder;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
import org.junit.Test;

public class ResolveAddressIT {

@Test
public void keep_contact_point_unresolved_after_restart_same_cluster() {
// These tests rely on localhost mapping to 127.0.0.1 by default
try (CcmBridge ccmBridge = CcmBridge.builder().withNodes(1).withIpPrefix("127.0.0.").build()) {
ccmBridge.create();
ccmBridge.start();
try (DriverConfigLoader loader =
new DefaultProgrammaticDriverConfigLoaderBuilder()
.withBoolean(TypedDriverOption.RESOLVE_CONTACT_POINTS.getRawOption(), false)
.withStringList(
TypedDriverOption.CONTACT_POINTS.getRawOption(),
Collections.singletonList("localhost:9042"))
.build();
CqlSession session = new CqlSessionBuilder().withConfigLoader(loader).build()) {

Collection<Node> nodes = session.getMetadata().getNodes().values();
Set<Node> filteredNodes;
filteredNodes =
nodes.stream()
.filter(x -> x.toString().contains("localhost/<unresolved>:9042"))
.collect(Collectors.toSet());
assertThat(filteredNodes).hasSize(1);

for (int reconnects = 0; reconnects < 3; reconnects++) {
ccmBridge.stop();
ccmBridge.start();

nodes = session.getMetadata().getNodes().values();
filteredNodes =
nodes.stream()
.filter(x -> x.toString().contains("localhost/<unresolved>:9042"))
.collect(Collectors.toSet());
assertThat(filteredNodes).hasSize(1);
}
}
}
}

@Test
public void keep_contact_point_unresolved_after_recreate_different_cluster() {
DriverConfigLoader loader =
new DefaultProgrammaticDriverConfigLoaderBuilder()
.withBoolean(TypedDriverOption.RESOLVE_CONTACT_POINTS.getRawOption(), false)
.withBoolean(TypedDriverOption.RECONNECT_ON_INIT.getRawOption(), true)
.withStringList(
TypedDriverOption.CONTACT_POINTS.getRawOption(),
Collections.singletonList("localhost:9042"))
.build();
CqlSessionBuilder builder = new CqlSessionBuilder().withConfigLoader(loader);
CqlSession session;
try (CcmBridge ccmBridge = CcmBridge.builder().withNodes(1).withIpPrefix("127.0.0.").build()) {
ccmBridge.create();
ccmBridge.start();
session = builder.build();
Collection<Node> nodes = session.getMetadata().getNodes().values();
Set<Node> filteredNodes;
filteredNodes =
nodes.stream()
.filter(x -> x.toString().contains("localhost/<unresolved>:9042"))
.collect(Collectors.toSet());
assertThat(filteredNodes).hasSize(1);
}
try (CcmBridge ccmBridge = CcmBridge.builder().withNodes(1).withIpPrefix("127.0.0.").build()) {
ccmBridge.create();
ccmBridge.start();

Collection<Node> nodes = session.getMetadata().getNodes().values();
Set<Node> filteredNodes;
filteredNodes =
nodes.stream()
.filter(x -> x.toString().contains("localhost/<unresolved>:9042"))
.collect(Collectors.toSet());
assertThat(filteredNodes).hasSize(1);
}
session.close();
}
}
Loading