|
| 1 | +package com.apurebase.kgraphql.integration |
| 2 | + |
| 3 | +import com.apurebase.kgraphql.KGraphQL |
| 4 | +import org.junit.jupiter.api.Test |
| 5 | + |
| 6 | +class GitHubIssuesBugTest { |
| 7 | + data class SearchHit(val spanData: Span) |
| 8 | + data class Tag(val key: String, val type: String, val value: String) |
| 9 | + data class LogPoint(val timestamp: Int, val fields: List<LogPointField>) |
| 10 | + data class LogPointField(val key: String, val value: String) |
| 11 | + data class Trace(val traceID: String, val spans: ArrayList<Span>) { |
| 12 | + companion object { |
| 13 | + fun fromSearchHits(traceID: String, hits: Array<SearchHit>): Trace { |
| 14 | + val spansArray = hits.map { Span.fromSearchHit(it) }.toTypedArray<Span>() |
| 15 | + return Trace(traceID, ArrayList(spansArray.sortedBy { it.startTime })) |
| 16 | + } |
| 17 | + } |
| 18 | + } |
| 19 | + 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>?) { |
| 20 | + companion object { |
| 21 | + fun fromSearchHit(hit: SearchHit) = hit.spanData |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + fun `issue-75 object is not of declaring class - full sample`() { |
| 27 | + val schema = KGraphQL.schema { |
| 28 | + configure { |
| 29 | + useDefaultPrettyPrinter = true |
| 30 | + } |
| 31 | + |
| 32 | + query("findTrace") { |
| 33 | + resolver { traceID: String -> |
| 34 | + Trace( |
| 35 | + traceID = "646851f15cb2dad1", |
| 36 | + spans = arrayListOf( |
| 37 | + Span( |
| 38 | + traceID = "646851f15cb2dad1", |
| 39 | + spanID = "32b1133c2e838c56", |
| 40 | + parentSpanID = "646851f15cb2dad1", |
| 41 | + duration = 1701547, |
| 42 | + startTime = 1581974975400889, |
| 43 | + operationName = "banana", |
| 44 | + serviceName = "example1", |
| 45 | + logs = arrayListOf(), |
| 46 | + tags = arrayListOf( |
| 47 | + Tag(type = "string", value = "sample text", key = "_tracestep_stack"), |
| 48 | + Tag(type = "bool", value = "true", key = "_tracestep_main"), |
| 49 | + Tag(type = "string", value = "proto", key = "internal.span.format") |
| 50 | + ) |
| 51 | + ), |
| 52 | + Span( |
| 53 | + traceID = "646851f15cb2dad1", |
| 54 | + spanID = "7381e3787bb621db", |
| 55 | + parentSpanID = "32b1133c2e838c56", |
| 56 | + duration = 1000503, |
| 57 | + startTime = 1581974975401257, |
| 58 | + operationName = "start-req2", |
| 59 | + serviceName = "example2", |
| 60 | + logs = arrayListOf(), |
| 61 | + tags = arrayListOf( |
| 62 | + Tag(type = "string", value = "sample text", key = "_tracestep_stack"), |
| 63 | + Tag(type = "bool", value = "false", key = "_tracestep_main"), |
| 64 | + Tag(type = "string", value = "proto", key = "internal.span.format") |
| 65 | + ) |
| 66 | + ) |
| 67 | + ) |
| 68 | + ) |
| 69 | + }.withArgs { |
| 70 | + arg<String> { name = "traceID"} |
| 71 | + } |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + schema.executeBlocking(""" |
| 76 | + query findTrace(${'$'}traceID: String!) { |
| 77 | + findTrace(traceID: ${'$'}traceID) { |
| 78 | + traceID |
| 79 | + spans { |
| 80 | + spanID |
| 81 | + tags { |
| 82 | + key |
| 83 | + value |
| 84 | + __typename |
| 85 | + } |
| 86 | + __typename |
| 87 | + } |
| 88 | + __typename |
| 89 | + } |
| 90 | + } |
| 91 | + """, "{\"traceID\": \"646851f15cb2dad1\"}").let(::println) |
| 92 | + } |
| 93 | +} |
0 commit comments