kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | a8bc347c63dec7344c97e8a2618018a60ab2d55fdb6d8037b5c1d33b4b450672 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2016-05-10 12:00 -07:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-05-11 11:24 -07:00 |
| Parents | 174fb0a64d43 |
2 files changed
modified driver-core/src/main/java/com/datastax/driver/core/QueryLogger.java +3 −3
| @@ -614,6 +614,9 @@ | ||
| 614 | 614 | */ |
| 615 | 615 | @Override |
| 616 | 616 | public void update(Host host, Statement statement, Exception exception, long newLatencyNanos) { |
| 617 | + if (statement instanceof StatementWrapper) | |
| 618 | + statement = ((StatementWrapper) statement).getWrappedStatement(); | |
| 619 | + | |
| 617 | 620 | long latencyMs = NANOSECONDS.toMillis(newLatencyNanos); |
| 618 | 621 | if (exception == null) { |
| 619 | 622 | maybeLogNormalOrSlowQuery(host, statement, latencyMs); |
| @@ -745,9 +748,6 @@ | ||
| 745 | 748 | } |
| 746 | 749 | |
| 747 | 750 | protected int append(Statement statement, StringBuilder buffer, int remaining) { |
| 748 | - if (statement instanceof StatementWrapper) | |
| 749 | - statement = ((StatementWrapper) statement).getWrappedStatement(); | |
| 750 | - | |
| 751 | 751 | if (statement instanceof RegularStatement) { |
| 752 | 752 | remaining = append(((RegularStatement) statement).getQueryString().trim(), buffer, remaining); |
| 753 | 753 | } else if (statement instanceof BoundStatement) { |
modified driver-core/src/test/java/com/datastax/driver/core/QueryLoggerTest.java +28 −0
| @@ -15,6 +15,7 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | +import com.datastax.driver.core.StatementWrapperTest.CustomStatement; | |
| 18 | 19 | import com.datastax.driver.core.exceptions.DriverException; |
| 19 | 20 | import com.datastax.driver.core.utils.CassandraVersion; |
| 20 | 21 | import com.google.common.base.Function; |
| @@ -713,6 +714,33 @@ | ||
| 713 | 714 | .contains("pk:42"); |
| 714 | 715 | } |
| 715 | 716 | |
| 717 | + @CassandraVersion(major=2.0) | |
| 718 | + @Test(groups = "short") | |
| 719 | + public void should_log_wrapped_bound_statement() throws Exception { | |
| 720 | + // given | |
| 721 | + normal.setLevel(TRACE); | |
| 722 | + queryLogger = QueryLogger.builder(cluster) | |
| 723 | + .withConstantThreshold(Long.MAX_VALUE) | |
| 724 | + .withMaxQueryStringLength(Integer.MAX_VALUE) | |
| 725 | + .build(); | |
| 726 | + cluster.register(queryLogger); | |
| 727 | + // when | |
| 728 | + String query = "UPDATE test SET c_text = :param1 WHERE pk = :param2"; | |
| 729 | + PreparedStatement ps = session.prepare(query); | |
| 730 | + BoundStatement bs = ps.bind(); | |
| 731 | + bs.setString("param1", "foo"); | |
| 732 | + bs.setInt("param2", 42); | |
| 733 | + session.execute(new CustomStatement(bs)); | |
| 734 | + // then | |
| 735 | + String line = normalAppender.waitAndGet(10000); | |
| 736 | + assertThat(line) | |
| 737 | + .contains("Query completed normally") | |
| 738 | + .contains(ipOfNode(1)) | |
| 739 | + .contains(query) | |
| 740 | + .contains("param2:42") | |
| 741 | + .contains("param1:'foo'"); | |
| 742 | + } | |
| 743 | + | |
| 716 | 744 | @Override |
| 717 | 745 | protected List<String> getTableDefinitions() { |
| 718 | 746 | return Lists.newArrayList("CREATE TABLE test (pk int PRIMARY KEY, " + definitions + ")"); |