kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 8d6440c290051b0d67e4b179566c3359ad141ce0bc46955cd83d67fd4aca447f |
|---|---|
| Author | tommy stendahl <tommy.stendahl@ericsson.com> · 2016-02-25 12:24 +01:00 |
| Committer | tommy stendahl <tommy.stendahl@ericsson.com> · 2016-02-25 12:24 +01:00 |
| Parents | f0a2d1e938a3 |
3 files changed
modified changelog/README.md +1 −0
| @@ -18,6 +18,7 @@ | ||
| 18 | 18 | - [improvement] JAVA-979: Update javadoc for RegularStatement toString() and getQueryString() to indicate that consistency level and other parameters are not maintained in the query string. |
| 19 | 19 | - [improvement] JAVA-1038: Fetch node info by rpc_address if its broadcast_address is not in system.peers. |
| 20 | 20 | - [improvement] JAVA-974: Validate accessor parameter types against bound statement. |
| 21 | +- [improvement] JAVA-1040: SimpleStatement parameters support in QueryLogger | |
| 21 | 22 | |
| 22 | 23 | Merged from 2.0 branch: |
| 23 | 24 |
modified driver-core/src/main/java/com/datastax/driver/core/QueryLogger.java +76 −7
| @@ -148,8 +148,9 @@ | ||
| 148 | 148 | * within a configurable threshold in milliseconds. |
| 149 | 149 | * <p/> |
| 150 | 150 | * This logger is activated by setting its level to {@code DEBUG} or {@code TRACE}. |
| 151 | - * Additionally, if the level is set to {@code TRACE} and the statement being logged is a {@link BoundStatement}, | |
| 152 | - * then the query parameters (if any) will be logged as well (names and actual values). | |
| 151 | + * Additionally, if the level is set to {@code TRACE} and the statement being logged is a {@link BoundStatement} | |
| 152 | + * or a {@link SimpleStatement}, then the query parameters (if any) will be logged. For a {@link BoundStatement} | |
| 153 | + * names and actual values are logged and for a {@link SimpleStatement} values are logged in positional order. | |
| 153 | 154 | * <p/> |
| 154 | 155 | * The name of this logger is {@code com.datastax.driver.core.QueryLogger.NORMAL}. |
| 155 | 156 | */ |
| @@ -160,8 +161,9 @@ | ||
| 160 | 161 | * but whose execution time exceeded a configurable threshold in milliseconds. |
| 161 | 162 | * <p/> |
| 162 | 163 | * This logger is activated by setting its level to {@code DEBUG} or {@code TRACE}. |
| 163 | - * Additionally, if the level is set to {@code TRACE} and the statement being logged is a {@link BoundStatement}, | |
| 164 | - * then the query parameters (if any) will be logged as well (names and actual values). | |
| 164 | + * Additionally, if the level is set to {@code TRACE} and the statement being logged is a {@link BoundStatement} | |
| 165 | + * or a {@link SimpleStatement}, then the query parameters (if any) will be logged. For a {@link BoundStatement} | |
| 166 | + * names and actual values are logged and for a {@link SimpleStatement} values are logged in positional order. | |
| 165 | 167 | * <p/> |
| 166 | 168 | * The name of this logger is {@code com.datastax.driver.core.QueryLogger.SLOW}. |
| 167 | 169 | */ |
| @@ -171,8 +173,9 @@ | ||
| 171 | 173 | * The logger used to log unsuccessful queries, i.e., queries that did not complete normally and threw an exception. |
| 172 | 174 | * <p/> |
| 173 | 175 | * This logger is activated by setting its level to {@code DEBUG} or {@code TRACE}. |
| 174 | - * Additionally, if the level is set to {@code TRACE} and the statement being logged is a {@link BoundStatement}, | |
| 175 | - * then the query parameters (if any) will be logged as well (names and actual values). | |
| 176 | + * Additionally, if the level is set to {@code TRACE} and the statement being logged is a {@link BoundStatement} | |
| 177 | + * or a {@link SimpleStatement}, then the query parameters (if any) will be logged. For a {@link BoundStatement} | |
| 178 | + * names and actual values are logged and for a {@link SimpleStatement} values are logged in positional order. | |
| 176 | 179 | * Note this this logger will also print the full stack trace of the reported exception. |
| 177 | 180 | * <p/> |
| 178 | 181 | * The name of this logger is {@code com.datastax.driver.core.QueryLogger.ERROR}. |
| @@ -646,13 +649,19 @@ | ||
| 646 | 649 | StringBuilder params = new StringBuilder(); |
| 647 | 650 | if (statement instanceof BoundStatement) { |
| 648 | 651 | appendParameters((BoundStatement) statement, params, maxLoggedParameters); |
| 649 | - } else if (statement instanceof BatchStatement) { | |
| 652 | + } else if (statement instanceof SimpleStatement) { | |
| 653 | + appendParameters((SimpleStatement) statement, params, maxLoggedParameters); | |
| 654 | + } | |
| 655 | + else if (statement instanceof BatchStatement) { | |
| 650 | 656 | BatchStatement batchStatement = (BatchStatement) statement; |
| 651 | 657 | int remaining = maxLoggedParameters; |
| 652 | 658 | for (Statement inner : batchStatement.getStatements()) { |
| 653 | 659 | if (inner instanceof BoundStatement) { |
| 654 | 660 | remaining = appendParameters((BoundStatement) inner, params, remaining); |
| 655 | 661 | } |
| 662 | + else if (inner instanceof SimpleStatement) { | |
| 663 | + remaining = appendParameters((SimpleStatement) inner, params, remaining); | |
| 664 | + } | |
| 656 | 665 | } |
| 657 | 666 | } |
| 658 | 667 | if (params.length() > 0) |
| @@ -673,6 +682,9 @@ | ||
| 673 | 682 | } else if (statement instanceof BoundStatement) { |
| 674 | 683 | int boundValues = ((BoundStatement) statement).wrapper.values.length; |
| 675 | 684 | sb.append("[" + boundValues + " bound values] "); |
| 685 | + } else if (statement instanceof SimpleStatement) { | |
| 686 | + int boundValues = ((SimpleStatement) statement).valuesCount(); | |
| 687 | + sb.append("[" + boundValues + " bound values] "); | |
| 676 | 688 | } |
| 677 | 689 | |
| 678 | 690 | append(statement, sb, maxQueryStringLength); |
| @@ -684,6 +696,8 @@ | ||
| 684 | 696 | for (Statement s : bs.getStatements()) { |
| 685 | 697 | if (s instanceof BoundStatement) |
| 686 | 698 | count += ((BoundStatement) s).wrapper.values.length; |
| 699 | + else if (s instanceof SimpleStatement) | |
| 700 | + count += ((SimpleStatement) s).valuesCount(); | |
| 687 | 701 | } |
| 688 | 702 | return count; |
| 689 | 703 | } |
| @@ -746,6 +760,61 @@ | ||
| 746 | 760 | return valueStr; |
| 747 | 761 | } |
| 748 | 762 | |
| 763 | + protected int appendParameters(SimpleStatement statement, StringBuilder buffer, int remaining) { | |
| 764 | + if (remaining == 0) | |
| 765 | + return 0; | |
| 766 | + int numberOfParameters = statement.valuesCount(); | |
| 767 | + if (numberOfParameters > 0) { | |
| 768 | + int numberOfLoggedParameters; | |
| 769 | + if (remaining == -1) { | |
| 770 | + numberOfLoggedParameters = numberOfParameters; | |
| 771 | + } else { | |
| 772 | + numberOfLoggedParameters = remaining > numberOfParameters ? numberOfParameters : remaining; | |
| 773 | + remaining -= numberOfLoggedParameters; | |
| 774 | + } | |
| 775 | + for (int i = 0; i < numberOfLoggedParameters; i++) { | |
| 776 | + if (buffer.length() == 0) | |
| 777 | + buffer.append(" ["); | |
| 778 | + else | |
| 779 | + buffer.append(", "); | |
| 780 | + buffer.append(parameterValueAsString(statement.getObject(i))); | |
| 781 | + } | |
| 782 | + if (numberOfLoggedParameters < numberOfParameters) { | |
| 783 | + buffer.append(FURTHER_PARAMS_OMITTED); | |
| 784 | + } | |
| 785 | + } | |
| 786 | + return remaining; | |
| 787 | + } | |
| 788 | + | |
| 789 | + protected String parameterValueAsString(Object value) { | |
| 790 | + String valueStr; | |
| 791 | + if (value == null) { | |
| 792 | + valueStr = "NULL"; | |
| 793 | + } else { | |
| 794 | + DataType type = TypeCodec.getDataTypeFor(value); | |
| 795 | + int maxParameterValueLength = this.maxParameterValueLength; | |
| 796 | + if (type.equals(DataType.blob()) && maxParameterValueLength != -1) { | |
| 797 | + // prevent large blobs from being converted to strings | |
| 798 | + ByteBuffer buf = (ByteBuffer) value; | |
| 799 | + int maxBufferLength = Math.max(2, (maxParameterValueLength - 2) / 2); | |
| 800 | + boolean bufferTooLarge = buf.remaining() > maxBufferLength; | |
| 801 | + if (bufferTooLarge) { | |
| 802 | + value = (ByteBuffer) buf.duplicate().limit(maxBufferLength); | |
| 803 | + } | |
| 804 | + valueStr = type.format(value); | |
| 805 | + if (bufferTooLarge) { | |
| 806 | + valueStr = valueStr + TRUNCATED_OUTPUT; | |
| 807 | + } | |
| 808 | + } else { | |
| 809 | + valueStr = type.format(value); | |
| 810 | + if (maxParameterValueLength != -1 && valueStr.length() > maxParameterValueLength) { | |
| 811 | + valueStr = valueStr.substring(0, maxParameterValueLength) + TRUNCATED_OUTPUT; | |
| 812 | + } | |
| 813 | + } | |
| 814 | + } | |
| 815 | + return valueStr; | |
| 816 | + } | |
| 817 | + | |
| 749 | 818 | private ProtocolVersion protocolVersion() { |
| 750 | 819 | // Since the QueryLogger can be registered before the Cluster was initialized, we can't retrieve |
| 751 | 820 | // it at construction time. Cache it field at first use (a volatile field is good enough since we |
modified driver-core/src/test/java/com/datastax/driver/core/QueryLoggerTest.java +239 −11
| @@ -372,7 +372,7 @@ | ||
| 372 | 372 | |
| 373 | 373 | @Test(groups = "short") |
| 374 | 374 | @CassandraVersion(major = 2.0) |
| 375 | - public void should_log_non_null_named_parameter() throws Exception { | |
| 375 | + public void should_log_non_null_named_parameter_bound_statements() throws Exception { | |
| 376 | 376 | // given |
| 377 | 377 | normal.setLevel(TRACE); |
| 378 | 378 | queryLogger = QueryLogger.builder(cluster()) |
| @@ -398,7 +398,7 @@ | ||
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | @Test(groups = "short") |
| 401 | - public void should_log_non_null_positional_parameter() throws Exception { | |
| 401 | + public void should_log_non_null_positional_parameter_bound_statements() throws Exception { | |
| 402 | 402 | // given |
| 403 | 403 | normal.setLevel(TRACE); |
| 404 | 404 | queryLogger = QueryLogger.builder(cluster()).build(); |
| @@ -421,7 +421,27 @@ | ||
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | @Test(groups = "short") |
| 424 | - public void should_log_null_parameter() throws Exception { | |
| 424 | + public void should_log_non_null_positional_parameter_simple_statements() throws Exception { | |
| 425 | + // given | |
| 426 | + normal.setLevel(TRACE); | |
| 427 | + queryLogger = QueryLogger.builder(cluster()).build(); | |
| 428 | + cluster().register(queryLogger); | |
| 429 | + // when | |
| 430 | + String query = "UPDATE test SET c_text = ? WHERE pk = ?"; | |
| 431 | + SimpleStatement ss = new SimpleStatement(query, "foo", 42); | |
| 432 | + session().execute(ss); | |
| 433 | + // then | |
| 434 | + String line = normalAppender.waitAndGet(10000); | |
| 435 | + assertThat(line) | |
| 436 | + .contains("Query completed normally") | |
| 437 | + .contains(ipOfNode(1)) | |
| 438 | + .contains(query) | |
| 439 | + .contains("42") | |
| 440 | + .contains("'foo'"); | |
| 441 | + } | |
| 442 | + | |
| 443 | + @Test(groups = "short") | |
| 444 | + public void should_log_null_parameter_bound_statements() throws Exception { | |
| 425 | 445 | // given |
| 426 | 446 | normal.setLevel(TRACE); |
| 427 | 447 | queryLogger = QueryLogger.builder(cluster()).build(); |
| @@ -443,6 +463,26 @@ | ||
| 443 | 463 | .contains("c_text:NULL"); |
| 444 | 464 | } |
| 445 | 465 | |
| 466 | + @Test(groups = "short") | |
| 467 | + public void should_log_null_parameter_simple_statements() throws Exception { | |
| 468 | + // given | |
| 469 | + normal.setLevel(TRACE); | |
| 470 | + queryLogger = QueryLogger.builder(cluster()).build(); | |
| 471 | + cluster().register(queryLogger); | |
| 472 | + // when | |
| 473 | + String query = "UPDATE test SET c_text = ? WHERE pk = ?"; | |
| 474 | + SimpleStatement ss = new SimpleStatement(query, null, 42); | |
| 475 | + session().execute(ss); | |
| 476 | + // then | |
| 477 | + String line = normalAppender.waitAndGet(10000); | |
| 478 | + assertThat(line) | |
| 479 | + .contains("Query completed normally") | |
| 480 | + .contains(ipOfNode(1)) | |
| 481 | + .contains(query) | |
| 482 | + .contains("42") | |
| 483 | + .contains("NULL"); | |
| 484 | + } | |
| 485 | + | |
| 446 | 486 | @Test(groups = "short") |
| 447 | 487 | @CassandraVersion(major = 2.0) |
| 448 | 488 | public void should_log_bound_statement_parameters_inside_batch_statement() throws Exception { |
| @@ -469,10 +509,38 @@ | ||
| 469 | 509 | .contains("c_text:'foo'") |
| 470 | 510 | .contains("c_int:12345"); |
| 471 | 511 | } |
| 512 | + | |
| 513 | + @Test(groups = "short") | |
| 514 | + @CassandraVersion(major = 2.0) | |
| 515 | + public void should_log_simple_statement_parameters_inside_batch_statement() throws Exception { | |
| 516 | + // given | |
| 517 | + normal.setLevel(TRACE); | |
| 518 | + queryLogger = QueryLogger.builder(cluster()).build(); | |
| 519 | + cluster().register(queryLogger); | |
| 520 | + // when | |
| 521 | + String query1 = "UPDATE test SET c_text = ? WHERE pk = ?"; | |
| 522 | + String query2 = "UPDATE test SET c_int = ? WHERE pk = ?"; | |
| 523 | + BatchStatement batch = new BatchStatement(); | |
| 524 | + batch.add(new SimpleStatement(query1, "foo", 42)); | |
| 525 | + batch.add(new SimpleStatement(query2, 12345, 43)); | |
| 526 | + session().execute(batch); | |
| 527 | + // then | |
| 528 | + String line = normalAppender.waitAndGet(10000); | |
| 529 | + assertThat(line) | |
| 530 | + .contains("Query completed normally") | |
| 531 | + .contains(ipOfNode(1)) | |
| 532 | + .contains(query1) | |
| 533 | + .contains(query2) | |
| 534 | + .contains("42") | |
| 535 | + .contains("43") | |
| 536 | + .contains("'foo'") | |
| 537 | + .contains("12345"); | |
| 538 | + } | |
| 539 | + | |
| 472 | 540 | // Test different CQL types |
| 473 | 541 | |
| 474 | 542 | @Test(groups = "short") |
| 475 | - public void should_log_all_parameter_types() throws Exception { | |
| 543 | + public void should_log_all_parameter_types_bound_statements() throws Exception { | |
| 476 | 544 | // given |
| 477 | 545 | normal.setLevel(TRACE); |
| 478 | 546 | queryLogger = QueryLogger.builder(cluster()) |
| @@ -495,6 +563,29 @@ | ||
| 495 | 563 | } |
| 496 | 564 | } |
| 497 | 565 | |
| 566 | + @Test(groups = "short") | |
| 567 | + public void should_log_all_parameter_types_simple_statements() throws Exception { | |
| 568 | + // given | |
| 569 | + normal.setLevel(TRACE); | |
| 570 | + queryLogger = QueryLogger.builder(cluster()) | |
| 571 | + .withMaxParameterValueLength(Integer.MAX_VALUE) | |
| 572 | + .build(); | |
| 573 | + cluster().register(queryLogger); | |
| 574 | + // when | |
| 575 | + String query = "UPDATE test SET " + assignments + " WHERE pk = 42"; | |
| 576 | + SimpleStatement ss = new SimpleStatement(query, values.toArray()); | |
| 577 | + session().execute(ss); | |
| 578 | + // then | |
| 579 | + String line = normalAppender.waitAndGet(10000); | |
| 580 | + assertThat(line) | |
| 581 | + .contains("Query completed normally") | |
| 582 | + .contains(ipOfNode(1)) | |
| 583 | + .contains(query); | |
| 584 | + for (DataType type : dataTypes) { | |
| 585 | + assertThat(line).contains(type.format(getFixedValue(type))); | |
| 586 | + } | |
| 587 | + } | |
| 588 | + | |
| 498 | 589 | // Tests for truncation of query strings and parameter values |
| 499 | 590 | |
| 500 | 591 | @Test(groups = "short") |
| @@ -566,7 +657,7 @@ | ||
| 566 | 657 | |
| 567 | 658 | @CassandraVersion(major = 2.0) |
| 568 | 659 | @Test(groups = "short") |
| 569 | - public void should_truncate_parameter_when_max_length_exceeded() throws Exception { | |
| 660 | + public void should_truncate_parameter_when_max_length_exceeded_bound_statements() throws Exception { | |
| 570 | 661 | // given |
| 571 | 662 | normal.setLevel(TRACE); |
| 572 | 663 | queryLogger = QueryLogger.builder(cluster()) |
| @@ -589,8 +680,30 @@ | ||
| 589 | 680 | .doesNotContain("123456"); |
| 590 | 681 | } |
| 591 | 682 | |
| 683 | + @CassandraVersion(major = 2.0) | |
| 684 | + @Test(groups = "short") | |
| 685 | + public void should_truncate_parameter_when_max_length_exceeded_simple_statements() throws Exception { | |
| 686 | + // given | |
| 687 | + normal.setLevel(TRACE); | |
| 688 | + queryLogger = QueryLogger.builder(cluster()) | |
| 689 | + .withMaxParameterValueLength(5) | |
| 690 | + .build(); | |
| 691 | + cluster().register(queryLogger); | |
| 692 | + // when | |
| 693 | + String query = "UPDATE test SET c_int = ? WHERE pk = ?"; | |
| 694 | + SimpleStatement ss = new SimpleStatement(query, 123456, 42); | |
| 695 | + session().execute(ss); | |
| 696 | + // then | |
| 697 | + String line = normalAppender.waitAndGet(10000); | |
| 698 | + assertThat(line) | |
| 699 | + .contains("Query completed normally") | |
| 700 | + .contains(ipOfNode(1)) | |
| 701 | + .contains("12345" + TRUNCATED_OUTPUT) | |
| 702 | + .doesNotContain("123456"); | |
| 703 | + } | |
| 704 | + | |
| 592 | 705 | @Test(groups = "short") |
| 593 | - public void should_truncate_blob_parameter_when_max_length_exceeded() throws Exception { | |
| 706 | + public void should_truncate_blob_parameter_when_max_length_exceeded_bound_statements() throws Exception { | |
| 594 | 707 | // given |
| 595 | 708 | normal.setLevel(TRACE); |
| 596 | 709 | queryLogger = QueryLogger.builder(cluster()) |
| @@ -610,11 +723,32 @@ | ||
| 610 | 723 | .contains("Query completed normally") |
| 611 | 724 | .contains(ipOfNode(1)) |
| 612 | 725 | .contains("c_blob:0x0102" + TRUNCATED_OUTPUT) |
| 613 | - .doesNotContain("123456"); | |
| 726 | + .doesNotContain("0x010203"); | |
| 727 | + } | |
| 728 | + | |
| 729 | + @Test(groups = "short") | |
| 730 | + public void should_truncate_blob_parameter_when_max_length_exceeded_simple_statements() throws Exception { | |
| 731 | + // given | |
| 732 | + normal.setLevel(TRACE); | |
| 733 | + queryLogger = QueryLogger.builder(cluster()) | |
| 734 | + .withMaxParameterValueLength(6) | |
| 735 | + .build(); | |
| 736 | + cluster().register(queryLogger); | |
| 737 | + // when | |
| 738 | + String query = "UPDATE test SET c_blob = ? WHERE pk = ?"; | |
| 739 | + SimpleStatement ss = new SimpleStatement(query, ByteBuffer.wrap(Bytes.toArray(Lists.newArrayList(1, 2, 3))), 42); | |
| 740 | + session().execute(ss); | |
| 741 | + // then | |
| 742 | + String line = normalAppender.waitAndGet(10000); | |
| 743 | + assertThat(line) | |
| 744 | + .contains("Query completed normally") | |
| 745 | + .contains(ipOfNode(1)) | |
| 746 | + .contains("0x0102" + TRUNCATED_OUTPUT) | |
| 747 | + .doesNotContain("0x010203"); | |
| 614 | 748 | } |
| 615 | 749 | |
| 616 | 750 | @Test(groups = "short") |
| 617 | - public void should_not_truncate_parameter_when_max_length_unlimited() throws Exception { | |
| 751 | + public void should_not_truncate_parameter_when_max_length_unlimited_bound_statements() throws Exception { | |
| 618 | 752 | // given |
| 619 | 753 | normal.setLevel(TRACE); |
| 620 | 754 | queryLogger = QueryLogger.builder(cluster()) |
| @@ -638,7 +772,28 @@ | ||
| 638 | 772 | } |
| 639 | 773 | |
| 640 | 774 | @Test(groups = "short") |
| 641 | - public void should_not_log_exceeding_number_of_parameters() throws Exception { | |
| 775 | + public void should_not_truncate_parameter_when_max_length_unlimited_simple_statements() throws Exception { | |
| 776 | + // given | |
| 777 | + normal.setLevel(TRACE); | |
| 778 | + queryLogger = QueryLogger.builder(cluster()) | |
| 779 | + .withMaxParameterValueLength(-1) | |
| 780 | + .build(); | |
| 781 | + cluster().register(queryLogger); | |
| 782 | + // when | |
| 783 | + String query = "UPDATE test SET c_int = ? WHERE pk = ?"; | |
| 784 | + SimpleStatement ss = new SimpleStatement(query, 123456, 42); | |
| 785 | + session().execute(ss); | |
| 786 | + // then | |
| 787 | + String line = normalAppender.waitAndGet(10000); | |
| 788 | + assertThat(line) | |
| 789 | + .contains("Query completed normally") | |
| 790 | + .contains(ipOfNode(1)) | |
| 791 | + .contains("123456") | |
| 792 | + .doesNotContain(TRUNCATED_OUTPUT); | |
| 793 | + } | |
| 794 | + | |
| 795 | + @Test(groups = "short") | |
| 796 | + public void should_not_log_exceeding_number_of_parameters_bound_statements() throws Exception { | |
| 642 | 797 | // given |
| 643 | 798 | normal.setLevel(TRACE); |
| 644 | 799 | queryLogger = QueryLogger.builder(cluster()) |
| @@ -662,9 +817,31 @@ | ||
| 662 | 817 | .contains(FURTHER_PARAMS_OMITTED); |
| 663 | 818 | } |
| 664 | 819 | |
| 820 | + @Test(groups = "short") | |
| 821 | + public void should_not_log_exceeding_number_of_parameters_simple_statements() throws Exception { | |
| 822 | + // given | |
| 823 | + normal.setLevel(TRACE); | |
| 824 | + queryLogger = QueryLogger.builder(cluster()) | |
| 825 | + .withMaxLoggedParameters(1) | |
| 826 | + .build(); | |
| 827 | + cluster().register(queryLogger); | |
| 828 | + // when | |
| 829 | + String query = "UPDATE test SET c_int = ? WHERE pk = ?"; | |
| 830 | + SimpleStatement ss = new SimpleStatement(query, 123456, 42); | |
| 831 | + session().execute(ss); | |
| 832 | + // then | |
| 833 | + String line = normalAppender.waitAndGet(10000); | |
| 834 | + assertThat(line) | |
| 835 | + .contains("Query completed normally") | |
| 836 | + .contains(ipOfNode(1)) | |
| 837 | + .contains("123456") | |
| 838 | + .doesNotContain("42") | |
| 839 | + .contains(FURTHER_PARAMS_OMITTED); | |
| 840 | + } | |
| 841 | + | |
| 665 | 842 | @Test(groups = "short") |
| 666 | 843 | @CassandraVersion(major = 2.0) |
| 667 | - public void should_not_log_exceeding_number_of_parameters_in_batch_statement() throws Exception { | |
| 844 | + public void should_not_log_exceeding_number_of_parameters_in_batch_statement_bound_statements() throws Exception { | |
| 668 | 845 | // given |
| 669 | 846 | normal.setLevel(TRACE); |
| 670 | 847 | queryLogger = QueryLogger.builder(cluster()) |
| @@ -693,7 +870,37 @@ | ||
| 693 | 870 | } |
| 694 | 871 | |
| 695 | 872 | @Test(groups = "short") |
| 696 | - public void should_log_all_parameters_when_max_unlimited() throws Exception { | |
| 873 | + @CassandraVersion(major = 2.0) | |
| 874 | + public void should_not_log_exceeding_number_of_parameters_in_batch_statement_simple_statements() throws Exception { | |
| 875 | + // given | |
| 876 | + normal.setLevel(TRACE); | |
| 877 | + queryLogger = QueryLogger.builder(cluster()) | |
| 878 | + .withMaxLoggedParameters(1) | |
| 879 | + .build(); | |
| 880 | + cluster().register(queryLogger); | |
| 881 | + // when | |
| 882 | + String query1 = "UPDATE test SET c_text = ? WHERE pk = ?"; | |
| 883 | + String query2 = "UPDATE test SET c_int = ? WHERE pk = ?"; | |
| 884 | + BatchStatement batch = new BatchStatement(); | |
| 885 | + batch.add(new SimpleStatement(query1, "foo", 42)); | |
| 886 | + batch.add(new SimpleStatement(query2, 12345, 43)); | |
| 887 | + session().execute(batch); | |
| 888 | + // then | |
| 889 | + String line = normalAppender.waitAndGet(10000); | |
| 890 | + assertThat(line) | |
| 891 | + .contains("Query completed normally") | |
| 892 | + .contains(ipOfNode(1)) | |
| 893 | + .contains(query1) | |
| 894 | + .contains(query2) | |
| 895 | + .contains("'foo'") | |
| 896 | + .doesNotContain("42") | |
| 897 | + .doesNotContain("12345") | |
| 898 | + .doesNotContain("43") | |
| 899 | + .contains(FURTHER_PARAMS_OMITTED); | |
| 900 | + } | |
| 901 | + | |
| 902 | + @Test(groups = "short") | |
| 903 | + public void should_log_all_parameters_when_max_unlimited_bound_statements() throws Exception { | |
| 697 | 904 | // given |
| 698 | 905 | normal.setLevel(TRACE); |
| 699 | 906 | queryLogger = QueryLogger.builder(cluster()) |
| @@ -716,6 +923,27 @@ | ||
| 716 | 923 | .contains("pk:42"); |
| 717 | 924 | } |
| 718 | 925 | |
| 926 | + @Test(groups = "short") | |
| 927 | + public void should_log_all_parameters_when_max_unlimited_simple_statements() throws Exception { | |
| 928 | + // given | |
| 929 | + normal.setLevel(TRACE); | |
| 930 | + queryLogger = QueryLogger.builder(cluster()) | |
| 931 | + .withMaxLoggedParameters(-1) | |
| 932 | + .build(); | |
| 933 | + cluster().register(queryLogger); | |
| 934 | + // when | |
| 935 | + String query = "UPDATE test SET c_int = ? WHERE pk = ?"; | |
| 936 | + SimpleStatement ss = new SimpleStatement(query, 123456, 42); | |
| 937 | + session().execute(ss); | |
| 938 | + // then | |
| 939 | + String line = normalAppender.waitAndGet(10000); | |
| 940 | + assertThat(line) | |
| 941 | + .contains("Query completed normally") | |
| 942 | + .contains(ipOfNode(1)) | |
| 943 | + .contains("123456") | |
| 944 | + .contains("42"); | |
| 945 | + } | |
| 946 | + | |
| 719 | 947 | @Override |
| 720 | 948 | public void onTestContextInitialized() { |
| 721 | 949 | execute("CREATE TABLE test (pk int PRIMARY KEY, " + definitions + ")"); |