Skip to content

Commit 63cbebd

Browse files
djatnieksolim7t
authored andcommitted
JAVA-1068: Unwrap StatementWrappers when hashing the paging state.
1 parent bb9d214 commit 63cbebd

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- [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.
1919
- [improvement] JAVA-1038: Fetch node info by rpc_address if its broadcast_address is not in system.peers.
2020
- [improvement] JAVA-974: Validate accessor parameter types against bound statement.
21+
- [bug] JAVA-1068: Unwrap StatementWrappers when hashing the paging state.
2122

2223
Merged from 2.0 branch:
2324

driver-core/src/main/java/com/datastax/driver/core/PagingState.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ private byte[] hash(Statement statement, ProtocolVersion protocolVersion) {
7474
byte[] digest;
7575
ByteBuffer[] values;
7676
MessageDigest md;
77+
if (statement instanceof StatementWrapper) {
78+
statement = ((StatementWrapper) statement).getWrappedStatement();
79+
}
7780
assert !(statement instanceof BatchStatement);
7881
try {
7982
md = MessageDigest.getInstance("MD5");

driver-core/src/test/java/com/datastax/driver/core/PagingStateTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,27 @@ public void should_fail_if_paging_state_altered() {
112112
}
113113
}
114114

115+
/**
116+
* Validates that {@link PagingState} can be reused with a wrapped Statement.
117+
*
118+
* @test_category paging
119+
* @expected_result {@link ResultSet} from the query with the provided {@link PagingState} starts from the
120+
* subsequent row from the first query.
121+
*/
122+
@Test(groups = "short")
123+
public void should_use_state_with_wrapped_statement() {
124+
Statement st = new TestWrapper(new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)));
125+
ResultSet result = session().execute(st.setFetchSize(20));
126+
int pageSize = result.getAvailableWithoutFetching();
127+
String savedPagingStateString = result.getExecutionInfo().getPagingState().toString();
128+
129+
st = new TestWrapper(new SimpleStatement(String.format("SELECT v FROM test WHERE k='%s'", KEY)));
130+
result = session().execute(st.setFetchSize(20).setPagingState(PagingState.fromString(savedPagingStateString)));
131+
132+
//We have the result starting from the next page we stopped
133+
assertThat(result.one().getInt("v")).isEqualTo(pageSize);
134+
}
135+
115136
/**
116137
* Validates that {@link PagingState} can be reused with the same {@link BoundStatement}.
117138
*
@@ -224,5 +245,10 @@ public void should_complete_when_using_unsafe_paging_state() {
224245
assertThat(result.one().getInt("v")).isEqualTo(pageSize);
225246
}
226247

248+
static class TestWrapper extends StatementWrapper {
249+
TestWrapper(Statement wrapped) {
250+
super(wrapped);
251+
}
252+
}
227253
}
228254

0 commit comments

Comments
 (0)