Skip to content

Commit 13732a6

Browse files
committed
Add compatibility with Couchbase 5.5
Upgrade Couchbase Client library to 2.6.1
1 parent 9e23334 commit 13732a6

File tree

4 files changed

+54
-23
lines changed

4 files changed

+54
-23
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<url>https://github.com/differentway/testcontainers-java-module-couchbase</url>
2121

2222
<properties>
23-
<couchbase.client.version>2.5.8</couchbase.client.version>
23+
<couchbase.client.version>2.6.1</couchbase.client.version>
2424
</properties>
2525

2626
<licenses>

src/main/java/com/couchbase/client/core/config/DefaultCouchbaseBucketConfig.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.couchbase.client.core.logging.CouchbaseLoggerFactory;
2020
import com.couchbase.client.core.service.ServiceType;
2121
import com.couchbase.client.core.utils.NetworkAddress;
22+
import com.couchbase.client.deps.com.fasterxml.jackson.annotation.JacksonInject;
2223
import com.couchbase.client.deps.com.fasterxml.jackson.annotation.JsonCreator;
2324
import com.couchbase.client.deps.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
2425
import com.couchbase.client.deps.com.fasterxml.jackson.annotation.JsonProperty;
@@ -27,6 +28,7 @@
2728
import java.util.*;
2829
import java.util.stream.Collectors;
2930

31+
import static com.couchbase.client.core.logging.RedactableArgument.meta;
3032
import static com.couchbase.client.core.logging.RedactableArgument.system;
3133

3234
/**
@@ -50,25 +52,27 @@ public class DefaultCouchbaseBucketConfig extends AbstractBucketConfig implement
5052
/**
5153
* Creates a new {@link CouchbaseBucketConfig}.
5254
*
53-
* @param rev the revision of the config.
54-
* @param name the name of the bucket.
55-
* @param uri the URI for this bucket.
56-
* @param streamingUri the streaming URI for this bucket.
55+
* @param rev the revision of the config.
56+
* @param name the name of the bucket.
57+
* @param uri the URI for this bucket.
58+
* @param streamingUri the streaming URI for this bucket.
5759
* @param partitionInfo partition info for this bucket.
58-
* @param nodeInfos related node information.
59-
* @param portInfos port info for the nodes, including services.
60+
* @param nodeInfos related node information.
61+
* @param portInfos port info for the nodes, including services.
6062
*/
6163
@JsonCreator
6264
public DefaultCouchbaseBucketConfig(
6365
@JsonProperty("rev") long rev,
66+
@JsonProperty("uuid") String uuid,
6467
@JsonProperty("name") String name,
6568
@JsonProperty("uri") String uri,
6669
@JsonProperty("streamingUri") String streamingUri,
6770
@JsonProperty("vBucketServerMap") CouchbasePartitionInfo partitionInfo,
6871
@JsonProperty("nodes") List<NodeInfo> nodeInfos,
6972
@JsonProperty("nodesExt") List<PortInfo> portInfos,
70-
@JsonProperty("bucketCapabilities") List<BucketCapabilities> bucketCapabilities) {
71-
super(name, BucketNodeLocator.VBUCKET, uri, streamingUri, nodeInfos, getPortInfos(portInfos), bucketCapabilities);
73+
@JsonProperty("bucketCapabilities") List<BucketCapabilities> bucketCapabilities,
74+
@JacksonInject("origin") NetworkAddress origin) {
75+
super(uuid, name, BucketNodeLocator.VBUCKET, uri, streamingUri, nodeInfos, getPortInfos(portInfos), bucketCapabilities, origin);
7276
this.partitionInfo = partitionInfo;
7377
this.tainted = partitionInfo.tainted();
7478
List<NodeInfo> extendedNodeInfos = this.nodes(); // includes ports for SSL services
@@ -92,12 +96,12 @@ private static List<PortInfo> getPortInfos(List<PortInfo> portInfos) {
9296
/**
9397
* Pre-computes a set of nodes that have primary partitions active.
9498
*
95-
* @param nodeInfos the list of nodes.
99+
* @param nodeInfos the list of nodes.
96100
* @param partitions the partitions.
97101
* @return a set containing the addresses of nodes with primary partitions.
98102
*/
99103
private static Set<NetworkAddress> buildNodesWithPrimaryPartitions(final List<NodeInfo> nodeInfos,
100-
final List<Partition> partitions) {
104+
final List<Partition> partitions) {
101105
Set<NetworkAddress> nodes = new HashSet<NetworkAddress>(nodeInfos.size());
102106
for (Partition partition : partitions) {
103107
int index = partition.master();
@@ -111,7 +115,7 @@ private static Set<NetworkAddress> buildNodesWithPrimaryPartitions(final List<No
111115
/**
112116
* Helper method to reference the partition hosts from the raw node list.
113117
*
114-
* @param nodeInfos the node infos.
118+
* @param nodeInfos the node infos.
115119
* @param partitionInfo the partition info.
116120
* @return a ordered reference list for the partition hosts.
117121
*/
@@ -251,13 +255,13 @@ public boolean ephemeral() {
251255
@Override
252256
public String toString() {
253257
return "DefaultCouchbaseBucketConfig{"
254-
+ "name='" + name() + '\''
255-
+ ", locator=" + locator()
256-
+ ", uri='" + uri() + '\''
257-
+ ", streamingUri='" + streamingUri() + '\''
258-
+ ", nodeInfo=" + nodes()
259-
+ ", partitionInfo=" + partitionInfo
260-
+ ", tainted=" + tainted
261-
+ ", rev=" + rev + '}';
258+
+ "name='" + name() + '\''
259+
+ ", locator=" + locator()
260+
+ ", uri='" + uri() + '\''
261+
+ ", streamingUri='" + streamingUri() + '\''
262+
+ ", nodeInfo=" + nodes()
263+
+ ", partitionInfo=" + partitionInfo
264+
+ ", tainted=" + tainted
265+
+ ", rev=" + rev + '}';
262266
}
263267
}

src/main/java/org/testcontainers/couchbase/CouchbaseContainer.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.jetbrains.annotations.NotNull;
3434
import org.testcontainers.containers.GenericContainer;
3535
import org.testcontainers.containers.wait.HttpWaitStrategy;
36+
import org.testcontainers.shaded.com.google.common.collect.Lists;
3637

3738
import java.io.DataOutputStream;
3839
import java.io.IOException;
@@ -270,7 +271,9 @@ public void createBucket(BucketSettings bucketSetting, boolean primaryIndex) {
270271
logger().debug("Creating bucket admin user '{}'", bucketSetting.name());
271272
UserSettings userSettings = UserSettings.build()
272273
.password(bucketSetting.password())
273-
.roles(Collections.singletonList(new UserRole("bucket_admin", bucketSetting.name())));
274+
.roles(Lists.newArrayList(
275+
new UserRole("bucket_admin", bucketSetting.name()),
276+
new UserRole("bucket_full_access", bucketSetting.name())));
274277
try {
275278
clusterManager.upsertUser(AuthDomain.LOCAL, bucketSetting.name(), userSettings);
276279
} catch (Exception e) {
@@ -335,7 +338,7 @@ private DefaultCouchbaseEnvironment createCouchbaseEnvironment() {
335338
}
336339

337340
private PortInfo createPortInfo() {
338-
DefaultPortInfo portInfo = new DefaultPortInfo(new HashMap<>(), null);
341+
DefaultPortInfo portInfo = new DefaultPortInfo(new HashMap<>(), null, null);
339342
try {
340343
portInfo.ports().put(ServiceType.VIEW, getMappedPort(VIEW_PORT));
341344
portInfo.ports().put(ServiceType.CONFIG, getMappedPort(CONFIG_PORT));

src/test/java/org/testcontainers/couchbase/CouchbaseContainerTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,27 @@
44
import com.couchbase.client.java.query.N1qlQuery;
55
import com.couchbase.client.java.query.N1qlQueryResult;
66
import com.couchbase.client.java.query.N1qlQueryRow;
7+
import com.couchbase.client.java.query.util.IndexInfo;
78
import org.junit.Assert;
89
import org.junit.Test;
910

1011
import java.util.List;
12+
import java.util.stream.Collectors;
13+
14+
import static java.lang.String.format;
1115

1216
/**
1317
* @author ctayeb
14-
* created on 18/06/2017
18+
* created on 18/06/2017
1519
*/
1620
public class CouchbaseContainerTest extends AbstractCouchbaseTest {
1721

1822
private static final String ID = "toto";
1923

2024
private static final String DOCUMENT = "{\"name\":\"toto\"}";
2125

26+
private static final String INDEX_NAME = "name";
27+
2228
@Test
2329
public void should_insert_document() {
2430
RawJsonDocument expected = RawJsonDocument.create(ID, DOCUMENT);
@@ -38,4 +44,22 @@ public void should_execute_n1ql() {
3844
Assert.assertEquals(1, n1qlQueryRows.size());
3945
Assert.assertEquals(DOCUMENT, n1qlQueryRows.get(0).value().get(TEST_BUCKET).toString());
4046
}
47+
48+
@Test
49+
public void should_create_index() {
50+
// Given a primary index request
51+
String request = format("CREATE INDEX `%s` ON `%s`(`%s`)", INDEX_NAME, TEST_BUCKET, INDEX_NAME);
52+
53+
// When we execute the query
54+
getBucket().query(N1qlQuery.simple(request));
55+
56+
// Then the index should be Created
57+
List<IndexInfo> indexInfos = getBucket().bucketManager().listN1qlIndexes().stream()
58+
.filter(indexInfo -> indexInfo.name().equals(INDEX_NAME))
59+
.collect(Collectors.toList());
60+
Assert.assertEquals(1, indexInfos.size());
61+
IndexInfo indexInfo = indexInfos.get(0);
62+
Assert.assertEquals(INDEX_NAME, indexInfo.name());
63+
Assert.assertEquals(format("`%s`", INDEX_NAME), indexInfo.indexKey().get(0));
64+
}
4165
}

0 commit comments

Comments
 (0)