Skip to content

Commit 79afbbb

Browse files
committed
tmp, some prints, some waits in the test
1 parent 13ab845 commit 79afbbb

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

core/src/main/java/com/datastax/oss/driver/internal/core/channel/ChannelFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,14 @@ private void connect(
208208

209209
nettyOptions.afterBootstrapInitialized(bootstrap);
210210

211+
System.out.println("Calling booststrap connect for " + endPoint);
211212
ChannelFuture connectFuture = bootstrap.connect(RESOLVER.resolve(endPoint.resolve()));
212213

213214
connectFuture.addListener(
214215
cf -> {
215216
if (connectFuture.isSuccess()) {
216217
Channel channel = connectFuture.channel();
218+
System.out.println("new channel from connect future " + channel);
217219
DriverChannel driverChannel =
218220
new DriverChannel(endPoint, channel, context.getWriteCoalescer(), currentVersion);
219221
// If this is the first successful connection, remember the protocol version and

core/src/main/java/com/datastax/oss/driver/internal/core/control/ControlConnection.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ private void init(
336336

337337
private CompletionStage<Boolean> reconnect() {
338338
assert adminExecutor.inEventLoop();
339-
Queue<Node> nodes = context.getLoadBalancingPolicyWrapper().newQueryPlan();
339+
Queue<Node> nodes = context.getLoadBalancingPolicyWrapper().newControlConnectionQueryPlan();
340+
System.out.println("Running reconnect with newControlConnectionQueryPlan");
340341
CompletableFuture<Boolean> result = new CompletableFuture<>();
341342
connect(
342343
nodes,
@@ -356,6 +357,7 @@ private void connect(
356357
Consumer<Throwable> onFailure) {
357358
assert adminExecutor.inEventLoop();
358359
Node node = nodes.poll();
360+
System.out.println("Running connect() current node: " + (node == null ? "null" : node.toString()));
359361
if (node == null) {
360362
onFailure.accept(AllNodesFailedException.fromErrors(errors));
361363
} else {

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/LoadBalancingPolicyWrapper.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import edu.umd.cs.findbugs.annotations.NonNull;
3333
import edu.umd.cs.findbugs.annotations.Nullable;
3434
import java.util.ArrayList;
35+
import java.util.Arrays;
3536
import java.util.Collections;
3637
import java.util.HashMap;
3738
import java.util.List;
@@ -165,6 +166,19 @@ public Queue<Node> newQueryPlan() {
165166
return newQueryPlan(null, DriverExecutionProfile.DEFAULT_NAME, null);
166167
}
167168

169+
@NonNull
170+
public Queue<Node> newControlConnectionQueryPlan() {
171+
Queue<Node> regularQueryPlan = newQueryPlan();
172+
if (regularQueryPlan.isEmpty()) {
173+
List<Node> nodes = new ArrayList<>(context.getMetadataManager().getContactPoints());
174+
Collections.shuffle(nodes);
175+
System.out.println("Returning original contact points: " + Arrays.toString(nodes.toArray()));
176+
return new ConcurrentLinkedQueue<>(nodes);
177+
} else {
178+
return regularQueryPlan;
179+
}
180+
}
181+
168182
// when it comes in from the outside
169183
private void onNodeStateEvent(NodeStateEvent event) {
170184
eventFilter.accept(event);

integration-tests/src/test/java/com/datastax/oss/driver/core/resolver/MockResolverIT.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public void run_replace_test_20_times() {
253253
}
254254
}
255255

256-
@Test(expected = NoNodeAvailableException.class)
256+
@Test
257257
public void cannot_reconnect_with_resolved_socket() {
258258
DriverConfigLoader loader =
259259
new DefaultProgrammaticDriverConfigLoaderBuilder()
@@ -308,13 +308,23 @@ public void cannot_reconnect_with_resolved_socket() {
308308
assertThat(filteredNodes).hasSize(1);
309309
}
310310
int counter = 0;
311-
while (filteredNodes.size() == 1) {
312-
counter = (counter + 1) % 253 + 1;
311+
for(int xx = 0; xx < 100000; xx++){
312+
//while (filteredNodes.size() == 1) {
313+
counter = (counter + 1) % 253;
314+
if (counter == 0) counter++;
313315
LOG.warn(
314316
"Launching another cluster until we lose resolved socket from metadata (run {}).",
315317
counter);
316318
try (CcmBridge ccmBridge =
317319
CcmBridge.builder().withNodes(3).withIpPrefix("127.0."+counter+".").build()) {
320+
RESOLVER_FACTORY.updateResponse(
321+
"test.cluster.fake",
322+
new ValidResponse(
323+
new InetAddress[] {
324+
getNodeInetAddress(ccmBridge, 1),
325+
getNodeInetAddress(ccmBridge, 2),
326+
getNodeInetAddress(ccmBridge, 3)
327+
}));
318328
ccmBridge.create();
319329
ccmBridge.start();
320330
for (int i = 0; i < 15; i++) {
@@ -343,14 +353,21 @@ public void cannot_reconnect_with_resolved_socket() {
343353
nodes.stream()
344354
.filter(x -> x.toString().contains("test.cluster.fake"))
345355
.collect(Collectors.toSet());
356+
System.out.println("Filtered nodes size: " + filteredNodes.size());
346357
if (filteredNodes.size() > 1) {
347358
fail(
348359
"Somehow there is more than 1 node in metadata with unresolved hostname. This should not ever happen.");
349360
}
350361
if(filteredNodes.size() == 0) {
351362
System.out.println("pause");
352363
}
364+
try {
365+
Thread.sleep(1000 * 15);
366+
} catch (InterruptedException e) {
367+
throw new RuntimeException(e);
368+
}
353369
}
370+
354371
}
355372
Iterator<Node> iterator = nodes.iterator();
356373
while (iterator.hasNext()) {
@@ -381,6 +398,7 @@ public void cannot_reconnect_with_resolved_socket() {
381398
}
382399
}
383400
session.execute("SELECT * FROM system.local");
401+
384402
}
385403
session.close();
386404
}

0 commit comments

Comments
 (0)