Skip to content

Commit b89fb4a

Browse files
authored
chore: speed up filesystem tests (#34)
As per usual, the trick with perf is doing less
1 parent c28327b commit b89fb4a

File tree

3 files changed

+53
-76
lines changed

3 files changed

+53
-76
lines changed

server/src/test/kotlin/io/typestream/filesystem/FileSystemTest.kt

Lines changed: 53 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import io.typestream.testing.avro.buildAuthor
1212
import io.typestream.testing.konfig.testKonfig
1313
import kotlinx.coroutines.Dispatchers
1414
import org.assertj.core.api.Assertions.assertThat
15-
import org.junit.jupiter.api.BeforeEach
15+
import org.junit.jupiter.api.BeforeAll
1616
import org.junit.jupiter.api.Nested
1717
import org.junit.jupiter.api.Test
1818
import org.junit.jupiter.params.ParameterizedTest
@@ -21,76 +21,27 @@ import org.junit.jupiter.params.provider.MethodSource
2121
import org.testcontainers.junit.jupiter.Container
2222
import org.testcontainers.junit.jupiter.Testcontainers
2323
import java.util.stream.Stream
24-
import kotlin.test.assertNull
2524

2625
@Testcontainers
2726
internal class FileSystemTest {
27+
companion object {
28+
private lateinit var fileSystem: FileSystem
2829

29-
@Container
30-
private val testKafka = RedpandaContainerWrapper()
31-
32-
private lateinit var fileSystem: FileSystem
33-
34-
@BeforeEach
35-
fun beforeEach() {
36-
fileSystem = FileSystem(SourcesConfig(testKonfig(testKafka)), Dispatchers.IO)
37-
}
38-
39-
@Test
40-
fun `expands paths correctly`() {
41-
fileSystem.use {
42-
assertThat(fileSystem.expandPath("dev", "/")).isEqualTo("/dev")
43-
assertThat(fileSystem.expandPath("dev/", "/")).isEqualTo("/dev")
44-
assertThat(fileSystem.expandPath("kafka", "/dev")).isEqualTo("/dev/kafka")
45-
assertThat(fileSystem.expandPath("/dev/kafka", "/")).isEqualTo("/dev/kafka")
46-
assertThat(fileSystem.expandPath("/dev/kafka", "/dev")).isEqualTo("/dev/kafka")
47-
assertThat(fileSystem.expandPath("", "/")).isEqualTo("/")
48-
assertThat(fileSystem.expandPath("..", "/dev")).isEqualTo("/")
49-
assertThat(fileSystem.expandPath("..", "/dev/kafka")).isEqualTo("/dev")
50-
assertNull(fileSystem.expandPath("dev/whatever", "/"))
51-
}
52-
}
53-
54-
@Nested
55-
inner class EncodingRules {
56-
@Test
57-
fun `infers simple encoding`() {
58-
fileSystem.use {
59-
testKafka.produceRecords("authors", buildAuthor("Octavia E. Butler"))
60-
61-
fileSystem.refresh()
62-
63-
val dataCommand = Cat(listOf(Expr.BareWord("/dev/kafka/local/topics/authors")))
64-
65-
dataCommand.dataStreams.add(author())
66-
67-
assertThat(fileSystem.inferEncoding(dataCommand)).isEqualTo(Encoding.AVRO)
68-
}
69-
}
70-
71-
@Test
72-
fun `infers pipeline encoding`() {
73-
fileSystem.use {
74-
testKafka.produceRecords("authors", buildAuthor("Emily St. John Mandel"))
75-
76-
fileSystem.refresh()
77-
78-
val cat = Cat(listOf(Expr.BareWord("/dev/kafka/local/topics/authors")))
79-
80-
cat.dataStreams.add(author())
30+
@Container
31+
private val testKafka = RedpandaContainerWrapper()
8132

82-
val grep = Grep(listOf(Expr.BareWord("Mandel")))
33+
@JvmStatic
34+
@BeforeAll
35+
fun beforeAll() {
36+
fileSystem = FileSystem(SourcesConfig(testKonfig(testKafka)), Dispatchers.IO)
8337

84-
val pipeline = Pipeline(listOf(cat, grep))
38+
testKafka.produceRecords("authors", buildAuthor("Octavia E. Butler"))
8539

86-
assertThat(fileSystem.inferEncoding(pipeline)).isEqualTo(Encoding.AVRO)
87-
}
40+
fileSystem.refresh()
8841
}
89-
}
9042

91-
companion object {
9243
@JvmStatic
93-
fun incompletePaths(): Stream<Arguments> = Stream.of(
44+
fun completePathCases(): Stream<Arguments> = Stream.of(
9445
Arguments.of("d", "/", listOf("dev/")),
9546
Arguments.of("/d", "/", listOf("/dev/")),
9647
Arguments.of("ka", "/dev", listOf("kafka/")),
@@ -105,26 +56,55 @@ internal class FileSystemTest {
10556
)
10657
),
10758
)
59+
60+
@JvmStatic
61+
fun expandPathCases(): Stream<Arguments> = Stream.of(
62+
Arguments.of("dev", "/", "/dev"),
63+
Arguments.of("dev/", "/", "/dev"),
64+
Arguments.of("kafka", "/dev", "/dev/kafka"),
65+
Arguments.of("/dev/kafka", "/", "/dev/kafka"),
66+
Arguments.of("/dev/kafka", "/dev", "/dev/kafka"),
67+
Arguments.of("", "/", "/"),
68+
Arguments.of("..", "/dev", "/"),
69+
Arguments.of("..", "/dev/kafka", "/dev"),
70+
Arguments.of("dev/whatever", "/", null),
71+
)
10872
}
10973

11074
@ParameterizedTest
111-
@MethodSource("incompletePaths")
75+
@MethodSource("completePathCases")
11276
fun `completes correctly`(incompletePath: String, pwd: String, suggestions: List<String>) {
113-
fileSystem.use {
114-
assertThat(fileSystem.completePath(incompletePath, pwd)).contains(*suggestions.toTypedArray())
115-
}
77+
assertThat(fileSystem.completePath(incompletePath, pwd)).contains(*suggestions.toTypedArray())
11678
}
11779

118-
@Test
119-
fun `only completes directories with trailing slash`() {
120-
fileSystem.use {
121-
testKafka.produceRecords("authors", buildAuthor("Chimamanda Ngozi Adichie"))
80+
@ParameterizedTest
81+
@MethodSource("expandPathCases")
82+
fun `expands paths correctly`(path: String, pwd: String, expected: String?) {
83+
assertThat(fileSystem.expandPath(path, pwd)).isEqualTo(expected)
84+
}
12285

123-
fileSystem.refresh()
86+
@Nested
87+
inner class EncodingRules {
88+
@Test
89+
fun `infers simple encoding`() {
90+
val dataCommand = Cat(listOf(Expr.BareWord("/dev/kafka/local/topics/authors")))
91+
92+
dataCommand.dataStreams.add(author())
93+
94+
assertThat(fileSystem.inferEncoding(dataCommand)).isEqualTo(Encoding.AVRO)
95+
}
96+
97+
@Test
98+
fun `infers pipeline encoding`() {
99+
val cat = Cat(listOf(Expr.BareWord("/dev/kafka/local/topics/authors")))
100+
101+
cat.dataStreams.add(author())
102+
103+
val grep = Grep(listOf(Expr.BareWord("Butler")))
104+
105+
val pipeline = Pipeline(listOf(cat, grep))
124106

125-
assertThat(
126-
fileSystem.completePath("dev/kafka/local/topics/a", "/")
127-
).contains("dev/kafka/local/topics/authors")
107+
assertThat(fileSystem.inferEncoding(pipeline)).isEqualTo(Encoding.AVRO)
128108
}
129109
}
130110
}

server/src/test/kotlin/io/typestream/grpc/InteractiveSessionServiceTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.typestream.grpc
22

3-
import io.github.oshai.kotlinlogging.KotlinLogging
43
import io.grpc.inprocess.InProcessChannelBuilder
54
import io.grpc.inprocess.InProcessServerBuilder
65
import io.grpc.testing.GrpcCleanupRule

tools/src/test/kotlin/io/typestream/tools/command/SeedKtTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package io.typestream.tools.command
33
import io.typestream.testing.RedpandaContainerWrapper
44
import io.typestream.testing.avro.Author
55
import io.typestream.testing.avro.Book
6-
import io.typestream.testing.avro.PageView
7-
import io.typestream.testing.avro.Rating
86
import io.typestream.testing.avro.User
97
import io.typestream.testing.kafka.AdminClientWrapper
108
import io.typestream.testing.kafka.KafkaConsumerWrapper

0 commit comments

Comments
 (0)