|
16 | 16 | package com.datastax.driver.core; |
17 | 17 |
|
18 | 18 | import com.datastax.driver.core.policies.*; |
| 19 | +import com.datastax.driver.core.utils.CassandraVersion; |
19 | 20 | import com.google.common.collect.Lists; |
20 | 21 | import org.testng.annotations.Test; |
21 | 22 |
|
|
26 | 27 | import static org.assertj.core.api.Assertions.assertThat; |
27 | 28 |
|
28 | 29 | public class StatementWrapperTest extends CCMBridge.PerClassSingleNodeCluster { |
| 30 | + |
| 31 | + private static final String INSERT_QUERY = "insert into test (k, v) values (?, ?)"; |
| 32 | + private static final String SELECT_QUERY = "select * from test where k = ?"; |
| 33 | + |
29 | 34 | @Override |
30 | 35 | protected Collection<String> getTableDefinitions() { |
31 | | - return Lists.newArrayList(); |
| 36 | + return Lists.newArrayList( |
| 37 | + "create table test (k text primary key, v int)" |
| 38 | + ); |
32 | 39 | } |
33 | 40 |
|
34 | 41 | CustomLoadBalancingPolicy loadBalancingPolicy = new CustomLoadBalancingPolicy(); |
@@ -83,6 +90,56 @@ public void should_pass_wrapped_statement_to_retry_policy() { |
83 | 90 | assertThat(retryPolicy.customStatementsHandled.get()).isEqualTo(1); |
84 | 91 | } |
85 | 92 |
|
| 93 | + @CassandraVersion(major=2.0) |
| 94 | + @Test(groups = "short") |
| 95 | + public void should_execute_wrapped_simple_statement() { |
| 96 | + session.execute(new CustomStatement(new SimpleStatement(INSERT_QUERY, "key_simple", 1))); |
| 97 | + |
| 98 | + ResultSet rs = session.execute(new CustomStatement(new SimpleStatement(SELECT_QUERY, "key_simple"))); |
| 99 | + assertThat(rs.one().getInt("v")).isEqualTo(1); |
| 100 | + } |
| 101 | + |
| 102 | + @Test(groups = "short") |
| 103 | + public void should_execute_wrapped_bound_statement() { |
| 104 | + PreparedStatement preparedStatement = session.prepare(new SimpleStatement(INSERT_QUERY)); |
| 105 | + session.execute(new CustomStatement(preparedStatement.bind("key_bound", 1))); |
| 106 | + |
| 107 | + preparedStatement = session.prepare(new SimpleStatement(SELECT_QUERY)); |
| 108 | + ResultSet rs = session.execute(new CustomStatement(preparedStatement.bind("key_bound"))); |
| 109 | + assertThat(rs.one().getInt("v")).isEqualTo(1); |
| 110 | + } |
| 111 | + |
| 112 | + @CassandraVersion(major=2.0) |
| 113 | + @Test(groups = "short") |
| 114 | + public void should_execute_wrapped_batch_statement() { |
| 115 | + BatchStatement batchStatement = new BatchStatement(); |
| 116 | + batchStatement.add(new SimpleStatement(INSERT_QUERY, "key_batch", 1)); |
| 117 | + |
| 118 | + session.execute(new CustomStatement(batchStatement)); |
| 119 | + |
| 120 | + ResultSet rs = session.execute(SELECT_QUERY, "key_batch"); |
| 121 | + assertThat(rs.one().getInt("v")).isEqualTo(1); |
| 122 | + } |
| 123 | + |
| 124 | + @CassandraVersion(major=2.0) |
| 125 | + @Test(groups = "short") |
| 126 | + public void should_add_wrapped_batch_statement_to_batch_statement() { |
| 127 | + BatchStatement batchStatementForWrapping = new BatchStatement(); |
| 128 | + batchStatementForWrapping.add(new SimpleStatement(INSERT_QUERY, "key1", 1)); |
| 129 | + |
| 130 | + BatchStatement batchStatement = new BatchStatement(); |
| 131 | + batchStatement.add(new CustomStatement(new SimpleStatement(INSERT_QUERY, "key2", 2))); |
| 132 | + batchStatement.add(new CustomStatement(batchStatementForWrapping)); |
| 133 | + |
| 134 | + session.execute(batchStatement); |
| 135 | + |
| 136 | + ResultSet rs = session.execute(SELECT_QUERY, "key1"); |
| 137 | + assertThat(rs.one().getInt("v")).isEqualTo(1); |
| 138 | + |
| 139 | + rs = session.execute(SELECT_QUERY, "key2"); |
| 140 | + assertThat(rs.one().getInt("v")).isEqualTo(2); |
| 141 | + } |
| 142 | + |
86 | 143 | /** |
87 | 144 | * A custom wrapper that's just used to mark statements. |
88 | 145 | */ |
|
0 commit comments