use of io.helidon.tests.integration.dbclient.common.AbstractIT.Pokemon in project helidon by oracle.
the class Utils method verifyPokemonsIdRange.
/**
* Verify that {@code Multi<DbRow> rows} argument contains pokemons matching specified IDs range.
* @param rows database query result to verify
* @param idMin beginning of ID range
* @param idMax end of ID range
*/
public static void verifyPokemonsIdRange(Multi<DbRow> rows, int idMin, int idMax) {
assertThat(rows, notNullValue());
List<DbRow> rowsList = rows.collectList().await();
// Build Map of valid pokemons
Map<Integer, Pokemon> valid = new HashMap<>(POKEMONS.size());
for (Map.Entry<Integer, Pokemon> entry : POKEMONS.entrySet()) {
int id = entry.getKey();
Pokemon pokemon = entry.getValue();
if (id > idMin && id < idMax) {
valid.put(id, pokemon);
}
}
// assertThat(rowsList, hasSize(valid.size()));
for (DbRow row : rowsList) {
Integer id = row.column(1).as(Integer.class);
String name = row.column(2).as(String.class);
LOGGER.info(() -> String.format("Pokemon id=%d, name=%s", id, name));
assertThat(valid.containsKey(id), equalTo(true));
assertThat(name, equalTo(valid.get(id).getName()));
}
}
use of io.helidon.tests.integration.dbclient.common.AbstractIT.Pokemon 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.tests.integration.dbclient.common.AbstractIT.Pokemon in project helidon by oracle.
the class Utils method verifyUpdatePokemon.
/**
* Verify that provided pokemon was successfully updated in the database.
*
* @param result DML statement result
* @param pokemon pokemon to compare with
*/
public static void verifyUpdatePokemon(Long result, AbstractIT.Pokemon pokemon) {
assertThat(result, equalTo(1L));
Optional<DbRow> maybeRow = DB_CLIENT.execute(exec -> exec.namedGet("select-pokemon-by-id", pokemon.getId())).await();
assertThat(maybeRow.isPresent(), equalTo(true));
DbRow row = maybeRow.get();
Integer id = row.column(1).as(Integer.class);
String name = row.column(2).as(String.class);
assertThat(id, equalTo(pokemon.getId()));
assertThat(name, pokemon.getName().equals(name));
}
use of io.helidon.tests.integration.dbclient.common.AbstractIT.Pokemon in project helidon by oracle.
the class Utils method verifyInsertPokemon.
/**
* Verify that provided pokemon was successfully inserted into the database.
*
* @param result DML statement result
* @param pokemon pokemon to compare with
*/
public static void verifyInsertPokemon(Long result, AbstractIT.Pokemon pokemon) {
assertThat(result, equalTo(1L));
Optional<DbRow> maybeRow = DB_CLIENT.execute(exec -> exec.namedGet("select-pokemon-by-id", pokemon.getId())).await();
assertThat(maybeRow.isPresent(), equalTo(true));
DbRow row = maybeRow.get();
Integer id = row.column("id").as(Integer.class);
String name = row.column("name").as(String.class);
assertThat(id, equalTo(pokemon.getId()));
assertThat(name, pokemon.getName().equals(name));
}
use of io.helidon.tests.integration.dbclient.common.AbstractIT.Pokemon in project helidon by oracle.
the class Utils method verifyPokemonsIdRange.
/**
* Verify that {@code Multi<DbRow> rows} argument contains single pokemon matching specified IDs range.
* @param maybeRow database query result to verify
* @param idMin beginning of ID range
* @param idMax end of ID range
*/
public static void verifyPokemonsIdRange(Optional<DbRow> maybeRow, int idMin, int idMax) {
assertThat(maybeRow.isPresent(), equalTo(true));
DbRow row = maybeRow.get();
// Build Map of valid pokemons
Map<Integer, Pokemon> valid = new HashMap<>(POKEMONS.size());
for (Map.Entry<Integer, Pokemon> entry : POKEMONS.entrySet()) {
int id = entry.getKey();
Pokemon pokemon = entry.getValue();
if (id > idMin && id < idMax) {
valid.put(id, pokemon);
}
}
Integer id = row.column(1).as(Integer.class);
String name = row.column(2).as(String.class);
assertThat(valid.containsKey(id), equalTo(true));
assertThat(name, equalTo(valid.get(id).getName()));
}
Aggregations