use of com.datastax.driver.core.Row in project aroma-data-operations by RedRoma.
the class MappersTest method testAuthenticationTokenMapper.
@Test
public void testAuthenticationTokenMapper() throws Exception {
Function<Row, AuthenticationToken> mapper = Mappers.tokenMapper();
assertThat(mapper, notNullValue());
token.unsetOrganizationName();
Row tokenRow = rowFor(token);
AuthenticationToken result = mapper.apply(tokenRow);
assertThat(result, is(token));
}
use of com.datastax.driver.core.Row in project aroma-data-operations by RedRoma.
the class MappersTest method testUserMapper.
@Test
public void testUserMapper() {
Function<Row, User> mapper = Mappers.userMapper();
assertThat(mapper, notNullValue());
Row userRow = rowFor(user);
User result = mapper.apply(userRow);
assertThat(result, notNullValue());
assertThat(result.userId, is(user.userId));
assertThat(result.firstName, is(user.firstName));
assertThat(result.middleName, is(user.middleName));
assertThat(result.lastName, is(user.lastName));
assertThat(result.birthdate, is(user.birthdate));
}
use of com.datastax.driver.core.Row in project ignite by apache.
the class CassandraSessionImpl method execute.
/** {@inheritDoc} */
@Override
public <V> V execute(ExecutionAssistant<V> assistant) {
int attempt = 0;
Throwable error = null;
String errorMsg = "Failed to execute Cassandra CQL statement: " + assistant.getStatement();
RandomSleeper sleeper = newSleeper();
incrementSessionRefs();
try {
while (attempt < CQL_EXECUTION_ATTEMPTS_COUNT) {
error = null;
if (attempt != 0) {
log.warning("Trying " + (attempt + 1) + " attempt to execute Cassandra CQL statement: " + assistant.getStatement());
}
try {
PreparedStatement preparedSt = prepareStatement(assistant.getTable(), assistant.getStatement(), assistant.getPersistenceSettings(), assistant.tableExistenceRequired());
if (preparedSt == null)
return null;
Statement statement = tuneStatementExecutionOptions(assistant.bindStatement(preparedSt));
ResultSet res = session().execute(statement);
Row row = res == null || !res.iterator().hasNext() ? null : res.iterator().next();
return row == null ? null : assistant.process(row);
} catch (Throwable e) {
error = e;
if (CassandraHelper.isTableAbsenceError(e)) {
if (!assistant.tableExistenceRequired()) {
log.warning(errorMsg, e);
return null;
}
handleTableAbsenceError(assistant.getTable(), assistant.getPersistenceSettings());
} else if (CassandraHelper.isHostsAvailabilityError(e))
handleHostsAvailabilityError(e, attempt, errorMsg);
else if (CassandraHelper.isPreparedStatementClusterError(e))
handlePreparedStatementClusterError(e);
else
// For an error which we don't know how to handle, we will not try next attempts and terminate.
throw new IgniteException(errorMsg, e);
}
if (!CassandraHelper.isTableAbsenceError(error))
sleeper.sleep();
attempt++;
}
} catch (Throwable e) {
error = e;
} finally {
decrementSessionRefs();
}
log.error(errorMsg, error);
throw new IgniteException(errorMsg, error);
}
use of com.datastax.driver.core.Row in project logging-log4j2 by apache.
the class CassandraAppenderIT method appendManyEvents.
@Test
public void appendManyEvents() throws Exception {
final Logger logger = CTX.getLogger();
ThreadContext.put("test", "mdc");
ThreadContext.push("ndc");
for (int i = 0; i < 20; i++) {
logger.info(MarkerManager.getMarker("MARKER"), "Test log message");
}
ThreadContext.clearAll();
TimeUnit.SECONDS.sleep(3);
int i = 0;
try (final Session session = CASSANDRA.connect()) {
for (final Row row : session.execute("SELECT * FROM logs")) {
assertNotNull(row.get("id", UUID.class));
assertNotNull(row.get("timeid", UUID.class));
assertNotNull(row.get("timestamp", Date.class));
assertEquals("Test log message", row.getString("message"));
assertEquals("MARKER", row.getString("marker"));
assertEquals("INFO", row.getString("level"));
assertEquals(getClass().getName(), row.getString("logger"));
final Map<String, String> mdc = row.getMap("mdc", String.class, String.class);
assertEquals(1, mdc.size());
assertEquals("mdc", mdc.get("test"));
final List<String> ndc = row.getList("ndc", String.class);
assertEquals(1, ndc.size());
assertEquals("ndc", ndc.get(0));
++i;
}
}
assertEquals(20, i);
}
Aggregations