Skip to content

Commit ce91938

Browse files
authored
DEVADV-1516: Update the java SDK version (#4)
- adds maven's target directory into .gitignore, removes associated files from repository (those are for cacing anyway and will be regenerated by maven) - Lowers memory quotas - reconfigures CI * Sets minimum durability level for the bucket * durability level * action syntax error * Updates the SDK, adds maven configuration for tests * Updates the couchbase server to 7.0.3 * Updates couchbase java sdk to 3.2.4 * Adds testing matrix for Java 8, 11, and 17
1 parent 0b2faae commit ce91938

File tree

7 files changed

+119
-15
lines changed

7 files changed

+119
-15
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Run maven tests using couchbase service container
2+
on:
3+
push:
4+
schedule:
5+
- cron: "0 11 * * 0"
6+
jobs:
7+
tests:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
java-version: ['8', '11', '17']
12+
steps:
13+
- name: Update repositories
14+
run: |
15+
apt update || echo "apt-update failed" # && apt -y upgrade
16+
- name: Set up JDK 11
17+
uses: actions/setup-java@v2
18+
with:
19+
java-version: ${{ matrix.java-version }}
20+
distribution: 'adopt'
21+
- name: Setup couchbase
22+
run: |
23+
apt install -y iputils-ping || echo "apt-install failed"
24+
ping -c 1 couchbase && (
25+
apt install -y socat
26+
socat TCP-LISTEN:8091,fork TCP:couchbase:8091 &
27+
socat TCP-LISTEN:8092,fork TCP:couchbase:8092 &
28+
socat TCP-LISTEN:8093,fork TCP:couchbase:8093 &
29+
socat TCP-LISTEN:8094,fork TCP:couchbase:8094 &
30+
socat TCP-LISTEN:8095,fork TCP:couchbase:8095 &
31+
socat TCP-LISTEN:8096,fork TCP:couchbase:8096 &
32+
socat TCP-LISTEN:9140,fork TCP:couchbase:9140 &
33+
socat TCP-LISTEN:11210,fork TCP:couchbase:11210 &
34+
socat TCP-LISTEN:11211,fork TCP:couchbase:11211 &
35+
socat TCP-LISTEN:11207,fork TCP:couchbase:11207 &
36+
socat TCP-LISTEN:18091,fork TCP:couchbase:18091 &
37+
socat TCP-LISTEN:18092,fork TCP:couchbase:18092 &
38+
socat TCP-LISTEN:18093,fork TCP:couchbase:18093 &
39+
socat TCP-LISTEN:18094,fork TCP:couchbase:18094 &
40+
socat TCP-LISTEN:18095,fork TCP:couchbase:18095 &
41+
socat TCP-LISTEN:18096,fork TCP:couchbase:18096 &
42+
) && echo "Initialized couchbase port forwarding" || echo "ping couchbase failed, not forwarding ports"
43+
printf "Waiting for CB startup..."
44+
wget -O /dev/null http://localhost:8091/ && echo "DONE" || (echo "FAIL" && panic)
45+
curl -v -X POST http://localhost:8091/node/controller/setupServices -d 'services=kv%2Cn1ql%2Cindex'
46+
curl -v -X POST http://localhost:8091/pools/default -d 'memoryQuota=256' -d 'indexMemoryQuota=256'
47+
curl -u Administrator:password -v -X POST http://localhost:8091/settings/web -d 'password=password&username=Administrator&port=SAME'
48+
curl -v -X POST http://localhost:8091/pools/default/buckets \
49+
-u Administrator:password \
50+
-d name=user_profile \
51+
-d bucketType=couchbase\
52+
-d ramQuotaMB=1024 \
53+
-d durabilityMinLevel=majorityAndPersistActive
54+
curl -u Administrator:password -v -X POST http://localhost:8091/settings/indexes -d 'storageMode=memory_optimized'
55+
curl -u Administrator:password -v -X GET http://localhost:8091/pools/default | jq '.' | grep hostname
56+
- uses: actions/checkout@v2
57+
- name: Build with Maven
58+
run: mvn --batch-mode --update-snapshots -B package --file pom.xml verify -Dspring.couchbase.bootstrap-host=couchbase
59+
services:
60+
couchbase:
61+
image: couchbase:enterprise-7.0.3
62+
ports:
63+
- 8091:8091
64+
- 8092:8092
65+
- 8093:8093
66+
- 8094:8094
67+
- 8095:8095
68+
- 8096:8096
69+
- 9140:9140
70+
- 11210:11210
71+
- 11211:11211
72+
- 11207:11207
73+
- 18091:18091
74+
- 18092:18092
75+
- 18093:18093
76+
- 18094:18094
77+
- 18095:18095
78+
- 18096:18096

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# maven target directory
2+
target/
13
# Compiled class file
24
*.class
35

@@ -31,3 +33,12 @@ hs_err_pid*
3133
*.swp
3234

3335
target/surefire-reports/
36+
37+
# eclipse
38+
.classpath
39+
.factorypath
40+
.project
41+
.settings
42+
43+
# tags
44+
tags

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<maven.compiler.target>8</maven.compiler.target>
2323
<swagger.version>3.0.0</swagger.version>
2424
<springweb.version>3.0.0</springweb.version>
25-
<couchbase.version>3.1.5</couchbase.version>
25+
<couchbase.version>3.2.4</couchbase.version>
2626
<junit.version>4.13.1</junit.version>
2727
<mavensurefire.version>3.0.0-M5</mavensurefire.version>
2828
</properties>
@@ -108,4 +108,4 @@
108108
</plugins>
109109
</build>
110110

111-
</project>
111+
</project>

src/main/java/org/couchbase/quickstart/configs/CouchbaseConfig.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.couchbase.quickstart.configs;
22

33
import com.couchbase.client.core.error.BucketExistsException;
4+
import com.couchbase.client.core.msg.kv.DurabilityLevel;
45
import com.couchbase.client.java.Bucket;
56
import com.couchbase.client.java.Cluster;
67
import com.couchbase.client.java.manager.bucket.BucketSettings;
@@ -26,9 +27,11 @@ public Bucket getCouchbaseBucket(Cluster cluster){
2627

2728
//Creates the cluster if it does not exist yet
2829
if( !cluster.buckets().getAllBuckets().containsKey(dbProp.getBucketName())) {
29-
cluster.buckets().createBucket(BucketSettings.create(dbProp.getBucketName())
30+
cluster.buckets().createBucket(
31+
BucketSettings.create(dbProp.getBucketName())
3032
.bucketType(BucketType.COUCHBASE)
31-
.ramQuotaMB(256));
33+
.minimumDurabilityLevel(DurabilityLevel.NONE)
34+
.ramQuotaMB(128));
3235
}
3336
return cluster.bucket(dbProp.getBucketName());
3437
}

src/main/java/org/couchbase/quickstart/controllers/ProfileController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class ProfileController {
3434
private DBProperties dbProperties;
3535

3636
public ProfileController(Cluster cluster, Bucket bucket, DBProperties dbProperties) {
37+
System.out.println("Initializing profile controller, cluster: " + cluster + "; bucket: " + bucket);
3738
this.cluster = cluster;
3839
this.profileCol = bucket.collection(PROFILE);
3940
this.dbProperties = dbProperties;

src/main/java/org/couchbase/quickstart/runners/DBSetupRunner.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,45 @@ public class DBSetupRunner implements CommandLineRunner {
3131
public void run(String... args) {
3232
try {
3333
cluster.queryIndexes().createPrimaryIndex(props.getBucketName());
34+
System.out.println("Created primary index" + props.getBucketName());
3435
} catch (Exception e) {
3536
System.out.println("Primary index already exists on bucket "+props.getBucketName());
37+
e.printStackTrace();
3638
}
3739

3840
CollectionManager collectionManager = bucket.collections();
3941
try {
4042
CollectionSpec spec = CollectionSpec.create(CollectionNames.PROFILE, bucket.defaultScope().name());
4143
collectionManager.createCollection(spec);
42-
Thread.sleep(15000);
44+
System.out.println("Created collection '" + spec.name() + "' in scope '" + spec.scopeName() + "' of bucket '" + bucket.name() + "'");
45+
Thread.sleep(1000);
4346
} catch (CollectionExistsException e){
4447
System.out.println(String.format("Collection <%s> already exists", CollectionNames.PROFILE));
4548
} catch (Exception e) {
4649
System.out.println(String.format("Generic error <%s>",e.getMessage()));
4750
}
4851

4952
try {
50-
final QueryResult result = cluster.query("CREATE PRIMARY INDEX default_profile_index ON "+props.getBucketName()+"._default."+ CollectionNames.PROFILE);
53+
final String query = "CREATE PRIMARY INDEX default_profile_index ON "+props.getBucketName()+"._default."+ CollectionNames.PROFILE;
54+
System.out.println(String.format("Creating default_profile_index: <%s>", query));
55+
final QueryResult result = cluster.query(query);
5156
for (JsonObject row : result.rowsAsObject()){
5257
System.out.println(String.format("Index Creation Status %s",row.getObject("meta").getString("status")));
5358
}
54-
Thread.sleep(10000);
59+
System.out.println("Created primary index on collection " + CollectionNames.PROFILE);
60+
Thread.sleep(1000);
5561
} catch (IndexExistsException e){
5662
System.out.println(String.format("Collection's primary index already exists"));
5763
} catch (Exception e){
5864
System.out.println(String.format("General error <%s> when trying to create index ",e.getMessage()));
5965
}
60-
66+
67+
try {
68+
final QueryResult result = cluster.query("CREATE INDEX default_profile_firstName_index ON " + props.getBucketName() + "._default." + CollectionNames.PROFILE + "(firstName)");
69+
Thread.sleep(1000);
70+
} catch (Exception e) {
71+
System.out.println(String.format("Failed to create secondary index on profile.firstName: %s", e.getMessage()));
72+
}
6173
}
6274
//
6375
// private QueryResult createCollectionIndex() throws Exception {

src/test/java/org/couchbase/quickstart/userProfile/UserProfileTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
import org.couchbase.quickstart.configs.DBProperties;
99
import org.couchbase.quickstart.models.Profile;
1010
import org.couchbase.quickstart.models.ProfileRequest;
11-
1211
import org.hamcrest.MatcherAssert;
1312
import org.hamcrest.Matchers;
14-
import org.junit.Before;
13+
import org.junit.After;
1514
import org.junit.Rule;
15+
import org.junit.Test;
16+
import org.junit.jupiter.api.AfterEach;
1617
import org.junit.rules.ExpectedException;
18+
import org.junit.runner.RunWith;
1719
import org.springframework.beans.factory.annotation.Autowired;
1820
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
1921
import org.springframework.boot.test.context.SpringBootTest;
@@ -22,14 +24,10 @@
2224
import org.springframework.test.web.reactive.server.EntityExchangeResult;
2325
import org.springframework.test.web.reactive.server.WebTestClient;
2426

25-
import org.junit.Test;
26-
import org.junit.runner.RunWith;
27-
2827
import java.util.List;
2928
import java.util.UUID;
3029

3130
import static org.junit.Assert.*;
32-
import org.mindrot.jbcrypt.*;
3331

3432

3533
@RunWith(SpringRunner.class)
@@ -49,7 +47,8 @@ public class UserProfileTest {
4947
@Rule
5048
public ExpectedException exceptionRule = ExpectedException.none();
5149

52-
@Before
50+
51+
@After
5352
public void cleanDB() {
5453
cluster.query("DELETE FROM "+prop.getBucketName()+"._default.profile ");
5554
}

0 commit comments

Comments
 (0)