Skip to content

Commit 21c3d60

Browse files
authored
Merge pull request #69 from aPureBase/data-loader-idea-testing
New DataLoader executor
2 parents 3bd2944 + b304b02 commit 21c3d60

File tree

70 files changed

+1464
-158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1464
-158
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.idea/vcs.xml
2+
.idea/inspectionProfiles
13

24
# Created by https://www.gitignore.io/api/java,gradle,intellij+all
35
# Edit at https://www.gitignore.io/?templates=java,gradle,intellij+all

.idea/.name

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
plugins {
2-
id "org.jetbrains.kotlin.jvm" version "1.3.50"
2+
id "org.jetbrains.kotlin.jvm" version "1.3.61"
33
id "com.github.ben-manes.versions" version "0.24.0"
44
id "com.jfrog.bintray" version "1.8.4"
55
id "maven-publish"
6+
id "jacoco"
67
}
78

89
allprojects {
@@ -26,9 +27,12 @@ allprojects {
2627

2728

2829
testCompile "io.netty:netty-all:$netty_version"
29-
testCompile "junit:junit:$junit_version"
3030
testCompile "org.hamcrest:hamcrest:$hamcrest_version"
3131
testCompile "org.amshove.kluent:kluent:$kluent_version"
32+
testCompile "org.junit.jupiter:junit-jupiter-api:$junit_version"
33+
testCompile "org.junit.jupiter:junit-jupiter-params:$junit_version"
34+
testRuntime "org.junit.jupiter:junit-jupiter-engine:$junit_version"
35+
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-debug:$coroutine_version"
3236
}
3337

3438
task sourcesJar(type: Jar, dependsOn: classes) {
@@ -75,5 +79,12 @@ allprojects {
7579
}
7680
}
7781
}
82+
83+
84+
85+
86+
test {
87+
useJUnitPlatform()
88+
}
7889
}
7990

gradle.properties

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# KGraphQL version
2-
version=0.9.2
2+
version=0.10.0
33

44
# Dependencies
55
kotlin_version=1.3.50
66
coroutine_version=1.3.2
77
jackson_version=2.9.7
88
caffeine_version=2.8.0
9-
9+
serialization_version=0.14.0
10+
kDataLoader_version=0.1.1
1011

1112
# Test-Dependencies
1213
kotlin_html_version=0.6.12
1314
netty_version=4.1.42.Final
14-
junit_version=4.12
15+
junit_version=5.5.2
1516
kluent_version=1.56
1617
hamcrest_version=2.2
1718

kgraphql-ktor/src/test/kotlin/com/apurebase/kgraphql/KtorFeatureTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.apurebase.kgraphql
22

33
import org.amshove.kluent.shouldEqual
4-
import org.junit.Test
4+
import org.junit.jupiter.api.Test
55

66
class KtorFeatureTest {
77
@Test

kgraphql/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
dependencies {
22
compile "com.github.ben-manes.caffeine:caffeine:$caffeine_version"
3+
compile "de.nidomiro:KDataLoader:$kDataLoader_version"
4+
5+
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
6+
compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version" // JVM dependency
37
}

kgraphql/src/jmh/kotlin/com/apurebase/kgraphql/FunctionExecutionBenchmark.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.apurebase.kgraphql
22

33
import com.apurebase.kgraphql.schema.model.FunctionWrapper
44
import kotlinx.coroutines.runBlocking
5-
import org.junit.Test
5+
import org.junit.jupiter.api.Test
66
import org.openjdk.jmh.annotations.*
77
import java.util.concurrent.ThreadLocalRandom
88
import java.util.concurrent.TimeUnit

kgraphql/src/jmh/kotlin/com/apurebase/kgraphql/ParallelExecutionBenchmark.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import org.openjdk.jmh.annotations.*
55
import java.util.concurrent.ThreadLocalRandom
66
import java.util.concurrent.TimeUnit
77
import kotlinx.coroutines.*
8-
import org.junit.Test
8+
import org.junit.jupiter.api.Test
99

1010
@State(Scope.Benchmark)
1111
@Warmup(iterations = 5)

kgraphql/src/jmh/kotlin/com/apurebase/kgraphql/SimpleExecutionOverheadBenchmark.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import com.apurebase.kgraphql.schema.Schema
77
import com.fasterxml.jackson.databind.ObjectMapper
88
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
99
import kotlinx.coroutines.runBlocking
10-
import org.junit.Test
10+
import org.junit.jupiter.api.Test
1111
import org.openjdk.jmh.annotations.*
1212
import java.util.concurrent.TimeUnit
1313

kgraphql/src/main/kotlin/com/apurebase/kgraphql/Extensions.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.apurebase.kgraphql
22

3+
import kotlinx.coroutines.*
4+
import kotlinx.coroutines.channels.Channel
5+
import kotlin.coroutines.EmptyCoroutineContext
36
import kotlin.reflect.KClass
47
import kotlin.reflect.KParameter
58
import kotlin.reflect.KType
@@ -30,3 +33,34 @@ internal fun KType.getIterableElementType(): KType? {
3033

3134
internal fun not(boolean: Boolean) = !boolean
3235

36+
37+
38+
internal suspend fun <T, R> Collection<T>.toMapAsync(
39+
dispatcher: CoroutineDispatcher = Dispatchers.Default,
40+
block: suspend (T) -> R
41+
): Map<T, R> = coroutineScope {
42+
val channel = Channel<Pair<T, R>>()
43+
val jobs = map { item ->
44+
launch(dispatcher) {
45+
try {
46+
val res = block(item)
47+
channel.send(item to res)
48+
} catch (e: Exception) {
49+
channel.close(e)
50+
}
51+
}
52+
}
53+
val resultMap = mutableMapOf<T, R>()
54+
repeat(size) {
55+
try {
56+
val (item, result) = channel.receive()
57+
resultMap[item] = result
58+
} catch (e: Exception) {
59+
jobs.forEach { job: Job -> job.cancel() }
60+
throw e
61+
}
62+
}
63+
64+
channel.close()
65+
resultMap
66+
}

0 commit comments

Comments
 (0)