Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
3236306e
Commit
3236306e
authored
Mar 27, 2018
by
Yulin Qin
Committed by
Stephane Nicoll
Apr 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace Couchbase's deprecated methods
See gh-12655
parent
92d94797
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
143 additions
and
7 deletions
+143
-7
CouchbaseAutoConfiguration.java
...t/autoconfigure/couchbase/CouchbaseAutoConfiguration.java
+11
-3
CouchbaseProperties.java
...ork/boot/autoconfigure/couchbase/CouchbaseProperties.java
+88
-0
CouchbaseAutoConfigurationTests.java
...oconfigure/couchbase/CouchbaseAutoConfigurationTests.java
+44
-4
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java
View file @
3236306e
...
@@ -16,6 +16,9 @@
...
@@ -16,6 +16,9 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
couchbase
;
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.Bucket
;
import
com.couchbase.client.java.Cluster
;
import
com.couchbase.client.java.Cluster
;
import
com.couchbase.client.java.CouchbaseBucket
;
import
com.couchbase.client.java.CouchbaseBucket
;
...
@@ -40,6 +43,7 @@ import org.springframework.context.annotation.Primary;
...
@@ -40,6 +43,7 @@ import org.springframework.context.annotation.Primary;
*
*
* @author Eddú Meléndez
* @author Eddú Meléndez
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Yulin Qin
* @since 1.4.0
* @since 1.4.0
*/
*/
@Configuration
@Configuration
...
@@ -102,14 +106,18 @@ public class CouchbaseAutoConfiguration {
...
@@ -102,14 +106,18 @@ 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
.
k
vEndpoints
(
endpoints
.
getKeyValue
(
));
builder
=
builder
.
k
eyValueServiceConfig
(
KeyValueServiceConfig
.
create
(
endpoints
.
getKeyValue
()
));
if
(
timeouts
.
getKeyValue
()
!=
null
)
{
if
(
timeouts
.
getKeyValue
()
!=
null
)
{
builder
=
builder
.
kvTimeout
(
timeouts
.
getKeyValue
().
toMillis
());
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
)
{
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
())
builder
=
builder
.
queryTimeout
(
timeouts
.
getQuery
().
toMillis
())
.
view
Endpoints
(
endpoints
.
getView
(
));
.
view
ServiceConfig
(
ViewServiceConfig
.
create
(
minView
,
maxView
));
}
}
if
(
timeouts
.
getSocketConnect
()
!=
null
)
{
if
(
timeouts
.
getSocketConnect
()
!=
null
)
{
builder
=
builder
.
socketConnectTimeout
(
builder
=
builder
.
socketConnectTimeout
(
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseProperties.java
View file @
3236306e
...
@@ -20,6 +20,7 @@ import java.time.Duration;
...
@@ -20,6 +20,7 @@ import java.time.Duration;
import
java.util.List
;
import
java.util.List
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.DeprecatedConfigurationProperty
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
/**
/**
...
@@ -27,6 +28,7 @@ import org.springframework.util.StringUtils;
...
@@ -27,6 +28,7 @@ import org.springframework.util.StringUtils;
*
*
* @author Eddú Meléndez
* @author Eddú Meléndez
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Yulin Qin
* @since 1.4.0
* @since 1.4.0
*/
*/
@ConfigurationProperties
(
prefix
=
"spring.couchbase"
)
@ConfigurationProperties
(
prefix
=
"spring.couchbase"
)
...
@@ -126,6 +128,16 @@ public class CouchbaseProperties {
...
@@ -126,6 +128,16 @@ public class CouchbaseProperties {
*/
*/
private
int
view
=
1
;
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
()
{
public
int
getKeyValue
()
{
return
this
.
keyValue
;
return
this
.
keyValue
;
}
}
...
@@ -134,24 +146,100 @@ public class CouchbaseProperties {
...
@@ -134,24 +146,100 @@ public class CouchbaseProperties {
this
.
keyValue
=
keyValue
;
this
.
keyValue
=
keyValue
;
}
}
@Deprecated
@DeprecatedConfigurationProperty
(
replacement
=
"spring.couchbase.env.endpoints.queryservice"
)
public
int
getQuery
()
{
public
int
getQuery
()
{
return
this
.
query
;
return
this
.
query
;
}
}
@Deprecated
public
void
setQuery
(
int
query
)
{
public
void
setQuery
(
int
query
)
{
this
.
query
=
query
;
this
.
query
=
query
;
}
}
@Deprecated
@DeprecatedConfigurationProperty
(
replacement
=
"spring.couchbase.env.endpoints.viewservice"
)
public
int
getView
()
{
public
int
getView
()
{
return
this
.
view
;
return
this
.
view
;
}
}
@Deprecated
public
void
setView
(
int
view
)
{
public
void
setView
(
int
view
)
{
this
.
view
=
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
{
public
static
class
Ssl
{
/**
/**
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java
View file @
3236306e
...
@@ -43,6 +43,7 @@ import static org.mockito.Mockito.mock;
...
@@ -43,6 +43,7 @@ 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
{
...
@@ -84,16 +85,55 @@ public class CouchbaseAutoConfigurationTests {
...
@@ -84,16 +85,55 @@ public class CouchbaseAutoConfigurationTests {
}
}
@Test
@Test
public
void
customizeEnvEndpoints
()
{
public
void
customizeEnvEndpoints
IfBothStaticAndDynamicAreSetThenStaticEndpointsTakePriorityForBackwardsCompatibility
()
{
testCouchbaseEnv
((
env
)
->
{
testCouchbaseEnv
((
env
)
->
{
assertThat
(
env
.
kvEndpoints
()).
isEqualTo
(
4
);
assertThat
(
env
.
kvServiceConfig
().
minEndpoints
()).
isEqualTo
(
4
);
assertThat
(
env
.
queryEndpoints
()).
isEqualTo
(
5
);
assertThat
(
env
.
kvServiceConfig
().
maxEndpoints
()).
isEqualTo
(
4
);
assertThat
(
env
.
viewEndpoints
()).
isEqualTo
(
6
);
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.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.query=5"
,
"spring.couchbase.env.endpoints.viewservice.min-endpoints=2"
,
"spring.couchbase.env.endpoints.viewservice.max-endpoints=3"
,
"spring.couchbase.env.endpoints.view=6"
);
"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
@Test
public
void
customizeEnvTimeouts
()
{
public
void
customizeEnvTimeouts
()
{
testCouchbaseEnv
((
env
)
->
{
testCouchbaseEnv
((
env
)
->
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment