Elffuss BraidHub

kikocis/java-driver public

Fix UDT parsing at init when using the default protocol version (JAVA-509).
Changeset5bfa14f71abf2a4967c3eb377e12a667c8f1d05b6e233236410e6108857586d5
Authorolim7t <omichallat+github@gmail.com> · 2014-10-20 12:03 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2014-10-20 12:21 +02:00
Parentsd456ce00dbfc

Browse the files at this changeset

4 files changed

modified driver-core/CHANGELOG.rst +1 −0
@@ -5,6 +5,7 @@
55 ------
66
77 - [bug] Ignore static fields in mapper (JAVA-510)
8+- [bug] Fix UDT parsing at init when using the default protocol version (JAVA-509)
89
910 Merged from 2.0 branch:
1011
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +0 −2
@@ -1218,8 +1218,6 @@
12181218 try {
12191219 try {
12201220 controlConnection.connect();
1221- if (connectionFactory.protocolVersion == null)
1222- connectionFactory.protocolVersion = ProtocolVersion.NEWEST_SUPPORTED;
12231221 } catch (UnsupportedProtocolVersionException e) {
12241222 logger.debug("Cannot connect with protocol {}, trying {}", e.unsupportedVersion, e.serverVersion);
12251223
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +4 −0
@@ -233,6 +233,10 @@
233233 private Connection tryConnect(Host host, boolean isInitialConnection) throws ConnectionException, ExecutionException, InterruptedException, UnsupportedProtocolVersionException, ClusterNameMismatchException {
234234 Connection connection = cluster.connectionFactory.open(host);
235235
236+ // If no protocol version was specified, set the default as soon as a connection succeeds (it's needed to parse UDTs in refreshSchema)
237+ if (cluster.connectionFactory.protocolVersion == null)
238+ cluster.connectionFactory.protocolVersion = ProtocolVersion.NEWEST_SUPPORTED;
239+
236240 try {
237241 logger.trace("[Control connection] Registering for events");
238242 List<ProtocolEvent.Type> evs = Arrays.asList(
modified driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +37 −1
@@ -61,7 +61,43 @@
6161 assertThat(loadBalancingPolicy.counter.get()).isEqualTo(1);
6262 }
6363
64- static class QueryPlanCountingPolicy extends DelegatingLoadBalancingPolicy {
64+ /**
65+ * Test for JAVA-509: UDT definitions were not properly parsed when using the default protocol version.
66+ *
67+ * This did not appear with other tests because the UDT needs to already exist when the driver initializes.
68+ * Therefore we use two different driver instances in this test.
69+ */
70+ @Test(groups = "short")
71+ public void should_parse_UDT_definitions_when_using_default_protocol_version() {
72+ TestUtils.versionCheck(2.1, 0, "This will only work with C* 2.1.0");
73+
74+ CCMBridge ccm = null;
75+ Cluster cluster = null;
76+
77+ try {
78+ ccm = CCMBridge.create("test", 1);
79+
80+ // First driver instance: create UDT
81+ cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build();
82+ Session session = cluster.connect();
83+ session.execute("create keyspace ks WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}");
84+ session.execute("create type ks.foo (i int)");
85+ cluster.close();
86+
87+ // Second driver instance: read UDT definition
88+ cluster = Cluster.builder().addContactPoint(CCMBridge.ipOfNode(1)).build();
89+ UserType fooType = cluster.getMetadata().getKeyspace("ks").getUserType("foo");
90+
91+ assertThat(fooType.getFieldNames()).containsExactly("i");
92+ } finally {
93+ if (cluster != null)
94+ cluster.close();
95+ if (ccm != null)
96+ ccm.remove();
97+ }
98+ }
99+
100+ static class QueryPlanCountingPolicy extends DelegatingLoadBalancingPolicy {
65101
66102 final AtomicInteger counter = new AtomicInteger();
67103