11/*
2- * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
2+ * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
33 */
44
55package kotlinx.rpc.krpc.test.api
66
7- import kotlinx.coroutines.flow.toList
87import kotlinx.rpc.krpc.internal.CancellationType
98import kotlinx.rpc.krpc.internal.KrpcMessage
109import kotlinx.rpc.krpc.internal.KrpcPlugin
1110import kotlinx.rpc.krpc.internal.KrpcPluginKey
1211import kotlinx.rpc.krpc.test.api.util.GoldUtils.NewLine
13- import kotlinx.rpc.krpc.test.plainFlow
14- import org.jetbrains.krpc.test.api.util.SamplingData
1512import org.junit.Test
1613import java.nio.file.Path
1714import kotlin.io.path.Path
18- import kotlin.io.path.isDirectory
19- import kotlin.io.path.listDirectoryEntries
20- import kotlin.io.path.name
21- import kotlin.test.Ignore
22- import kotlin.test.assertEquals
2315import kotlin.test.fail
2416
2517class ApiVersioningTest {
@@ -45,82 +37,10 @@ class ApiVersioningTest {
4537 testEnum<CancellationType >()
4638 }
4739
48- @Test
49- fun testEchoSampling () = wireSamplingTest(" echo" ) {
50- sample {
51- val response = echo(" Hello" , SamplingData (" data" ))
52- assertEquals(SamplingData (" data" ), response)
53- }
54- }
55-
56- @Test
57- @Ignore(" Flow sampling tests are too unstable. Ignored until better fix" )
58- fun testClientStreamSampling () = wireSamplingTest(" clientStream" ) {
59- sample {
60- val response = clientStream(plainFlow { it }).joinToString()
61- val expected = List (5 ) { it }.joinToString()
62-
63- assertEquals(expected, response)
64- }
65- }
66-
67- @Test
68- @Ignore(" Flow sampling tests are too unstable. Ignored until better fix" )
69- fun testServerStreamSampling () = wireSamplingTest(" serverStream" ) {
70- sample {
71- val response = serverFlow().toList().joinToString()
72- val expected = List (5 ) { SamplingData (" data" ) }.joinToString()
73-
74- assertEquals(expected, response)
75- }
76- }
77-
78- @Test
79- fun testCallExceptionSampling () = wireSamplingTest(" callException" ) {
80- // ignore protobuf here, as it's hard to properly sample stacktrace
81- // in Json we can just cut it out
82- sample(SamplingFormat .Json ) {
83- try {
84- callException()
85- fail(" Expected exception to be thrown" )
86- } catch (e: IllegalStateException ) {
87- assertEquals(" Server exception" , e.message)
88- }
89- }
90- }
91-
9240 companion object {
93- val LIBRARY_VERSION_DIR = System .getenv(" LIBRARY_VERSION" )?.versionToDirName()
94- ? : error(" Expected LIBRARY_VERSION env variable" )
41+ val CLASS_DUMPS_DIR : Path = Path (" src/jvmTest/resources/class_dumps/" )
9542
96- val CURRENT_CLASS_DUMPS_DIR : Path = Path (" src/jvmTest/resources/class_dumps/" )
97- .resolve(LIBRARY_VERSION_DIR )
98-
99- val LATEST_CLASS_DUMPS_DIR : Path = Path (" src/jvmTest/resources/class_dumps/" )
100- .latestVersionOrCurrent()
101-
102- val WIRE_DUMPS_DIR : Path = Path (" src/jvmTest/resources/wire_dumps/" )
10343 val INDEXED_ENUM_DUMPS_DIR : Path = Path (" src/jvmTest/resources/indexed_enum_dumps/" )
104-
105- private fun String.versionToDirName (): String {
106- return replace(' .' , ' _' ).replace(' -' , ' _' ).substringBefore(" -" )
107- }
108-
109- fun Path.latestVersionOrCurrent (): Path {
110- return listDirectoryEntries()
111- .filter { it.isDirectory() }
112- .sortedWith { a, b ->
113- val aBeta = a.name.contains(" beta" )
114- val bBeta = b.name.contains(" beta" )
115- when {
116- aBeta && bBeta -> a.compareTo(b)
117- aBeta -> - 1
118- bBeta -> 1
119- else -> a.name.substringBefore(" -" ).compareTo(b.name.substringBefore(" -" ))
120- }
121- }.lastOrNull()
122- ? : resolve(LIBRARY_VERSION_DIR )
123- }
12444 }
12545}
12646
0 commit comments