1
1
/*
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.
3
3
*/
4
4
5
5
package kotlinx.rpc.krpc.test.api
6
6
7
- import kotlinx.coroutines.flow.toList
8
7
import kotlinx.rpc.krpc.internal.CancellationType
9
8
import kotlinx.rpc.krpc.internal.KrpcMessage
10
9
import kotlinx.rpc.krpc.internal.KrpcPlugin
11
10
import kotlinx.rpc.krpc.internal.KrpcPluginKey
12
11
import kotlinx.rpc.krpc.test.api.util.GoldUtils.NewLine
13
- import kotlinx.rpc.krpc.test.plainFlow
14
- import org.jetbrains.krpc.test.api.util.SamplingData
15
12
import org.junit.Test
16
13
import java.nio.file.Path
17
14
import 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
23
15
import kotlin.test.fail
24
16
25
17
class ApiVersioningTest {
@@ -45,82 +37,10 @@ class ApiVersioningTest {
45
37
testEnum<CancellationType >()
46
38
}
47
39
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
-
92
40
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/" )
95
42
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/" )
103
43
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
- }
124
44
}
125
45
}
126
46
0 commit comments