Search in sources :

Example 16 with Message

use of tech.aroma.thrift.Message in project aroma-data-operations by RedRoma.

the class CassandraMessageRepository method getByTitle.

@Override
public List<Message> getByTitle(String applicationId, String title) throws TException {
    checkAppId(applicationId);
    checkTitle(title);
    Statement query = createQueryToFindMessagesByTitle(title);
    ResultSet results = tryToExecute(query, "Could not get messages by Title: " + title + ", App: " + applicationId);
    List<Message> messages = Lists.create();
    for (Row row : results) {
        Message message = createMessageFromRow(row);
        messages.add(message);
    }
    LOG.debug("Found {} messages by app with ID [{}]", messages.size(), applicationId);
    return messages;
}
Also used : Message(tech.aroma.thrift.Message) Statement(com.datastax.driver.core.Statement) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row)

Example 17 with Message

use of tech.aroma.thrift.Message in project aroma-data-operations by RedRoma.

the class MemoryInboxRepository method saveMessageForUser.

@Override
public void saveMessageForUser(@Required User user, @Required Message message, @Required LengthOfTime lifetime) throws TException {
    checkThat(message).throwing(InvalidArgumentException.class).is(validMessage());
    checkThat(user).throwing(InvalidArgumentException.class).is(validUser());
    String userId = user.userId;
    List<Message> messages = messagesForUser.getOrDefault(userId, Lists.create());
    messages.add(message);
    messagesForUser.put(userId, messages);
}
Also used : InvalidArgumentException(tech.aroma.thrift.exceptions.InvalidArgumentException) RequestAssertions.validMessage(tech.aroma.data.assertions.RequestAssertions.validMessage) Message(tech.aroma.thrift.Message) StringAssertions.nonEmptyString(tech.sirwellington.alchemy.arguments.assertions.StringAssertions.nonEmptyString)

Example 18 with Message

use of tech.aroma.thrift.Message in project aroma-data-operations by RedRoma.

the class CassandraMessageRepositoryIT method testGetMessage.

@Test
public void testGetMessage() throws Exception {
    instance.saveMessage(message, MESSAGE_LIFETIME);
    Message result = instance.getMessage(appId, msgId);
    assertMessagesMostlyMatch(result, message);
}
Also used : Message(tech.aroma.thrift.Message) IntegrationTest(tech.sirwellington.alchemy.annotations.testing.IntegrationTest) Test(org.junit.Test)

Example 19 with Message

use of tech.aroma.thrift.Message in project aroma-data-operations by RedRoma.

the class MemoryMessageRepositoryTest method testGetByTitleWhenApplicationIdDoesNotMatch.

@Test
public void testGetByTitleWhenApplicationIdDoesNotMatch() throws Exception {
    messages.forEach(msg -> msg.setTitle(title));
    saveMessages(messages);
    String otherAppId = one(uuids);
    List<Message> result = instance.getByTitle(otherAppId, title);
    assertThat(result, is(empty()));
}
Also used : Message(tech.aroma.thrift.Message) GenerateString(tech.sirwellington.alchemy.test.junit.runners.GenerateString) Test(org.junit.Test)

Example 20 with Message

use of tech.aroma.thrift.Message in project aroma-data-operations by RedRoma.

the class MemoryMessageRepositoryTest method testSaveMessage.

@Test
public void testSaveMessage() throws Exception {
    instance.saveMessage(message);
    assertThat(instance.containsMessage(applicationId, messageId), is(true));
    assertThrows(() -> instance.saveMessage(null)).isInstanceOf(InvalidArgumentException.class);
    assertThrows(() -> instance.saveMessage(new Message())).isInstanceOf(InvalidArgumentException.class);
}
Also used : Message(tech.aroma.thrift.Message) Test(org.junit.Test)

Aggregations

Message (tech.aroma.thrift.Message)22 Test (org.junit.Test)12 Statement (com.datastax.driver.core.Statement)8 Row (com.datastax.driver.core.Row)7 ResultSet (com.datastax.driver.core.ResultSet)6 RequestAssertions.validMessage (tech.aroma.data.assertions.RequestAssertions.validMessage)5 InvalidArgumentException (tech.aroma.thrift.exceptions.InvalidArgumentException)5 DontRepeat (tech.sirwellington.alchemy.test.junit.runners.DontRepeat)5 TException (org.apache.thrift.TException)3 User (tech.aroma.thrift.User)3 Session (com.datastax.driver.core.Session)2 List (java.util.List)2 Function (java.util.function.Function)2 LengthOfTime (tech.aroma.thrift.LengthOfTime)2 OperationFailedException (tech.aroma.thrift.exceptions.OperationFailedException)2 IntegrationTest (tech.sirwellington.alchemy.annotations.testing.IntegrationTest)2 QueryBuilder (com.datastax.driver.core.querybuilder.QueryBuilder)1 QueryBuilder.desc (com.datastax.driver.core.querybuilder.QueryBuilder.desc)1 QueryBuilder.eq (com.datastax.driver.core.querybuilder.QueryBuilder.eq)1 QueryBuilder.ttl (com.datastax.driver.core.querybuilder.QueryBuilder.ttl)1