Skip to content

Commit fa7e84c

Browse files
Merge pull request #940 from ie3-institute/sp/#755-couchbase-it-fails
Fixing sometimes failing tests
2 parents b729d38 + 8fe7ae0 commit fa7e84c

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Added
1010

1111
### Fixed
12+
- Fixed Couchbase integration tests that randomly failed [#755](https://github.com/ie3-institute/PowerSystemDataModel/issues/755)
1213

1314
### Changed
1415
- Changing from comparing strings to comparing uuids in `EntitySource.findFirstEntityByUuid` [#829](https://github.com/ie3-institute/PowerSystemDataModel/issues/829)

src/main/java/edu/ie3/datamodel/io/connectors/CouchbaseConnector.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
import com.couchbase.client.core.diagnostics.PingResult;
99
import com.couchbase.client.java.AsyncCollection;
1010
import com.couchbase.client.java.Cluster;
11+
import com.couchbase.client.java.ClusterOptions;
1112
import com.couchbase.client.java.Collection;
1213
import com.couchbase.client.java.kv.GetResult;
1314
import com.couchbase.client.java.kv.MutationResult;
1415
import com.couchbase.client.java.query.QueryResult;
16+
import java.time.Duration;
1517
import java.util.List;
1618
import java.util.concurrent.CompletableFuture;
1719

@@ -36,6 +38,24 @@ public CouchbaseConnector(String url, String bucketName, String username, String
3638
cluster = Cluster.connect(url, username, password);
3739
}
3840

41+
/**
42+
* Initializes a new CouchbaseConnector with given KV timeout
43+
*
44+
* @param url the url to the cluster
45+
* @param bucketName the name of the bucket to connect to
46+
* @param username the user name
47+
* @param password the user password
48+
* @param kvTimeout the key-value access timeout
49+
*/
50+
public CouchbaseConnector(
51+
String url, String bucketName, String username, String password, Duration kvTimeout) {
52+
this.bucketName = bucketName;
53+
ClusterOptions clusterOptions =
54+
ClusterOptions.clusterOptions(username, password)
55+
.environment(env -> env.timeoutConfig(to -> to.kvTimeout(kvTimeout)));
56+
cluster = Cluster.connect(url, clusterOptions);
57+
}
58+
3959
/**
4060
* Return the couchbase java sdk equivalent of a session - a collection - to the previously set
4161
* bucket

src/test/groovy/edu/ie3/datamodel/io/factory/result/SystemParticipantResultFactoryTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ class SystemParticipantResultFactoryTest extends Specification implements Factor
156156
"p" : "2",
157157
"q" : "2",
158158
]
159-
expect: "that the factory should not need more than 2 seconds for processing 100.000 entities"
159+
expect: "that the factory should not need more than 3 seconds for processing 10.000 entities"
160160
Long startTime = System.currentTimeMillis()
161161
10000.times {
162162
resultFactory.get(new SimpleEntityData(parameter, StorageResult))
163163
}
164164
BigDecimal elapsedTime = (System
165165
.currentTimeMillis() - startTime) / 1000.0
166-
elapsedTime < 2
166+
elapsedTime < 3
167167
}
168168
}

src/test/groovy/edu/ie3/datamodel/io/source/couchbase/CouchbaseWeatherSourceCosmoIT.groovy

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.testcontainers.utility.MountableFile
2323
import spock.lang.Shared
2424
import spock.lang.Specification
2525

26+
import java.time.Duration
2627
import java.time.ZoneId
2728

2829
@Testcontainers
@@ -32,9 +33,10 @@ class CouchbaseWeatherSourceCosmoIT extends Specification implements TestContain
3233
BucketDefinition bucketDefinition = new BucketDefinition("ie3_in")
3334

3435
@Shared
35-
CouchbaseContainer couchbaseContainer = new CouchbaseContainer("couchbase/server:6.0.2")
36+
CouchbaseContainer couchbaseContainer = new CouchbaseContainer("couchbase/server:6.6.0")
3637
.withBucket(bucketDefinition)
3738
.withExposedPorts(8091, 8092, 8093, 8094, 11210)
39+
.withStartupAttempts(3) // 3 attempts because startup (node renaming) sometimes fails when executed too early
3840

3941
@Shared
4042
CouchbaseWeatherSource source
@@ -63,7 +65,13 @@ class CouchbaseWeatherSourceCosmoIT extends Specification implements TestContain
6365
"--generate-key", "weather::%" + coordinateIdColumnName + "%::%time%",
6466
"--dataset", "file:///home/weather_cosmo.json")
6567

66-
def connector = new CouchbaseConnector(couchbaseContainer.connectionString, bucketDefinition.name, couchbaseContainer.username, couchbaseContainer.password)
68+
// increased timeout to deal with CI under high load
69+
def connector = new CouchbaseConnector(
70+
couchbaseContainer.connectionString,
71+
bucketDefinition.name,
72+
couchbaseContainer.username,
73+
couchbaseContainer.password,
74+
Duration.ofSeconds(20))
6775
def dtfPattern = "yyyy-MM-dd'T'HH:mm:ssxxx"
6876
def weatherFactory = new CosmoTimeBasedWeatherValueFactory(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, dtfPattern))
6977
source = new CouchbaseWeatherSource(connector, CosmoWeatherTestData.coordinateSource, coordinateIdColumnName, weatherFactory, dtfPattern)

src/test/groovy/edu/ie3/datamodel/io/source/couchbase/CouchbaseWeatherSourceIconIT.groovy

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import org.testcontainers.spock.Testcontainers
2020
import spock.lang.Shared
2121
import spock.lang.Specification
2222

23+
import java.time.Duration
2324
import java.time.ZoneId
2425

2526
@Testcontainers
@@ -29,8 +30,10 @@ class CouchbaseWeatherSourceIconIT extends Specification implements TestContaine
2930
BucketDefinition bucketDefinition = new BucketDefinition("ie3_in")
3031

3132
@Shared
32-
CouchbaseContainer couchbaseContainer = new CouchbaseContainer("couchbase/server:6.0.2").withBucket(bucketDefinition)
33+
CouchbaseContainer couchbaseContainer = new CouchbaseContainer("couchbase/server:6.6.0")
34+
.withBucket(bucketDefinition)
3335
.withExposedPorts(8091, 8092, 8093, 8094, 11210)
36+
.withStartupAttempts(3) // 3 attempts because startup (node renaming) sometimes fails when executed too early
3437

3538
@Shared
3639
CouchbaseWeatherSource source
@@ -59,7 +62,13 @@ class CouchbaseWeatherSourceIconIT extends Specification implements TestContaine
5962
"--generate-key", "weather::%" + coordinateIdColumnName + "%::%time%",
6063
"--dataset", "file:///home/weather_icon.json")
6164

62-
def connector = new CouchbaseConnector(couchbaseContainer.connectionString, bucketDefinition.name, couchbaseContainer.username, couchbaseContainer.password)
65+
// increased timeout to deal with CI under high load
66+
def connector = new CouchbaseConnector(
67+
couchbaseContainer.connectionString,
68+
bucketDefinition.name,
69+
couchbaseContainer.username,
70+
couchbaseContainer.password,
71+
Duration.ofSeconds(20))
6372
def dtfPattern = "yyyy-MM-dd'T'HH:mm:ssxxx"
6473
def weatherFactory = new IconTimeBasedWeatherValueFactory(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, dtfPattern))
6574
source = new CouchbaseWeatherSource(connector, IconWeatherTestData.coordinateSource, coordinateIdColumnName, weatherFactory, dtfPattern)

0 commit comments

Comments
 (0)