Created
February 19, 2020 17:24
-
-
Save jeggy/ac6650a479d03d4e2122898cdb2f2ae4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.apurebase.kgraphql.integration | |
import com.apurebase.kgraphql.KGraphQL | |
import org.junit.jupiter.api.Test | |
class GitHubIssuesBugTest { | |
data class SearchHit(val spanData: Span) | |
data class Tag(val key: String, val type: String, val value: String) | |
data class LogPoint(val timestamp: Int, val fields: List<LogPointField>) | |
data class LogPointField(val key: String, val value: String) | |
data class Trace(val traceID: String, val spans: ArrayList<Span>) { | |
companion object { | |
fun fromSearchHits(traceID: String, hits: Array<SearchHit>): Trace { | |
val spansArray = hits.map { Span.fromSearchHit(it) }.toTypedArray<Span>() | |
return Trace(traceID, ArrayList(spansArray.sortedBy { it.startTime })) | |
} | |
} | |
} | |
data class Span(val traceID: String, val spanID: String, val parentSpanID: String?, val duration: Int, val startTime: Long, val operationName: String, val serviceName: String, val logs: ArrayList<LogPoint>?, val tags: ArrayList<Tag>?) { | |
companion object { | |
fun fromSearchHit(hit: SearchHit) = hit.spanData | |
} | |
} | |
@Test | |
fun `issue-75 object is not of declaring class`() { | |
val schema = KGraphQL.schema { | |
configure { | |
useDefaultPrettyPrinter = true | |
} | |
fun generateSpan(traceID: String) = Span( | |
traceID, | |
traceID, | |
traceID, | |
100, | |
200000, | |
"someName", | |
"serviceName", | |
arrayListOf( | |
LogPoint( | |
2000, listOf( | |
LogPointField("key1", "value1"), | |
LogPointField("key2", "value2"), | |
LogPointField("key3", "value3") | |
) | |
) | |
), | |
arrayListOf( | |
Tag("TK", "Tag", "Tag Value") | |
) | |
) | |
query("findTrace") { | |
resolver { traceID: String -> | |
Trace.fromSearchHits(traceID, arrayOf( | |
SearchHit(generateSpan(traceID)), | |
SearchHit(generateSpan("$traceID-Next")) | |
)) | |
}.withArgs { | |
arg<String> { name = "traceID"} | |
} | |
} | |
} | |
schema.executeBlocking(""" | |
query findTrace(${'$'}traceID: String!) { | |
findTrace(traceID: ${'$'}traceID) { | |
traceID | |
spans { | |
spanID | |
tags { | |
key | |
value | |
__typename | |
} | |
__typename | |
} | |
__typename | |
} | |
} | |
""", "{\"traceID\": \"646851f15cb2dad1\"}").let(::println) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment