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

View File

@ -27,17 +27,18 @@ public enum ScopedSupplier {
public <T> Supplier<T> supplier(Supplier<T> supplier) { public <T> Supplier<T> supplier(Supplier<T> supplier) {
return switch (this) { switch (this) {
case singleton -> { case singleton:
T got = supplier.get(); T got = supplier.get();
yield () -> got; return () -> got;
} case thread:
case thread -> {
ThreadLocal<T> tlsupplier = ThreadLocal.withInitial(supplier); ThreadLocal<T> tlsupplier = ThreadLocal.withInitial(supplier);
yield () -> tlsupplier.get(); return tlsupplier::get;
} case caller:
case caller -> supplier; 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.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import io.nosqlbench.nb.api.content.NBIO;
import org.junit.Test; import org.junit.Test;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -14,43 +15,11 @@ public class PMatrixElemTest {
@Test @Test
public void testMatrixElem() { public void testMatrixElem() {
Gson gson = new GsonBuilder().create(); Gson gson = new GsonBuilder().create();
String json = """ String json = NBIO.classpath().name("test.json").one().asString();
{
"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" ]
]
}
]
}
}""";
Type type = new TypeToken<PromQueryResult<PMatrixData>>() { Type type = new TypeToken<PromQueryResult<PMatrixData>>() {
}.getType(); }.getType();
Object result = gson.fromJson(json, type); Object result = gson.fromJson(json, type);
assertThat(result).isOfAnyClassIn(PromQueryResult.class); 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> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<configuration> <configuration>
<debug>true</debug> <debug>true</debug>
<!-- <release>${java.target.version}</release>--> <!-- <release>${java.target.version}</release>-->
<source>15</source> <source>11</source>
<target>15</target> <target>11</target>
<!-- <compilerArgs>--> <!-- <compilerArgs>-->
<!-- &#45;&#45;enable-preview--> <!-- &#45;&#45;enable-preview-->
<!-- </compilerArgs>--> <!-- </compilerArgs>-->
<!--<compilerArgument>-Xdoclint:all</compilerArgument>--> <!--<compilerArgument>-Xdoclint:all</compilerArgument>-->
<!-- <compilerArgument>-Xlint:all</compilerArgument>--> <!-- <compilerArgument>-Xlint:all</compilerArgument>-->
</configuration> </configuration>
</plugin> </plugin>