Polish "Replace Couchbase's deprecated methods"

Closes gh-12655
pull/12784/head
Stephane Nicoll 7 years ago
parent 3236306e53
commit 6692301d51

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -106,18 +106,21 @@ public class CouchbaseAutoConfiguration {
if (timeouts.getConnect() != null) { if (timeouts.getConnect() != null) {
builder = builder.connectTimeout(timeouts.getConnect().toMillis()); builder = builder.connectTimeout(timeouts.getConnect().toMillis());
} }
builder = builder.keyValueServiceConfig(KeyValueServiceConfig.create(endpoints.getKeyValue())); builder = builder.keyValueServiceConfig(KeyValueServiceConfig.create(
endpoints.getKeyValue()));
if (timeouts.getKeyValue() != null) { if (timeouts.getKeyValue() != null) {
builder = builder.kvTimeout(timeouts.getKeyValue().toMillis()); builder = builder.kvTimeout(timeouts.getKeyValue().toMillis());
} }
int minQuery = endpoints.getQuery() != 1 ? endpoints.getQuery() : endpoints.getQueryservice().getMinEndpoints(); CouchbaseServiceConfig queryConfig = determineCouchbaseServiceConfig(
int maxQuery = endpoints.getQuery() != 1 ? endpoints.getQuery() : endpoints.getQueryservice().getMaxEndpoints(); endpoints.getQueryservice(), endpoints.getQuery());
builder = builder.queryServiceConfig(QueryServiceConfig.create(minQuery, maxQuery)); builder = builder.queryServiceConfig(QueryServiceConfig.create(
queryConfig.minEndpoints, queryConfig.maxEndpoints));
if (timeouts.getQuery() != null) { if (timeouts.getQuery() != null) {
int minView = endpoints.getView() != 1 ? endpoints.getView() : endpoints.getViewservice().getMinEndpoints(); CouchbaseServiceConfig viewConfig = determineCouchbaseServiceConfig(
int maxView = endpoints.getView() != 1 ? endpoints.getView() : endpoints.getViewservice().getMaxEndpoints(); endpoints.getViewservice(), endpoints.getView());
builder = builder.queryTimeout(timeouts.getQuery().toMillis()) builder = builder.queryTimeout(timeouts.getQuery().toMillis())
.viewServiceConfig(ViewServiceConfig.create(minView, maxView)); .viewServiceConfig(ViewServiceConfig.create(
viewConfig.minEndpoints, viewConfig.maxEndpoints));
} }
if (timeouts.getSocketConnect() != null) { if (timeouts.getSocketConnect() != null) {
builder = builder.socketConnectTimeout( builder = builder.socketConnectTimeout(
@ -139,6 +142,28 @@ public class CouchbaseAutoConfiguration {
return builder; return builder;
} }
private CouchbaseServiceConfig determineCouchbaseServiceConfig(
CouchbaseProperties.Endpoints.CouchbaseService couchbaseService,
Integer fallback) {
if (couchbaseService.getMinEndpoints() != 1
|| couchbaseService.getMaxEndpoints() != 1) {
return new CouchbaseServiceConfig(couchbaseService.getMinEndpoints(),
couchbaseService.getMaxEndpoints());
}
int endpoints = (fallback != null ? fallback : 1);
return new CouchbaseServiceConfig(endpoints, endpoints);
}
private static class CouchbaseServiceConfig {
private int minEndpoints;
private int maxEndpoints;
CouchbaseServiceConfig(int minEndpoints, int maxEndpoints) {
this.minEndpoints = minEndpoints;
this.maxEndpoints = maxEndpoints;
}
}
} }
/** /**

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -119,105 +119,73 @@ public class CouchbaseProperties {
private int keyValue = 1; private int keyValue = 1;
/** /**
* Number of sockets per node against the query (N1QL) service. * Query (N1QL) service configuration.
*/ */
private int query = 1; private final CouchbaseService queryservice = new CouchbaseService();
/** /**
* Number of sockets per node against the view service. * View service configuration.
*/ */
private int view = 1; private final CouchbaseService viewservice = new CouchbaseService();
/** /**
* Dynamic query service configuration. * Number of sockets per node against the query (N1QL) service.
*/ */
private Queryservice queryservice = new Queryservice(); private Integer query;
/** /**
* Dynamic view service configuration. * Number of sockets per node against the view service.
*/ */
private Viewservice viewservice = new Viewservice(); private Integer view;
public int getKeyValue() { public int getKeyValue() {
return this.keyValue; return this.keyValue;
} }
@Deprecated
public void setKeyValue(int keyValue) { public void setKeyValue(int keyValue) {
this.keyValue = keyValue; this.keyValue = keyValue;
} }
@Deprecated @Deprecated
@DeprecatedConfigurationProperty(replacement = "spring.couchbase.env.endpoints.queryservice") @DeprecatedConfigurationProperty(replacement = "spring.couchbase.env.endpoints.queryservice.max-endpoints")
public int getQuery() { public Integer getQuery() {
return this.query; return this.query;
} }
@Deprecated @Deprecated
public void setQuery(int query) { public void setQuery(Integer query) {
this.query = query; this.query = query;
} }
public CouchbaseService getQueryservice() {
return this.queryservice;
}
@Deprecated @Deprecated
@DeprecatedConfigurationProperty(replacement = "spring.couchbase.env.endpoints.viewservice") @DeprecatedConfigurationProperty(replacement = "spring.couchbase.env.endpoints.viewservice.max-endpoints")
public int getView() { public Integer getView() {
return this.view; return this.view;
} }
@Deprecated @Deprecated
public void setView(int view) { public void setView(Integer view) {
this.view = view; this.view = view;
} }
public Queryservice getQueryservice() { public CouchbaseService getViewservice() {
return this.queryservice;
}
public void setQueryservice(Queryservice queryservice) {
this.queryservice = queryservice;
}
public Viewservice getViewservice() {
return this.viewservice; return this.viewservice;
} }
public void setViewservice(Viewservice viewservice) { public static class CouchbaseService {
this.viewservice = viewservice;
}
public static class Queryservice {
/** /**
* Minimum Number of sockets per node against the query (N1QL) service. * Minimum number of sockets per node.
*/ */
private int minEndpoints = 1; 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. * Maximum number of sockets per node.
*/
private int minEndpoints = 1;
/**
* Maximum Number of sockets per node against the view service.
*/ */
private int maxEndpoints = 1; private int maxEndpoints = 1;
@ -236,7 +204,9 @@ public class CouchbaseProperties {
public void setMaxEndpoints(int maxEndpoints) { public void setMaxEndpoints(int maxEndpoints) {
this.maxEndpoints = maxEndpoints; this.maxEndpoints = maxEndpoints;
} }
} }
} }

@ -43,7 +43,6 @@ import static org.mockito.Mockito.mock;
* *
* @author Eddú Meléndez * @author Eddú Meléndez
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Yulin Qin
*/ */
public class CouchbaseAutoConfigurationTests { public class CouchbaseAutoConfigurationTests {
@ -85,53 +84,59 @@ public class CouchbaseAutoConfigurationTests {
} }
@Test @Test
public void customizeEnvEndpointsIfBothStaticAndDynamicAreSetThenStaticEndpointsTakePriorityForBackwardsCompatibility() { public void customizeEnvEndpoints() {
testCouchbaseEnv((env) -> { testCouchbaseEnv((env) -> {
assertThat(env.kvServiceConfig().minEndpoints()).isEqualTo(4); assertThat(env.kvServiceConfig().minEndpoints()).isEqualTo(2);
assertThat(env.kvServiceConfig().maxEndpoints()).isEqualTo(4); assertThat(env.kvServiceConfig().maxEndpoints()).isEqualTo(2);
assertThat(env.queryServiceConfig().minEndpoints()).isEqualTo(5); assertThat(env.queryServiceConfig().minEndpoints()).isEqualTo(3);
assertThat(env.queryServiceConfig().maxEndpoints()).isEqualTo(5); assertThat(env.queryServiceConfig().maxEndpoints()).isEqualTo(5);
assertThat(env.viewServiceConfig().minEndpoints()).isEqualTo(6); assertThat(env.viewServiceConfig().minEndpoints()).isEqualTo(4);
assertThat(env.viewServiceConfig().maxEndpoints()).isEqualTo(6); assertThat(env.viewServiceConfig().maxEndpoints()).isEqualTo(6);
}, "spring.couchbase.env.endpoints.keyValue=4", }, "spring.couchbase.env.endpoints.key-value=2",
"spring.couchbase.env.endpoints.queryservice.min-endpoints=2", "spring.couchbase.env.endpoints.queryservice.min-endpoints=3",
"spring.couchbase.env.endpoints.queryservice.max-endpoints=3", "spring.couchbase.env.endpoints.queryservice.max-endpoints=5",
"spring.couchbase.env.endpoints.query=5", "spring.couchbase.env.endpoints.viewservice.min-endpoints=4",
"spring.couchbase.env.endpoints.viewservice.min-endpoints=2", "spring.couchbase.env.endpoints.viewservice.max-endpoints=6");
"spring.couchbase.env.endpoints.viewservice.max-endpoints=3",
"spring.couchbase.env.endpoints.view=6");
} }
@Test @Test
public void customizeEnvEndpointsWhenQueryAndViewStillWork() { @Deprecated
public void customizeEnvEndpointsWithDeprecatedProperties() {
testCouchbaseEnv((env) -> { testCouchbaseEnv((env) -> {
assertThat(env.kvServiceConfig().minEndpoints()).isEqualTo(3); assertThat(env.queryServiceConfig().minEndpoints()).isEqualTo(3);
assertThat(env.kvServiceConfig().maxEndpoints()).isEqualTo(3); assertThat(env.queryServiceConfig().maxEndpoints()).isEqualTo(3);
assertThat(env.queryServiceConfig().minEndpoints()).isEqualTo(2); assertThat(env.viewServiceConfig().minEndpoints()).isEqualTo(4);
assertThat(env.queryServiceConfig().maxEndpoints()).isEqualTo(2); assertThat(env.viewServiceConfig().maxEndpoints()).isEqualTo(4);
assertThat(env.viewServiceConfig().minEndpoints()).isEqualTo(3); }, "spring.couchbase.env.endpoints.query=3",
assertThat(env.viewServiceConfig().maxEndpoints()).isEqualTo(3); "spring.couchbase.env.endpoints.view=4");
}, "spring.couchbase.env.endpoints.keyValue=3",
"spring.couchbase.env.endpoints.query=2",
"spring.couchbase.env.endpoints.view=3");
} }
@Test
public void customizeEnvEndpointsUsesNewInfrastructure() {
testCouchbaseEnv((env) -> {
assertThat(env.queryServiceConfig().minEndpoints()).isEqualTo(3);
assertThat(env.queryServiceConfig().maxEndpoints()).isEqualTo(5);
assertThat(env.viewServiceConfig().minEndpoints()).isEqualTo(4);
assertThat(env.viewServiceConfig().maxEndpoints()).isEqualTo(6);
}, "spring.couchbase.env.endpoints.query=33",
"spring.couchbase.env.endpoints.queryservice.min-endpoints=3",
"spring.couchbase.env.endpoints.queryservice.max-endpoints=5",
"spring.couchbase.env.endpoints.view=44",
"spring.couchbase.env.endpoints.viewservice.min-endpoints=4",
"spring.couchbase.env.endpoints.viewservice.max-endpoints=6");
}
@Test @Test
public void customizeEnvEndpointsIfOnlyDynamicEndpointsAreSet() { public void customizeEnvEndpointsUsesNewInfrastructureWithOnlyMax() {
testCouchbaseEnv((env) -> { testCouchbaseEnv((env) -> {
assertThat(env.kvServiceConfig().minEndpoints()).isEqualTo(4); assertThat(env.queryServiceConfig().minEndpoints()).isEqualTo(1);
assertThat(env.kvServiceConfig().maxEndpoints()).isEqualTo(4); assertThat(env.queryServiceConfig().maxEndpoints()).isEqualTo(5);
assertThat(env.queryServiceConfig().minEndpoints()).isEqualTo(2); assertThat(env.viewServiceConfig().minEndpoints()).isEqualTo(1);
assertThat(env.queryServiceConfig().maxEndpoints()).isEqualTo(3); assertThat(env.viewServiceConfig().maxEndpoints()).isEqualTo(6);
assertThat(env.viewServiceConfig().minEndpoints()).isEqualTo(2); }, "spring.couchbase.env.endpoints.query=33",
assertThat(env.viewServiceConfig().maxEndpoints()).isEqualTo(3); "spring.couchbase.env.endpoints.queryservice.max-endpoints=5",
}, "spring.couchbase.env.endpoints.keyValue=4", "spring.couchbase.env.endpoints.view=44",
"spring.couchbase.env.endpoints.queryservice.min-endpoints=2", "spring.couchbase.env.endpoints.viewservice.max-endpoints=6");
"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 @Test

@ -573,8 +573,10 @@ content into your application. Rather, pick only the properties that you need.
spring.couchbase.bucket.name=default # Name of the bucket to connect to. spring.couchbase.bucket.name=default # Name of the bucket to connect to.
spring.couchbase.bucket.password= # Password of the bucket. spring.couchbase.bucket.password= # Password of the bucket.
spring.couchbase.env.endpoints.key-value=1 # Number of sockets per node against the key/value service. spring.couchbase.env.endpoints.key-value=1 # Number of sockets per node against the key/value service.
spring.couchbase.env.endpoints.query=1 # Number of sockets per node against the query (N1QL) service. spring.couchbase.env.endpoints.queryservice.min-endpoints=1 # Minimum number of sockets per node.
spring.couchbase.env.endpoints.view=1 # Number of sockets per node against the view service. spring.couchbase.env.endpoints.queryservice.max-endpoints=1 # Maximum number of sockets per node.
spring.couchbase.env.endpoints.viewservice.min-endpoints=1 # Minimum number of sockets per node.
spring.couchbase.env.endpoints.viewservice.max-endpoints=1 # Maximum number of sockets per node.
spring.couchbase.env.ssl.enabled= # Whether to enable SSL support. Enabled automatically if a "keyStore" is provided unless specified otherwise. spring.couchbase.env.ssl.enabled= # Whether to enable SSL support. Enabled automatically if a "keyStore" is provided unless specified otherwise.
spring.couchbase.env.ssl.key-store= # Path to the JVM key store that holds the certificates. spring.couchbase.env.ssl.key-store= # Path to the JVM key store that holds the certificates.
spring.couchbase.env.ssl.key-store-password= # Password used to access the key store. spring.couchbase.env.ssl.key-store-password= # Password used to access the key store.

Loading…
Cancel
Save