Elffuss BraidHub

kikocis/java-driver public

JAVA-1184: Handle wrapped statements earlier in query logger.
Changeseta8bc347c63dec7344c97e8a2618018a60ab2d55fdb6d8037b5c1d33b4b450672
Authorolim7t <omichallat+github@gmail.com> · 2016-05-10 12:00 -07:00
Committerolim7t <omichallat+github@gmail.com> · 2016-05-11 11:24 -07:00
Parents174fb0a64d43

Browse the files at this changeset

2 files changed

modified driver-core/src/main/java/com/datastax/driver/core/QueryLogger.java +3 −3
@@ -614,6 +614,9 @@
614614 */
615615 @Override
616616 public void update(Host host, Statement statement, Exception exception, long newLatencyNanos) {
617+ if (statement instanceof StatementWrapper)
618+ statement = ((StatementWrapper) statement).getWrappedStatement();
619+
617620 long latencyMs = NANOSECONDS.toMillis(newLatencyNanos);
618621 if (exception == null) {
619622 maybeLogNormalOrSlowQuery(host, statement, latencyMs);
@@ -745,9 +748,6 @@
745748 }
746749
747750 protected int append(Statement statement, StringBuilder buffer, int remaining) {
748- if (statement instanceof StatementWrapper)
749- statement = ((StatementWrapper) statement).getWrappedStatement();
750-
751751 if (statement instanceof RegularStatement) {
752752 remaining = append(((RegularStatement) statement).getQueryString().trim(), buffer, remaining);
753753 } else if (statement instanceof BoundStatement) {
modified driver-core/src/test/java/com/datastax/driver/core/QueryLoggerTest.java +28 −0
@@ -15,6 +15,7 @@
1515 */
1616 package com.datastax.driver.core;
1717
18+import com.datastax.driver.core.StatementWrapperTest.CustomStatement;
1819 import com.datastax.driver.core.exceptions.DriverException;
1920 import com.datastax.driver.core.utils.CassandraVersion;
2021 import com.google.common.base.Function;
@@ -713,6 +714,33 @@
713714 .contains("pk:42");
714715 }
715716
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+
716744 @Override
717745 protected List<String> getTableDefinitions() {
718746 return Lists.newArrayList("CREATE TABLE test (pk int PRIMARY KEY, " + definitions + ")");