update syntax to work with JLS 11

This commit is contained in:
Jonathan Shook 2021-02-05 12:24:28 -06:00
parent d7ab72e7b7
commit 80321e3853
4 changed files with 72 additions and 52 deletions
engine-api/src/main/java/io/nosqlbench/engine/api/scoping
engine-clients/src/test/java/io/nosqlbench/engine/clients/prometheus
mvn-defaults

View File

@ -27,17 +27,18 @@ public enum ScopedSupplier {
public <T> Supplier<T> supplier(Supplier<T> supplier) {
return switch (this) {
case singleton -> {
switch (this) {
case singleton:
T got = supplier.get();
yield () -> got;
}
case thread -> {
return () -> got;
case thread:
ThreadLocal<T> tlsupplier = ThreadLocal.withInitial(supplier);
yield () -> tlsupplier.get();
}
case caller -> supplier;
};
return tlsupplier::get;
case caller:
return supplier;
default:
throw new RuntimeException("Unknown scope type:" + this);
}
}
}

View File

@ -3,6 +3,7 @@ package io.nosqlbench.engine.clients.prometheus;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import io.nosqlbench.nb.api.content.NBIO;
import org.junit.Test;
import java.lang.reflect.Type;
@ -14,43 +15,11 @@ public class PMatrixElemTest {
@Test
public void testMatrixElem() {
Gson gson = new GsonBuilder().create();
String json = """
{
"status" : "success",
"data" : {
"resultType" : "matrix",
"result" : [
{
"metric" : {
"__name__" : "up",
"job" : "prometheus",
"instance" : "localhost:9090"
},
"values" : [
[ 1435781430.781, "1" ],
[ 1435781445.781, "1" ],
[ 1435781460.781, "1" ]
]
},
{
"metric" : {
"__name__" : "up",
"job" : "node",
"instance" : "localhost:9091"
},
"values" : [
[ 1435781430.781, "0" ],
[ 1435781445.781, "0" ],
[ 1435781460.781, "1" ]
]
}
]
}
}""";
String json = NBIO.classpath().name("test.json").one().asString();
Type type = new TypeToken<PromQueryResult<PMatrixData>>() {
}.getType();
Object result = gson.fromJson(json, type);
assertThat(result).isOfAnyClassIn(PromQueryResult.class);
}
}
}

View File

@ -0,0 +1,50 @@
{
"status": "success",
"data": {
"resultType": "matrix",
"result": [
{
"metric": {
"__name__": "up",
"job": "prometheus",
"instance": "localhost:9090"
},
"values": [
[
1435781430.781,
"1"
],
[
1435781445.781,
"1"
],
[
1435781460.781,
"1"
]
]
},
{
"metric": {
"__name__": "up",
"job": "node",
"instance": "localhost:9091"
},
"values": [
[
1435781430.781,
"0"
],
[
1435781445.781,
"0"
],
[
1435781460.781,
"1"
]
]
}
]
}
}

View File

@ -499,15 +499,15 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<debug>true</debug>
<!-- <release>${java.target.version}</release>-->
<source>15</source>
<target>15</target>
<!-- <compilerArgs>-->
<!-- &#45;&#45;enable-preview-->
<!-- </compilerArgs>-->
<!--<compilerArgument>-Xdoclint:all</compilerArgument>-->
<!-- <compilerArgument>-Xlint:all</compilerArgument>-->
<debug>true</debug>
<!-- <release>${java.target.version}</release>-->
<source>11</source>
<target>11</target>
<!-- <compilerArgs>-->
<!-- &#45;&#45;enable-preview-->
<!-- </compilerArgs>-->
<!--<compilerArgument>-Xdoclint:all</compilerArgument>-->
<!-- <compilerArgument>-Xlint:all</compilerArgument>-->
</configuration>
</plugin>