kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 5bfa14f71abf2a4967c3eb377e12a667c8f1d05b6e233236410e6108857586d5 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-10-20 12:03 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-10-20 12:21 +02:00 |
| Parents | d456ce00dbfc |
4 files changed
modified driver-core/CHANGELOG.rst +1 −0
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | ------ |
| 6 | 6 | |
| 7 | 7 | - [bug] Ignore static fields in mapper (JAVA-510) |
| 8 | +- [bug] Fix UDT parsing at init when using the default protocol version (JAVA-509) | |
| 8 | 9 | |
| 9 | 10 | Merged from 2.0 branch: |
| 10 | 11 |
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +0 −2
| @@ -1218,8 +1218,6 @@ | ||
| 1218 | 1218 | try { |
| 1219 | 1219 | try { |
| 1220 | 1220 | controlConnection.connect(); |
| 1221 | - if (connectionFactory.protocolVersion == null) | |
| 1222 | - connectionFactory.protocolVersion = ProtocolVersion.NEWEST_SUPPORTED; | |
| 1223 | 1221 | } catch (UnsupportedProtocolVersionException e) { |
| 1224 | 1222 | logger.debug("Cannot connect with protocol {}, trying {}", e.unsupportedVersion, e.serverVersion); |
| 1225 | 1223 |
modified driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java +4 −0
| @@ -233,6 +233,10 @@ | ||
| 233 | 233 | private Connection tryConnect(Host host, boolean isInitialConnection) throws ConnectionException, ExecutionException, InterruptedException, UnsupportedProtocolVersionException, ClusterNameMismatchException { |
| 234 | 234 | Connection connection = cluster.connectionFactory.open(host); |
| 235 | 235 | |
| 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 | + | |
| 236 | 240 | try { |
| 237 | 241 | logger.trace("[Control connection] Registering for events"); |
| 238 | 242 | List<ProtocolEvent.Type> evs = Arrays.asList( |
modified driver-core/src/test/java/com/datastax/driver/core/ControlConnectionTest.java +37 −1
| @@ -61,7 +61,43 @@ | ||
| 61 | 61 | assertThat(loadBalancingPolicy.counter.get()).isEqualTo(1); |
| 62 | 62 | } |
| 63 | 63 | |
| 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 { | |
| 65 | 101 | |
| 66 | 102 | final AtomicInteger counter = new AtomicInteger(); |
| 67 | 103 |