Search in sources :

Example 1 with CreateLogStreamResult

use of com.amazonaws.services.logs.model.CreateLogStreamResult in project cloudbreak by hortonworks.

the class CloudwatchRecordWorkerTest method testDescribeLogStreamsWhenLogStreamDoesNotExist.

@Test
public void testDescribeLogStreamsWhenLogStreamDoesNotExist() {
    DescribeLogStreamsRequest describeLogStreamsRequest = new DescribeLogStreamsRequest();
    describeLogStreamsRequest.setLogGroupName("TestGroup");
    describeLogStreamsRequest.setLogStreamNamePrefix(underTest.initLogStream("TestStream"));
    DescribeLogStreamsResult describeLogStreamsResult = new DescribeLogStreamsResult();
    Set<LogStream> logStreams = new HashSet<>();
    describeLogStreamsResult.setLogStreams(logStreams);
    when(awsLogsClient.describeLogStreams(describeLogStreamsRequest)).thenReturn(describeLogStreamsResult);
    when(awsLogsClient.describeLogStreams(describeLogStreamsRequest)).thenReturn(describeLogStreamsResult);
    CreateLogStreamRequest createLogStreamRequest = new CreateLogStreamRequest();
    createLogStreamRequest.setLogGroupName("TestGroup");
    createLogStreamRequest.setLogStreamName(underTest.initLogStream("TestStream"));
    when(awsLogsClient.createLogStream(createLogStreamRequest)).thenReturn(new CreateLogStreamResult());
    underTest.describeLogStreams();
    verify(awsLogsClient, times(2)).describeLogStreams(describeLogStreamsRequest);
    verify(awsLogsClient, times(1)).createLogStream(createLogStreamRequest);
}
Also used : CreateLogStreamRequest(com.amazonaws.services.logs.model.CreateLogStreamRequest) CreateLogStreamResult(com.amazonaws.services.logs.model.CreateLogStreamResult) DescribeLogStreamsRequest(com.amazonaws.services.logs.model.DescribeLogStreamsRequest) LogStream(com.amazonaws.services.logs.model.LogStream) DescribeLogStreamsResult(com.amazonaws.services.logs.model.DescribeLogStreamsResult) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 2 with CreateLogStreamResult

use of com.amazonaws.services.logs.model.CreateLogStreamResult in project cloudwatch-logback-appender by j256.

the class CloudWatchAppenderTest method testMoreAwsCallsMissingGroupAndStream.

@Test(timeout = 10000)
public void testMoreAwsCallsMissingGroupAndStream() throws InterruptedException {
    CloudWatchAppender appender = new CloudWatchAppender();
    AWSLogs logsClient = createMock(AWSLogs.class);
    AmazonEC2 ec2Client = createMock(AmazonEC2.class);
    appender.setTestAwsLogsClient(logsClient);
    appender.setTestAmazonEc2Client(ec2Client);
    appender.setMaxBatchSize(1);
    appender.setRegion("region");
    final String logGroup = "pfqoejpfqe";
    appender.setLogGroup(logGroup);
    final String logStream = "pffqjfqjpoqoejpfqe";
    appender.setLogStream(logStream);
    appender.setContext(LOGGER_CONTEXT);
    PatternLayout layout = new PatternLayout();
    layout.setContext(LOGGER_CONTEXT);
    layout.setPattern("[%thread] %level %logger{20} - %msg%n%xThrowable");
    layout.start();
    appender.setLayout(layout);
    final String loggerName = "name";
    final Level level = Level.DEBUG;
    String message = "kuuyuyuykkkyjtyh";
    LoggingEvent event = createEvent(loggerName, level, message, System.currentTimeMillis());
    String threadName = Thread.currentThread().getName();
    final String fullMessage = "[" + threadName + "] " + level + " " + loggerName + " - " + message + "\n";
    DescribeLogGroupsResult logGroupsResult = new DescribeLogGroupsResult().withLogGroups(Collections.<LogGroup>emptyList());
    expect(logsClient.describeLogGroups(isA(DescribeLogGroupsRequest.class))).andReturn(logGroupsResult);
    CreateLogGroupResult createLogGroupResult = new CreateLogGroupResult();
    expect(logsClient.createLogGroup(isA(CreateLogGroupRequest.class))).andReturn(createLogGroupResult);
    DescribeLogStreamsResult logStreamsResult = new DescribeLogStreamsResult().withLogStreams(Collections.<LogStream>emptyList());
    expect(logsClient.describeLogStreams(isA(DescribeLogStreamsRequest.class))).andReturn(logStreamsResult);
    CreateLogStreamResult createLogStreamResult = new CreateLogStreamResult();
    expect(logsClient.createLogStream(isA(CreateLogStreamRequest.class))).andReturn(createLogStreamResult);
    final PutLogEventsResult putLogEventsResult = new PutLogEventsResult();
    String sequence = "ewopjfewfj";
    putLogEventsResult.setNextSequenceToken(sequence);
    expect(logsClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() {

        @Override
        public PutLogEventsResult answer() {
            PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0];
            assertEquals(logGroup, request.getLogGroupName());
            assertEquals(logStream, request.getLogStreamName());
            List<InputLogEvent> events = request.getLogEvents();
            assertEquals(1, events.size());
            assertEquals(fullMessage, events.get(0).getMessage());
            return putLogEventsResult;
        }
    }).times(2);
    logsClient.shutdown();
    // =====================================
    replay(logsClient, ec2Client);
    appender.start();
    // for coverage
    appender.start();
    appender.append(event);
    Thread.sleep(100);
    appender.append(event);
    while (appender.getEventsWrittenCount() < 2) {
        Thread.sleep(100);
    }
    appender.stop();
    verify(logsClient, ec2Client);
}
Also used : CreateLogGroupResult(com.amazonaws.services.logs.model.CreateLogGroupResult) DescribeLogGroupsResult(com.amazonaws.services.logs.model.DescribeLogGroupsResult) InputLogEvent(com.amazonaws.services.logs.model.InputLogEvent) PatternLayout(ch.qos.logback.classic.PatternLayout) PutLogEventsResult(com.amazonaws.services.logs.model.PutLogEventsResult) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) AWSLogs(com.amazonaws.services.logs.AWSLogs) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) IAnswer(org.easymock.IAnswer) CreateLogGroupRequest(com.amazonaws.services.logs.model.CreateLogGroupRequest) CreateLogStreamRequest(com.amazonaws.services.logs.model.CreateLogStreamRequest) CreateLogStreamResult(com.amazonaws.services.logs.model.CreateLogStreamResult) Level(ch.qos.logback.classic.Level) DescribeLogStreamsRequest(com.amazonaws.services.logs.model.DescribeLogStreamsRequest) DescribeLogGroupsRequest(com.amazonaws.services.logs.model.DescribeLogGroupsRequest) DescribeLogStreamsResult(com.amazonaws.services.logs.model.DescribeLogStreamsResult) PutLogEventsRequest(com.amazonaws.services.logs.model.PutLogEventsRequest) Test(org.junit.Test)

Aggregations

CreateLogStreamRequest (com.amazonaws.services.logs.model.CreateLogStreamRequest)2 CreateLogStreamResult (com.amazonaws.services.logs.model.CreateLogStreamResult)2 DescribeLogStreamsRequest (com.amazonaws.services.logs.model.DescribeLogStreamsRequest)2 DescribeLogStreamsResult (com.amazonaws.services.logs.model.DescribeLogStreamsResult)2 Level (ch.qos.logback.classic.Level)1 PatternLayout (ch.qos.logback.classic.PatternLayout)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)1 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)1 AWSLogs (com.amazonaws.services.logs.AWSLogs)1 CreateLogGroupRequest (com.amazonaws.services.logs.model.CreateLogGroupRequest)1 CreateLogGroupResult (com.amazonaws.services.logs.model.CreateLogGroupResult)1 DescribeLogGroupsRequest (com.amazonaws.services.logs.model.DescribeLogGroupsRequest)1 DescribeLogGroupsResult (com.amazonaws.services.logs.model.DescribeLogGroupsResult)1 InputLogEvent (com.amazonaws.services.logs.model.InputLogEvent)1 LogStream (com.amazonaws.services.logs.model.LogStream)1 PutLogEventsRequest (com.amazonaws.services.logs.model.PutLogEventsRequest)1 PutLogEventsResult (com.amazonaws.services.logs.model.PutLogEventsResult)1 HashSet (java.util.HashSet)1 IAnswer (org.easymock.IAnswer)1