Skip to content

Commit 324f34e

Browse files
committed
KCBC-62 Temporarily remove OptIn requirements for volatile and uncommitted API
Motivation ---------- Kotlin's opt-in system has not yet been stabilized in Kotlin 1.6. Rather than risk incompatibility with the future stable implementation, we're going to hold off on adding opt-in requirements. Modifications ------------- Features annotated with @VolatileCouchbaseApi and @UncommittedCouchbaseApi no longer require opt-in. Note that they will likely require opt-in in the future, once Kotlin's opt-in feature has stabilized. Change-Id: Ia7c5014d2fbb96bb5e53eae5b704cfa449179b91 Reviewed-on: https://review.couchbase.org/c/couchbase-jvm-clients/+/170986 Tested-by: Build Bot <[email protected]> Reviewed-by: David Nault <[email protected]>
1 parent 93f7c39 commit 324f34e

File tree

19 files changed

+41
-58
lines changed

19 files changed

+41
-58
lines changed

kotlin-client/pom.xml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
44

55
<modelVersion>4.0.0</modelVersion>
66

@@ -22,7 +22,7 @@
2222
<kotlin.coroutines.version>1.6.0</kotlin.coroutines.version>
2323
<kotlin.code.style>official</kotlin.code.style>
2424
<dokka.version>1.6.0</dokka.version>
25-
<moshi.version>1.12.0</moshi.version>
25+
<moshi.version>1.13.0</moshi.version>
2626
</properties>
2727

2828

@@ -97,7 +97,7 @@
9797
<dependency>
9898
<groupId>io.github.microutils</groupId>
9999
<artifactId>kotlin-logging-jvm</artifactId>
100-
<version>2.0.8</version>
100+
<version>2.1.21</version>
101101
<scope>test</scope>
102102
<exclusions>
103103
<!-- prevent stdlib version mismatch -->
@@ -125,15 +125,12 @@
125125
<!-- Require explicit visibility modifiers so we don't
126126
accidentally leak stuff into the public API -->
127127
<arg>-Xexplicit-api=strict</arg>
128-
129-
<!-- Flag uncommitted and volatile API -->
130-
<arg>-Xopt-in=kotlin.RequiresOptIn</arg>
131128
</args>
132129
</configuration>
133130
<executions>
134131
<execution>
135132
<id>compile</id>
136-
<phase>compile</phase>
133+
<phase>process-sources</phase>
137134
<goals>
138135
<goal>compile</goal>
139136
</goals>

kotlin-client/src/integrationTest/kotlin/com/couchbase/client/kotlin/KeyValueIntegrationTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ import java.time.temporal.ChronoUnit.SECONDS as ChronoSeconds
6868
// with Gerrit verification. Remove when mock is fixed:
6969
// http://review.couchbase.org/c/CouchbaseMock/+/148081
7070
@IgnoreWhen(clusterTypes = [ClusterType.MOCKED])
71-
@OptIn(VolatileCouchbaseApi::class)
7271
internal class KeyValueIntegrationTest : KotlinIntegrationTest() {
7372

7473
val nearFutureExpiry = Expiry.of(Instant.now().plus(3, ChronoDays).truncatedTo(ChronoSeconds))
@@ -140,7 +139,6 @@ internal class KeyValueIntegrationTest : KotlinIntegrationTest() {
140139
}
141140

142141
@Nested
143-
@VolatileCouchbaseApi
144142
inner class GetAnyReplicaOrNull {
145143
@Test
146144
fun `returns null`(): Unit = runBlocking {

kotlin-client/src/integrationTest/kotlin/com/couchbase/client/kotlin/LookupInIntegrationTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.couchbase.client.kotlin
33
import com.couchbase.client.core.error.DocumentNotFoundException
44
import com.couchbase.client.core.error.subdoc.DocumentTooDeepException
55
import com.couchbase.client.core.msg.kv.CodecFlags
6-
import com.couchbase.client.kotlin.annotations.VolatileCouchbaseApi
76
import com.couchbase.client.kotlin.codec.Content
87
import com.couchbase.client.kotlin.internal.toStringUtf8
98
import com.couchbase.client.kotlin.kv.LookupInSpec
@@ -20,7 +19,6 @@ import org.junit.jupiter.api.Nested
2019
import org.junit.jupiter.api.Test
2120
import org.junit.jupiter.api.assertThrows
2221

23-
@OptIn(VolatileCouchbaseApi::class)
2422
@IgnoreWhen(clusterTypes = [ClusterType.MOCKED])
2523
internal class LookupInIntegrationTest : KotlinIntegrationTest() {
2624

kotlin-client/src/integrationTest/kotlin/com/couchbase/client/kotlin/SubdocMutateIntegrationTest.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import com.couchbase.client.core.error.DocumentNotFoundException
2020
import com.couchbase.client.core.error.subdoc.PathExistsException
2121
import com.couchbase.client.core.error.subdoc.PathNotFoundException
2222
import com.couchbase.client.core.error.subdoc.XattrInvalidKeyComboException
23-
import com.couchbase.client.kotlin.annotations.VolatileCouchbaseApi
2423
import com.couchbase.client.kotlin.kv.Expiry
2524
import com.couchbase.client.kotlin.kv.LookupInSpec
2625
import com.couchbase.client.kotlin.kv.MutateInMacro
@@ -380,7 +379,6 @@ internal class SubdocMutateIntegrationTest : KotlinIntegrationTest() {
380379
assertEquals(7, updatedContent.getInt("foo"))
381380
}
382381

383-
@OptIn(VolatileCouchbaseApi::class)
384382
@IgnoreWhen(clusterTypes = [MOCKED])
385383
@Test
386384
fun `insert expand macro xattr do not flag`(): Unit = runBlocking {
@@ -390,7 +388,6 @@ internal class SubdocMutateIntegrationTest : KotlinIntegrationTest() {
390388
assertEquals("\${Mutation.CAS}", updatedContent.getString("foo"))
391389
}
392390

393-
@OptIn(VolatileCouchbaseApi::class)
394391
@IgnoreWhen(clusterTypes = [MOCKED])
395392
@Test
396393
fun `insert expand macro xattr`(): Unit = runBlocking {
@@ -400,7 +397,6 @@ internal class SubdocMutateIntegrationTest : KotlinIntegrationTest() {
400397
assertThat(updatedContent.getString("foo")).matches(HEX_ENCODED_INT64)
401398
}
402399

403-
@OptIn(VolatileCouchbaseApi::class)
404400
@IgnoreWhen(clusterTypes = [MOCKED])
405401
@Test
406402
fun `insert expand macro crc32 xattr`(): Unit = runBlocking {
@@ -410,7 +406,6 @@ internal class SubdocMutateIntegrationTest : KotlinIntegrationTest() {
410406
assertThat(updatedContent.getString("foo")).matches(HEX_ENCODED_INT32)
411407
}
412408

413-
@OptIn(VolatileCouchbaseApi::class)
414409
@IgnoreWhen(clusterTypes = [MOCKED])
415410
@Test
416411
fun `insert expand macro seqno xattr`(): Unit = runBlocking {
@@ -420,7 +415,6 @@ internal class SubdocMutateIntegrationTest : KotlinIntegrationTest() {
420415
assertThat(updatedContent.getString("foo")).matches(HEX_ENCODED_INT64)
421416
}
422417

423-
@OptIn(VolatileCouchbaseApi::class)
424418
@IgnoreWhen(clusterTypes = [MOCKED])
425419
@Test
426420
fun `upsert expand macro xattr`(): Unit = runBlocking {

kotlin-client/src/integrationTest/kotlin/com/couchbase/client/kotlin/ViewIntegrationTest.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.couchbase.client.kotlin
1818

19-
import com.couchbase.client.kotlin.annotations.VolatileCouchbaseApi
2019
import com.couchbase.client.kotlin.manager.view.DesignDocument
2120
import com.couchbase.client.kotlin.manager.view.View
2221
import com.couchbase.client.kotlin.manager.view.ViewIndexManager
@@ -38,9 +37,7 @@ import org.junit.jupiter.api.Assertions.assertNotNull
3837
import org.junit.jupiter.api.Assertions.assertNull
3938
import org.junit.jupiter.api.BeforeAll
4039
import org.junit.jupiter.api.Test
41-
import java.util.*
4240

43-
@OptIn(VolatileCouchbaseApi::class)
4441
@IgnoreWhen(clusterTypes = [MOCKED, CAVES])
4542
internal class ViewIntegrationTest : KotlinIntegrationTest() {
4643
private val DDOC_NAME = "everything"

kotlin-client/src/main/kotlin/com/couchbase/client/kotlin/Cluster.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import com.couchbase.client.kotlin.analytics.AnalyticsParameters
4242
import com.couchbase.client.kotlin.analytics.AnalyticsPriority
4343
import com.couchbase.client.kotlin.analytics.AnalyticsScanConsistency
4444
import com.couchbase.client.kotlin.analytics.internal.AnalyticsExecutor
45-
import com.couchbase.client.kotlin.annotations.VolatileCouchbaseApi
4645
import com.couchbase.client.kotlin.codec.JsonSerializer
4746
import com.couchbase.client.kotlin.diagnostics.DiagnosticsResult
4847
import com.couchbase.client.kotlin.diagnostics.PingResult
@@ -297,7 +296,6 @@ public class Cluster internal constructor(
297296
* @sample com.couchbase.client.kotlin.samples.checkSearchQueryResultForPartialFailure
298297
* @sample com.couchbase.client.kotlin.samples.searchQueryWithFacets
299298
*/
300-
@Stability.Volatile
301299
public fun searchQuery(
302300
indexName: String,
303301
query: SearchQuery,
@@ -464,7 +462,6 @@ public class Cluster internal constructor(
464462
* @sample com.couchbase.client.kotlin.samples.singleValueQueryAnonymous
465463
* @sample com.couchbase.client.kotlin.samples.singleValueQueryNamed
466464
*/
467-
@OptIn(VolatileCouchbaseApi::class)
468465
public fun query(
469466
statement: String,
470467
common: CommonOptions = CommonOptions.Default,

kotlin-client/src/main/kotlin/com/couchbase/client/kotlin/Collection.kt

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public class Collection internal constructor(
125125
* To work around this limitation, consider specifying shallower paths or
126126
* fetching the whole document.
127127
*
128-
* @throws DocumentNotFoundException if the document id is not found in the collection.
128+
* @throws DocumentNotFoundException if a document with ID [id] is not found in the collection.
129129
*/
130130
public suspend fun get(
131131
id: String,
@@ -171,7 +171,7 @@ public class Collection internal constructor(
171171
}
172172

173173
/**
174-
* @throws DocumentNotFoundException if the document id is not found in the collection.
174+
* @throws DocumentNotFoundException if a document with ID [id] is not found in the collection.
175175
*/
176176
public suspend fun getAndLock(
177177
id: String,
@@ -234,7 +234,6 @@ public class Collection internal constructor(
234234
id: String,
235235
common: CommonOptions = CommonOptions.Default,
236236
): GetReplicaResult {
237-
@OptIn(VolatileCouchbaseApi::class)
238237
return getAnyReplicaOrNull(id, common)
239238
?: throw DocumentUnretrievableException(ReducedKeyValueErrorContext.create(id, collectionId))
240239
}
@@ -288,6 +287,10 @@ public class Collection internal constructor(
288287
}
289288
}
290289

290+
/**
291+
* @throws DocumentNotFoundException if a document with ID [id] is not found in the collection.
292+
* @throws CasMismatchException if [cas] != 0 and does not match the existing document's CAS value.
293+
*/
291294
public suspend fun remove(
292295
id: String,
293296
common: CommonOptions = CommonOptions.Default,
@@ -313,6 +316,27 @@ public class Collection internal constructor(
313316
}
314317
}
315318

319+
/**
320+
* Like [remove], but returns null instead of throwing
321+
* [DocumentNotFoundException] if the document was not found.
322+
*/
323+
@VolatileCouchbaseApi
324+
public suspend fun removeOrNull(
325+
id: String,
326+
common: CommonOptions = CommonOptions.Default,
327+
durability: Durability = Durability.none(),
328+
cas: Long = 0,
329+
): MutationResult? {
330+
return try {
331+
remove(id, common, durability, cas)
332+
} catch (_: DocumentNotFoundException) {
333+
null;
334+
}
335+
}
336+
337+
/**
338+
* @throws DocumentExistsException if a document with the same ID already exists.
339+
*/
316340
public suspend inline fun <reified T> insert(
317341
id: String,
318342
content: T,
@@ -418,6 +442,10 @@ public class Collection internal constructor(
418442
}
419443
}
420444

445+
/**
446+
* @throws DocumentNotFoundException if a document with ID [id] is not found in the collection.
447+
* @throws CasMismatchException if [cas] != 0 and does not match the existing document's CAS value.
448+
*/
421449
public suspend inline fun <reified T> replace(
422450
id: String,
423451
content: T,
@@ -629,7 +657,6 @@ public class Collection internal constructor(
629657
val encodedCommands = spec.commands.map { it.encode(defaultCreateParent, serializer ?: defaultJsonSerializer) }
630658
val timeout = common.actualKvTimeout(durability)
631659

632-
@OptIn(VolatileCouchbaseApi::class)
633660
val request = SubdocMutateRequest(
634661
timeout,
635662
core.context(),

kotlin-client/src/main/kotlin/com/couchbase/client/kotlin/Scope.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.couchbase.client.kotlin
1818

1919
import com.couchbase.client.core.Core
20+
import com.couchbase.client.core.annotation.SinceCouchbase
2021
import com.couchbase.client.core.io.CollectionIdentifier
2122
import com.couchbase.client.core.io.CollectionIdentifier.DEFAULT_COLLECTION
2223
import com.couchbase.client.core.io.CollectionIdentifier.DEFAULT_SCOPE
@@ -25,7 +26,6 @@ import com.couchbase.client.kotlin.analytics.AnalyticsParameters
2526
import com.couchbase.client.kotlin.analytics.AnalyticsPriority
2627
import com.couchbase.client.kotlin.analytics.AnalyticsScanConsistency
2728
import com.couchbase.client.kotlin.analytics.internal.AnalyticsExecutor
28-
import com.couchbase.client.kotlin.annotations.VolatileCouchbaseApi
2929
import com.couchbase.client.kotlin.codec.JsonSerializer
3030
import com.couchbase.client.kotlin.internal.toOptional
3131
import com.couchbase.client.kotlin.query.QueryFlowItem
@@ -36,7 +36,6 @@ import com.couchbase.client.kotlin.query.QueryResult
3636
import com.couchbase.client.kotlin.query.QueryRow
3737
import com.couchbase.client.kotlin.query.QueryScanConsistency
3838
import com.couchbase.client.kotlin.query.internal.QueryExecutor
39-
import com.couchbase.client.core.annotation.SinceCouchbase
4039
import kotlinx.coroutines.flow.Flow
4140
import java.util.*
4241
import java.util.concurrent.ConcurrentHashMap
@@ -145,7 +144,6 @@ public class Scope(
145144
* @param raw an "escape hatch" for passing arbitrary query options that
146145
* aren't otherwise exposed by this method.
147146
*/
148-
@OptIn(VolatileCouchbaseApi::class)
149147
public fun query(
150148
statement: String,
151149
common: CommonOptions = CommonOptions.Default,

kotlin-client/src/main/kotlin/com/couchbase/client/kotlin/analytics/AnalyticsResult.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import com.couchbase.client.kotlin.annotations.VolatileCouchbaseApi
2121
import com.couchbase.client.kotlin.codec.JsonSerializer
2222
import com.couchbase.client.kotlin.codec.typeRef
2323
import kotlinx.coroutines.flow.Flow
24-
import kotlinx.coroutines.flow.collect
2524

2625
public class AnalyticsResult(
2726
public val rows: List<AnalyticsRow>,

kotlin-client/src/main/kotlin/com/couchbase/client/kotlin/annotations/Api.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ import com.couchbase.client.core.annotation.Stability
3535
* Couchbase Java SDK and core-io library. The Kotlin SDK uses a separate
3636
* annotation in order to specify opt-in requirements.
3737
*/
38-
@RequiresOptIn(level = RequiresOptIn.Level.ERROR)
38+
@MustBeDocumented
3939
public annotation class VolatileCouchbaseApi
4040

4141
/**
42-
* No commitment is made about the API.
42+
* The API will probably remain stable, but no commitment has been made yet.
4343
*
4444
* It may be changed in incompatible ways or dropped from one release
4545
* to another. The difference between uncommitted and volatile
@@ -52,5 +52,5 @@ public annotation class VolatileCouchbaseApi
5252
* Couchbase Java SDK and core-io library. The Kotlin SDK uses a separate
5353
* annotation in order to specify opt-in requirements.
5454
*/
55-
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
55+
@MustBeDocumented
5656
public annotation class UncommittedCouchbaseApi

0 commit comments

Comments
 (0)