Search in sources :

Example 11 with Message

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

the class CassandraMessageRepository method getByApplication.

@Override
public List<Message> getByApplication(String applicationId) throws TException {
    checkAppId(applicationId);
    Statement query = createQueryToFindMessagesByApplication(applicationId);
    ResultSet results = tryToExecute(query, "Could not query for messages by 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 12 with Message

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

the class CassandraMessageRepository method getByHostname.

@Override
public List<Message> getByHostname(String hostname) throws TException {
    checkThat(hostname).usingMessage("missing hostname").throwing(InvalidArgumentException.class).is(nonEmptyString()).is(stringWithLengthGreaterThanOrEqualTo(1));
    Statement query = createQueryToFindMessageByHostname(hostname);
    ResultSet results = tryToExecute(query, "Could not query for mesages by hostname: " + hostname);
    List<Message> messages = Lists.create();
    for (Row row : results) {
        Message message = createMessageFromRow(row);
        messages.add(message);
    }
    LOG.debug("Found {} messages by hostname {}", messages.size(), hostname);
    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 13 with Message

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

the class CassandraMessageRepository method getMessage.

@Override
public Message getMessage(String applicationId, String messageId) throws TException {
    checkMessageId(messageId);
    checkAppId(applicationId);
    Statement query = createQueryForMessageWithId(applicationId, messageId);
    LOG.debug("Querying cassandra for message with ID [{}] and App [{}]", messageId, applicationId);
    ResultSet results = tryToExecute(query, "Failed to query for message with ID: " + messageId);
    Row row = results.one();
    checkThat(row).throwing(MessageDoesNotExistException.class).usingMessage(format("No Message with App ID [%s] and Msg ID [%s]", applicationId, messageId)).is(notNull());
    Message message = createMessageFromRow(row);
    return message;
}
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 14 with Message

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

the class CassandraInboxRepositoryIT method testGetMessagesForUser.

@Test
public void testGetMessagesForUser() throws Exception {
    saveMessagesInInbox(messages);
    List<Message> result = instance.getMessagesForUser(userId);
    assertThat(result.size(), is(messages.size()));
    for (Message m : result) {
        assertThat(messageMapping.containsKey(m.messageId), is(true));
        Message expected = messageMapping.get(m.messageId);
        assertMostlySame(m, expected);
    }
}
Also used : Message(tech.aroma.thrift.Message) IntegrationTest(tech.sirwellington.alchemy.annotations.testing.IntegrationTest) Test(org.junit.Test)

Example 15 with Message

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

the class RequestAssertionsTest method testValidMessageWithBadMessages.

@DontRepeat
@Test
public void testValidMessageWithBadMessages() {
    AlchemyAssertion<Message> assertion = RequestAssertions.validMessage();
    assertThrows(() -> assertion.check(null)).isInstanceOf(FailedAssertionException.class);
    Message emptyMessage = new Message();
    assertThrows(() -> assertion.check(emptyMessage)).isInstanceOf(FailedAssertionException.class);
    Message messageWithoutTitle = emptyMessage.setMessageId(one(uuids));
    assertThrows(() -> assertion.check(messageWithoutTitle)).isInstanceOf(FailedAssertionException.class);
    Message messageWithInvalidId = new Message(message).setMessageId(invalidId);
    assertThrows(() -> assertion.check(messageWithInvalidId)).isInstanceOf(FailedAssertionException.class);
    Message messageWithInvalidAppId = new Message(message).setApplicationId(invalidId);
    assertThrows(() -> assertion.check(messageWithInvalidAppId)).isInstanceOf(FailedAssertionException.class);
}
Also used : Message(tech.aroma.thrift.Message) Test(org.junit.Test) DontRepeat(tech.sirwellington.alchemy.test.junit.runners.DontRepeat)

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