kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | f8044222657f4876f4f2a7a5359eb01e0bde79b95545ecb523e3384e54646615 |
|---|---|
| Author | blerer <benjamin.lerer@datastax.com> · 2015-05-19 10:58 +02:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-05-28 15:33 +02:00 |
| Parents | a8b456b7755f |
3 files changed
modified driver-core/src/main/java/com/datastax/driver/core/QueryTrace.java +1 −1
| @@ -232,7 +232,7 @@ | ||
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | if (tries > MAX_TRIES) |
| 235 | - throw new TraceRetrievalException(String.format("Unable to retrieve complete query trace after %d tries", MAX_TRIES)); | |
| 235 | + throw new TraceRetrievalException(String.format("Unable to retrieve complete query trace for id %s after %d tries", traceId, MAX_TRIES)); | |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
modified driver-core/src/main/java/com/datastax/driver/core/SessionManager.java +5 −3
| @@ -454,7 +454,11 @@ | ||
| 454 | 454 | if (serialConsistency == null) |
| 455 | 455 | serialConsistency = configuration().getQueryOptions().getSerialConsistencyLevel(); |
| 456 | 456 | |
| 457 | - return makeRequestMessage(statement, consistency, serialConsistency, pagingState); | |
| 457 | + Message.Request request = makeRequestMessage(statement, consistency, serialConsistency, pagingState); | |
| 458 | + if (statement.isTracing()) | |
| 459 | + request.setTracingRequested(); | |
| 460 | + | |
| 461 | + return request; | |
| 458 | 462 | } |
| 459 | 463 | |
| 460 | 464 | Message.Request makeRequestMessage(Statement statement, ConsistencyLevel cl, ConsistencyLevel scl, ByteBuffer pagingState) { |
| @@ -569,8 +573,6 @@ | ||
| 569 | 573 | } |
| 570 | 574 | |
| 571 | 575 | ResultSetFuture executeQuery(Message.Request msg, Statement statement) { |
| 572 | - if (statement.isTracing()) | |
| 573 | - msg.setTracingRequested(); | |
| 574 | 576 | |
| 575 | 577 | DefaultResultSetFuture future = new DefaultResultSetFuture(this, msg); |
| 576 | 578 | execute(future, statement); |
added driver-core/src/test/java/com/datastax/driver/core/TracingTest.java +73 −0
| @@ -0,0 +1,73 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2012-2015 DataStax Inc. | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | +package com.datastax.driver.core; | |
| 17 | + | |
| 18 | +import java.util.Collection; | |
| 19 | +import java.util.Collections; | |
| 20 | +import java.util.List; | |
| 21 | +import java.util.UUID; | |
| 22 | + | |
| 23 | +import com.datastax.driver.core.utils.CassandraVersion; | |
| 24 | +import org.testng.annotations.BeforeClass; | |
| 25 | +import org.testng.annotations.Test; | |
| 26 | + | |
| 27 | +import static org.assertj.core.api.Assertions.assertThat; | |
| 28 | + | |
| 29 | +@CassandraVersion(major=2.0) | |
| 30 | +public class TracingTest extends CCMBridge.PerClassSingleNodeCluster { | |
| 31 | + | |
| 32 | + public static final String KEY = "tracing_test"; | |
| 33 | + | |
| 34 | + @Override | |
| 35 | + protected Collection<String> getTableDefinitions() { | |
| 36 | + return Collections.singletonList("CREATE TABLE test (k text, v int, PRIMARY KEY (k, v))"); | |
| 37 | + } | |
| 38 | + | |
| 39 | + @BeforeClass(groups = "short") | |
| 40 | + public void initData() { | |
| 41 | + for (int i = 0; i < 100; i++) { | |
| 42 | + session.execute(String.format("INSERT INTO test (k, v) VALUES ('%s', %d)", KEY, i)); | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + /** | |
| 47 | + * Validates that for each page the {@link ExecutionInfo} will have a different tracing ID. | |
| 48 | + * | |
| 49 | + * @test_category tracing | |
| 50 | + * @expected_result {@link ResultSet} where all the {@link ExecutionInfo} will contains a different tracing ID and | |
| 51 | + * that the events can be retrieved for the last query. | |
| 52 | + */ | |
| 53 | + @Test(groups = "short") | |
| 54 | + public void should_have_a_different_tracingId_for_each_page() { | |
| 55 | + SimpleStatement st = new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)); | |
| 56 | + ResultSet result = session.execute(st.setFetchSize(40).enableTracing()); | |
| 57 | + result.all(); | |
| 58 | + | |
| 59 | + List<ExecutionInfo> executions = result.getAllExecutionInfo(); | |
| 60 | + | |
| 61 | + UUID previousTraceId = null; | |
| 62 | + for (ExecutionInfo executionInfo : executions) { | |
| 63 | + QueryTrace queryTrace = executionInfo.getQueryTrace(); | |
| 64 | + assertThat(queryTrace).isNotNull(); | |
| 65 | + assertThat(queryTrace.getTraceId()).isNotEqualTo(previousTraceId); | |
| 66 | + previousTraceId = queryTrace.getTraceId(); | |
| 67 | + } | |
| 68 | + | |
| 69 | + assertThat(result.getExecutionInfo().getQueryTrace().getEvents()).isNotNull() | |
| 70 | + .isNotEmpty(); | |
| 71 | + } | |
| 72 | +} | |
| 73 | + |