Replace Couchbase's deprecated methods

See gh-12655
pull/12784/head
Yulin Qin 7 years ago committed by Stephane Nicoll
parent 92d9479765
commit 3236306e53

@ -16,6 +16,9 @@
package org.springframework.boot.autoconfigure.couchbase;
import com.couchbase.client.core.env.KeyValueServiceConfig;
import com.couchbase.client.core.env.QueryServiceConfig;
import com.couchbase.client.core.env.ViewServiceConfig;
import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.CouchbaseBucket;
@ -40,6 +43,7 @@ import org.springframework.context.annotation.Primary;
*
* @author Eddú Meléndez
* @author Stephane Nicoll
* @author Yulin Qin
* @since 1.4.0
*/
@Configuration
@ -102,14 +106,18 @@ public class CouchbaseAutoConfiguration {
if (timeouts.getConnect() != null) {
builder = builder.connectTimeout(timeouts.getConnect().toMillis());
}
builder = builder.kvEndpoints(endpoints.getKeyValue());
builder = builder.keyValueServiceConfig(KeyValueServiceConfig.create(endpoints.getKeyValue()));
if (timeouts.getKeyValue() != null) {
builder = builder.kvTimeout(timeouts.getKeyValue().toMillis());
}
builder = builder.queryEndpoints(endpoints.getQuery());
int minQuery = endpoints.getQuery() != 1 ? endpoints.getQuery() : endpoints.getQueryservice().getMinEndpoints();
int maxQuery = endpoints.getQuery() != 1 ? endpoints.getQuery() : endpoints.getQueryservice().getMaxEndpoints();
builder = builder.queryServiceConfig(QueryServiceConfig.create(minQuery, maxQuery));
if (timeouts.getQuery() != null) {
int minView = endpoints.getView() != 1 ? endpoints.getView() : endpoints.getViewservice().getMinEndpoints();
int maxView = endpoints.getView() != 1 ? endpoints.getView() : endpoints.getViewservice().getMaxEndpoints();
builder = builder.queryTimeout(timeouts.getQuery().toMillis())
.viewEndpoints(endpoints.getView());
.viewServiceConfig(ViewServiceConfig.create(minView, maxView));
}
if (timeouts.getSocketConnect() != null) {
builder = builder.socketConnectTimeout(

@ -20,6 +20,7 @@ import java.time.Duration;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
import org.springframework.util.StringUtils;
/**
@ -27,6 +28,7 @@ import org.springframework.util.StringUtils;
*
* @author Eddú Meléndez
* @author Stephane Nicoll
* @author Yulin Qin
* @since 1.4.0
*/
@ConfigurationProperties(prefix = "spring.couchbase")
@ -126,6 +128,16 @@ public class CouchbaseProperties {
*/
private int view = 1;
/**
* Dynamic query service configuration.
*/
private Queryservice queryservice = new Queryservice();
/**
* Dynamic view service configuration.
*/
private Viewservice viewservice = new Viewservice();
public int getKeyValue() {
return this.keyValue;
}
@ -134,24 +146,100 @@ public class CouchbaseProperties {
this.keyValue = keyValue;
}
@Deprecated
@DeprecatedConfigurationProperty(replacement = "spring.couchbase.env.endpoints.queryservice")
public int getQuery() {
return this.query;
}
@Deprecated
public void setQuery(int query) {
this.query = query;
}
@Deprecated
@DeprecatedConfigurationProperty(replacement = "spring.couchbase.env.endpoints.viewservice")
public int getView() {
return this.view;
}
@Deprecated
public void setView(int view) {
this.view = view;
}
public Queryservice getQueryservice() {
return this.queryservice;
}
public void setQueryservice(Queryservice queryservice) {
this.queryservice = queryservice;
}
public Viewservice getViewservice() {
return this.viewservice;
}
public void setViewservice(Viewservice viewservice) {
this.viewservice = viewservice;
}
public static class Queryservice {
/**
* Minimum Number of sockets per node against the query (N1QL) service.
*/
private int minEndpoints = 1;
/**
* Maximum Number of sockets per node against the query (N1QL) service.
*/
private int maxEndpoints = 1;
public int getMinEndpoints() {
return this.minEndpoints;
}
public void setMinEndpoints(int minEndpoints) {
this.minEndpoints = minEndpoints;
}
public int getMaxEndpoints() {
return this.maxEndpoints;
}
public void setMaxEndpoints(int maxEndpoints) {
this.maxEndpoints = maxEndpoints;
}
}
public static class Viewservice {
/**
* Minimum Number of sockets per node against the view service.
*/
private int minEndpoints = 1;
/**
* Maximum Number of sockets per node against the view service.
*/
private int maxEndpoints = 1;
public int getMinEndpoints() {
return this.minEndpoints;
}
public void setMinEndpoints(int minEndpoints) {
this.minEndpoints = minEndpoints;
}
public int getMaxEndpoints() {
return this.maxEndpoints;
}
public void setMaxEndpoints(int maxEndpoints) {
this.maxEndpoints = maxEndpoints;
}
}
}
public static class Ssl {
/**

@ -43,6 +43,7 @@ import static org.mockito.Mockito.mock;
*
* @author Eddú Meléndez
* @author Stephane Nicoll
* @author Yulin Qin
*/
public class CouchbaseAutoConfigurationTests {
@ -84,16 +85,55 @@ public class CouchbaseAutoConfigurationTests {
}
@Test
public void customizeEnvEndpoints() {
public void customizeEnvEndpointsIfBothStaticAndDynamicAreSetThenStaticEndpointsTakePriorityForBackwardsCompatibility() {
testCouchbaseEnv((env) -> {
assertThat(env.kvEndpoints()).isEqualTo(4);
assertThat(env.queryEndpoints()).isEqualTo(5);
assertThat(env.viewEndpoints()).isEqualTo(6);
assertThat(env.kvServiceConfig().minEndpoints()).isEqualTo(4);
assertThat(env.kvServiceConfig().maxEndpoints()).isEqualTo(4);
assertThat(env.queryServiceConfig().minEndpoints()).isEqualTo(5);
assertThat(env.queryServiceConfig().maxEndpoints()).isEqualTo(5);
assertThat(env.viewServiceConfig().minEndpoints()).isEqualTo(6);
assertThat(env.viewServiceConfig().maxEndpoints()).isEqualTo(6);
}, "spring.couchbase.env.endpoints.keyValue=4",
"spring.couchbase.env.endpoints.queryservice.min-endpoints=2",
"spring.couchbase.env.endpoints.queryservice.max-endpoints=3",
"spring.couchbase.env.endpoints.query=5",
"spring.couchbase.env.endpoints.viewservice.min-endpoints=2",
"spring.couchbase.env.endpoints.viewservice.max-endpoints=3",
"spring.couchbase.env.endpoints.view=6");
}
@Test
public void customizeEnvEndpointsWhenQueryAndViewStillWork() {
testCouchbaseEnv((env) -> {
assertThat(env.kvServiceConfig().minEndpoints()).isEqualTo(3);
assertThat(env.kvServiceConfig().maxEndpoints()).isEqualTo(3);
assertThat(env.queryServiceConfig().minEndpoints()).isEqualTo(2);
assertThat(env.queryServiceConfig().maxEndpoints()).isEqualTo(2);
assertThat(env.viewServiceConfig().minEndpoints()).isEqualTo(3);
assertThat(env.viewServiceConfig().maxEndpoints()).isEqualTo(3);
}, "spring.couchbase.env.endpoints.keyValue=3",
"spring.couchbase.env.endpoints.query=2",
"spring.couchbase.env.endpoints.view=3");
}
@Test
public void customizeEnvEndpointsIfOnlyDynamicEndpointsAreSet() {
testCouchbaseEnv((env) -> {
assertThat(env.kvServiceConfig().minEndpoints()).isEqualTo(4);
assertThat(env.kvServiceConfig().maxEndpoints()).isEqualTo(4);
assertThat(env.queryServiceConfig().minEndpoints()).isEqualTo(2);
assertThat(env.queryServiceConfig().maxEndpoints()).isEqualTo(3);
assertThat(env.viewServiceConfig().minEndpoints()).isEqualTo(2);
assertThat(env.viewServiceConfig().maxEndpoints()).isEqualTo(3);
}, "spring.couchbase.env.endpoints.keyValue=4",
"spring.couchbase.env.endpoints.queryservice.min-endpoints=2",
"spring.couchbase.env.endpoints.queryservice.max-endpoints=3",
"spring.couchbase.env.endpoints.viewservice.min-endpoints=2",
"spring.couchbase.env.endpoints.viewservice.max-endpoints=3");
}
@Test
public void customizeEnvTimeouts() {
testCouchbaseEnv((env) -> {

Loading…
Cancel
Save