From c407aad8cfe0e47e48eba9484ea2ab439356fee5 Mon Sep 17 00:00:00 2001 From: John Blum Date: Tue, 9 Aug 2016 14:55:28 -0700 Subject: [PATCH] DATACASS-328 - Polish. Original pull request: #81. --- .../cassandra/core/ConsistencyLevel.java | 10 +- .../core/ConsistencyLevelResolver.java | 15 +- .../cassandra/core/CqlTemplate.java | 12 +- .../cassandra/core/QueryOptions.java | 140 +++++++++--------- .../cassandra/core/RetryPolicy.java | 8 +- .../cassandra/core/RetryPolicyResolver.java | 11 +- .../cassandra/core/WriteOptions.java | 74 ++++----- .../cassandra/core/CqlTemplateUnitTests.java | 20 +-- .../cassandra/core/QueryOptionsUnitTests.java | 12 +- .../cassandra/core/WriteOptionsUnitTests.java | 24 +-- 10 files changed, 155 insertions(+), 171 deletions(-) diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevel.java b/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevel.java index dead430ee..eb5239f3d 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevel.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevel.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2016 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,7 @@ package org.springframework.cassandra.core; /** * Generic Consistency Levels associated with Cassandra. - * + * * @author David Webb * @author Antoine Toulme * @deprecated Use the driver's {@link com.datastax.driver.core.ConsistencyLevel}. @@ -40,7 +40,7 @@ public enum ConsistencyLevel { /** * @deprecated Use {@link #EACH_QUORUM} */ - @Deprecated EACH_QUOROM, // + @Deprecated EACH_QUOROM, ALL, LOCAL_ONE, SERIAL, LOCAL_SERIAL, diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevelResolver.java b/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevelResolver.java index 2296f99cd..30c4cee7e 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevelResolver.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/ConsistencyLevelResolver.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2016 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,7 +19,7 @@ import org.springframework.util.Assert; /** * Determine driver consistency level based on ConsistencyLevel - * + * * @author David Webb * @author Antoine Toulme * @deprecated Use the driver's {@link com.datastax.driver.core.ConsistencyLevel}. @@ -34,17 +34,16 @@ public final class ConsistencyLevelResolver { /** * Decode the generic spring data cassandra enum to the type required by the DataStax Driver. - * + * * @param level the consistency level to resolve, must not be {@literal null}. * @return The DataStax Driver Consistency Level. */ + @SuppressWarnings("deprecation") public static com.datastax.driver.core.ConsistencyLevel resolve(ConsistencyLevel level) { Assert.notNull(level, "ConsistencyLevel must not be null"); - /* - * Determine the driver level based on our enum - */ + // Determine the driver ConsistencyLevel based on SD Cassandra's enum switch (level) { case ONE: return com.datastax.driver.core.ConsistencyLevel.ONE; diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/CqlTemplate.java b/spring-cql/src/main/java/org/springframework/cassandra/core/CqlTemplate.java index 99685cbde..c05d84d42 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/CqlTemplate.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/CqlTemplate.java @@ -137,10 +137,9 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { * @param queryOptions query options (e.g. consistency level) to add to the Cassandra {@link PreparedStatement}. */ public static PreparedStatement addPreparedStatementOptions(PreparedStatement preparedStatement, - QueryOptions queryOptions) { + QueryOptions queryOptions) { if (queryOptions != null) { - if (queryOptions.getDriverConsistencyLevel() != null) { preparedStatement.setConsistencyLevel(queryOptions.getDriverConsistencyLevel()); } else if (queryOptions.getConsistencyLevel() != null) { @@ -167,7 +166,6 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { public static T addQueryOptions(T statement, QueryOptions queryOptions) { if (queryOptions != null) { - if (queryOptions.getDriverConsistencyLevel() != null) { statement.setConsistencyLevel(queryOptions.getDriverConsistencyLevel()); } else if (queryOptions.getConsistencyLevel() != null) { @@ -180,14 +178,14 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations { statement.setRetryPolicy(RetryPolicyResolver.resolve(queryOptions.getRetryPolicy())); } - if (queryOptions.getReadTimeout() != null) { - statement.setReadTimeoutMillis(queryOptions.getReadTimeout().intValue()); - } - if (queryOptions.getFetchSize() != null) { statement.setFetchSize(queryOptions.getFetchSize()); } + if (queryOptions.getReadTimeout() != null) { + statement.setReadTimeoutMillis(queryOptions.getReadTimeout().intValue()); + } + if (queryOptions.getTracing() != null) { if (queryOptions.getTracing()) { statement.enableTracing(); diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/QueryOptions.java b/spring-cql/src/main/java/org/springframework/cassandra/core/QueryOptions.java index d40954719..128ec631f 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/QueryOptions.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/QueryOptions.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2014 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,7 +24,7 @@ import com.datastax.driver.core.SocketOptions; /** * Cassandra Query Options for queries. {@link QueryOptions} allow tuning of various query options on a per-request * level. Only options that are set are applied to queries. - * + * * @author David Webb * @author Mark Paluch */ @@ -36,10 +36,12 @@ public class QueryOptions { private RetryPolicy retryPolicy; private com.datastax.driver.core.policies.RetryPolicy driverRetryPolicy; - private Long readTimeout; - private Integer fetchSize; private Boolean tracing; + private Integer fetchSize; + + private Long readTimeout; + /** * Creates new {@link QueryOptions}. */ @@ -47,7 +49,7 @@ public class QueryOptions { /** * Creates new {@link QueryOptions} for the given {@link ConsistencyLevel} and {@link RetryPolicy}. - * + * * @param consistencyLevel the consistency level, may be {@literal null}. * @param retryPolicy the retry policy, may be {@literal null}. */ @@ -58,7 +60,7 @@ public class QueryOptions { /** * Creates a new {@link QueryOptionsBuilder}. - * + * * @return a new {@link QueryOptionsBuilder}. * @since 1.5 */ @@ -68,7 +70,7 @@ public class QueryOptions { /** * Returns the {@link ConsistencyLevel}. - * + * * @return the consistencyLevel. * @deprecated Use {@link #setConsistencyLevel(com.datastax.driver.core.ConsistencyLevel)} */ @@ -80,7 +82,7 @@ public class QueryOptions { /** * Sets the driver {@link ConsistencyLevel}. Setting both ({@link ConsistencyLevel} and * {@link com.datastax.driver.core.ConsistencyLevel driver ConsistencyLevel}) consistency levels is not supported. - * + * * @param consistencyLevel the consistencyLevel to set. * @throws IllegalStateException if the {@link com.datastax.driver.core.ConsistencyLevel driver ConsistencyLevel} is * set @@ -172,30 +174,6 @@ public class QueryOptions { return driverRetryPolicy; } - /** - * Sets the read timeout in milliseconds. Overrides the default per-host read timeout ( - * {@link SocketOptions#getReadTimeoutMillis()}). - * - * @param readTimeout the read timeout in milliseconds. Negative values are not allowed. If it is {@code 0}, the read timeout - * will be disabled for this statement. - * @since 1.5 - * @see SocketOptions#getReadTimeoutMillis() - * @see com.datastax.driver.core.Cluster.Builder#withSocketOptions(SocketOptions) - */ - public void setReadTimeout(long readTimeout) { - - Assert.isTrue(readTimeout >= 0, "ReadTimeout must be greater or equal to zero"); - this.readTimeout = readTimeout; - } - - /** - * @return the read timeout in milliseconds. May be {@literal null} if not set. - * @since 1.5 - */ - protected Long getReadTimeout() { - return readTimeout; - } - /** * Sets the query fetch size for {@link com.datastax.driver.core.ResultSet} chunks. *

@@ -211,7 +189,7 @@ public class QueryOptions { */ public void setFetchSize(int fetchSize) { - Assert.isTrue(fetchSize >= 0, "FetchSize must be greater or equal to zero"); + Assert.isTrue(fetchSize >= 0, "FetchSize must be greater than equal to zero"); this.fetchSize = fetchSize; } @@ -223,6 +201,30 @@ public class QueryOptions { return fetchSize; } + /** + * Sets the read timeout in milliseconds. Overrides the default per-host read timeout ( + * {@link SocketOptions#getReadTimeoutMillis()}). + * + * @param readTimeout the read timeout in milliseconds. Negative values are not allowed. If it is {@code 0}, the read timeout + * will be disabled for this statement. + * @since 1.5 + * @see SocketOptions#getReadTimeoutMillis() + * @see com.datastax.driver.core.Cluster.Builder#withSocketOptions(SocketOptions) + */ + public void setReadTimeout(long readTimeout) { + + Assert.isTrue(readTimeout >= 0, "ReadTimeout must be greater than equal to zero"); + this.readTimeout = readTimeout; + } + + /** + * @return the read timeout in milliseconds. May be {@literal null} if not set. + * @since 1.5 + */ + protected Long getReadTimeout() { + return readTimeout; + } + /** * Enables statement tracing. * @@ -253,12 +255,28 @@ public class QueryOptions { private RetryPolicy retryPolicy; private com.datastax.driver.core.policies.RetryPolicy driverRetryPolicy; - private Long readTimeout; - private Integer fetchSize; private Boolean tracing; + private Integer fetchSize; + + private Long readTimeout; + QueryOptionsBuilder() {} + /** + * Sets the {@link com.datastax.driver.core.ConsistencyLevel} to use. + * + * @param driverConsistencyLevel must not be {@literal null}. + * @return {@code this} {@link QueryOptionsBuilder} + */ + public QueryOptionsBuilder consistencyLevel(com.datastax.driver.core.ConsistencyLevel driverConsistencyLevel) { + + Assert.notNull(driverConsistencyLevel, "Driver ConsistencyLevel must not be null"); + + this.driverConsistencyLevel = driverConsistencyLevel; + return this; + } + /** * Sets the {@link RetryPolicy} to use. Setting both ({@link RetryPolicy} and * {@link com.datastax.driver.core.policies.RetryPolicy driver RetryPolicy}) retry policies is not supported. @@ -297,16 +315,23 @@ public class QueryOptions { } /** - * Sets the {@link com.datastax.driver.core.ConsistencyLevel} to use. + * Sets the query fetch size for {@link com.datastax.driver.core.ResultSet} chunks. + *

+ * The fetch size controls how much resulting rows will be retrieved simultaneously (the goal being to avoid loading + * too much results in memory for queries yielding large results). Please note that while value as low as 1 can be + * used, it is *highly* discouraged to use such a low value in practice as it will yield very poor performance. * - * @param driverConsistencyLevel must not be {@literal null}. + * @param fetchSize the number of rows to fetch per chunking request. To disable chunking of the result set, use + * {@code fetchSize == Integer.MAX_VALUE}. Negative values are not allowed. * @return {@code this} {@link QueryOptionsBuilder} + * @see com.datastax.driver.core.QueryOptions#getFetchSize() + * @see com.datastax.driver.core.Cluster.Builder#withQueryOptions(com.datastax.driver.core.QueryOptions) */ - public QueryOptionsBuilder consistencyLevel(com.datastax.driver.core.ConsistencyLevel driverConsistencyLevel) { + public QueryOptionsBuilder fetchSize(int fetchSize) { - Assert.notNull(driverConsistencyLevel, "Driver ConsistencyLevel must not be null"); + Assert.isTrue(fetchSize >= 0, "FetchSize must be greater or equal to zero"); - this.driverConsistencyLevel = driverConsistencyLevel; + this.fetchSize = fetchSize; return this; } @@ -348,27 +373,6 @@ public class QueryOptions { return this; } - /** - * Sets the query fetch size for {@link com.datastax.driver.core.ResultSet} chunks. - *

- * The fetch size controls how much resulting rows will be retrieved simultaneously (the goal being to avoid loading - * too much results in memory for queries yielding large results). Please note that while value as low as 1 can be - * used, it is *highly* discouraged to use such a low value in practice as it will yield very poor performance. - * - * @param fetchSize the number of rows to fetch per chunking request. To disable chunking of the result set, use - * {@code fetchSize == Integer.MAX_VALUE}. Negative values are not allowed. - * @return {@code this} {@link QueryOptionsBuilder} - * @see com.datastax.driver.core.QueryOptions#getFetchSize() - * @see com.datastax.driver.core.Cluster.Builder#withQueryOptions(com.datastax.driver.core.QueryOptions) - */ - public QueryOptionsBuilder fetchSize(int fetchSize) { - - Assert.isTrue(fetchSize >= 0, "FetchSize must be greater or equal to zero"); - - this.fetchSize = fetchSize; - return this; - } - /** * Enables statement tracing. * @@ -383,7 +387,7 @@ public class QueryOptions { /** * Enables statement tracing. - * + * * @return {@code this} {@link QueryOptionsBuilder} */ public QueryOptionsBuilder withTracing() { @@ -405,14 +409,14 @@ public class QueryOptions { queryOptions.setRetryPolicy(retryPolicy); queryOptions.setRetryPolicy(driverRetryPolicy); - if (readTimeout != null) { - queryOptions.setReadTimeout(readTimeout); - } - if (fetchSize != null) { queryOptions.setFetchSize(fetchSize); } + if (readTimeout != null) { + queryOptions.setReadTimeout(readTimeout); + } + if (tracing != null) { queryOptions.setTracing(tracing); } diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicy.java b/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicy.java index dc71de6ac..c9c441b44 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicy.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicy.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2016 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,7 +21,9 @@ package org.springframework.cassandra.core; * * @author David Webb * @author Mark Paluch + * @deprecated Use the driver's {@link com.datastax.driver.core.policies.RetryPolicy}. */ +@Deprecated public enum RetryPolicy { DEFAULT, DOWNGRADING_CONSISTENCY, FALLTHROUGH, diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicyResolver.java b/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicyResolver.java index cae6645c5..d6bff307a 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicyResolver.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/RetryPolicyResolver.java @@ -24,6 +24,7 @@ import com.datastax.driver.core.policies.FallthroughRetryPolicy; * * @author David Webb */ +@Deprecated public final class RetryPolicyResolver { /** @@ -33,17 +34,16 @@ public final class RetryPolicyResolver { /** * Decode the generic spring data cassandra enum to the type required by the DataStax Driver. - * + * * @param level * @return The DataStax Driver Consistency Level. */ + @SuppressWarnings("deprecation") public static com.datastax.driver.core.policies.RetryPolicy resolve(RetryPolicy policy) { - com.datastax.driver.core.policies.RetryPolicy resolvedPolicy = DefaultRetryPolicy.INSTANCE; + com.datastax.driver.core.policies.RetryPolicy resolvedPolicy; - /* - * Determine the driver level based on our enum - */ + // Determine the driver RetryPolicy based on SD Cassandra's enum switch (policy) { case DEFAULT: resolvedPolicy = DefaultRetryPolicy.INSTANCE; @@ -60,6 +60,5 @@ public final class RetryPolicyResolver { } return resolvedPolicy; - } } diff --git a/spring-cql/src/main/java/org/springframework/cassandra/core/WriteOptions.java b/spring-cql/src/main/java/org/springframework/cassandra/core/WriteOptions.java index 5f361d76f..17f99451d 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/core/WriteOptions.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/core/WriteOptions.java @@ -1,12 +1,12 @@ /* * Copyright 2013-2016 the original author or authors - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,7 +20,7 @@ import java.util.concurrent.TimeUnit; /** * Cassandra Write Options are an extension to {@link QueryOptions} for write operations. {@link WriteOptions}allow * tuning of various query options on a per-request level. Only options that are set are applied to queries. - * + * * @author David Webb * @author Mark Paluch * @see QueryOptions @@ -36,7 +36,7 @@ public class WriteOptions extends QueryOptions { /** * Creates new {@link WriteOptions} for the given {@link ConsistencyLevel} and {@link RetryPolicy}. - * + * * @param consistencyLevel the consistency level, may be {@literal null}. * @param retryPolicy the retry policy, may be {@literal null}. */ @@ -46,7 +46,7 @@ public class WriteOptions extends QueryOptions { /** * Creates new {@link WriteOptions} for the given {@link ConsistencyLevel}, {@link RetryPolicy} and {@code ttl}. - * + * * @param consistencyLevel the consistency level, may be {@literal null}. * @param retryPolicy the retry policy, may be {@literal null}. * @param ttl the ttl, may be {@literal null}. @@ -75,7 +75,7 @@ public class WriteOptions extends QueryOptions { /** * Sets the time to live for write operations. - * + * * @param ttl the ttl to set. */ public void setTtl(Integer ttl) { @@ -94,6 +94,15 @@ public class WriteOptions extends QueryOptions { private WriteOptionsBuilder() {} + /* + * (non-Javadoc) + * @see org.springframework.cassandra.core.QueryOptions.QueryOptionsBuilder#consistencyLevel(com.datastax.driver.core.ConsistencyLevel) + */ + @Override + public WriteOptionsBuilder consistencyLevel(com.datastax.driver.core.ConsistencyLevel driverConsistencyLevel) { + return (WriteOptionsBuilder) super.consistencyLevel(driverConsistencyLevel); + } + /* * (non-Javadoc) * @see org.springframework.cassandra.core.QueryOptions.QueryOptionsBuilder#retryPolicy(org.springframework.cassandra.core.RetryPolicy) @@ -112,34 +121,7 @@ public class WriteOptions extends QueryOptions { return (WriteOptionsBuilder) super.retryPolicy(retryPolicy); } - /* - * (non-Javadoc) - * @see org.springframework.cassandra.core.QueryOptions.QueryOptionsBuilder#consistencyLevel(com.datastax.driver.core.ConsistencyLevel) - */ - @Override - public WriteOptionsBuilder consistencyLevel(com.datastax.driver.core.ConsistencyLevel driverConsistencyLevel) { - return (WriteOptionsBuilder) super.consistencyLevel(driverConsistencyLevel); - } - - /* - * (non-Javadoc) - * @see org.springframework.cassandra.core.QueryOptions.QueryOptionsBuilder#readTimeout(long) - */ - @Override - public WriteOptionsBuilder readTimeout(long readTimeout) { - return (WriteOptionsBuilder) super.readTimeout(readTimeout); - } - - /* - * (non-Javadoc) - * @see org.springframework.cassandra.core.QueryOptions.QueryOptionsBuilder#readTimeout(long, java.util.concurrent.TimeUnit) - */ - @Override - public WriteOptionsBuilder readTimeout(long readTimeout, TimeUnit timeUnit) { - return (WriteOptionsBuilder) super.readTimeout(readTimeout, timeUnit); - } - - /* + /* * (non-Javadoc) * @see org.springframework.cassandra.core.QueryOptions.QueryOptionsBuilder#fetchSize(int) */ @@ -148,7 +130,25 @@ public class WriteOptions extends QueryOptions { return (WriteOptionsBuilder) super.fetchSize(fetchSize); } - /* + /* + * (non-Javadoc) + * @see org.springframework.cassandra.core.QueryOptions.QueryOptionsBuilder#readTimeout(long) + */ + @Override + public WriteOptionsBuilder readTimeout(long readTimeout) { + return (WriteOptionsBuilder) super.readTimeout(readTimeout); + } + + /* + * (non-Javadoc) + * @see org.springframework.cassandra.core.QueryOptions.QueryOptionsBuilder#readTimeout(long, java.util.concurrent.TimeUnit) + */ + @Override + public WriteOptionsBuilder readTimeout(long readTimeout, TimeUnit timeUnit) { + return (WriteOptionsBuilder) super.readTimeout(readTimeout, timeUnit); + } + + /* * (non-Javadoc) * @see org.springframework.cassandra.core.QueryOptions.QueryOptionsBuilder#tracing(boolean) */ @@ -157,7 +157,7 @@ public class WriteOptions extends QueryOptions { return (WriteOptionsBuilder) super.tracing(tracing); } - /* + /* * (non-Javadoc) * @see org.springframework.cassandra.core.QueryOptions.QueryOptionsBuilder#withTracing() */ diff --git a/spring-cql/src/test/java/org/springframework/cassandra/core/CqlTemplateUnitTests.java b/spring-cql/src/test/java/org/springframework/cassandra/core/CqlTemplateUnitTests.java index c639bbc7d..48eb53036 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/core/CqlTemplateUnitTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/CqlTemplateUnitTests.java @@ -67,13 +67,13 @@ public class CqlTemplateUnitTests { private CqlTemplate template; - @Mock private Session mockSession; + @Mock private Insert mockInsert; @Mock private PreparedStatement mockPreparedStatement; - @Mock private Statement mockStatement; + @Mock private Session mockSession; - @Mock private Insert mockInsert; + @Mock private Statement mockStatement; @Mock private Update mockUpdate; @@ -449,8 +449,8 @@ public class CqlTemplateUnitTests { @Test public void addPreparedStatementOptionsShouldAddOurQueryOptions() { - QueryOptions queryOptions = QueryOptions.builder() // - .retryPolicy(RetryPolicy.FALLTHROUGH).build(); + QueryOptions queryOptions = QueryOptions.builder().retryPolicy(RetryPolicy.FALLTHROUGH).build(); + queryOptions.setConsistencyLevel(org.springframework.cassandra.core.ConsistencyLevel.LOCAL_QUOROM); template.addPreparedStatementOptions(mockPreparedStatement, queryOptions); @@ -465,7 +465,8 @@ public class CqlTemplateUnitTests { @Test public void addStatementQueryOptionsShouldAddDriverQueryOptions() { - QueryOptions queryOptions = QueryOptions.builder().consistencyLevel(ConsistencyLevel.EACH_QUORUM) // + QueryOptions queryOptions = QueryOptions.builder() + .consistencyLevel(ConsistencyLevel.EACH_QUORUM) // .retryPolicy(FallthroughRetryPolicy.INSTANCE) // .build(); @@ -481,9 +482,8 @@ public class CqlTemplateUnitTests { @Test public void addStatementQueryOptionsShouldAddOurQueryOptions() { - QueryOptions queryOptions = QueryOptions.builder() // - .retryPolicy(RetryPolicy.FALLTHROUGH) // - .build(); + QueryOptions queryOptions = QueryOptions.builder().retryPolicy(RetryPolicy.FALLTHROUGH).build(); + queryOptions.setConsistencyLevel(org.springframework.cassandra.core.ConsistencyLevel.LOCAL_QUOROM); template.addQueryOptions(mockStatement, queryOptions); @@ -512,8 +512,8 @@ public class CqlTemplateUnitTests { public void addStatementQueryOptionsShouldAddGenericQueryOptions() { QueryOptions queryOptions = QueryOptions.builder() // - .readTimeout(1, TimeUnit.MINUTES) // .fetchSize(10) // + .readTimeout(1, TimeUnit.MINUTES) // .withTracing() // .build(); diff --git a/spring-cql/src/test/java/org/springframework/cassandra/core/QueryOptionsUnitTests.java b/spring-cql/src/test/java/org/springframework/cassandra/core/QueryOptionsUnitTests.java index a8b09b876..149e865a3 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/core/QueryOptionsUnitTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/QueryOptionsUnitTests.java @@ -29,7 +29,7 @@ import com.datastax.driver.core.policies.LoggingRetryPolicy; /** * Unit tests for {@link QueryOptions}. - * + * * @author Mark Paluch */ public class QueryOptionsUnitTests { @@ -90,9 +90,7 @@ public class QueryOptionsUnitTests { */ @Test(expected = IllegalStateException.class) public void builderShouldRejectSettingOurAndDriverRetryPolicy() { - - QueryOptions.builder() // - .retryPolicy(RetryPolicy.DEFAULT).retryPolicy(FallthroughRetryPolicy.INSTANCE); + QueryOptions.builder().retryPolicy(RetryPolicy.DEFAULT).retryPolicy(FallthroughRetryPolicy.INSTANCE); } /** @@ -100,11 +98,7 @@ public class QueryOptionsUnitTests { */ @Test(expected = IllegalStateException.class) public void builderShouldRejectSettingDriverAndOurRetryPolicy() { - - QueryOptions.builder() // - .retryPolicy(FallthroughRetryPolicy.INSTANCE)// - .retryPolicy(RetryPolicy.DEFAULT); - + QueryOptions.builder().retryPolicy(FallthroughRetryPolicy.INSTANCE).retryPolicy(RetryPolicy.DEFAULT); } /** diff --git a/spring-cql/src/test/java/org/springframework/cassandra/core/WriteOptionsUnitTests.java b/spring-cql/src/test/java/org/springframework/cassandra/core/WriteOptionsUnitTests.java index 19cde2f12..2b7943c6c 100644 --- a/spring-cql/src/test/java/org/springframework/cassandra/core/WriteOptionsUnitTests.java +++ b/spring-cql/src/test/java/org/springframework/cassandra/core/WriteOptionsUnitTests.java @@ -26,7 +26,7 @@ import com.datastax.driver.core.policies.FallthroughRetryPolicy; /** * Unit tests for {@link WriteOptions}. - * + * * @author Mark Paluch */ public class WriteOptionsUnitTests { @@ -61,9 +61,7 @@ public class WriteOptionsUnitTests { @Test public void buildReadTimeoutOptionsWriteOptions() { - WriteOptions writeOptions = WriteOptions.builder() // - .readTimeout(1, TimeUnit.MINUTES)// - .build(); // + WriteOptions writeOptions = WriteOptions.builder().readTimeout(1, TimeUnit.MINUTES).build(); assertThat(writeOptions.getReadTimeout(), is(60L * 1000L)); assertThat(writeOptions.getFetchSize(), is(nullValue())); @@ -76,9 +74,7 @@ public class WriteOptionsUnitTests { @Test public void buildQueryOptionsWithDriverRetryPolicy() { - QueryOptions writeOptions = QueryOptions.builder() // - .retryPolicy(FallthroughRetryPolicy.INSTANCE) // - .build(); // + QueryOptions writeOptions = QueryOptions.builder().retryPolicy(FallthroughRetryPolicy.INSTANCE).build(); assertThat(writeOptions.getRetryPolicy(), is(nullValue())); assertThat(writeOptions.getDriverRetryPolicy(), @@ -91,9 +87,7 @@ public class WriteOptionsUnitTests { @Test public void buildQueryOptionsWithRetryPolicy() { - QueryOptions writeOptions = QueryOptions.builder() // - .retryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY) // - .build(); // + QueryOptions writeOptions = QueryOptions.builder().retryPolicy(RetryPolicy.DOWNGRADING_CONSISTENCY).build(); assertThat(writeOptions.getRetryPolicy(), is(RetryPolicy.DOWNGRADING_CONSISTENCY)); assertThat(writeOptions.getDriverRetryPolicy(), is(nullValue())); @@ -104,9 +98,7 @@ public class WriteOptionsUnitTests { */ @Test(expected = IllegalStateException.class) public void builderShouldRejectSettingOurAndDriverRetryPolicy() { - - WriteOptions.builder() // - .retryPolicy(RetryPolicy.DEFAULT).retryPolicy(FallthroughRetryPolicy.INSTANCE); + WriteOptions.builder().retryPolicy(RetryPolicy.DEFAULT).retryPolicy(FallthroughRetryPolicy.INSTANCE); } /** @@ -114,10 +106,6 @@ public class WriteOptionsUnitTests { */ @Test(expected = IllegalStateException.class) public void builderShouldRejectSettingDriverAndOurRetryPolicy() { - - WriteOptions.builder() // - .retryPolicy(FallthroughRetryPolicy.INSTANCE)// - .retryPolicy(RetryPolicy.DEFAULT); - + WriteOptions.builder().retryPolicy(FallthroughRetryPolicy.INSTANCE).retryPolicy(RetryPolicy.DEFAULT); } }