use of io.helidon.dbclient.DbRow in project helidon by oracle.
the class ServerMetricsCheckIT method testHttpMetrics.
/**
* Read and check DB Client metrics from Helidon Web Server.
*
* @throws InterruptedException if the current thread was interrupted
* @throws IOException if an I/O error occurs when sending or receiving HTTP request
*/
@Test
public void testHttpMetrics() throws IOException, InterruptedException {
// Call select-pokemons to trigger it
Multi<DbRow> rows = DB_CLIENT.execute(exec -> exec.namedQuery("select-pokemons"));
List<DbRow> pokemonList = rows.collectList().await();
// Call insert-pokemon to trigger it
Pokemon pokemon = new Pokemon(BASE_ID + 1, "Lickitung", TYPES.get(1));
Long result = DB_CLIENT.execute(exec -> exec.namedInsert("insert-pokemon", pokemon.getId(), pokemon.getName())).await();
// Read and process metrics response
String response = get(URL + "/metrics/application");
LOGGER.info("RESPONSE: " + response);
JsonObject application = null;
try (JsonReader jr = Json.createReader(new StringReader(response))) {
application = jr.readObject();
} catch (JsonParsingException | IllegalStateException ex) {
fail(String.format("Error parsing response: %s", ex.getMessage()));
}
assertThat(application, notNullValue());
assertThat(application.getValueType(), equalTo(JsonValue.ValueType.OBJECT));
assertThat(application.size(), greaterThan(0));
assertThat(application.containsKey("db.counter.select-pokemons"), equalTo(true));
assertThat(application.containsKey("db.counter.insert-pokemon"), equalTo(true));
int selectPokemons = application.getInt("db.counter.select-pokemons");
int insertPokemons = application.getInt("db.counter.insert-pokemon");
assertThat(selectPokemons, equalTo(1));
assertThat(insertPokemons, equalTo(1));
assertThat(application.containsKey("db.timer.insert-pokemon"), equalTo(true));
JsonObject insertTimer = application.getJsonObject("db.timer.insert-pokemon");
assertThat(insertTimer.containsKey("count"), equalTo(true));
assertThat(insertTimer.containsKey("min"), equalTo(true));
assertThat(insertTimer.containsKey("max"), equalTo(true));
int timerCount = insertTimer.getInt("count");
assertThat(timerCount, equalTo(1));
}
use of io.helidon.dbclient.DbRow in project helidon by oracle.
the class InterceptorService method testStatementInterceptor.
// Check that statement interceptor was called before statement execution.
private void testStatementInterceptor(final ServerRequest request, final ServerResponse response) {
LOGGER.fine(() -> "Running Interceptor.testStatementInterceptor on server");
Multi<DbRow> rows = dbClient().execute(exec -> exec.createNamedQuery("select-pokemon-named-arg").addParam("name", Pokemon.POKEMONS.get(6).getName()).execute());
final JsonArrayBuilder jab = Json.createArrayBuilder();
rows.forEach(row -> jab.add(row.as(JsonObject.class))).onComplete(() -> {
if (((TestClientService) interceptor).called()) {
response.send(AppResponse.okStatus(jab.build()));
} else {
response.send(exceptionStatus(new RemoteTestException("Interceptor service was not called")));
}
}).exceptionally(t -> {
response.send(exceptionStatus(t));
return null;
});
}
use of io.helidon.dbclient.DbRow in project helidon by oracle.
the class TransactionQueriesService method executeTest.
// Common test execution code
private void executeTest(final ServerRequest request, final ServerResponse response, final String testName, final TestFunction test) {
LOGGER.fine(() -> String.format("Running SimpleQueryService.%s on server", testName));
try {
String name = param(request, QUERY_NAME_PARAM);
Multi<DbRow> future = test.apply(name);
final JsonArrayBuilder jab = Json.createArrayBuilder();
future.forEach(dbRow -> jab.add(dbRow.as(JsonObject.class))).onComplete(() -> response.send(AppResponse.okStatus(jab.build()))).exceptionally(t -> {
response.send(exceptionStatus(t));
return null;
});
} catch (RemoteTestException ex) {
LOGGER.fine(() -> String.format("Error in SimpleQueryService.%s on server", testName));
response.send(exceptionStatus(ex));
}
}
use of io.helidon.dbclient.DbRow in project helidon by oracle.
the class SimpleQueryService method executeTest.
// Common test execution code
private void executeTest(final ServerRequest request, final ServerResponse response, final String testName, final TestFunction test) {
LOGGER.fine(() -> String.format("Running SimpleQueryService.%s on server", testName));
try {
String name = param(request, QUERY_NAME_PARAM);
Multi<DbRow> future = test.apply(name);
final JsonArrayBuilder jab = Json.createArrayBuilder();
future.forEach(dbRow -> jab.add(dbRow.as(JsonObject.class))).onComplete(() -> response.send(AppResponse.okStatus(jab.build()))).exceptionally(t -> {
response.send(exceptionStatus(t));
return null;
});
} catch (RemoteTestException ex) {
LOGGER.fine(() -> String.format("Error in SimpleQueryService.%s on server", testName));
response.send(exceptionStatus(ex));
}
}
use of io.helidon.dbclient.DbRow in project helidon by oracle.
the class InterceptorIT method testStatementInterceptor.
/**
* Check that statement interceptor was called before statement execution.
*/
@Test
public void testStatementInterceptor() {
TestClientService interceptor = new TestClientService();
DbClient dbClient = initDbClient(interceptor);
Multi<DbRow> rows = dbClient.execute(exec -> exec.createNamedQuery("select-pokemon-named-arg").addParam("name", POKEMONS.get(6).getName()).execute());
assertThat(interceptor.called(), equalTo(true));
}
Aggregations