use of tech.aroma.thrift.Message in project aroma-data-operations by RedRoma.
the class MemoryInboxRepositoryTest method testSaveMessageForUserWithBadArguments.
@DontRepeat
public void testSaveMessageForUserWithBadArguments() throws Exception {
assertThrows(() -> instance.saveMessageForUser(null, message)).isInstanceOf(InvalidArgumentException.class);
assertThrows(() -> instance.saveMessageForUser(user, null)).isInstanceOf(InvalidArgumentException.class);
assertThrows(() -> instance.saveMessageForUser(new User(), message)).isInstanceOf(InvalidArgumentException.class);
assertThrows(() -> instance.saveMessageForUser(user, new Message())).isInstanceOf(InvalidArgumentException.class);
}
use of tech.aroma.thrift.Message in project aroma-data-operations by RedRoma.
the class MemoryMessageRepository method deleteMessage.
@Override
public void deleteMessage(String applicationId, String messageId) throws TException {
checkThat(applicationId, messageId).throwing(InvalidArgumentException.class).are(nonEmptyString());
if (!messages.containsKey(messageId)) {
return;
}
Message message = messages.remove(messageId);
String appId = message.applicationId;
Set<String> appMessages = messagesByApplication.getOrDefault(appId, Sets.create());
appMessages.remove(messageId);
messagesByApplication.put(appId, appMessages);
}
use of tech.aroma.thrift.Message in project aroma-data-operations by RedRoma.
the class MemoryMessageRepository method getMessage.
@Override
public Message getMessage(String applicationId, String messageId) throws TException {
checkThat(applicationId, messageId).throwing(InvalidArgumentException.class).are(nonEmptyString());
checkThat(messageId).throwing(MessageDoesNotExistException.class).is(keyInMap(messages));
Message message = messages.get(messageId);
checkThat(message.applicationId).throwing(MessageDoesNotExistException.class).usingMessage("Message does not correspond to the given App ID").is(equalTo(applicationId));
return message;
}
use of tech.aroma.thrift.Message in project aroma-data-operations by RedRoma.
the class CassandraInboxRepository method getMessagesForUser.
@Override
public List<Message> getMessagesForUser(String userId) throws TException {
checkThat(userId).throwing(InvalidArgumentException.class).is(validUserId());
Statement query = createQueryToGetMessagesFor(userId);
ResultSet results;
try {
results = cassandra.execute(query);
} catch (Exception ex) {
LOG.error("Failed to query for Messages in Inbox for User [{}]", userId, ex);
throw new OperationFailedException("Could not fetch inbox: " + ex.getMessage());
}
checkThat(results).throwing(OperationFailedException.class).usingMessage("Cassandra returned null results").is(notNull());
List<Message> messages = Lists.create();
for (Row row : results) {
Message message = messageMapper.apply(row);
messages.add(message);
}
return messages;
}
use of tech.aroma.thrift.Message in project aroma-data-operations by RedRoma.
the class CassandraInboxRepository method saveMessageForUser.
@Override
public void saveMessageForUser(@Required User user, @Required Message message, @Required LengthOfTime lifetime) throws TException {
checkThat(message).throwing(ex -> new InvalidArgumentException(ex.getMessage())).is(validMessage());
checkThat(user).throwing(ex -> new InvalidArgumentException(ex.getMessage())).is(validUser());
Statement insertStatement = createStatementToSaveMessage(message, user, lifetime);
try {
cassandra.execute(insertStatement);
} catch (Exception ex) {
LOG.error("Failed to save Message in Cassandra Inbox. User [{}] Message [{}]", user.userId, message, ex);
throw new OperationFailedException("Could not save message in Inbox: " + ex.getMessage());
}
}
Aggregations