Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCSP-36306 openssl tool link fix #154

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Pull Request Info

[PR Reviewing Guidelines](https://github.com/mongodb/docs-java/blob/master/REVIEWING.md)
[PR Reviewing Guidelines](https://github.com/mongodb/docs-kotlin/blob/master/REVIEWING.md)

JIRA - https://jira.mongodb.org/browse/DOCSP-NNNNN
Staging - https://docs-mongodbcom-staging.corp.mongodb.com/drivers/docsworker-xlarge/NNNNN/
JIRA - <https://jira.mongodb.org/browse/DOCSP-NNNNN>
Staging - <https://docs-mongodbcom-staging.corp.mongodb.com/drivers/docsworker-xlarge/NNNNN/>

## Self-Review Checklist

- [ ] Is this free of any warnings or errors in the RST?
- [ ] Did you run a spell-check?
- [ ] Did you run a grammar-check?
- [ ] Are all the links working?
- [ ] Are the [facets and meta keywords](https://wiki.corp.mongodb.com/display/DE/Docs+Taxonomy) accurate?
3 changes: 2 additions & 1 deletion examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repositories {
dependencies {
implementation("org.mongodb:mongodb-driver-kotlin-coroutine:$kotlin_mongodb_version")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
testImplementation(kotlin("test"))
testImplementation("org.jetbrains.kotlin:kotlin-test:1.8.10")
implementation("org.slf4j:slf4j-api:2.0.5")
implementation("ch.qos.logback:logback-classic:1.4.7")
implementation("io.github.cdimascio:dotenv-kotlin:6.4.1")
Expand All @@ -29,6 +29,7 @@ dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
implementation("org.mongodb:bson-kotlinx:4.10.0-alpha1")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
}

tasks.test {
Expand Down
2 changes: 1 addition & 1 deletion examples/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
kotlin.code.style=official
kotlin_mongodb_version=4.10.0
kotlin_mongodb_version=4.11.0
43 changes: 42 additions & 1 deletion examples/src/test/kotlin/AggregatesBuilderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.mongodb.client.model.geojson.Position
import com.mongodb.client.model.search.SearchOperator
import com.mongodb.client.model.search.SearchOptions
import com.mongodb.client.model.search.SearchPath
import com.mongodb.client.model.search.VectorSearchOptions.vectorSearchOptions
import com.mongodb.kotlin.client.coroutine.MongoClient
import config.getConfig
import kotlinx.coroutines.flow.firstOrNull
Expand Down Expand Up @@ -80,6 +81,15 @@ class AggregatesBuilderTest {
)
// :snippet-end:

// :snippet-start: vector-search-data-class
data class MovieAlt(
val title: String,
val year: Int,
val plot: String,
val plotEmbedding: List<Double>
)
// :snippet-end:

companion object {
val config = getConfig()
private val client = MongoClient.create(config.connectionUri)
Expand Down Expand Up @@ -674,7 +684,15 @@ class AggregatesBuilderTest {
// :snippet-end:
Aggregates.sort(Sorts.descending(Results::count.name, "_id"))))
val results = resultsFlow.toList()
val actual = listOf(Results("Drama", 8), Results("Crime", 3), Results("Action", 2), Results("Thriller", 1), Results("Sci-Fi", 1), Results("Romance", 1), Results("Mystery", 1),)
val actual = listOf(
Results("Drama", 8),
Results("Crime", 3),
Results("Action", 2),
Results("Thriller", 1),
Results("Sci-Fi", 1),
Results("Romance", 1),
Results("Mystery", 1)
)
assertEquals(results, actual)
}

Expand Down Expand Up @@ -951,4 +969,27 @@ class AggregatesBuilderTest {
assertEquals(1, resultsFlow.toList().size)
assertEquals(1, results.first().get("count", Document::class.java).get("lowerBound", java.lang.Long::class.java)?.toInt())
}

/* NOTE: Test is not run by default. Vector search requires the creation of a vector search index on the collection before running.
*/
@Ignore
fun vectorSearchTest() = runBlocking {
val resultsFlow = movieCollection.aggregate<Document>(
listOf(
// :snippet-start: vector-search
Aggregates.vectorSearch(
SearchPath.fieldPath(MovieAlt::plotEmbedding.name),
listOf(-0.0072121937, -0.030757688, -0.012945653),
"mflix_movies_embedding_index",
2.toLong(),
1.toLong(),
vectorSearchOptions().filter(Filters.gte(MovieAlt::year.name, 2016))
)
// :snippet-end:
)
)
val results = resultsFlow.toList()
assertEquals(1, resultsFlow.toList().size)
assertEquals(1, results.first().get("count", Document::class.java).get("lowerBound", java.lang.Long::class.java)?.toInt())
}
}
32 changes: 32 additions & 0 deletions examples/src/test/kotlin/ChangeStreamsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import config.getConfig
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.bson.BsonDocument
import org.bson.Document
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.AfterEach
Expand Down Expand Up @@ -136,6 +137,37 @@ internal class ChangeStreamsTest {

}

// Ignore annotation added because this test requires a MongoDB 7.0 deployment
@Ignore
fun splitLargeChangeStreamTest() = runBlocking {
val changeEvents = mutableListOf<ChangeStreamDocument<Document>>()
// :snippet-start: split-large-change-stream
val pipeline = listOf(BsonDocument().append("\$changeStreamSplitLargeEvent", BsonDocument()))

val job = launch {
val changeStream = collection.watch(pipeline)
changeStream.collect {
println("Received a change event: $it")
changeEvents.add(it) // :remove:
}
}
// :snippet-end:

// Perform MongoDB operations that trigger change events...
delay(1)
val testData = Document("city", "Rio de Janeiro")
collection.insertOne(testData)

// Wait for change events
delay(1000)

// Cancel the change stream when you're done listening for events.
job.cancel()

// Change stream only captures the insert event, not the delete event.
assertEquals(1, changeEvents.size)
}

// NOTE: Test is being ignored because it will not work with a shared M0 cluster.
// Must have a local cluster with a replica set or >=M10 on Atlas to successfully run.
@Ignore
Expand Down
2 changes: 0 additions & 2 deletions examples/src/test/kotlin/InsertTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


import com.mongodb.MongoBulkWriteException
import com.mongodb.kotlin.client.coroutine.MongoClient
import config.getConfig
Expand Down
60 changes: 60 additions & 0 deletions examples/src/test/kotlin/KotlinXSerializationTest.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import com.mongodb.client.model.Filters.eq
import com.mongodb.kotlin.client.coroutine.MongoClient
import config.getConfig
import kotlinx.coroutines.flow.first
Expand All @@ -8,11 +9,22 @@ import kotlinx.serialization.Contextual
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.datetime.*
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerializationException
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.encodeToJsonElement
import org.bson.BsonDateTime
import org.bson.Document
import org.bson.codecs.configuration.CodecRegistries
import org.bson.codecs.kotlinx.BsonConfiguration
import org.bson.codecs.kotlinx.BsonDecoder
import org.bson.codecs.kotlinx.BsonEncoder
import org.bson.codecs.kotlinx.KotlinSerializerCodec
import org.bson.codecs.kotlinx.ObjectIdSerializer
import org.bson.types.ObjectId
Expand All @@ -22,6 +34,7 @@ import org.junit.jupiter.api.Assertions.assertFalse

import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import java.util.Date

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
internal class KotlinXSerializationTest {
Expand Down Expand Up @@ -118,5 +131,52 @@ internal class KotlinXSerializationTest {
collection.drop()
}

// :snippet-start: kserializer
object InstantAsBsonDateTime : KSerializer<Instant> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("InstantAsBsonDateTime", PrimitiveKind.LONG)

override fun serialize(encoder: Encoder, value: Instant) {
when (encoder) {
is BsonEncoder -> encoder.encodeBsonValue(BsonDateTime(value.toEpochMilliseconds()))
else -> throw SerializationException("Instant is not supported by ${encoder::class}")
}
}

override fun deserialize(decoder: Decoder): Instant {
return when (decoder) {
is BsonDecoder -> Instant.fromEpochMilliseconds(decoder.decodeBsonValue().asDateTime().value)
else -> throw SerializationException("Instant is not supported by ${decoder::class}")
}
}
}
// :snippet-end:

@Test
fun customKSerializerTest() = runBlocking {
// :snippet-start: kserializer-dataclass
@Serializable
data class PaintOrder(
val color: String,
val qty: Int,
@Serializable(with = InstantAsBsonDateTime::class)
val orderDate: Instant,
)
// :snippet-end:

val collection = database.getCollection<PaintOrder>("orders")
val paintOrder = PaintOrder("magenta", 5, Instant.parse("2024-01-15T00:00:00Z"))
val insertOneResult = collection.insertOne(paintOrder)

val resultsFlow = collection.withDocumentClass<Document>()
.find(eq(PaintOrder::color.name, "magenta"))
.firstOrNull()

if (resultsFlow != null) {
assertEquals(resultsFlow["orderDate"], Date.from(java.time.Instant.parse("2024-01-15T00:00:00Z")))
}

collection.drop()
}

}

119 changes: 119 additions & 0 deletions examples/src/test/kotlin/SearchIndexesTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@

import com.mongodb.client.model.SearchIndexModel
import com.mongodb.kotlin.client.coroutine.MongoClient
import config.getConfig
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking
import org.bson.Document
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import kotlin.test.Ignore
import kotlin.test.assertFalse

// :replace-start: {
// "terms": {
// "CONNECTION_URI_PLACEHOLDER": "\"<connection string>\""
// }
// }
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class SearchIndexesTest {

companion object {
private val config = getConfig()
private val CONNECTION_URI_PLACEHOLDER = config.connectionUri

val mongoClient = MongoClient.create(CONNECTION_URI_PLACEHOLDER)
val database = mongoClient.getDatabase("sample_mflix")
val moviesCollection = database.getCollection<Document>("movies")

@AfterAll
@JvmStatic
fun afterAll() {
runBlocking {
moviesCollection.drop()
}
mongoClient.close()
}
}

@Ignore
@Test
fun singleSearchIndexTest() = runBlocking {
// :snippet-start: single-search-index-create
val index = Document(
"mappings",
Document("dynamic", true)
)
val resultCreateIndex = moviesCollection.createSearchIndex("myIndex", index)
// :snippet-end:
println("Index created: $resultCreateIndex")
assertEquals("myIndex", resultCreateIndex)
}

@Ignore
@Test
fun multipleSearchIndexTest() = runBlocking {
// :snippet-start: multi-search-index-create
val indexOne = SearchIndexModel(
"myIndex1",
Document("analyzer", "lucene.standard").append(
"mappings", Document("dynamic", true)
)
)

val indexTwo = SearchIndexModel(
"myIndex2",
Document("analyzer", "lucene.simple").append(
"mappings", Document("dynamic", true)
)
)

val resultCreateIndexes = moviesCollection
.createSearchIndexes(listOf(indexOne, indexTwo))
// :snippet-end:
assertEquals(listOf("myIndex1", "myIndex2"), resultCreateIndexes.toList())
}

@Ignore
@Test
fun listSearchIndexTest() = runBlocking {
// :snippet-start: list-search-indexes
val searchIndexesList = moviesCollection.listSearchIndexes().toList()
// :snippet-end:

assertFalse(searchIndexesList.isEmpty())
}

@Ignore
@Test
fun updateSearchIndexTest() = runBlocking {
// :snippet-start: update-search-indexes
moviesCollection.updateSearchIndex(
"myIndex",
Document("analyzer", "lucene.simple").append(
"mappings",
Document("dynamic", false)
.append(
"fields",
Document(
"title",
Document("type", "string")
)
)
)
)
// :snippet-end:
}

@Ignore
@Test
fun dropSearchIndexTest() = runBlocking {
// :snippet-start: drop-search-index
moviesCollection.dropSearchIndex("myIndex");
// :snippet-end:
}

}
// :replace-end:
Loading
Loading