Skip to content

Commit

Permalink
XD-1189 added to parametrized test
Browse files Browse the repository at this point in the history
  • Loading branch information
leostryuk committed Jan 16, 2025
1 parent 347f6d9 commit e0a58e2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
3 changes: 2 additions & 1 deletion query/src/main/kotlin/jetbrains/exodus/query/SortEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import jetbrains.exodus.entitystore.EntityIterable
import jetbrains.exodus.entitystore.orientdb.OEntityIterable
import jetbrains.exodus.entitystore.orientdb.OVertexEntity
import jetbrains.exodus.entitystore.orientdb.iterate.OEntityIterableBase
import jetbrains.exodus.entitystore.orientdb.iterate.link.OMultipleEntitiesIterable
import jetbrains.exodus.query.metadata.ModelMetaData

open class SortEngine {
Expand Down Expand Up @@ -68,7 +69,7 @@ open class SortEngine {
source: Iterable<Entity>,
asc: Boolean
): Iterable<Entity> {
if (source is OEntityIterable) {
if (source is OEntityIterable && source !is OMultipleEntitiesIterable) {
val txn = queryEngine.persistentStore.andCheckCurrentTransaction
return txn.sort(entityType, "${OVertexEntity.edgeClassName(linkName)}.$propName", source.unwrap(), asc)
} else {
Expand Down
40 changes: 39 additions & 1 deletion query/src/test/kotlin/jetbrains/exodus/query/OQueryEngineTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import jetbrains.exodus.entitystore.Entity
import jetbrains.exodus.entitystore.EntityIterable
import jetbrains.exodus.entitystore.orientdb.OStoreTransaction
import jetbrains.exodus.entitystore.orientdb.iterate.OEntityIterableBase
import jetbrains.exodus.entitystore.orientdb.iterate.link.OMultipleEntitiesIterable
import jetbrains.exodus.entitystore.orientdb.testutil.*
import jetbrains.exodus.query.metadata.EntityMetaData
import jetbrains.exodus.query.metadata.ModelMetaData
Expand Down Expand Up @@ -53,7 +54,13 @@ class OQueryEngineTest(
it.id.typeId >= 0
}
InMemoryEntityIterable(filteringSequence.asIterable(), currentTx, engine)
}, "InMemory")
}, "InMemory"),
arrayOf({ engine: QueryEngine, currentTx: OStoreTransaction ->
val filteringSequence = engine.instantiateGetAll(Issues.CLASS).asSequence().filter {
it.id.typeId >= 0
}
OMultipleEntitiesIterable(currentTx, filteringSequence.toList())
}, "MultipleEntitiesIterable")
)
}
}
Expand Down Expand Up @@ -644,6 +651,37 @@ class OQueryEngineTest(
}
}

@Test
fun `should query by property sorted`() {
// Given
val test = givenTestCase()

val metadata = givenModelMetadata().withEntityMetaData(Issues.CLASS)
val engine = givenOQueryEngine(metadata)

// When
withStoreTx { tx ->
val sortByPropertyAsc = SortByProperty(
null, // child node
"name", // link property name
true // ascending
)
val issuesAsc = engine.query(iterableGetter(engine, tx), Issues.CLASS, sortByPropertyAsc)

val sortByLinkPropertyDesc = SortByProperty(
null, // child node
"name", // link property name
false // descending
)
val issuesDesc = engine.query(iterableGetter(engine, tx), Issues.CLASS, sortByLinkPropertyDesc)

// Then
// As sorted by project name
assertOrderedNamesExactly(issuesDesc, "issue3", "issue2", "issue1")
assertOrderedNamesExactly(issuesAsc, "issue1", "issue2", "issue3")
}
}

private fun assertOrderedNamesExactly(result: Iterable<Entity>, vararg names: String) {
assertThat(result.map { it.getProperty("name") }).containsExactly(*names).inOrder()
}
Expand Down

0 comments on commit e0a58e2

Please sign in to comment.