diff --git a/spring-cql/src/main/java/org/springframework/cassandra/config/PoolingOptionsFactoryBean.java b/spring-cql/src/main/java/org/springframework/cassandra/config/PoolingOptionsFactoryBean.java index d8fc45a78..f12108d6d 100644 --- a/spring-cql/src/main/java/org/springframework/cassandra/config/PoolingOptionsFactoryBean.java +++ b/spring-cql/src/main/java/org/springframework/cassandra/config/PoolingOptionsFactoryBean.java @@ -58,40 +58,40 @@ public void afterPropertiesSet() throws Exception { poolingOptions = new PoolingOptions(); - if (localMinSimultaneousRequests != null) { - poolingOptions.setMinSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, localMinSimultaneousRequests); + if (localMaxConnections != null) { + poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, localMaxConnections); } - + + if (localCoreConnections != null) { + poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, localCoreConnections); + } + if (localMaxSimultaneousRequests != null) { poolingOptions.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, localMaxSimultaneousRequests); } - - if (localCoreConnections != null) { - poolingOptions.setCoreConnectionsPerHost(HostDistance.LOCAL, localCoreConnections); + + if (localMinSimultaneousRequests != null) { + poolingOptions.setMinSimultaneousRequestsPerConnectionThreshold(HostDistance.LOCAL, localMinSimultaneousRequests); } - if (localMaxConnections != null) { - poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, localMaxConnections); + if (remoteMaxConnections != null) { + poolingOptions.setMaxConnectionsPerHost(HostDistance.REMOTE, remoteMaxConnections); } - - if (remoteMinSimultaneousRequests != null) { - poolingOptions.setMinSimultaneousRequestsPerConnectionThreshold(HostDistance.REMOTE, - remoteMinSimultaneousRequests); + + if (remoteCoreConnections != null) { + poolingOptions.setCoreConnectionsPerHost(HostDistance.REMOTE, remoteCoreConnections); } - + if (remoteMaxSimultaneousRequests != null) { poolingOptions.setMaxSimultaneousRequestsPerConnectionThreshold(HostDistance.REMOTE, remoteMaxSimultaneousRequests); } - - if (remoteCoreConnections != null) { - poolingOptions.setCoreConnectionsPerHost(HostDistance.REMOTE, remoteCoreConnections); - } - - if (remoteMaxConnections != null) { - poolingOptions.setMaxConnectionsPerHost(HostDistance.REMOTE, remoteMaxConnections); + + if (remoteMinSimultaneousRequests != null) { + poolingOptions.setMinSimultaneousRequestsPerConnectionThreshold(HostDistance.REMOTE, + remoteMinSimultaneousRequests); } - + } @Override diff --git a/spring-cql/src/test/java/org/springframework/cassandra/test/unit/config/PollingOptionsFactoryBeanTest.java b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/config/PollingOptionsFactoryBeanTest.java new file mode 100644 index 000000000..485ec4842 --- /dev/null +++ b/spring-cql/src/test/java/org/springframework/cassandra/test/unit/config/PollingOptionsFactoryBeanTest.java @@ -0,0 +1,56 @@ +/* + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cassandra.test.unit.config; + +import junit.framework.Assert; +import org.junit.Test; +import org.springframework.cassandra.config.PoolingOptionsFactoryBean; + +/** + * Pooling Options Factory Bean Test. + * https://jira.spring.io/browse/DATACASS-176 + * + * @author Sumit Kumar + */ +public class PollingOptionsFactoryBeanTest { + + /** + * The max values should be set before setting core values. + * Otherwise the core values will be compared with the default max values which is 8. + * Same for other min-max properties pairs. This test checks the same. + */ + @Test + public void testAfterPropertiesSet() { + boolean gotException = false; + PoolingOptionsFactoryBean factoryBean = new PoolingOptionsFactoryBean(); + factoryBean.setLocalMaxConnections(200); + factoryBean.setLocalCoreConnections(100); + factoryBean.setLocalMaxSimultaneousRequests(128); + factoryBean.setLocalMinSimultaneousRequests(101); + factoryBean.setRemoteMaxConnections(200); + factoryBean.setRemoteCoreConnections(100); + factoryBean.setRemoteMaxSimultaneousRequests(128); + factoryBean.setRemoteMinSimultaneousRequests(101); + try { + factoryBean.afterPropertiesSet(); + } catch (Exception e) { + e.printStackTrace(); + gotException = true; + } + Assert.assertFalse(gotException); + } + +}