|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package com.datastax.oss.driver.internal.core.cql; |
| 19 | + |
| 20 | +import static org.assertj.core.api.Assertions.assertThat; |
| 21 | + |
| 22 | +import com.datastax.oss.driver.api.core.ConsistencyLevel; |
| 23 | +import com.datastax.oss.driver.api.core.DefaultConsistencyLevel; |
| 24 | +import com.datastax.oss.driver.api.core.DefaultProtocolVersion; |
| 25 | +import com.datastax.oss.driver.api.core.RequestRoutingType; |
| 26 | +import com.datastax.oss.driver.api.core.cql.BoundStatement; |
| 27 | +import com.datastax.oss.driver.api.core.cql.ColumnDefinitions; |
| 28 | +import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry; |
| 29 | +import com.datastax.oss.protocol.internal.util.Bytes; |
| 30 | +import java.util.Collections; |
| 31 | +import org.junit.Test; |
| 32 | + |
| 33 | +public class DefaultPreparedStatementTest { |
| 34 | + |
| 35 | + @Test |
| 36 | + public void should_not_keep_inferred_routing_type_after_bound_consistency_override() { |
| 37 | + DefaultPreparedStatement preparedStatement = |
| 38 | + newPreparedStatement(DefaultConsistencyLevel.LOCAL_SERIAL, null, null); |
| 39 | + |
| 40 | + assertThat(preparedStatement.getRequestRoutingType()).isEqualTo(RequestRoutingType.LWT); |
| 41 | + |
| 42 | + BoundStatement boundStatement = |
| 43 | + preparedStatement.bind().setConsistencyLevel(DefaultConsistencyLevel.ONE); |
| 44 | + |
| 45 | + assertThat(boundStatement.getConsistencyLevel()).isEqualTo(DefaultConsistencyLevel.ONE); |
| 46 | + assertThat(boundStatement.getRequestRoutingType()).isNull(); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void should_keep_detected_lwt_routing_type_after_bound_consistency_override() { |
| 51 | + DefaultPreparedStatement preparedStatement = |
| 52 | + newPreparedStatement(DefaultConsistencyLevel.LOCAL_SERIAL, null, RequestRoutingType.LWT); |
| 53 | + |
| 54 | + BoundStatement boundStatement = |
| 55 | + preparedStatement.bind().setConsistencyLevel(DefaultConsistencyLevel.ONE); |
| 56 | + |
| 57 | + assertThat(boundStatement.getRequestRoutingType()).isEqualTo(RequestRoutingType.LWT); |
| 58 | + } |
| 59 | + |
| 60 | + private DefaultPreparedStatement newPreparedStatement( |
| 61 | + ConsistencyLevel consistencyLevel, |
| 62 | + ConsistencyLevel serialConsistencyLevel, |
| 63 | + RequestRoutingType requestRoutingType) { |
| 64 | + ColumnDefinitions variableDefinitions = |
| 65 | + DefaultColumnDefinitions.valueOf(Collections.emptyList()); |
| 66 | + return new DefaultPreparedStatement( |
| 67 | + Bytes.fromHexString("0x"), |
| 68 | + "SELECT * FROM test.foo WHERE pk = ?", |
| 69 | + variableDefinitions, |
| 70 | + Collections.emptyList(), |
| 71 | + null, |
| 72 | + null, |
| 73 | + null, |
| 74 | + null, |
| 75 | + Collections.emptyMap(), |
| 76 | + null, |
| 77 | + null, |
| 78 | + null, |
| 79 | + null, |
| 80 | + null, |
| 81 | + Collections.emptyMap(), |
| 82 | + null, |
| 83 | + null, |
| 84 | + null, |
| 85 | + Integer.MIN_VALUE, |
| 86 | + consistencyLevel, |
| 87 | + serialConsistencyLevel, |
| 88 | + false, |
| 89 | + CodecRegistry.DEFAULT, |
| 90 | + DefaultProtocolVersion.DEFAULT, |
| 91 | + requestRoutingType); |
| 92 | + } |
| 93 | +} |
0 commit comments